EDIT: Nervermind, the release build works perfectly. I was just confused by the cefclient which caused such high CPU loads. Thanks once more for your great support!Which process is maxing out the core?
The process that calls the message loop.
I attached a debugger an paused the test application to get a stack trace:
You can also add your own code
A piece of hacky code:
- Code: Select all
#include <Windows.h>
#include <iostream>
#include <d3d9.h>
#include <D3dx9tex.h>
#include "include/cef_app.h"
#include "include/cef_client.h"
#include "include/cef_render_handler.h"
LPDIRECT3DTEXTURE9 pTexture = NULL;
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if (message == WM_DESTROY)
{
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
unsigned int lastTick = 0;
class Client : public CefClient, public CefRenderHandler
{
public:
virtual CefRefPtr<CefRenderHandler> GetRenderHandler() override
{
return this;
}
virtual bool GetViewRect(CefRefPtr<CefBrowser> browser, CefRect& rect) override
{
rect.x = 0;
rect.y = 0;
rect.width = 700;
rect.height = 450;
return true;
}
virtual void OnPaint(CefRefPtr<CefBrowser> browser, CefRenderHandler::PaintElementType paintType, const CefRenderHandler::RectList& dirtyRects, const void* buffer, int width, int height) override
{
D3DLOCKED_RECT LockedRect;
D3DSURFACE_DESC SurfaceDesc;
IDirect3DSurface9* pSurface;
pTexture->GetSurfaceLevel(0, &pSurface);
pSurface->GetDesc(&SurfaceDesc);
pSurface->LockRect(&LockedRect, NULL, 0);
memcpy(LockedRect.pBits, buffer, width * height * 4);
pSurface->UnlockRect();
unsigned int diffTime = GetTickCount() - lastTick;
lastTick = GetTickCount();
}
IMPLEMENT_REFCOUNTING(Client);
};
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
ZeroMemory(&wc, sizeof(WNDCLASSEX));
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszClassName = "WindowClass";
RegisterClassEx(&wc);
HWND hWnd = CreateWindowEx(NULL, "WindowClass", "Tests", WS_OVERLAPPEDWINDOW, 300, 300, 800, 600, NULL, NULL, hInstance, NULL);
ShowWindow(hWnd, nCmdShow);
LPDIRECT3D9 d3d = Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hWnd;
LPDIRECT3DDEVICE9 d3ddev;
d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);
LPD3DXSPRITE pSprite;
D3DXCreateTexture(d3ddev, 700, 450, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &pTexture);
D3DXCreateSprite(d3ddev, &pSprite);
CefMainArgs args;
CefSettings settings;
Client client;
settings.no_sandbox = true;
CefExecuteProcess(args, NULL, NULL);
CefInitialize(args, settings, NULL, NULL);
CefBrowserSettings browserSettings;
CefWindowInfo windowInfo;
windowInfo.SetAsOffScreen(nullptr);
CefRefPtr<CefBrowser> pBrowser = CefBrowserHost::CreateBrowserSync(windowInfo, &client, "http://nyan.cat", browserSettings, NULL);
MSG msg;
for (;;)
{
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if (msg.message == WM_QUIT)
break;
// Update CEF
CefDoMessageLoopWork();
// Render and display the frame
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0);
d3ddev->BeginScene();
pSprite->Begin(D3DXSPRITE_ALPHABLEND);
D3DXVECTOR3 vPosition(50.0f, 50.0f, 0.0f);
D3DCOLOR Color = 0xFFFFFFFF;
HRESULT hr = pSprite->Draw(pTexture, NULL, NULL, &vPosition, Color);
pSprite->End();
d3ddev->EndScene();
d3ddev->Present(NULL, NULL, NULL, NULL);
// Wait a short moment
Sleep(100);
}
CefShutdown();
d3ddev->Release();
d3d->Release();
return true;
}
"diffTime" was always around 100ms for me.
I also increased the time to sleep between the frames, but that didn't change anything since the load is caused by the CEF process.
What OS and CEF version are you testing with?
Windows 8.1 x64 and CEF 3.1750.1658 (x86)