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

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: Formatted cl using git format option. 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
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..1be1a03103a4f80aa2db2694eed984b073b31834 100644
--- a/content/common/gpu/client/gl_helper.cc
+++ b/content/common/gpu/client/gl_helper.cc
@@ -178,6 +178,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 +343,12 @@ 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) {
piman 2014/02/20 00:32:18 nit: no blank line
sivag 2014/02/21 11:40:51 Done.
- 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,10 @@ 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);
+
piman 2014/02/20 00:32:18 nit: no blank line
sivag 2014/02/21 11:40:51 Done.
+ if (!IsReadBackConfigSupported(bitmap_config)) {
callback.Run(false);
return;
}
@@ -413,7 +410,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 +456,8 @@ 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);
+
piman 2014/02/20 00:32:18 nit: no blank line
sivag 2014/02/21 11:40:51 Done.
+ if (!IsReadBackConfigSupported(bitmap_config)) {
callback.Run(false);
return;
}
@@ -509,24 +504,26 @@ 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) {
+
piman 2014/02/20 00:32:18 nit: no blank line
sivag 2014/02/21 11:40:51 Done.
+ 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 +537,12 @@ 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);
+
piman 2014/02/20 00:32:18 nit: no blank line
sivag 2014/02/21 11:40:51 Done.
+ if (!IsReadBackConfigSupported(bitmap_config))
return;
- }
+
ScopedFramebuffer dst_framebuffer(gl_);
ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_,
dst_framebuffer);
@@ -558,12 +552,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 +577,15 @@ GLuint GLHelper::CopyTextureToImpl::CopyAndScaleTexture(
quality);
}
+bool GLHelper::CopyTextureToImpl::IsReadBackConfigSupported(
+ SkBitmap::Config bitmap_config) {
+ if (!helper_) {
+ NOTREACHED();
piman 2014/02/20 00:32:18 nit: just DCHECK(helper_).
sivag 2014/02/21 11:40:51 Done.
+ return false;
+ }
+ return helper_->IsReadBackConfigSupported(bitmap_config);
+}
+
void GLHelper::CopyTextureToImpl::ReadbackDone(Request* finished_request,
int bytes_per_pixel) {
TRACE_EVENT0("mirror",
@@ -649,10 +652,11 @@ 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) {}
+ : gl_(gl), context_support_(context_support) {
+ for (int i = 0; i < SkBitmap::kConfigCount; ++i) {
+ format_support_table_[i] = FORMAT_NONE;
+ }
+}
GLHelper::~GLHelper() {}
@@ -875,27 +879,18 @@ 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_;
- }
+bool GLHelper::SupportsFormat(GLint format, GLint type) {
const int kTestSize = 64;
GLuint dst_texture = 0u;
+ bool supports_format = false;
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);
+ gl_->TexImage2D(
+ GL_TEXTURE_2D, 0, format, kTestSize, kTestSize, 0, format, type, NULL);
ScopedFramebuffer dst_framebuffer(gl_);
ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_,
dst_framebuffer);
@@ -908,11 +903,38 @@ bool GLHelper::CanUseRgb565Readback() {
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;
+ if ((ext_format == format) && (ext_type == type)) {
+ supports_format = true;
+ }
+ return supports_format;
+}
+
+bool GLHelper::IsReadBackConfigSupported(
+ const SkBitmap::Config& bitmap_format) {
+
piman 2014/02/20 00:32:18 nit: no blank line.
+ if (format_support_table_[bitmap_format] != FORMAT_NONE) {
+ return format_support_table_[bitmap_format];
+ }
+
+ bool supports_format = false;
+
+ switch (bitmap_format) {
+ case SkBitmap::kRGB_565_Config:
+ supports_format = SupportsFormat(GL_RGB, GL_UNSIGNED_SHORT_5_6_5);
+ break;
+ case SkBitmap::kARGB_8888_Config:
+ supports_format = SupportsFormat(GL_RGBA, GL_UNSIGNED_BYTE);
+ break;
+ case SkBitmap::kA8_Config:
+ case SkBitmap::kARGB_4444_Config:
+ default:
+ NOTREACHED();
+ supports_format = false;
+ break;
}
- initialized_565_format_check_ = true;
- return support_565_format_;
+ format_support_table_[bitmap_format] =
+ supports_format ? FORMAT_SUPPORTED : FORMAT_NOT_SUPPORTED;
+ return supports_format;
}
void GLHelper::CopyTextureToImpl::ReadbackPlane(

Powered by Google App Engine
This is Rietveld 408576698