Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(867)

Unified Diff: content/renderer/media/renderer_gpu_video_accelerator_factories.cc

Issue 456823002: Use GLHelper for glReadPixels and format detection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Integrate feedback from oetuaho-nv Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/media/renderer_gpu_video_accelerator_factories.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/media/renderer_gpu_video_accelerator_factories.cc
diff --git a/content/renderer/media/renderer_gpu_video_accelerator_factories.cc b/content/renderer/media/renderer_gpu_video_accelerator_factories.cc
index d90123e78ae6a878151bdcc2d0f8fe90cc3d770e..40d4eb65b82e13db1b7278039693f5e445a9bb27 100644
--- a/content/renderer/media/renderer_gpu_video_accelerator_factories.cc
+++ b/content/renderer/media/renderer_gpu_video_accelerator_factories.cc
@@ -10,6 +10,7 @@
#include "base/bind.h"
#include "content/child/child_thread.h"
#include "content/common/gpu/client/context_provider_command_buffer.h"
+#include "content/common/gpu/client/gl_helper.h"
#include "content/common/gpu/client/gpu_channel_host.h"
#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
#include "content/renderer/render_thread_impl.h"
@@ -64,11 +65,24 @@ RendererGpuVideoAcceleratorFactories::GetContext3d() {
if (context_provider_->IsContextLost()) {
context_provider_->VerifyContexts();
context_provider_ = NULL;
+ gl_helper_.reset(NULL);
return NULL;
}
return context_provider_->WebContext3D();
}
+GLHelper* RendererGpuVideoAcceleratorFactories::GetGLHelper() {
+ if (!GetContext3d())
+ return NULL;
+
+ if (gl_helper_.get() == NULL) {
+ gl_helper_.reset(new GLHelper(GetContext3d()->GetImplementation(),
+ GetContext3d()->GetContextSupport()));
+ }
+
+ return gl_helper_.get();
+}
+
scoped_ptr<media::VideoDecodeAccelerator>
RendererGpuVideoAcceleratorFactories::CreateVideoDecodeAccelerator() {
DCHECK(task_runner_->BelongsToCurrentThread());
@@ -178,59 +192,29 @@ void RendererGpuVideoAcceleratorFactories::ReadPixels(
const SkBitmap& pixels) {
DCHECK(task_runner_->BelongsToCurrentThread());
+ GLHelper* gl_helper = GetGLHelper();
WebGraphicsContext3DCommandBufferImpl* context = GetContext3d();
- if (!context)
- return;
- gpu::gles2::GLES2Implementation* gles2 = context->GetImplementation();
+ if (!gl_helper || !context)
+ return;
+ // Copy texture from texture_id to tmp_texture as texture might be external
+ // (GL_TEXTURE_EXTERNAL_OES)
GLuint tmp_texture;
- gles2->GenTextures(1, &tmp_texture);
- gles2->BindTexture(GL_TEXTURE_2D, tmp_texture);
- gles2->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- gles2->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- gles2->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- gles2->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ tmp_texture = gl_helper->CreateTexture();
context->copyTextureCHROMIUM(
GL_TEXTURE_2D, texture_id, tmp_texture, 0, GL_RGBA, GL_UNSIGNED_BYTE);
- GLuint fb;
- gles2->GenFramebuffers(1, &fb);
- gles2->BindFramebuffer(GL_FRAMEBUFFER, fb);
- gles2->FramebufferTexture2D(
- GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tmp_texture, 0);
- gles2->PixelStorei(GL_PACK_ALIGNMENT, 4);
-
-#if SK_B32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_R32_SHIFT == 16 && \
- SK_A32_SHIFT == 24
- GLenum skia_format = GL_BGRA_EXT;
- GLenum read_format = GL_BGRA_EXT;
- GLint supported_format = 0;
- GLint supported_type = 0;
- gles2->GetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &supported_format);
- gles2->GetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &supported_type);
- if (supported_format != GL_BGRA_EXT || supported_type != GL_UNSIGNED_BYTE) {
- read_format = GL_RGBA;
- }
-#elif SK_R32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_B32_SHIFT == 16 && \
- SK_A32_SHIFT == 24
- GLenum skia_format = GL_RGBA;
- GLenum read_format = GL_RGBA;
-#else
-#error Unexpected Skia ARGB_8888 layout!
-#endif
- gles2->ReadPixels(visible_rect.x(),
- visible_rect.y(),
- visible_rect.width(),
- visible_rect.height(),
- read_format,
- GL_UNSIGNED_BYTE,
- pixels.pixelRef()->pixels());
- gles2->DeleteFramebuffers(1, &fb);
- gles2->DeleteTextures(1, &tmp_texture);
-
- if (skia_format != read_format) {
- DCHECK(read_format == GL_RGBA);
+ unsigned char* pixel_data =
+ static_cast<unsigned char*>(pixels.pixelRef()->pixels());
+
+ if (gl_helper->IsReadbackConfigSupported(pixels.colorType())) {
+ gl_helper->ReadbackTextureSync(
+ tmp_texture, visible_rect, pixel_data, pixels.colorType());
+ } else if (pixels.colorType() == kN32_SkColorType) {
+ gl_helper->ReadbackTextureSync(
+ tmp_texture, visible_rect, pixel_data, kRGBA_8888_SkColorType);
+
int pixel_count = visible_rect.width() * visible_rect.height();
uint32_t* pixels_ptr = static_cast<uint32_t*>(pixels.pixelRef()->pixels());
for (int i = 0; i < pixel_count; ++i) {
@@ -243,9 +227,11 @@ void RendererGpuVideoAcceleratorFactories::ReadPixels(
(b << SK_B32_SHIFT) |
(a << SK_A32_SHIFT);
}
+ } else {
+ NOTREACHED();
}
- DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR));
+ gl_helper->DeleteTexture(tmp_texture);
}
base::SharedMemory* RendererGpuVideoAcceleratorFactories::CreateSharedMemory(
« no previous file with comments | « content/renderer/media/renderer_gpu_video_accelerator_factories.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698