modify gl translate

This commit is contained in:
brige 2024-12-19 10:57:42 +08:00
parent e12567aded
commit c6d0254f1b
6 changed files with 245 additions and 30 deletions

View File

@ -133,7 +133,7 @@ HumanAppContextImpl::HumanAppContextImpl(CefRefPtr<CefCommandLine> command_line,
if (background_color_ == 0 && !use_views_) {
// Set an explicit background color.
background_color_ = CefColorSetARGB(0, 255, 255, 255);
background_color_ = CefColorSetARGB(0, 0, 0, 0);
}
// |browser_background_color_| should remain 0 to enable transparent painting.
@ -221,7 +221,7 @@ void HumanAppContextImpl::PopulateOsrSettings(OsrRendererSettings* settings) {
#if defined(OS_WIN)
settings->render_type = shared_texture_enabled_ ?
OsrRendererSettings::OsrRendererType::D3D11 : OsrRendererSettings::OsrRendererType::Navtive;
OsrRendererSettings::OsrRendererType::D3D11 : OsrRendererSettings::OsrRendererType::OpenGL;
#endif
settings->external_begin_frame_enabled = external_begin_frame_enabled_;
settings->begin_frame_rate = windowless_frame_rate_;

View File

@ -1,4 +1,4 @@
#if 1
#include <Windows.h>
#include "HumanAppContextImpl.h"
@ -125,4 +125,214 @@ static int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevI
return result;
}
#else
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <windowsx.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <dwmapi.h>
#pragma comment (lib, "opengl32.lib")
#pragma comment (lib, "glu32.lib")
#pragma comment (lib, "dwmapi.lib")
#include <assert.h>
#include <tchar.h>
#ifdef assert
#define verify(expr) if(!expr) assert(0)
#else verify(expr) expr
#endif
const TCHAR szAppName[]=_T("TransparentGL");
const TCHAR wcWndName[]=_T("TransparentGL");
HDC hDC;
HGLRC m_hrc;
int w = 240;
int h = 240;
BOOL initSC() {
glEnable(GL_ALPHA_TEST);
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glClearColor(0, 0, 0, 0);
return 0;
}
void resizeSC(int width,int height) {
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW );
glLoadIdentity();
}
BOOL renderSC() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix();
glColor3f(0, 1, 1);
glBegin(GL_TRIANGLES); // Drawing Using Triangles
glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red
glVertex3f( 0.0f, 1.0f, 0.0f); // Top
glColor3f(0.0f,1.0f,0.0f); // Set The Color To Green
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glColor3f(0.0f,0.0f,1.0f); // Set The Color To Blue
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glEnd();
glPopMatrix();
glFlush();
return 0;
}
BOOL CreateHGLRC(HWND hWnd) {
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1, // Version Number
PFD_DRAW_TO_WINDOW | // Format Must Support Window
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
PFD_SUPPORT_COMPOSITION | // Format Must Support Composition
PFD_DOUBLEBUFFER, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
32, // Select Our Color Depth
0, 0, 0, 0, 0, 0, // Color Bits Ignored
8, // An Alpha Buffer
0, // Shift Bit Ignored
0, // No Accumulation Buffer
0, 0, 0, 0, // Accumulation Bits Ignored
24, // 16Bit Z-Buffer (Depth Buffer)
8, // Some Stencil Buffer
0, // No Auxiliary Buffer
PFD_MAIN_PLANE, // Main Drawing Layer
0, // Reserved
0, 0, 0 // Layer Masks Ignored
};
HDC hdc = GetDC(hWnd);
int PixelFormat = ChoosePixelFormat(hdc, &pfd);
if (PixelFormat == 0) {
assert(0);
return FALSE ;
}
BOOL bResult = SetPixelFormat(hdc, PixelFormat, &pfd);
if (bResult==FALSE) {
assert(0);
return FALSE ;
}
m_hrc = wglCreateContext(hdc);
if (!m_hrc){
assert(0);
return FALSE;
}
ReleaseDC(hWnd, hdc);
return TRUE;
}
LRESULT CALLBACK WindowFunc(HWND hWnd,UINT msg, WPARAM wParam, LPARAM lParam) {
PAINTSTRUCT ps;
switch(msg) {
case WM_CREATE:
break;
case WM_DESTROY:
if(m_hrc) {
wglMakeCurrent(NULL, NULL);
wglDeleteContext(m_hrc) ;
}
PostQuitMessage(0) ;
break;
default:
return DefWindowProc(hWnd,msg,wParam,lParam);
}
return 0;
}
static int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine, _In_ int nCmdShow) {
WNDCLASSEX wc;
memset(&wc, 0, sizeof(wc));
wc.cbSize = sizeof(WNDCLASSEX);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WindowFunc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)CreateSolidBrush(0x00000000);
wc.lpszClassName = szAppName;
if(!RegisterClassEx(&wc)) {
MessageBox(NULL, _T("RegisterClassEx - failed"), _T("Error"), MB_OK | MB_ICONERROR);
return FALSE;
}
HWND hWnd = CreateWindowEx(WS_EX_APPWINDOW, szAppName, wcWndName,
WS_VISIBLE | WS_POPUP, 200, 150, w, h,
NULL, NULL, hInstance, NULL);
if(!hWnd) {
MessageBox(NULL, _T("CreateWindowEx - failed"), _T("Error"), MB_OK | MB_ICONERROR);
return FALSE;
}
DWM_BLURBEHIND bb = {0};
HRGN hRgn = CreateRectRgn(0, 0, -1, -1);
bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION;
bb.hRgnBlur = hRgn;
bb.fEnable = TRUE;
DwmEnableBlurBehindWindow(hWnd, &bb);
CreateHGLRC(hWnd);
HDC hdc = GetDC(hWnd);
wglMakeCurrent(hdc, m_hrc);
initSC();
resizeSC(w, h);
ReleaseDC(hWnd, hdc);
MSG msg;
while(1) {
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else {
HDC hdc = GetDC(hWnd);
wglMakeCurrent(hdc, m_hrc);
renderSC();
SwapBuffers(hdc);
ReleaseDC(hWnd, hdc);
}
}
return (FALSE);
}
#endif

