diff --git a/example/QCefViewTest/MainWindow.cpp b/example/QCefViewTest/MainWindow.cpp index fad86d5..ae253ac 100644 --- a/example/QCefViewTest/MainWindow.cpp +++ b/example/QCefViewTest/MainWindow.cpp @@ -98,18 +98,24 @@ MainWindow::createRightCefView() #endif setting.setWindowlessFrameRate(240); setting.setHardwareAcceleration(true); - // setting.setBackgroundColor(Qt::cyan); - // setting.setBackgroundColor(QColor::fromRgba(qRgba(255, 255, 220, 255))); + QColor background(18, 18, 20, 255); + setting.setBackgroundColor(background); // create the QCefView widget and add it to the layout container // m_pRightCefViewWidget = new QCefView(RIGHT_INDEX_URL, &setting, this); m_pRightCefViewWidget = new QCefView("https://www.testufo.com/", &setting, this); - auto vl = new QVBoxLayout(m_pRightCefViewWidget); - auto btn = new QPushButton("TEST BUTTON OVERLAY", m_pRightCefViewWidget); - vl->setAlignment(Qt::AlignTop); - vl->addWidget(btn); - m_pRightCefViewWidget->setLayout(vl); + // auto vl = new QVBoxLayout(m_pRightCefViewWidget); + // auto btn = new QPushButton("TEST BUTTON OVERLAY", m_pRightCefViewWidget); + //// btn->setFixedSize(320, 240); + // btn->setStyleSheet("background-color: rgba(1, 1, 1, 0);"); + // btn->setAttribute(Qt::WA_TranslucentBackground); + // btn->setWindowFlags(Qt::FramelessWindowHint); + // btn->setAttribute(Qt::WA_NoSystemBackground); + // vl->setAlignment(Qt::AlignVCenter); + + // vl->addWidget(btn); + // m_pRightCefViewWidget->setLayout(vl); // all the following values will disable the context menu for both NCW and OSR mode // m_pRightCefViewWidget->setContextMenuPolicy(Qt::NoContextMenu); diff --git a/example/QCefViewTest/MainWindow.ui b/example/QCefViewTest/MainWindow.ui index 35fc76b..8aefc20 100644 --- a/example/QCefViewTest/MainWindow.ui +++ b/example/QCefViewTest/MainWindow.ui @@ -181,7 +181,9 @@ - background-color: rgb(217, 183, 255) + QWidget#leftCefViewContainer { + background-color: rgb(217, 183, 255); +} @@ -203,7 +205,9 @@ - background-color: rgb(217, 183, 255) + QWidget#rightCefViewContainer { + background-color: rgb(217, 183, 255); +} diff --git a/src/details/QCefViewPrivate.cpp b/src/details/QCefViewPrivate.cpp index 1f7d819..b4222ad 100644 --- a/src/details/QCefViewPrivate.cpp +++ b/src/details/QCefViewPrivate.cpp @@ -76,8 +76,18 @@ QCefViewPrivate::createCefBrowser(QCefView* view, const QString& url, const QCef if (isOSRModeEnabled_) { auto winSize = q_ptr->size(); auto winBgColor = browserSettings.background_color; - std::shared_ptr renderer; + // set QWidget background + QPalette palette = q_ptr->palette(); + palette.setColor(q_ptr->backgroundRole(), // + QColor(CefColorGetR(winBgColor), // + CefColorGetG(winBgColor), // + CefColorGetB(winBgColor), // + CefColorGetA(winBgColor)) // + ); + q_ptr->setPalette(palette); + + std::shared_ptr renderer; #if defined(OS_WINDOWS) // if hardware is enabled if (setting && setting->hardwareAcceleration_) { diff --git a/src/win/details/render/hardware/DX11RenderBackend.cpp b/src/win/details/render/hardware/DX11RenderBackend.cpp index a37f4bd..44b19bf 100644 --- a/src/win/details/render/hardware/DX11RenderBackend.cpp +++ b/src/win/details/render/hardware/DX11RenderBackend.cpp @@ -61,12 +61,11 @@ float4 main(VS_OUTPUT input) : SV_Target bool DX11RenderBackend::CreateDeviceAndSwapchain() { - // we don't render directly to the window, but we // use the DirectComposition to render the CefView - // Create D3D11 device and context ComPtr pD3dDevice; ComPtr pD3dContext; +#if _WIN32_WINNT >= 0x602 HR_CHECK(S_OK == ::D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, @@ -135,6 +134,40 @@ DX11RenderBackend::CreateDeviceAndSwapchain() // Save m_dcompositionTarget = pDCompositionTarget; m_dcompositionDevice = pDecompositionDevice; +#else + // create device and swapchain + DXGI_SWAP_CHAIN_DESC sd = {}; + sd.BufferCount = 1; + sd.BufferDesc.Width = m_width; + sd.BufferDesc.Height = m_height; + sd.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; + sd.BufferDesc.RefreshRate.Numerator = 60; + sd.BufferDesc.RefreshRate.Denominator = 1; + + sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; + sd.OutputWindow = m_hWnd; + sd.SampleDesc.Count = 1; + sd.SampleDesc.Quality = 0; + sd.Windowed = TRUE; + + ComPtr pSwapChain; + HRESULT hr = ::D3D11CreateDeviceAndSwapChain(nullptr, + D3D_DRIVER_TYPE_HARDWARE, + nullptr, + 0, + nullptr, + 0, + D3D11_SDK_VERSION, + &sd, + pSwapChain.ReleaseAndGetAddressOf(), + pD3dDevice.ReleaseAndGetAddressOf(), + nullptr, + pD3dContext.ReleaseAndGetAddressOf()); + if (FAILED(hr)) { + return false; + } +#endif + m_swapChain = pSwapChain; m_d3dContext = pD3dContext; m_d3dDevice = pD3dDevice; @@ -413,7 +446,7 @@ DX11RenderBackend::UpdateTextureResource(Microsoft::WRL::ComPtr // need to recreate? bool needRecreate = false; - if (needRecreate // + if (!pTargetTexture // || sharedTextureDesc.Width != targetTextureDesc.Width // || sharedTextureDesc.Height != targetTextureDesc.Height // || sharedTextureDesc.Format != targetTextureDesc.Format // @@ -469,10 +502,10 @@ DX11RenderBackend::ClearTargetView() { // clear the back buffer (RGBA) float clearColor[4] = { - static_cast(CefColorGetR(m_backgroundColor)), - static_cast(CefColorGetG(m_backgroundColor)), - static_cast(CefColorGetB(m_backgroundColor)), - static_cast(CefColorGetA(m_backgroundColor)), + static_cast(CefColorGetR(m_backgroundColor) / 255.f), + static_cast(CefColorGetG(m_backgroundColor) / 255.f), + static_cast(CefColorGetB(m_backgroundColor) / 255.f), + static_cast(CefColorGetA(m_backgroundColor) / 255.f), }; m_d3dContext->ClearRenderTargetView(m_renderTargetView.Get(), clearColor); } @@ -495,7 +528,7 @@ DX11RenderBackend::DrawCefView() void DX11RenderBackend::DrawCefPopup() { - if (!m_showPopup) { + if (!m_showPopup || !m_popupSRV) { return; } @@ -580,6 +613,11 @@ DX11RenderBackend::initialize(void* wid, int width, int height, float scale, con void DX11RenderBackend::uninitialize() { +#if _WIN32_WINNT >= 0x602 + m_dcompositionDevice.Reset(); + m_dcompositionTarget.Reset(); +#endif + // Release resources m_inputLayout.Reset(); m_vertexShader.Reset(); @@ -654,6 +692,11 @@ void DX11RenderBackend::updatePopupVisibility(bool visible) { m_showPopup = visible; + + if (!m_showPopup) { + m_popupTexture.Reset(); + m_popupSRV.Reset(); + } } void diff --git a/src/win/details/render/hardware/DX11RenderBackend.h b/src/win/details/render/hardware/DX11RenderBackend.h index e99214e..1bc66e7 100644 --- a/src/win/details/render/hardware/DX11RenderBackend.h +++ b/src/win/details/render/hardware/DX11RenderBackend.h @@ -6,11 +6,14 @@ #include #include #include -#include #include #include #include +#if _WIN32_WINNT >= 0x602 +#include +#endif + #include #include "details/render/ICefViewRenderer.h" @@ -33,12 +36,18 @@ class DX11RenderBackend : public ICefViewRenderer // lock std::mutex m_d3dContextLock; - // device/context/swapchain + // device/context Microsoft::WRL::ComPtr m_d3dDevice; Microsoft::WRL::ComPtr m_d3dContext; + + // only works for windows 8 +#if _WIN32_WINNT >= 0x602 + Microsoft::WRL::ComPtr m_swapChain; Microsoft::WRL::ComPtr m_dcompositionDevice; Microsoft::WRL::ComPtr m_dcompositionTarget; - Microsoft::WRL::ComPtr m_swapChain; +#else + Microsoft::WRL::ComPtr m_swapChain; +#endif // IA stage Microsoft::WRL::ComPtr m_inputLayout;