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

Unified Diff: content/common/gpu/client/gl_helper.cc

Issue 149123008: Implement GLHelperReadbackSupport for GLHelper usage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unused gl_helper member. Created 6 years, 10 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/common/gpu/client/gl_helper.h ('k') | content/common/gpu/client/gl_helper_readback_support.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/gpu/client/gl_helper.cc
diff --git a/content/common/gpu/client/gl_helper.cc b/content/common/gpu/client/gl_helper.cc
index 5a36836a54d892d2a9f6c3b242f588f7a5c452cd..8fe6b737a0f101fb90664b520a5ac3281d603fe8 100644
--- a/content/common/gpu/client/gl_helper.cc
+++ b/content/common/gpu/client/gl_helper.cc
@@ -15,6 +15,7 @@
#include "base/message_loop/message_loop.h"
#include "base/strings/string_util.h"
#include "base/time/time.h"
+#include "content/common/gpu/client/gl_helper_readback_support.h"
#include "content/common/gpu/client/gl_helper_scaling.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "gpu/command_buffer/client/context_support.h"
@@ -178,6 +179,8 @@ class GLHelper::CopyTextureToImpl
// 0 if GL_EXT_draw_buffers is not available.
GLint MaxDrawBuffers() const { return max_draw_buffers_; }
+ bool IsReadbackConfigSupported(SkBitmap::Config bitmap_config);
+
private:
// A single request to CropScaleReadbackAndCleanTexture.
// The main thread can cancel the request, before it's handled by the helper
@@ -341,15 +344,11 @@ GLuint GLHelper::CopyTextureToImpl::ScaleTexture(
const gfx::Size& dst_size,
bool vertically_flip_texture,
bool swizzle,
- SkBitmap::Config config,
+ SkBitmap::Config bitmap_config,
GLHelper::ScalerQuality quality) {
-
- bool format_support = ((config == SkBitmap::kRGB_565_Config) ||
- (config == SkBitmap::kARGB_8888_Config));
- if (!format_support) {
- DCHECK(format_support);
+ if (!IsReadbackConfigSupported(bitmap_config))
return 0;
- }
+
scoped_ptr<ScalerInterface> scaler(
helper_->CreateScaler(quality,
src_size,
@@ -364,7 +363,7 @@ GLuint GLHelper::CopyTextureToImpl::ScaleTexture(
gl_->GenTextures(1, &dst_texture);
{
ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, dst_texture);
- switch (config) {
+ switch (bitmap_config) {
case SkBitmap::kARGB_8888_Config:
// Do nothing params already set.
break;
@@ -395,12 +394,9 @@ void GLHelper::CopyTextureToImpl::ReadbackAsync(
int32 bytes_per_row,
int32 row_stride_bytes,
unsigned char* out,
- const SkBitmap::Config config,
+ const SkBitmap::Config bitmap_config,
const base::Callback<void(bool)>& callback) {
- bool format_support = ((config == SkBitmap::kRGB_565_Config) ||
- (config == SkBitmap::kARGB_8888_Config));
- if (!format_support) {
- DCHECK(format_support);
+ if (!IsReadbackConfigSupported(bitmap_config)) {
callback.Run(false);
return;
}
@@ -413,7 +409,7 @@ void GLHelper::CopyTextureToImpl::ReadbackAsync(
GLenum format = GL_RGBA, type = GL_UNSIGNED_BYTE;
int bytes_per_pixel = 4;
- switch (config) {
+ switch (bitmap_config) {
case SkBitmap::kARGB_8888_Config:
// Do nothing params already set.
break;
@@ -459,10 +455,7 @@ void GLHelper::CopyTextureToImpl::CropScaleReadbackAndCleanTexture(
const SkBitmap::Config bitmap_config,
const base::Callback<void(bool)>& callback,
GLHelper::ScalerQuality quality) {
- bool format_support = ((bitmap_config == SkBitmap::kRGB_565_Config) ||
- (bitmap_config == SkBitmap::kARGB_8888_Config));
- if (!format_support) {
- DCHECK(format_support);
+ if (!IsReadbackConfigSupported(bitmap_config)) {
callback.Run(false);
return;
}
@@ -509,24 +502,25 @@ void GLHelper::CopyTextureToImpl::CropScaleReadbackAndCleanTexture(
gl_->DeleteTextures(1, &texture);
}
-void GLHelper::CopyTextureToImpl::ReadbackTextureSync(GLuint texture,
- const gfx::Rect& src_rect,
- unsigned char* out,
- SkBitmap::Config config) {
- DCHECK((config == SkBitmap::kRGB_565_Config) ||
- (config == SkBitmap::kARGB_8888_Config));
+void GLHelper::CopyTextureToImpl::ReadbackTextureSync(
+ GLuint texture,
+ const gfx::Rect& src_rect,
+ unsigned char* out,
+ SkBitmap::Config bitmap_config) {
+ if (!IsReadbackConfigSupported(bitmap_config))
+ return;
+
ScopedFramebuffer dst_framebuffer(gl_);
ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_,
dst_framebuffer);
ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture);
gl_->FramebufferTexture2D(
GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
- GLenum format = (config == SkBitmap::kRGB_565_Config) ?
- GL_RGB :
- GL_RGBA;
- GLenum type = (config == SkBitmap::kRGB_565_Config) ?
- GL_UNSIGNED_SHORT_5_6_5 :
- GL_UNSIGNED_BYTE;
+ GLenum format =
+ (bitmap_config == SkBitmap::kRGB_565_Config) ? GL_RGB : GL_RGBA;
+ GLenum type = (bitmap_config == SkBitmap::kRGB_565_Config)
+ ? GL_UNSIGNED_SHORT_5_6_5
+ : GL_UNSIGNED_BYTE;
gl_->ReadPixels(src_rect.x(),
src_rect.y(),
src_rect.width(),
@@ -540,15 +534,11 @@ void GLHelper::CopyTextureToImpl::ReadbackTextureAsync(
GLuint texture,
const gfx::Size& dst_size,
unsigned char* out,
- SkBitmap::Config config,
+ SkBitmap::Config bitmap_config,
const base::Callback<void(bool)>& callback) {
- // Only ARGB888 and RGB565 supported as of now.
- bool format_support = ((config == SkBitmap::kRGB_565_Config) ||
- (config == SkBitmap::kARGB_8888_Config));
- if (!format_support) {
- DCHECK(format_support);
+ if (!IsReadbackConfigSupported(bitmap_config))
return;
- }
+
ScopedFramebuffer dst_framebuffer(gl_);
ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_,
dst_framebuffer);
@@ -558,12 +548,12 @@ void GLHelper::CopyTextureToImpl::ReadbackTextureAsync(
GL_TEXTURE_2D,
texture,
0);
- int bytes_per_pixel = (config == SkBitmap::kRGB_565_Config) ? 2 : 4;
+ int bytes_per_pixel = (bitmap_config == SkBitmap::kRGB_565_Config) ? 2 : 4;
ReadbackAsync(dst_size,
dst_size.width() * bytes_per_pixel,
dst_size.width() * bytes_per_pixel,
out,
- config,
+ bitmap_config,
callback);
}
@@ -583,6 +573,15 @@ GLuint GLHelper::CopyTextureToImpl::CopyAndScaleTexture(
quality);
}
+bool GLHelper::CopyTextureToImpl::IsReadbackConfigSupported(
+ SkBitmap::Config bitmap_config) {
+ if (!helper_) {
+ DCHECK(helper_);
+ return false;
+ }
+ return helper_->IsReadbackConfigSupported(bitmap_config);
+}
+
void GLHelper::CopyTextureToImpl::ReadbackDone(Request* finished_request,
int bytes_per_pixel) {
TRACE_EVENT0("mirror",
@@ -651,8 +650,7 @@ void GLHelper::CopyTextureToImpl::CancelRequests() {
GLHelper::GLHelper(GLES2Interface* gl, gpu::ContextSupport* context_support)
: gl_(gl),
context_support_(context_support),
- initialized_565_format_check_(false),
- support_565_format_(false) {}
+ readback_support_(new GLHelperReadbackSupport(gl)) {}
GLHelper::~GLHelper() {}
@@ -875,46 +873,6 @@ void GLHelper::CopyTextureFullImage(GLuint texture, const gfx::Size& size) {
GL_TEXTURE_2D, 0, GL_RGB, 0, 0, size.width(), size.height(), 0);
}
-bool GLHelper::CanUseRgb565Readback() {
- if(initialized_565_format_check_){
- return support_565_format_;
- }
- const int kTestSize = 64;
- GLuint dst_texture = 0u;
- gl_->GenTextures(1, &dst_texture);
- ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, dst_texture);
- gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- gl_->TexImage2D(GL_TEXTURE_2D,
- 0,
- GL_RGB,
- kTestSize,
- kTestSize,
- 0,
- GL_RGB,
- GL_UNSIGNED_SHORT_5_6_5,
- NULL);
- ScopedFramebuffer dst_framebuffer(gl_);
- ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_,
- dst_framebuffer);
- gl_->FramebufferTexture2D(GL_FRAMEBUFFER,
- GL_COLOR_ATTACHMENT0,
- GL_TEXTURE_2D,
- dst_texture,
- 0);
- GLint ext_format = 0, ext_type = 0;
- gl_->GetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &ext_format);
- gl_->GetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &ext_type);
- gl_->DeleteTextures(1, &dst_texture);
- if ((ext_format == GL_RGB) && (ext_type == GL_UNSIGNED_SHORT_5_6_5)) {
- support_565_format_ = true;
- }
- initialized_565_format_check_ = true;
- return support_565_format_;
-}
-
void GLHelper::CopyTextureToImpl::ReadbackPlane(
TextureFrameBufferPair* source,
const scoped_refptr<media::VideoFrame>& target,
@@ -1190,6 +1148,11 @@ void GLHelper::CopyTextureToImpl::ReadbackYUV_MRT::ReadbackYUV(
media::LetterboxYUV(target, dst_subrect_);
}
+bool GLHelper::IsReadbackConfigSupported(SkBitmap::Config texture_format) {
+ DCHECK(readback_support_.get());
+ return readback_support_.get()->IsReadbackConfigSupported(texture_format);
+}
+
ReadbackYUVInterface* GLHelper::CopyTextureToImpl::CreateReadbackPipelineYUV(
GLHelper::ScalerQuality quality,
const gfx::Size& src_size,
« no previous file with comments | « content/common/gpu/client/gl_helper.h ('k') | content/common/gpu/client/gl_helper_readback_support.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698