mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
- Win: Improve redraw and scrolling performance (issue #360).
- Win: Fix CefBrowser::GetImage() and add "Get Image" example to cefclient (issue #377). - Pass the list of dirty rectangles to CefRenderHandler::Paint(). (issue #415). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@368 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "include/cef.h"
|
||||
#include "include/cef_runnable.h"
|
||||
#include "cefclient.h"
|
||||
#include "binding_test.h"
|
||||
#include "client_handler.h"
|
||||
@@ -17,6 +18,7 @@
|
||||
#include <direct.h>
|
||||
#include <sstream>
|
||||
|
||||
#include <shellapi.h>
|
||||
|
||||
#define MAX_LOADSTRING 100
|
||||
#define MAX_URL_LENGTH 255
|
||||
@@ -583,6 +585,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
if(browser.get())
|
||||
RunModalDialogTest(browser);
|
||||
return 0;
|
||||
case ID_TESTS_GETIMAGE:
|
||||
if(browser.get())
|
||||
RunGetImageTest(browser);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -694,3 +700,112 @@ void RunTransparentPopupTest(CefRefPtr<CefBrowser> browser)
|
||||
static_cast<CefRefPtr<CefClient> >(g_handler),
|
||||
"http://tests/transparency", settings);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// Determine a temporary path for the bitmap file.
|
||||
bool GetBitmapTempPath(LPWSTR szTempName)
|
||||
{
|
||||
DWORD dwRetVal;
|
||||
DWORD dwBufSize = 512;
|
||||
TCHAR lpPathBuffer[512];
|
||||
UINT uRetVal;
|
||||
|
||||
dwRetVal = GetTempPath(dwBufSize, // length of the buffer
|
||||
lpPathBuffer); // buffer for path
|
||||
if (dwRetVal > dwBufSize || (dwRetVal == 0))
|
||||
return false;
|
||||
|
||||
// Create a temporary file.
|
||||
uRetVal = GetTempFileName(lpPathBuffer, // directory for tmp files
|
||||
L"image", // temp file name prefix
|
||||
0, // create unique name
|
||||
szTempName); // buffer for name
|
||||
if (uRetVal == 0)
|
||||
return false;
|
||||
|
||||
size_t len = wcslen(szTempName);
|
||||
wcscpy(szTempName + len - 3, L"bmp");
|
||||
return true;
|
||||
}
|
||||
|
||||
void UIT_RunGetImageTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
int width, height;
|
||||
bool success = false;
|
||||
|
||||
// Retrieve the image size.
|
||||
if (browser->GetSize(PET_VIEW, width, height)) {
|
||||
void* bits;
|
||||
|
||||
// Populate the bitmap info header.
|
||||
BITMAPINFOHEADER info;
|
||||
info.biSize = sizeof(BITMAPINFOHEADER);
|
||||
info.biWidth = width;
|
||||
info.biHeight = -height; // minus means top-down bitmap
|
||||
info.biPlanes = 1;
|
||||
info.biBitCount = 32;
|
||||
info.biCompression = BI_RGB; // no compression
|
||||
info.biSizeImage = 0;
|
||||
info.biXPelsPerMeter = 1;
|
||||
info.biYPelsPerMeter = 1;
|
||||
info.biClrUsed = 0;
|
||||
info.biClrImportant = 0;
|
||||
|
||||
// Create the bitmap and retrieve the bit buffer.
|
||||
HDC screen_dc = GetDC(NULL);
|
||||
HBITMAP bitmap =
|
||||
CreateDIBSection(screen_dc, reinterpret_cast<BITMAPINFO*>(&info),
|
||||
DIB_RGB_COLORS, &bits, NULL, 0);
|
||||
ReleaseDC(NULL, screen_dc);
|
||||
|
||||
// Read the image into the bit buffer.
|
||||
if (bitmap && browser->GetImage(PET_VIEW, width, height, bits)) {
|
||||
// Populate the bitmap file header.
|
||||
BITMAPFILEHEADER file;
|
||||
file.bfType = 0x4d42;
|
||||
file.bfSize = sizeof(BITMAPFILEHEADER);
|
||||
file.bfReserved1 = 0;
|
||||
file.bfReserved2 = 0;
|
||||
file.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
|
||||
|
||||
TCHAR temp_path[512];
|
||||
if (GetBitmapTempPath(temp_path)) {
|
||||
// Write the bitmap to file.
|
||||
HANDLE file_handle =
|
||||
CreateFile(temp_path, GENERIC_WRITE, 0, 0, CREATE_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL, 0);
|
||||
if (file_handle != INVALID_HANDLE_VALUE) {
|
||||
DWORD bytes_written = 0;
|
||||
WriteFile(file_handle, &file, sizeof(file), &bytes_written, 0);
|
||||
WriteFile(file_handle, &info, sizeof(info), &bytes_written, 0);
|
||||
WriteFile(file_handle, bits, width * height * 4, &bytes_written, 0);
|
||||
|
||||
CloseHandle(file_handle);
|
||||
|
||||
// Open the bitmap in the default viewer.
|
||||
ShellExecute(NULL, L"open", temp_path, NULL, NULL, SW_SHOWNORMAL);
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DeleteObject(bitmap);
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
browser->GetMainFrame()->ExecuteJavaScript(
|
||||
"alert('Failed to create image!');",
|
||||
browser->GetMainFrame()->GetURL(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void RunGetImageTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
// Execute the test function on the UI thread.
|
||||
CefPostTask(TID_UI, NewCefRunnableFunction(UIT_RunGetImageTest, browser));
|
||||
}
|
||||
|
Reference in New Issue
Block a user