Chromium Code Reviews| Index: content/browser/renderer_host/compositor_impl_android.cc |
| diff --git a/content/browser/renderer_host/compositor_impl_android.cc b/content/browser/renderer_host/compositor_impl_android.cc |
| index 0b4eb580ea3a8710a5f78866a0825e3be81b0d50..fd3db084230ea642f61f3c7d3731d1a489f171b1 100644 |
| --- a/content/browser/renderer_host/compositor_impl_android.cc |
| +++ b/content/browser/renderer_host/compositor_impl_android.cc |
| @@ -11,6 +11,7 @@ |
| #include "base/android/jni_android.h" |
| #include "base/android/scoped_java_ref.h" |
| #include "base/bind.h" |
| +#include "base/callback_helpers.h" |
| #include "base/command_line.h" |
| #include "base/lazy_instance.h" |
| #include "base/logging.h" |
| @@ -212,7 +213,7 @@ void CompositorImpl::SetSurface(jobject surface) { |
| void CompositorImpl::SetVisible(bool visible) { |
| if (!visible) { |
| - ui_resource_map_.clear(); |
| + scoped_ui_resource_map_.clear(); |
| host_.reset(); |
| client_->UIResourcesAreInvalid(); |
| } else if (!host_) { |
| @@ -270,86 +271,46 @@ cc::UIResourceId CompositorImpl::GenerateUIResource( |
| const cc::UIResourceBitmap& bitmap) { |
| if (!host_) |
| return 0; |
| - scoped_ptr<cc::ScopedUIResource> ui_resource = |
| - cc::ScopedUIResource::Create(host_.get(), bitmap); |
| - cc::UIResourceId id = ui_resource->id(); |
| - ui_resource_map_.set(id, ui_resource.Pass()); |
| + |
| + cc::UIResourceId id = 0; |
| + if (bitmap.GetFormat() == cc::UIResourceBitmap::RGBA8) { |
| + scoped_ptr<cc::ScopedUIResource> resource = |
| + cc::ScopedUIResource::Create(host_.get(), bitmap); |
| + id = resource->id(); |
| + scoped_ui_resource_map_.set(id, resource.Pass()); |
| + } else if (bitmap.GetFormat() == cc::UIResourceBitmap::ETC1) { |
| + transient_ui_bitmap_ = make_scoped_ptr(new cc::UIResourceBitmap(bitmap)); |
|
no sievers
2014/01/29 21:13:48
as discussed: an alternate 'GenerateUIResource(bas
powei
2014/01/30 00:54:12
So I opted for the boolean flag for now since aeli
|
| + id = host_->CreateUIResource(this); |
| + } |
| + |
| return id; |
| } |
| void CompositorImpl::DeleteUIResource(cc::UIResourceId resource_id) { |
| - UIResourceMap::iterator it = ui_resource_map_.find(resource_id); |
| - if (it != ui_resource_map_.end()) |
| - ui_resource_map_.erase(it); |
| -} |
| + if (!host_) |
| + return; |
| -GLuint CompositorImpl::GenerateTexture(gfx::JavaBitmap& bitmap) { |
| - unsigned int texture_id = BuildBasicTexture(); |
| - gpu::gles2::GLES2Interface* gl = |
| - ImageTransportFactoryAndroid::GetInstance()->GetContextGL(); |
| - if (texture_id == 0u) |
| - return 0u; |
| - GLenum format = GetGLFormatForBitmap(bitmap); |
| - GLenum type = GetGLTypeForBitmap(bitmap); |
| - |
| - gl->TexImage2D(GL_TEXTURE_2D, |
| - 0, |
| - format, |
| - bitmap.size().width(), |
| - bitmap.size().height(), |
| - 0, |
| - format, |
| - type, |
| - bitmap.pixels()); |
| - gl->ShallowFlushCHROMIUM(); |
| - return texture_id; |
| + ScopedUIResourceMap::iterator it = scoped_ui_resource_map_.find(resource_id); |
| + if (it != scoped_ui_resource_map_.end()) { |
| + scoped_ui_resource_map_.erase(it); |
| + } else { |
| + host_->DeleteUIResource(resource_id); |
| + } |
| } |
| -GLuint CompositorImpl::GenerateCompressedTexture(gfx::Size& size, |
| - int data_size, |
| - void* data) { |
| - unsigned int texture_id = BuildBasicTexture(); |
| - gpu::gles2::GLES2Interface* gl = |
| - ImageTransportFactoryAndroid::GetInstance()->GetContextGL(); |
| - if (texture_id == 0u) |
| - return 0u; |
| - gl->CompressedTexImage2D(GL_TEXTURE_2D, |
| - 0, |
| - GL_ETC1_RGB8_OES, |
| - size.width(), |
| - size.height(), |
| - 0, |
| - data_size, |
| - data); |
| - gl->ShallowFlushCHROMIUM(); |
| - return texture_id; |
| -} |
| +cc::UIResourceBitmap CompositorImpl::GetBitmap(cc::UIResourceId resource_id, |
| + bool resource_lost) { |
| + if (transient_ui_bitmap_) |
| + return cc::UIResourceBitmap(*transient_ui_bitmap_.release()); |
| -void CompositorImpl::DeleteTexture(GLuint texture_id) { |
| - gpu::gles2::GLES2Interface* gl = |
| - ImageTransportFactoryAndroid::GetInstance()->GetContextGL(); |
| - gl->DeleteTextures(1, &texture_id); |
| - gl->ShallowFlushCHROMIUM(); |
| -} |
| + // When resource has been lost. |
| + DCHECK(resource_lost); |
| + SkBitmap tiny_bitmap; |
| + tiny_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); |
| + tiny_bitmap.allocPixels(); |
| + tiny_bitmap.setImmutable(); |
| -bool CompositorImpl::CopyTextureToBitmap(GLuint texture_id, |
| - gfx::JavaBitmap& bitmap) { |
| - return CopyTextureToBitmap(texture_id, gfx::Rect(bitmap.size()), bitmap); |
| -} |
| - |
| -bool CompositorImpl::CopyTextureToBitmap(GLuint texture_id, |
| - const gfx::Rect& sub_rect, |
| - gfx::JavaBitmap& bitmap) { |
| - // The sub_rect should match the bitmap size. |
| - DCHECK(bitmap.size() == sub_rect.size()); |
| - if (bitmap.size() != sub_rect.size() || texture_id == 0) return false; |
| - |
| - GLHelper* helper = ImageTransportFactoryAndroid::GetInstance()->GetGLHelper(); |
| - helper->ReadbackTextureSync(texture_id, |
| - sub_rect, |
| - static_cast<unsigned char*> (bitmap.pixels()), |
| - SkBitmap::kARGB_8888_Config); |
| - return true; |
| + return cc::UIResourceBitmap(tiny_bitmap); |
| } |
| static scoped_ptr<WebGraphicsContext3DCommandBufferImpl> |
| @@ -443,53 +404,6 @@ void CompositorImpl::DidAbortSwapBuffers() { |
| client_->OnSwapBuffersCompleted(); |
| } |
| -GLuint CompositorImpl::BuildBasicTexture() { |
| - gpu::gles2::GLES2Interface* gl = |
| - ImageTransportFactoryAndroid::GetInstance()->GetContextGL(); |
| - GLuint texture_id = 0u; |
| - gl->GenTextures(1, &texture_id); |
| - gl->BindTexture(GL_TEXTURE_2D, texture_id); |
| - gl->TexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| - gl->TexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| - gl->TexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| - gl->TexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| - return texture_id; |
| -} |
| - |
| -GLenum CompositorImpl::GetGLFormatForBitmap(gfx::JavaBitmap& bitmap) { |
| - switch (bitmap.format()) { |
| - case ANDROID_BITMAP_FORMAT_A_8: |
| - return GL_ALPHA; |
| - break; |
| - case ANDROID_BITMAP_FORMAT_RGBA_4444: |
| - return GL_RGBA; |
| - break; |
| - case ANDROID_BITMAP_FORMAT_RGBA_8888: |
| - return GL_RGBA; |
| - break; |
| - case ANDROID_BITMAP_FORMAT_RGB_565: |
| - default: |
| - return GL_RGB; |
| - } |
| -} |
| - |
| -GLenum CompositorImpl::GetGLTypeForBitmap(gfx::JavaBitmap& bitmap) { |
| - switch (bitmap.format()) { |
| - case ANDROID_BITMAP_FORMAT_A_8: |
| - return GL_UNSIGNED_BYTE; |
| - break; |
| - case ANDROID_BITMAP_FORMAT_RGBA_4444: |
| - return GL_UNSIGNED_SHORT_4_4_4_4; |
| - break; |
| - case ANDROID_BITMAP_FORMAT_RGBA_8888: |
| - return GL_UNSIGNED_BYTE; |
| - break; |
| - case ANDROID_BITMAP_FORMAT_RGB_565: |
| - default: |
| - return GL_UNSIGNED_SHORT_5_6_5; |
| - } |
| -} |
| - |
| void CompositorImpl::DidCommit() { |
| root_window_->OnCompositingDidCommit(); |
| } |