summaryrefslogtreecommitdiffstats
path: root/webkit/gpu
diff options
context:
space:
mode:
authorjbauman@chromium.org <jbauman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-08 22:53:23 +0000
committerjbauman@chromium.org <jbauman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-08 22:53:23 +0000
commitc0c0046bdeefe398f74fa68d262b19ded2c26548 (patch)
tree1c177d88f5c650deeebc3a42c7c174e11b99f7c9 /webkit/gpu
parent632983f7f420bc695e4bffc4c4ebd0d4a0b84261 (diff)
downloadchromium_src-c0c0046bdeefe398f74fa68d262b19ded2c26548.zip
chromium_src-c0c0046bdeefe398f74fa68d262b19ded2c26548.tar.gz
chromium_src-c0c0046bdeefe398f74fa68d262b19ded2c26548.tar.bz2
Add WebGraphicsContext support for readbacks from any framebuffer.
This is needed for https://bugs.webkit.org/show_bug.cgi?id=65658 . BUG=55927 TEST= Review URL: http://codereview.chromium.org/7566046 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95898 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/gpu')
-rw-r--r--webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc21
-rw-r--r--webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h2
-rw-r--r--webkit/gpu/webgraphicscontext3d_in_process_impl.cc26
-rw-r--r--webkit/gpu/webgraphicscontext3d_in_process_impl.h2
4 files changed, 38 insertions, 13 deletions
diff --git a/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc b/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc
index 0c70da7..661003b 100644
--- a/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc
+++ b/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc
@@ -822,10 +822,13 @@ void WebGraphicsContext3DInProcessCommandBufferImpl::FlipVertically(
bool WebGraphicsContext3DInProcessCommandBufferImpl::readBackFramebuffer(
unsigned char* pixels,
- size_t buffer_size) {
+ size_t buffer_size,
+ WebGLId framebuffer,
+ int width,
+ int height) {
// TODO(gmam): See if we can comment this in.
// ClearContext();
- if (buffer_size != static_cast<size_t>(4 * width() * height())) {
+ if (buffer_size != static_cast<size_t>(4 * width * height)) {
return false;
}
@@ -836,11 +839,11 @@ bool WebGraphicsContext3DInProcessCommandBufferImpl::readBackFramebuffer(
// vertical flip is only a temporary solution anyway until Chrome
// is fully GPU composited, it wasn't worth the complexity.
- bool mustRestoreFBO = (bound_fbo_ != 0);
+ bool mustRestoreFBO = (bound_fbo_ != framebuffer);
if (mustRestoreFBO) {
- gl_->BindFramebuffer(GL_FRAMEBUFFER, 0);
+ gl_->BindFramebuffer(GL_FRAMEBUFFER, framebuffer);
}
- gl_->ReadPixels(0, 0, cached_width_, cached_height_,
+ gl_->ReadPixels(0, 0, width, height,
GL_RGBA, GL_UNSIGNED_BYTE, pixels);
// Swizzle red and blue channels
@@ -855,13 +858,19 @@ bool WebGraphicsContext3DInProcessCommandBufferImpl::readBackFramebuffer(
#ifdef FLIP_FRAMEBUFFER_VERTICALLY
if (pixels) {
- FlipVertically(pixels, cached_width_, cached_height_);
+ FlipVertically(pixels, width, height);
}
#endif
return true;
}
+bool WebGraphicsContext3DInProcessCommandBufferImpl::readBackFramebuffer(
+ unsigned char* pixels,
+ size_t buffer_size) {
+ return readBackFramebuffer(pixels, buffer_size, 0, width(), height());
+}
+
void WebGraphicsContext3DInProcessCommandBufferImpl::synthesizeGLError(
WGC3Denum error) {
if (find(synthetic_errors_.begin(), synthetic_errors_.end(), error) ==
diff --git a/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h b/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h
index 6330a34..d100522 100644
--- a/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h
+++ b/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h
@@ -70,6 +70,8 @@ class WebGraphicsContext3DInProcessCommandBufferImpl
virtual void reshape(int width, int height);
virtual bool readBackFramebuffer(unsigned char* pixels, size_t buffer_size);
+ virtual bool readBackFramebuffer(unsigned char* pixels, size_t buffer_size,
+ WebGLId framebuffer, int width, int height);
virtual WebGLId getPlatformTextureId();
virtual void prepareTexture();
diff --git a/webkit/gpu/webgraphicscontext3d_in_process_impl.cc b/webkit/gpu/webgraphicscontext3d_in_process_impl.cc
index 6b8d7fc..9bcea10 100644
--- a/webkit/gpu/webgraphicscontext3d_in_process_impl.cc
+++ b/webkit/gpu/webgraphicscontext3d_in_process_impl.cc
@@ -588,8 +588,9 @@ void WebGraphicsContext3DInProcessImpl::FlipVertically(
#endif
bool WebGraphicsContext3DInProcessImpl::readBackFramebuffer(
- unsigned char* pixels, size_t bufferSize) {
- if (bufferSize != static_cast<size_t>(4 * width() * height()))
+ unsigned char* pixels, size_t bufferSize, WebGLId framebuffer,
+ int width, int height) {
+ if (bufferSize != static_cast<size_t>(4 * width * height))
return false;
makeContextCurrent();
@@ -601,8 +602,14 @@ bool WebGraphicsContext3DInProcessImpl::readBackFramebuffer(
// vertical flip is only a temporary solution anyway until Chrome
// is fully GPU composited, it wasn't worth the complexity.
- ResolveMultisampledFramebuffer(0, 0, cached_width_, cached_height_);
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo_);
+ // In this implementation fbo_, not 0, is the drawing buffer, so
+ // special-case that.
+ if (framebuffer == 0)
+ framebuffer = fbo_;
+
+ if (framebuffer == fbo_)
+ ResolveMultisampledFramebuffer(0, 0, width, height);
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer);
GLint pack_alignment = 4;
bool must_restore_pack_alignment = false;
@@ -616,13 +623,13 @@ bool WebGraphicsContext3DInProcessImpl::readBackFramebuffer(
// FIXME: consider testing for presence of GL_OES_read_format
// and GL_EXT_read_format_bgra, and using GL_BGRA_EXT here
// directly.
- glReadPixels(0, 0, cached_width_, cached_height_,
+ glReadPixels(0, 0, width, height,
GL_RGBA, GL_UNSIGNED_BYTE, pixels);
for (size_t i = 0; i < bufferSize; i += 4) {
std::swap(pixels[i], pixels[i + 2]);
}
} else {
- glReadPixels(0, 0, cached_width_, cached_height_,
+ glReadPixels(0, 0, width, height,
GL_BGRA, GL_UNSIGNED_BYTE, pixels);
}
@@ -633,12 +640,17 @@ bool WebGraphicsContext3DInProcessImpl::readBackFramebuffer(
#ifdef FLIP_FRAMEBUFFER_VERTICALLY
if (pixels)
- FlipVertically(pixels, cached_width_, cached_height_);
+ FlipVertically(pixels, width, height);
#endif
return true;
}
+bool WebGraphicsContext3DInProcessImpl::readBackFramebuffer(
+ unsigned char* pixels, size_t bufferSize) {
+ return readBackFramebuffer(pixels, bufferSize, fbo_, width(), height());
+}
+
void WebGraphicsContext3DInProcessImpl::synthesizeGLError(WGC3Denum error) {
if (synthetic_errors_set_.find(error) == synthetic_errors_set_.end()) {
synthetic_errors_set_.insert(error);
diff --git a/webkit/gpu/webgraphicscontext3d_in_process_impl.h b/webkit/gpu/webgraphicscontext3d_in_process_impl.h
index 65bf9cb..2d40506 100644
--- a/webkit/gpu/webgraphicscontext3d_in_process_impl.h
+++ b/webkit/gpu/webgraphicscontext3d_in_process_impl.h
@@ -70,6 +70,8 @@ class WebGraphicsContext3DInProcessImpl : public WebGraphicsContext3D {
virtual void reshape(int width, int height);
virtual bool readBackFramebuffer(unsigned char* pixels, size_t bufferSize);
+ virtual bool readBackFramebuffer(unsigned char* pixels, size_t buffer_size,
+ WebGLId framebuffer, int width, int height);
virtual WebGLId getPlatformTextureId();
virtual void prepareTexture();