From b5f2f5db3e29ce7bd12631d919b56624eec46dd2 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Wed, 23 May 2012 17:37:56 +0000 Subject: [PATCH] Improve the cefclient transparency test by adding the ability to view individual pixel values (issue #584). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@643 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- cef1/tests/cefclient/osrenderer.cpp | 22 +++++++++++ cef1/tests/cefclient/osrenderer.h | 7 ++++ cef1/tests/cefclient/osrplugin.cpp | 16 ++++++++ cef1/tests/cefclient/res/osrplugin.html | 3 ++ cef1/tests/cefclient/res/transparency.html | 45 +++++++++++++++++----- 5 files changed, 84 insertions(+), 9 deletions(-) diff --git a/cef1/tests/cefclient/osrenderer.cpp b/cef1/tests/cefclient/osrenderer.cpp index cbf0a1070..41b9ff66f 100644 --- a/cef1/tests/cefclient/osrenderer.cpp +++ b/cef1/tests/cefclient/osrenderer.cpp @@ -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/cef1/tests/cefclient/osrenderer.h b/cef1/tests/cefclient/osrenderer.h index bc5e39915..75ac808ac 100644 --- a/cef1/tests/cefclient/osrenderer.h +++ b/cef1/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/cef1/tests/cefclient/osrplugin.cpp b/cef1/tests/cefclient/osrplugin.cpp index 99e38f78a..5bbc95c01 100644 --- a/cef1/tests/cefclient/osrplugin.cpp +++ b/cef1/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/cef1/tests/cefclient/res/osrplugin.html b/cef1/tests/cefclient/res/osrplugin.html index ddf8b0d02..0115ee7e6 100644 --- a/cef1/tests/cefclient/res/osrplugin.html +++ b/cef1/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/cef1/tests/cefclient/res/transparency.html b/cef1/tests/cefclient/res/transparency.html index 3b8cf7fbb..a8dd3b46e 100644 --- a/cef1/tests/cefclient/res/transparency.html +++ b/cef1/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% +