View File

@ -8,7 +8,7 @@
#include "include/wrapper/cef_closure_task.h"
#include "include/wrapper/cef_helpers.h"
#include "CEF/UtilWin.h"
// #include "stb/stb_image_write.h"
// Helper that calls wglMakeCurrent.
class ScopedGLContext {
@ -33,7 +33,6 @@ class ScopedGLContext {
const bool swap_buffers_;
};
OsrRenderHandlerWinGL::OsrRenderHandlerWinGL(
const OsrRendererSettings& settings,
HWND hwnd)
@ -109,7 +108,7 @@ void OsrRenderHandlerWinGL::OnPaint(
int width,
int height) {
CEF_REQUIRE_UI_THREAD();
// stbi_write_png("d:/3.png", width, height, 4, buffer, width * 4);
if (painting_popup_) {
renderer_.OnPaint(browser, type, dirtyRects, buffer, width, height);
return;
@ -157,10 +156,11 @@ void OsrRenderHandlerWinGL::EnableGL() {
ZeroMemory(&pfd, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_SUPPORT_COMPOSITION | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.cColorBits = 32;
pfd.cDepthBits = 24;
pfd.cAlphaBits = 8;
pfd.iLayerType = PFD_MAIN_PLANE;
format = ChoosePixelFormat(hdc_, &pfd);
SetPixelFormat(hdc_, format, &pfd);
@ -193,4 +193,3 @@ void OsrRenderHandlerWinGL::DisableGL() {
hdc_ = nullptr;
hrc_ = nullptr;
}

View File

@ -9,8 +9,6 @@
#include "include/wrapper/cef_helpers.h"
#include "CEF/UtilWin.h"
#include "stb/stb_image_write.h"
OsrRenderHandlerWinNative::OsrRenderHandlerWinNative(
const OsrRendererSettings& settings,
HWND hwnd)
@ -110,17 +108,18 @@ void OsrRenderHandlerWinNative::OnPaint(
DWORD *pvBits = nullptr;
HBITMAP hBitmap = CreateDIBSection(hDc, &bmi, DIB_RGB_COLORS, reinterpret_cast<void**>(&pvBits), NULL, 0);
const int iTotal = width * height * 4;
for (int i = 0; i != height; ++i)
{
for (int j = 0; j != width; ++j)
{
pvBits[i * width + j] = reinterpret_cast<const DWORD*>(buffer)[(height - i - 1) * width + j];
byte *pByte = (byte*)&pvBits[i * width + j];
pByte[0] = pByte[0] * pByte[3] / 255;
pByte[1] = pByte[1] * pByte[3] / 255;
pByte[2] = pByte[2] * pByte[3] / 255;
}
}
// for (int i = 0; i != height; ++i)
// {
// for (int j = 0; j != width; ++j)
// {
// pvBits[i * width + j] = reinterpret_cast<const DWORD*>(buffer)[(height - i - 1) * width + j];
// byte *pByte = (byte*)&pvBits[i * width + j];
// pByte[0] = pByte[0] * pByte[3] / 255;
// pByte[1] = pByte[1] * pByte[3] / 255;
// pByte[2] = pByte[2] * pByte[3] / 255;
// }
// }
memcpy(pvBits, buffer, iTotal);
GdiFlush();
SelectObject(hMemDC, hBitmap);
@ -129,7 +128,7 @@ void OsrRenderHandlerWinNative::OnPaint(
ptSrc.x = 0;
ptSrc.y = 0;
POINT ptDst = ptSrc;
ClientToScreen(hwnd(), &ptDst);
// ClientToScreen(hwnd(), &ptDst);
SIZE szSrc;
szSrc.cx = width;
szSrc.cy = height;

View File

@ -111,6 +111,8 @@ void OsrRenderer::Render() {
{0.0f, 0.0f, -1.0f, 1.0f, 0.0f}};
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// glClearColor(0.0f,0.0f,0.0f,0.0f);
VERIFY_NO_ERROR;
glMatrixMode(GL_MODELVIEW);
@ -131,10 +133,10 @@ void OsrRenderer::Render() {
VERIFY_NO_ERROR;
// Don't check for errors until glEnd().
glBegin(GL_QUADS);
glColor4f(1.0, 0.0, 0.0, 1.0); // red
glColor4f(0.0, 0.0, 0.0, 0.0); // red
glVertex2f(-1.0, -1.0);
glVertex2f(1.0, -1.0);
glColor4f(0.0, 0.0, 1.0, 1.0); // blue
glColor4f(0.0, 0.0, 0.0, 0.0); // blue
glVertex2f(1.0, 1.0);
glVertex2f(-1.0, 1.0);
glEnd();

View File

@ -5,6 +5,8 @@
#include "CEF/RootWindowWin.h"
#include <shellscalingapi.h>
#include <dwmapi.h>
#pragma comment (lib, "dwmapi.lib")
#include "include/base/cef_build.h"
#include "include/base/cef_callback.h"
@ -369,10 +371,13 @@ void RootWindowWin::CreateRootWindow(const CefBrowserSettings& settings,
x, y, width, height, nullptr, nullptr, hInstance, this);
CHECK(hwnd_);
// SetWindowLong(hwnd_,GWL_STYLE,WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_SYSMENU);
SetWindowLong(hwnd_, GWL_EXSTYLE,
GetWindowLong(hwnd_, GWL_EXSTYLE) | WS_EX_LAYERED );
// SetLayeredWindowAttributes(hwnd_, RGB(255, 0, 0), 0, LWA_COLORKEY);
DWM_BLURBEHIND bb = {0};
HRGN rgn = CreateRectRgn(0, 0, -1, -1);
bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION;
bb.hRgnBlur = rgn;
bb.fEnable = TRUE;
DwmEnableBlurBehindWindow(hwnd_, &bb);
if (!called_enable_non_client_dpi_scaling_ && IsProcessPerMonitorDpiAware()) {
// This call gets Windows to scale the non-client area when WM_DPICHANGED