From 0bccf1bff255e4080aad8ccb633d87489f8b3dd2 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Fri, 25 May 2012 14:33:01 +0000 Subject: [PATCH] Merge revision 643 and revision 648 changes: - Improve the cefclient transparency test by adding the ability to view individual pixel values (issue #584). - Change cefclient off-screen rendering example to account for premultiplied alpha values (issue #584). git-svn-id: https://chromiumembedded.googlecode.com/svn/branches/1025@649 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- tests/cefclient/osrenderer.cpp | 26 ++++++++++++++-- tests/cefclient/osrenderer.h | 7 +++++ tests/cefclient/osrplugin.cpp | 16 ++++++++++ tests/cefclient/res/osrplugin.html | 3 ++ tests/cefclient/res/transparency.html | 45 +++++++++++++++++++++------ 5 files changed, 86 insertions(+), 11 deletions(-) diff --git a/tests/cefclient/osrenderer.cpp b/tests/cefclient/osrenderer.cpp index cbf0a1070..486e8f1e7 100644 --- a/tests/cefclient/osrenderer.cpp +++ b/tests/cefclient/osrenderer.cpp @@ -110,8 +110,8 @@ void ClientOSRenderer::Initialize() { glPixelStorei(GL_UNPACK_ALIGNMENT, 1); if (transparent_) { - // Alpha blending style. - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + // Alpha blending style. Texture values have premultiplied alpha. + glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); } initialized_ = true; @@ -355,6 +355,28 @@ void ClientOSRenderer::IncrementSpin(float spinDX, float spinDY) { spin_y_ -= spinDY; } +bool ClientOSRenderer::GetPixelValue(int x, int y, unsigned char& r, + unsigned char& g, unsigned char& b, + unsigned char& a) { + if (!view_buffer_) + return false; + + ASSERT(x >= 0 && x < view_width_); + ASSERT(y >= 0 && y < view_height_); + + int pixel_bytes = transparent_ ? 4 : 3; + int y_flipped = view_height_ - y; + int index = (view_width_ * y_flipped * pixel_bytes) + (x * pixel_bytes); + + r = view_buffer_[index]; + g = view_buffer_[index+1]; + b = view_buffer_[index+2]; + if (transparent_) + a = view_buffer_[index+3]; + + return true; +} + void ClientOSRenderer::SetBufferSize(int width, int height, bool view) { int dst_size = width * height * (transparent_?4:3); diff --git a/tests/cefclient/osrenderer.h b/tests/cefclient/osrenderer.h index bc5e39915..75ac808ac 100644 --- a/tests/cefclient/osrenderer.h +++ b/tests/cefclient/osrenderer.h @@ -40,6 +40,13 @@ class ClientOSRenderer { void SetSpin(float spinX, float spinY); void IncrementSpin(float spinDX, float spinDY); + // Retrieve the pixel value from the view buffer. |x| and |y| are relative to + // the upper-left corner of the view. + bool GetPixelValue(int x, int y, unsigned char& r, unsigned char& g, + unsigned char& b, unsigned char& a); + + bool IsTransparent() { return transparent_; } + private: void SetBufferSize(int width, int height, bool view); void SetRGBA(const void* src, int width, int height, bool view); diff --git a/tests/cefclient/osrplugin.cpp b/tests/cefclient/osrplugin.cpp index 99e38f78a..5bbc95c01 100644 --- a/tests/cefclient/osrplugin.cpp +++ b/tests/cefclient/osrplugin.cpp @@ -466,6 +466,22 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam, lastMousePos.x = curMousePos.x = LOWORD(lParam); lastMousePos.y = curMousePos.y = HIWORD(lParam); mouseRotation = true; + } else if (wParam & MK_CONTROL) { + // Retrieve the pixel value. + int x = LOWORD(lParam); + int y = HIWORD(lParam); + unsigned char r, g, b, a; + if (plugin->renderer.GetPixelValue(x, y, r, g, b, a)) { + std::stringstream ss; + ss << x << "," << y << " = R:" << static_cast(r) << " G:" << + static_cast(g) << " B:" << static_cast(b); + if (plugin->renderer.IsTransparent()) + ss << " A:" << static_cast(a); + + std::string js = + "document.getElementById('pixel').innerText = '" + ss.str() + "';"; + AppGetBrowser()->GetMainFrame()->ExecuteJavaScript(js, "", 0); + } } else { if (g_offscreenBrowser.get()) { g_offscreenBrowser->SendMouseClickEvent(LOWORD(lParam), HIWORD(lParam), diff --git a/tests/cefclient/res/osrplugin.html b/tests/cefclient/res/osrplugin.html index ddf8b0d02..0115ee7e6 100644 --- a/tests/cefclient/res/osrplugin.html +++ b/tests/cefclient/res/osrplugin.html @@ -43,6 +43,9 @@
+
+ Pixel value: Click the left mouse button while holding the control key to test a pixel value. +
diff --git a/tests/cefclient/res/transparency.html b/tests/cefclient/res/transparency.html index 3b8cf7fbb..a8dd3b46e 100644 --- a/tests/cefclient/res/transparency.html +++ b/tests/cefclient/res/transparency.html @@ -12,14 +12,38 @@ 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; +.box_white, .box_black { +font-size: 14px; font-weight: bold; +text-align: center; +padding: 10px; +display: inline-block; +width: 100px; +} +.box_white { +background-color: white; +border: 2px solid black; +color: black; +} +.box_black { +background-color: black; +border: 2px solid white; +color: white; +} +.box_0 { +opacity: 1.0; +} +.box_25 { +opacity: 0.75; +} +.box_50 { +opacity: 0.5; +} +.box_75 { +opacity: 0.25; +} +.box_100 { +opacity: 0; } @@ -30,7 +54,10 @@ Hover over an image to make it fully opaque.
klematis klematis -

Div Transparency

-
This is some text in a transparent box.
+

Block Transparency

+White 0% White 25% White 50% White 75% White 100% +
+Black 0% Black 25% Black 50% Black 75% Black 100% +