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
This commit is contained in:
Marshall Greenblatt 2012-05-25 14:33:01 +00:00
parent 2bd2007fb9
commit 0bccf1bff2
5 changed files with 86 additions and 11 deletions

View File

@ -110,8 +110,8 @@ void ClientOSRenderer::Initialize() {
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
if (transparent_) { if (transparent_) {
// Alpha blending style. // Alpha blending style. Texture values have premultiplied alpha.
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
} }
initialized_ = true; initialized_ = true;
@ -355,6 +355,28 @@ void ClientOSRenderer::IncrementSpin(float spinDX, float spinDY) {
spin_y_ -= 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) { void ClientOSRenderer::SetBufferSize(int width, int height, bool view) {
int dst_size = width * height * (transparent_?4:3); int dst_size = width * height * (transparent_?4:3);

View File

@ -40,6 +40,13 @@ class ClientOSRenderer {
void SetSpin(float spinX, float spinY); void SetSpin(float spinX, float spinY);
void IncrementSpin(float spinDX, float spinDY); 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: private:
void SetBufferSize(int width, int height, bool view); void SetBufferSize(int width, int height, bool view);
void SetRGBA(const void* src, int width, int height, bool view); void SetRGBA(const void* src, int width, int height, bool view);

View File

@ -466,6 +466,22 @@ LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT message, WPARAM wParam,
lastMousePos.x = curMousePos.x = LOWORD(lParam); lastMousePos.x = curMousePos.x = LOWORD(lParam);
lastMousePos.y = curMousePos.y = HIWORD(lParam); lastMousePos.y = curMousePos.y = HIWORD(lParam);
mouseRotation = true; 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<int>(r) << " G:" <<
static_cast<int>(g) << " B:" << static_cast<int>(b);
if (plugin->renderer.IsTransparent())
ss << " A:" << static_cast<int>(a);
std::string js =
"document.getElementById('pixel').innerText = '" + ss.str() + "';";
AppGetBrowser()->GetMainFrame()->ExecuteJavaScript(js, "", 0);
}
} else { } else {
if (g_offscreenBrowser.get()) { if (g_offscreenBrowser.get()) {
g_offscreenBrowser->SendMouseClickEvent(LOWORD(lParam), HIWORD(lParam), g_offscreenBrowser->SendMouseClickEvent(LOWORD(lParam), HIWORD(lParam),

View File

@ -43,6 +43,9 @@
<div style="padding: 2px; margin: 5px; border: red 1px solid; width: 960px;"> <div style="padding: 2px; margin: 5px; border: red 1px solid; width: 960px;">
<embed type="application/x-client-osr-plugin" width=960 height=400></embed> <embed type="application/x-client-osr-plugin" width=960 height=400></embed>
</div> </div>
<div style="padding: 2px; margin: 5px; width: 960px;" align="left">
<span style="font-size: 10pt; text-align:left;">Pixel value: <span id="pixel">Click the left mouse button while holding the control key to test a pixel value.</span></span>
</div>
</td> </td>
</tr> </tr>
</table> </table>

View File

@ -12,14 +12,38 @@ opacity:0.4;
img:hover { img:hover {
opacity:1.0; opacity:1.0;
} }
#transbox { .box_white, .box_black {
width: 300px; font-size: 14px;
margin: 0 50px;
background-color: #fff;
border: 2px solid black;
opacity: 0.3;
font-size: 18px;
font-weight: bold; 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;
} }
</style> </style>
</head> </head>
@ -30,7 +54,10 @@ 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/klematis.jpg" width="150" height="113" alt="klematis" />
<img src="http://www.w3schools.com/css/klematis2.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> <h1>Block Transparency</h1>
<div id="transbox">This is some text in a transparent box.</div> <span class="box_white box_0">White 0%</span> <span class="box_white box_25">White 25%</span> <span class="box_white box_50">White 50%</span> <span class="box_white box_75">White 75%</span> <span class="box_white box_100">White 100%</span>
<br>
<span class="box_black box_0">Black 0%</span> <span class="box_black box_25">Black 25%</span> <span class="box_black box_50">Black 50%</span> <span class="box_black box_75">Black 75%</span> <span class="box_black box_100">Black 100%</span>
</body> </body>
</html> </html>