Add support for transparency on Windows (issue #99).
- Enable the use of Skia instead of GDI for text rendering. - Add a new CefWindowInfo::m_bTransparentPainting member. - Add transparent popup window and off-screen rendering examples to cefclient. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@334 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
parent
34f6a2141e
commit
561bb6956b
2
cef.gypi
2
cef.gypi
|
@ -10,6 +10,8 @@
|
|||
'cef_directory' : '<!(echo %CEF_DIRECTORY%)',
|
||||
# Keep the build output in the CEF directory.
|
||||
'build_dir_prefix': '..\\<!(echo %CEF_DIRECTORY%)\\',
|
||||
# Use SKIA text rendering for transparency support.
|
||||
'enable_skia_text': 1,
|
||||
}, { # OS!="win"
|
||||
'cef_directory' : '<!(echo $CEF_DIRECTORY)',
|
||||
}],
|
||||
|
|
|
@ -82,6 +82,7 @@
|
|||
'tests/cefclient/res/modalmain.html',
|
||||
'tests/cefclient/res/osrplugin.html',
|
||||
'tests/cefclient/res/small.ico',
|
||||
'tests/cefclient/res/transparency.html',
|
||||
'tests/cefclient/res/uiplugin.html',
|
||||
'tests/cefclient/resource_util_win.cpp',
|
||||
'tests/cefclient/uiplugin.cpp',
|
||||
|
|
|
@ -74,6 +74,9 @@ typedef struct _cef_window_info_t
|
|||
// |m_hWndParent| to the window that will act as the parent for popup menus,
|
||||
// dialog boxes, etc.
|
||||
BOOL m_bWindowRenderingDisabled;
|
||||
|
||||
// Set to true to enable transparent painting.
|
||||
BOOL m_bTransparentPainting;
|
||||
|
||||
// Handle for the new browser window.
|
||||
cef_window_handle_t m_hWnd;
|
||||
|
|
|
@ -99,6 +99,7 @@ struct CefWindowInfoTraits {
|
|||
target->m_hWndParent = src->m_hWndParent;
|
||||
target->m_hMenu = src->m_hMenu;
|
||||
target->m_bWindowRenderingDisabled = src->m_bWindowRenderingDisabled;
|
||||
target->m_bTransparentPainting = src->m_bTransparentPainting;
|
||||
target->m_hWnd = src->m_hWnd;
|
||||
}
|
||||
};
|
||||
|
@ -144,6 +145,11 @@ public:
|
|||
m_bWindowRenderingDisabled = TRUE;
|
||||
m_hWndParent = hWndParent;
|
||||
}
|
||||
|
||||
void SetTransparentPainting(BOOL transparentPainting)
|
||||
{
|
||||
m_bTransparentPainting = transparentPainting;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "browser_settings.h"
|
||||
#include "printing/units.h"
|
||||
|
||||
#include "base/win/windows_version.h"
|
||||
#include "skia/ext/vector_canvas.h"
|
||||
#include "skia/ext/vector_platform_device_emf_win.h"
|
||||
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
|
||||
|
@ -18,14 +19,37 @@
|
|||
#include "ui/base/win/hwnd_util.h"
|
||||
#include "webkit/glue/webpreferences.h"
|
||||
|
||||
#include <dwmapi.h>
|
||||
#include <shellapi.h>
|
||||
#include <shlwapi.h>
|
||||
#include <wininet.h>
|
||||
#include <winspool.h>
|
||||
|
||||
#pragma comment(lib, "dwmapi.lib")
|
||||
|
||||
using WebKit::WebRect;
|
||||
using WebKit::WebSize;
|
||||
|
||||
namespace {
|
||||
|
||||
bool IsAeroGlassEnabled() {
|
||||
if (base::win::GetVersion() < base::win::VERSION_VISTA)
|
||||
return false;
|
||||
|
||||
BOOL enabled = FALSE;
|
||||
return SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled;
|
||||
}
|
||||
|
||||
void SetAeroGlass(HWND hWnd) {
|
||||
if (!IsAeroGlassEnabled())
|
||||
return;
|
||||
|
||||
// Make the whole window transparent.
|
||||
MARGINS mgMarInset = { -1, -1, -1, -1 };
|
||||
DwmExtendFrameIntoClientArea(hWnd, &mgMarInset);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
LPCTSTR CefBrowserImpl::GetWndClass()
|
||||
{
|
||||
|
@ -100,6 +124,13 @@ LRESULT CALLBACK CefBrowserImpl::WndProc(HWND hwnd, UINT message,
|
|||
|
||||
case WM_ERASEBKGND:
|
||||
return 0;
|
||||
|
||||
case WM_DWMCOMPOSITIONCHANGED:
|
||||
// Message sent to top-level windows when composition has been enabled or
|
||||
// disabled.
|
||||
if (browser->window_info_.m_bTransparentPainting)
|
||||
SetAeroGlass(hwnd);
|
||||
break;
|
||||
}
|
||||
|
||||
return DefWindowProc(hwnd, message, wParam, lParam);
|
||||
|
@ -148,6 +179,12 @@ void CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
|
|||
::GetModuleHandle(NULL), NULL);
|
||||
DCHECK(window_info_.m_hWnd != NULL);
|
||||
|
||||
if (window_info_.m_bTransparentPainting &&
|
||||
!(window_info_.m_dwStyle & WS_CHILD)) {
|
||||
// Transparent top-level windows will be given "sheet of glass" effect.
|
||||
SetAeroGlass(window_info_.m_hWnd);
|
||||
}
|
||||
|
||||
// Set window user data to this object for future reference from the window
|
||||
// procedure
|
||||
ui::SetWindowUserData(window_info_.m_hWnd, this);
|
||||
|
@ -174,6 +211,9 @@ void CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
|
|||
paint_delegate_.get(), dev_tools_agent_.get(),
|
||||
prefs));
|
||||
|
||||
if (window_info_.m_bTransparentPainting)
|
||||
webviewhost_->webview()->setIsTransparent(true);
|
||||
|
||||
if (!settings_.developer_tools_disabled)
|
||||
dev_tools_agent_->SetWebView(webviewhost_->webview());
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
|
||||
#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
|
||||
#include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h"
|
||||
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
|
||||
#include "third_party/WebKit/Source/WebKit/chromium/public/win/WebInputEventFactory.h"
|
||||
#include "third_party/WebKit/Source/WebKit/chromium/public/win/WebScreenInfoFactory.h"
|
||||
#include "ui/base/ime/composition_text.h"
|
||||
|
@ -709,6 +710,17 @@ void WebWidgetHost::PaintRect(const gfx::Rect& rect) {
|
|||
#endif
|
||||
DCHECK(canvas_.get());
|
||||
|
||||
if (!popup() && ((WebKit::WebView*)webwidget_)->isTransparent()) {
|
||||
// When using transparency mode clear the rectangle before painting.
|
||||
SkPaint clearpaint;
|
||||
clearpaint.setARGB(0,0,0,0);
|
||||
clearpaint.setXfermodeMode(SkXfermode::kClear_Mode);
|
||||
|
||||
SkRect skrc;
|
||||
skrc.set(rect.x(), rect.y(), rect.right(), rect.bottom());
|
||||
canvas_->drawRect(skrc, clearpaint);
|
||||
}
|
||||
|
||||
set_painting(true);
|
||||
webwidget_->paint(canvas_.get(), rect);
|
||||
set_painting(false);
|
||||
|
|
|
@ -33,4 +33,8 @@ void RunDOMAccessTest(CefRefPtr<CefBrowser> browser);
|
|||
void RunDragDropTest(CefRefPtr<CefBrowser> browser);
|
||||
void RunModalDialogTest(CefRefPtr<CefBrowser> browser);
|
||||
|
||||
#if defined(OS_WIN)
|
||||
void RunTransparentPopupTest(CefRefPtr<CefBrowser> browser);
|
||||
#endif
|
||||
|
||||
#endif // _CEFCLIENT_H
|
||||
|
|
|
@ -38,6 +38,7 @@ IDS_DOMACCESS BINARY "res\\domaccess.html"
|
|||
IDS_MODALMAIN BINARY "res\\modalmain.html"
|
||||
IDS_MODALDIALOG BINARY "res\\modaldialog.html"
|
||||
IDS_EXTENSIONPERF BINARY "res\\extensionperf.html"
|
||||
IDS_TRANSPARENCY BINARY "res\\transparency.html"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
|
@ -78,10 +79,12 @@ BEGIN
|
|||
MENUITEM "JavaScript Execute", ID_TESTS_JAVASCRIPT_EXECUTE
|
||||
MENUITEM "Plugin", ID_TESTS_PLUGIN
|
||||
MENUITEM "Popup Window", ID_TESTS_POPUP
|
||||
MENUITEM "Transparent Popup Window", ID_TESTS_TRANSPARENT_POPUP
|
||||
MENUITEM "Request", ID_TESTS_REQUEST
|
||||
MENUITEM "Scheme Handler", ID_TESTS_SCHEME_HANDLER
|
||||
MENUITEM "UI App Example", ID_TESTS_UIAPP
|
||||
MENUITEM "Off-Screen Rendering Example",ID_TESTS_OSRAPP
|
||||
MENUITEM "Transparent Off-Screen Rendering Example",ID_TESTS_TRANSPARENT_OSRAPP
|
||||
MENUITEM "Local Storage", ID_TESTS_LOCALSTORAGE
|
||||
MENUITEM "XMLHttpRequest", ID_TESTS_XMLHTTPREQUEST
|
||||
MENUITEM "WebURLRequest", ID_TESTS_WEBURLREQUEST
|
||||
|
|
|
@ -374,7 +374,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||
// Initialize window info to the defaults for a child window
|
||||
info.SetAsChild(hWnd, rect);
|
||||
|
||||
// Creat the new child child browser window
|
||||
// Creat the new child browser window
|
||||
CefBrowser::CreateBrowser(info,
|
||||
static_cast<CefRefPtr<CefClient> >(g_handler),
|
||||
"http://www.google.com", settings);
|
||||
|
@ -495,6 +495,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||
if(browser.get())
|
||||
RunPopupTest(browser);
|
||||
return 0;
|
||||
case ID_TESTS_TRANSPARENT_POPUP: // Test a transparent popup window
|
||||
if(browser.get())
|
||||
RunTransparentPopupTest(browser);
|
||||
return 0;
|
||||
case ID_TESTS_REQUEST: // Test a request
|
||||
if(browser.get())
|
||||
RunRequestTest(browser);
|
||||
|
@ -509,7 +513,11 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||
return 0;
|
||||
case ID_TESTS_OSRAPP: // Test the OSR app
|
||||
if(browser.get())
|
||||
RunOSRPluginTest(browser);
|
||||
RunOSRPluginTest(browser, false);
|
||||
return 0;
|
||||
case ID_TESTS_TRANSPARENT_OSRAPP: // Test the OSR app with transparency
|
||||
if(browser.get())
|
||||
RunOSRPluginTest(browser, true);
|
||||
return 0;
|
||||
case ID_TESTS_DOMACCESS: // Test DOM access
|
||||
if(browser.get())
|
||||
|
@ -665,3 +673,20 @@ std::string AppGetWorkingDirectory()
|
|||
{
|
||||
return szWorkingDir;
|
||||
}
|
||||
|
||||
void RunTransparentPopupTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
CefWindowInfo info;
|
||||
CefBrowserSettings settings;
|
||||
|
||||
// Initialize window info to the defaults for a popup window
|
||||
info.SetAsPopup(NULL, "TransparentPopup");
|
||||
info.SetTransparentPainting(TRUE);
|
||||
info.m_nWidth = 500;
|
||||
info.m_nHeight = 500;
|
||||
|
||||
// Creat the popup browser window
|
||||
CefBrowser::CreateBrowser(info,
|
||||
static_cast<CefRefPtr<CefClient> >(g_handler),
|
||||
"http://tests/transparency", settings);
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ void ClientHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser)
|
|||
REQUIRE_UI_THREAD();
|
||||
|
||||
AutoLock lock_scope(this);
|
||||
if(!browser->IsPopup())
|
||||
if(!m_Browser.get())
|
||||
{
|
||||
// We need to keep the main child window, but not popup windows
|
||||
m_Browser = browser;
|
||||
|
@ -47,7 +47,7 @@ bool ClientHandler::DoClose(CefRefPtr<CefBrowser> browser)
|
|||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if (!browser->IsPopup()) {
|
||||
if (m_BrowserHwnd == browser->GetWindowHandle()) {
|
||||
// Since the main window contains the browser window, we need to close
|
||||
// the parent window instead of the browser window.
|
||||
CloseMainWindow();
|
||||
|
@ -78,7 +78,7 @@ void ClientHandler::OnLoadStart(CefRefPtr<CefBrowser> browser,
|
|||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if(!browser->IsPopup() && frame->IsMain()) {
|
||||
if(m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain()) {
|
||||
// We've just started loading a page
|
||||
SetLoading(true);
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ void ClientHandler::OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if(!browser->IsPopup() && frame->IsMain()) {
|
||||
if(m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain()) {
|
||||
// We've just finished loading a page
|
||||
SetLoading(false);
|
||||
|
||||
|
|
|
@ -54,11 +54,11 @@ public:
|
|||
|
||||
// CefLifeSpanHandler methods
|
||||
virtual bool OnBeforePopup(CefRefPtr<CefBrowser> parentBrowser,
|
||||
const CefPopupFeatures& popupFeatures,
|
||||
CefWindowInfo& windowInfo,
|
||||
const CefString& url,
|
||||
CefRefPtr<CefClient>& client,
|
||||
CefBrowserSettings& settings) OVERRIDE;
|
||||
const CefPopupFeatures& popupFeatures,
|
||||
CefWindowInfo& windowInfo,
|
||||
const CefString& url,
|
||||
CefRefPtr<CefClient>& client,
|
||||
CefBrowserSettings& settings) OVERRIDE;
|
||||
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
||||
virtual bool DoClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
||||
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
||||
|
|
|
@ -24,7 +24,7 @@ bool ClientHandler::OnBeforePopup(CefRefPtr<CefBrowser> parentBrowser,
|
|||
|
||||
#ifdef TEST_REDIRECT_POPUP_URLS
|
||||
std::string urlStr = url;
|
||||
if(urlStr.find("resources/inspector/devtools.html") == std::string::npos) {
|
||||
if(urlStr.find("chrome-devtools:") == std::string::npos) {
|
||||
// Show all popup windows excluding DevTools in the current window.
|
||||
windowInfo.m_dwStyle &= ~WS_VISIBLE;
|
||||
client = new ClientPopupHandler(m_Browser);
|
||||
|
@ -95,6 +95,10 @@ bool ClientHandler::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
|||
resourceStream = GetBinaryResourceReader(IDS_MODALDIALOG);
|
||||
response->SetMimeType("text/html");
|
||||
response->SetStatus(200);
|
||||
} else if(url == "http://tests/transparency") {
|
||||
resourceStream = GetBinaryResourceReader(IDS_TRANSPARENCY);
|
||||
response->SetMimeType("text/html");
|
||||
response->SetStatus(200);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -120,7 +124,7 @@ void ClientHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
|
|||
|
||||
// Set the frame window title bar
|
||||
CefWindowHandle hwnd = browser->GetWindowHandle();
|
||||
if(!browser->IsPopup())
|
||||
if(m_BrowserHwnd == hwnd)
|
||||
{
|
||||
// The frame window will be the parent of the browser window
|
||||
hwnd = GetParent(hwnd);
|
||||
|
|
|
@ -4,9 +4,11 @@
|
|||
// found in the LICENSE file.
|
||||
|
||||
#include "include/cef.h"
|
||||
#include "osrplugin.h"
|
||||
#include "cefclient.h"
|
||||
#include "client_popup_handler.h"
|
||||
#include "osrplugin.h"
|
||||
#include "resource.h"
|
||||
#include "resource_util.h"
|
||||
#include "string_util.h"
|
||||
#include "util.h"
|
||||
#include <gl/gl.h>
|
||||
|
@ -28,6 +30,12 @@ float g_spinY = 0.0f;
|
|||
int g_width = -1, g_height = -1;
|
||||
CefRefPtr<CefBrowser> g_offscreenBrowser;
|
||||
|
||||
// If set to true alpha transparency will be used.
|
||||
bool g_offscreenTransparent = false;
|
||||
|
||||
#define GL_IMAGE_FORMAT (g_offscreenTransparent?GL_RGBA:GL_RGB)
|
||||
#define GL_BYTE_COUNT (g_offscreenTransparent?4:3)
|
||||
|
||||
// Class holding pointers for the client plugin window.
|
||||
class ClientPlugin
|
||||
{
|
||||
|
@ -48,6 +56,7 @@ public:
|
|||
class ClientOSRHandler : public CefClient,
|
||||
public CefLifeSpanHandler,
|
||||
public CefLoadHandler,
|
||||
public CefRequestHandler,
|
||||
public CefDisplayHandler,
|
||||
public CefRenderHandler
|
||||
{
|
||||
|
@ -73,6 +82,8 @@ public:
|
|||
{ return this; }
|
||||
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE
|
||||
{ return this; }
|
||||
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE
|
||||
{ return this; }
|
||||
virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() OVERRIDE
|
||||
{ return this; }
|
||||
virtual CefRefPtr<CefRenderHandler> GetRenderHandler() OVERRIDE
|
||||
|
@ -134,6 +145,27 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
// CefRequestHandler methods
|
||||
|
||||
virtual bool OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefString& redirectUrl,
|
||||
CefRefPtr<CefStreamReader>& resourceStream,
|
||||
CefRefPtr<CefResponse> response,
|
||||
int loadFlags) OVERRIDE
|
||||
{
|
||||
REQUIRE_IO_THREAD();
|
||||
|
||||
std::string url = request->GetURL();
|
||||
if(url == "http://tests/transparency") {
|
||||
resourceStream = GetBinaryResourceReader(IDS_TRANSPARENCY);
|
||||
response->SetMimeType("text/html");
|
||||
response->SetStatus(200);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// CefDisplayHandler methods
|
||||
|
||||
virtual void OnNavStateChange(CefRefPtr<CefBrowser> browser,
|
||||
|
@ -254,32 +286,55 @@ public:
|
|||
REQUIRE_UI_THREAD();
|
||||
|
||||
wglMakeCurrent(plugin_->hDC, plugin_->hRC);
|
||||
|
||||
|
||||
if (g_offscreenTransparent) {
|
||||
// Enable alpha blending.
|
||||
glEnable(GL_BLEND);
|
||||
}
|
||||
|
||||
// Enable 2D textures.
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, g_textureID);
|
||||
|
||||
if (type == PET_VIEW) {
|
||||
// Paint the view.
|
||||
SetRGB(buffer, g_width, g_height, true);
|
||||
if (g_offscreenTransparent)
|
||||
SetRGBA(buffer, g_width, g_height, true);
|
||||
else
|
||||
SetRGB(buffer, g_width, g_height, true);
|
||||
|
||||
// Update the whole texture. This is done for simplicity instead of
|
||||
// updating just the dirty region.
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, g_width, g_height, GL_RGB,
|
||||
GL_UNSIGNED_BYTE, view_buffer_);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, g_width, g_height,
|
||||
GL_IMAGE_FORMAT, GL_UNSIGNED_BYTE, view_buffer_);
|
||||
}
|
||||
|
||||
if(popup_rect_.width > 0) {
|
||||
if (type == PET_POPUP) {
|
||||
// Paint the popup.
|
||||
SetRGB(buffer, popup_rect_.width, popup_rect_.height, false);
|
||||
if (g_offscreenTransparent)
|
||||
SetRGBA(buffer, popup_rect_.width, popup_rect_.height, false);
|
||||
else
|
||||
SetRGB(buffer, popup_rect_.width, popup_rect_.height, false);
|
||||
}
|
||||
|
||||
if (popup_buffer_) {
|
||||
// Update the popup region.
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, popup_rect_.x,
|
||||
g_height-popup_rect_.y-popup_rect_.height, popup_rect_.width,
|
||||
popup_rect_.height, GL_RGB, GL_UNSIGNED_BYTE, popup_buffer_);
|
||||
popup_rect_.height, GL_IMAGE_FORMAT, GL_UNSIGNED_BYTE,
|
||||
popup_buffer_);
|
||||
}
|
||||
}
|
||||
|
||||
// Disable 2D textures.
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
if (g_offscreenTransparent) {
|
||||
// Disable alpha blending.
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnCursorChange(CefRefPtr<CefBrowser> browser,
|
||||
|
@ -305,18 +360,10 @@ private:
|
|||
AppGetBrowser()->GetMainFrame()->ExecuteJavaScript(ss.str(), "", 0);
|
||||
}
|
||||
|
||||
// Set the contents of the RGB buffer.
|
||||
void SetRGB(const void* src, int width, int height, bool view)
|
||||
{
|
||||
SetBufferSize(width, height, view);
|
||||
ConvertToRGB((unsigned char*)src, view?view_buffer_:popup_buffer_, width,
|
||||
height);
|
||||
}
|
||||
|
||||
// Size the RGB buffer.
|
||||
void SetBufferSize(int width, int height, bool view)
|
||||
{
|
||||
int dst_size = width * height * 3;
|
||||
int dst_size = width * height * GL_BYTE_COUNT;
|
||||
|
||||
// Allocate a new buffer if necesary.
|
||||
if (view) {
|
||||
|
@ -336,6 +383,38 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
// Set the contents of the RGBA buffer.
|
||||
void SetRGBA(const void* src, int width, int height, bool view)
|
||||
{
|
||||
SetBufferSize(width, height, view);
|
||||
ConvertToRGBA((unsigned char*)src, view?view_buffer_:popup_buffer_, width,
|
||||
height);
|
||||
}
|
||||
|
||||
// Convert from BGRA to RGBA format and from upper-left to lower-left origin.
|
||||
static void ConvertToRGBA(const unsigned char* src, unsigned char* dst,
|
||||
int width, int height)
|
||||
{
|
||||
int sp = 0, dp = (height-1) * width * 4;
|
||||
for(int i = 0; i < height; i++) {
|
||||
for(int j = 0; j < width; j++, dp += 4, sp += 4) {
|
||||
dst[dp] = src[sp+2]; // R
|
||||
dst[dp+1] = src[sp+1]; // G
|
||||
dst[dp+2] = src[sp]; // B
|
||||
dst[dp+3] = src[sp+3]; // A
|
||||
}
|
||||
dp -= width * 8;
|
||||
}
|
||||
}
|
||||
|
||||
// Set the contents of the RGB buffer.
|
||||
void SetRGB(const void* src, int width, int height, bool view)
|
||||
{
|
||||
SetBufferSize(width, height, view);
|
||||
ConvertToRGB((unsigned char*)src, view?view_buffer_:popup_buffer_, width,
|
||||
height);
|
||||
}
|
||||
|
||||
// Convert from BGRA to RGB format and from upper-left to lower-left origin.
|
||||
static void ConvertToRGB(const unsigned char* src, unsigned char* dst,
|
||||
int width, int height)
|
||||
|
@ -392,10 +471,14 @@ void EnableGL(HWND hWnd, HDC * hDC, HGLRC * hRC)
|
|||
wglMakeCurrent(*hDC, *hRC);
|
||||
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
// Necessary for non-power-of-2 textures to render correctly.
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
|
||||
if (g_offscreenTransparent) {
|
||||
// Alpha blending style.
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
}
|
||||
|
||||
// Disable GL.
|
||||
|
@ -424,6 +507,14 @@ void SizeGL(ClientPlugin* plugin, int width, int height)
|
|||
glLoadIdentity();
|
||||
glOrtho(0, 0, width, height, 0.1, 100.0);
|
||||
|
||||
if (g_offscreenTransparent) {
|
||||
// Enable alpha blending.
|
||||
glEnable(GL_BLEND);
|
||||
}
|
||||
|
||||
// Enable 2D textures.
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
// Delete the existing exture.
|
||||
if(g_textureID != -1)
|
||||
glDeleteTextures(1, &g_textureID);
|
||||
|
@ -435,12 +526,20 @@ void SizeGL(ClientPlugin* plugin, int width, int height)
|
|||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
|
||||
// Start with all white contents.
|
||||
int size = width * height * 3;
|
||||
int size = width * height * GL_BYTE_COUNT;
|
||||
unsigned char* buffer = new unsigned char[size];
|
||||
memset(buffer, 255, size);
|
||||
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
|
||||
GL_RGB, GL_UNSIGNED_BYTE, buffer);
|
||||
GL_IMAGE_FORMAT, GL_UNSIGNED_BYTE, buffer);
|
||||
|
||||
// Disable 2D textures.
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
if (g_offscreenTransparent) {
|
||||
// Disable alpha blending.
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
delete [] buffer;
|
||||
|
||||
|
@ -468,21 +567,43 @@ void RenderGL(ClientPlugin* plugin)
|
|||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
//glTranslatef(0.0f, 0.0f, -3.0f);
|
||||
|
||||
// Draw the background gradient.
|
||||
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
||||
glBegin(GL_QUADS);
|
||||
glColor4f(1.0,0.0,0.0,1.0); // red
|
||||
glVertex2f(-1.0,-1.0);
|
||||
glVertex2f(1.0,-1.0);
|
||||
glColor4f(0.0,0.0,1.0,1.0); // blue
|
||||
glVertex2f(1.0, 1.0);
|
||||
glVertex2f(-1.0, 1.0);
|
||||
glEnd();
|
||||
glPopAttrib();
|
||||
|
||||
// Rotate the view based on the mouse spin.
|
||||
glRotatef(-g_spinX, 1.0f, 0.0f, 0.0f);
|
||||
glRotatef(-g_spinY, 0.0f, 1.0f, 0.0f);
|
||||
|
||||
// Enable alpha blending.
|
||||
//glEnable(GL_BLEND);
|
||||
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
if (g_offscreenTransparent) {
|
||||
// Enable alpha blending.
|
||||
glEnable(GL_BLEND);
|
||||
}
|
||||
|
||||
// Enable 2D textures.
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
// Draw the facets with the texture.
|
||||
glBindTexture(GL_TEXTURE_2D, g_textureID);
|
||||
glInterleavedArrays(GL_T2F_V3F, 0, vertices);
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
|
||||
//glDisable(GL_BLEND);
|
||||
// Disable 2D textures.
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
if (g_offscreenTransparent) {
|
||||
// Disable alpha blending.
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
SwapBuffers(plugin->hDC);
|
||||
}
|
||||
|
@ -556,6 +677,8 @@ NPError NPP_SetWindowImpl(NPP instance, NPWindow* window_info) {
|
|||
CefWindowInfo windowInfo;
|
||||
CefBrowserSettings settings;
|
||||
windowInfo.SetAsOffScreen(plugin->hWnd);
|
||||
if (g_offscreenTransparent)
|
||||
windowInfo.SetTransparentPainting(TRUE);
|
||||
CefBrowser::CreateBrowser(windowInfo, new ClientOSRHandler(plugin),
|
||||
"http://www.google.com", settings);
|
||||
}
|
||||
|
@ -774,4 +897,9 @@ CefRefPtr<CefBrowser> GetOffScreenBrowser()
|
|||
return g_offscreenBrowser;
|
||||
}
|
||||
|
||||
void SetOffScreenTransparent(bool transparent)
|
||||
{
|
||||
g_offscreenTransparent = transparent;
|
||||
}
|
||||
|
||||
#endif // OS_WIN
|
||||
|
|
|
@ -22,6 +22,8 @@ NPError API_CALL NP_OSRShutdown(void);
|
|||
|
||||
CefRefPtr<CefBrowser> GetOffScreenBrowser();
|
||||
|
||||
void SetOffScreenTransparent(bool transparent);
|
||||
|
||||
#endif // OS_WIN
|
||||
|
||||
#endif // _CEFCLIENT_OSRPLUGIN_H
|
||||
|
|
|
@ -26,7 +26,7 @@ void InitOSRPluginTest()
|
|||
CefRegisterPlugin(plugin_info);
|
||||
}
|
||||
|
||||
void RunOSRPluginTest(CefRefPtr<CefBrowser> browser)
|
||||
void RunOSRPluginTest(CefRefPtr<CefBrowser> browser, bool transparent)
|
||||
{
|
||||
class Listener : public CefDOMEventListener
|
||||
{
|
||||
|
@ -58,9 +58,10 @@ void RunOSRPluginTest(CefRefPtr<CefBrowser> browser)
|
|||
CefString value = url->GetValue();
|
||||
if (!value.empty())
|
||||
browser->GetMainFrame()->LoadURL(value);
|
||||
} else if(elementId == "testWindowedPlugin") {
|
||||
// Run the windowed plugin test.
|
||||
RunPluginTest(browser);
|
||||
} else if(elementId == "testTransparency") {
|
||||
// Transparency test.
|
||||
browser->GetMainFrame()->LoadURL(
|
||||
"http://tests/transparency");
|
||||
} else if(elementId == "testWindowlessPlugin") {
|
||||
// Load flash, which is a windowless plugin.
|
||||
browser->GetMainFrame()->LoadURL(
|
||||
|
@ -101,7 +102,7 @@ void RunOSRPluginTest(CefRefPtr<CefBrowser> browser)
|
|||
RegisterClickListener(document, listener, "stop");
|
||||
RegisterClickListener(document, listener, "reload");
|
||||
RegisterClickListener(document, listener, "go");
|
||||
RegisterClickListener(document, listener, "testWindowedPlugin");
|
||||
RegisterClickListener(document, listener, "testTransparency");
|
||||
RegisterClickListener(document, listener, "testWindowlessPlugin");
|
||||
RegisterClickListener(document, listener, "viewSource");
|
||||
}
|
||||
|
@ -124,5 +125,6 @@ void RunOSRPluginTest(CefRefPtr<CefBrowser> browser)
|
|||
static_cast<ClientHandler*>(client.get())->AddDOMVisitor(
|
||||
"http://tests/osrapp", new Visitor());
|
||||
|
||||
SetOffScreenTransparent(transparent);
|
||||
browser->GetMainFrame()->LoadURL("http://tests/osrapp");
|
||||
}
|
||||
|
|
|
@ -11,6 +11,6 @@
|
|||
void InitOSRPluginTest();
|
||||
|
||||
// Run the test.
|
||||
void RunOSRPluginTest(CefRefPtr<CefBrowser> browser);
|
||||
void RunOSRPluginTest(CefRefPtr<CefBrowser> browser, bool transparent);
|
||||
|
||||
#endif // _CEFCLIENT_OSRPLUGIN_TEST_H
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
<ul>
|
||||
<li>Click and drag the view with the left mouse button while holding the shift key.</li>
|
||||
<li>Enter a URL and click the "Go!" button to browse to a new Website.</li>
|
||||
<li><a href="#" id="testWindowedPlugin">Click here</a> to test a windowed plugin. Windowed plugins must handle the WM_PRINTCLIENT message.</li>
|
||||
<li><a href="#" id="testWindowlessPlugin">Click here</a> to test a windowless plugin. Windowless plugins can be used without modification.</li>
|
||||
<li><a href="#" id="testTransparency">Click here</a> to test transparency.</li>
|
||||
<li><a href="#" id="testWindowlessPlugin">Click here</a> to test a windowless plugin.</li>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>Transparency Examples</title>
|
||||
<style type="text/css">
|
||||
body {
|
||||
font-family: Verdana, Arial;
|
||||
}
|
||||
img {
|
||||
opacity:0.4;
|
||||
}
|
||||
img:hover {
|
||||
opacity:1.0;
|
||||
}
|
||||
#transbox {
|
||||
width: 300px;
|
||||
margin: 0 50px;
|
||||
background-color: #fff;
|
||||
border: 2px solid black;
|
||||
opacity: 0.3;
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Image Transparency</h1>
|
||||
Hover over an image to make it fully opaque.<br>
|
||||
<img src="http://www.w3schools.com/css/klematis.jpg" width="150" height="113" alt="klematis" />
|
||||
<img src="http://www.w3schools.com/css/klematis2.jpg" width="150" height="113" alt="klematis" />
|
||||
|
||||
<h1>Div Transparency</h1>
|
||||
<div id="transbox">This is some text in a transparent box.</div>
|
||||
</body>
|
||||
</html>
|
|
@ -53,6 +53,8 @@
|
|||
#define ID_TESTS_OSRAPP 32793
|
||||
#define ID_TESTS_MODALDIALOG 32794
|
||||
#define ID_TESTS_JAVASCRIPT_PERFORMANCE 32795
|
||||
#define ID_TESTS_TRANSPARENT_POPUP 32796
|
||||
#define ID_TESTS_TRANSPARENT_OSRAPP 32797
|
||||
#define IDC_STATIC -1
|
||||
#define IDS_LOGO 1000
|
||||
#define IDS_UIPLUGIN 1001
|
||||
|
@ -64,6 +66,7 @@
|
|||
#define IDS_MODALMAIN 1007
|
||||
#define IDS_MODALDIALOG 1008
|
||||
#define IDS_EXTENSIONPERF 1009
|
||||
#define IDS_TRANSPARENCY 1010
|
||||
|
||||
// Avoid files associated with MacOS
|
||||
#define _X86_
|
||||
|
|
Loading…
Reference in New Issue