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..22a087b4524ba5698696a5b0142f5f67f2850869 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" |
| @@ -38,6 +39,7 @@ |
| #include "gpu/command_buffer/client/gles2_interface.h" |
| #include "third_party/khronos/GLES2/gl2.h" |
| #include "third_party/khronos/GLES2/gl2ext.h" |
| +#include "third_party/skia/include/core/SkMallocPixelRef.h" |
| #include "ui/base/android/window_android.h" |
| #include "ui/gfx/android/device_display_info.h" |
| #include "ui/gfx/android/java_bitmap.h" |
| @@ -90,6 +92,42 @@ class OutputSurfaceWithoutParent : public cc::OutputSurface { |
| } |
| }; |
| +class TransientUIResource : public cc::ScopedUIResource { |
| + public: |
| + static scoped_ptr<TransientUIResource> Create( |
| + cc::LayerTreeHost* host, |
| + const cc::UIResourceBitmap& bitmap) { |
| + return make_scoped_ptr(new TransientUIResource(host, bitmap)); |
| + } |
| + |
| + virtual cc::UIResourceBitmap GetBitmap(cc::UIResourceId uid, |
| + bool resource_lost) OVERRIDE { |
|
aelias_OOO_until_Jul13
2014/01/31 05:50:10
nit: indent
powei
2014/02/01 01:30:49
Done.
|
| + if (!retrieved_) { |
| + cc::UIResourceBitmap old_bitmap(bitmap_); |
| + |
| + // Return a place holder for all following calls to GetBitmap. |
| + SkBitmap tiny_bitmap; |
| + tiny_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); |
|
aelias_OOO_until_Jul13
2014/01/31 05:50:10
, kOpaque_SkAlphaType
powei
2014/02/01 01:30:49
Done.
|
| + tiny_bitmap.allocPixels(); |
|
aelias_OOO_until_Jul13
2014/01/31 05:50:10
This bitmap may actually be displayed on the scree
powei
2014/02/01 01:30:49
Done.
|
| + tiny_bitmap.setImmutable(); |
| + // Release our reference of the true bitmap. |
| + bitmap_ = cc::UIResourceBitmap(tiny_bitmap); |
| + |
| + retrieved_ = true; |
| + return old_bitmap; |
| + } |
| + return bitmap_; |
| + } |
| + |
| + protected: |
| + TransientUIResource(cc::LayerTreeHost* host, |
| + const cc::UIResourceBitmap& bitmap) |
| + : cc::ScopedUIResource(host, bitmap), retrieved_(false) {} |
| + |
| + private: |
| + bool retrieved_; |
| +}; |
| + |
| static bool g_initialized = false; |
| } // anonymous namespace |
| @@ -267,91 +305,49 @@ bool CompositorImpl::CompositeAndReadback(void *pixels, const gfx::Rect& rect) { |
| } |
| cc::UIResourceId CompositorImpl::GenerateUIResource( |
| - const cc::UIResourceBitmap& bitmap) { |
| + const cc::UIResourceBitmap& bitmap, |
| + bool is_transient) { |
| 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; |
| + scoped_ptr<cc::UIResourceClient> resource; |
| + if (is_transient) { |
| + scoped_ptr<TransientUIResource> transient_resource = |
| + TransientUIResource::Create(host_.get(), bitmap); |
| + id = transient_resource->id(); |
| + resource = transient_resource.Pass(); |
| + } else { |
| + scoped_ptr<cc::ScopedUIResource> scoped_resource = |
| + cc::ScopedUIResource::Create(host_.get(), bitmap); |
| + id = scoped_resource->id(); |
| + resource = scoped_resource.Pass(); |
| + } |
| + |
| + ui_resource_map_.set(id, resource.Pass()); |
| return id; |
| } |
| +cc::UIResourceId CompositorImpl::GenerateCompressedUIResource( |
| + gfx::Size& size, |
|
aelias_OOO_until_Jul13
2014/01/31 05:50:10
const gfx::Size&
powei
2014/02/01 01:30:49
Done.
|
| + int data_size, |
|
aelias_OOO_until_Jul13
2014/01/31 05:50:10
Please use size_t instead of int.
powei
2014/02/01 01:30:49
Done.
|
| + void* data, |
|
aelias_OOO_until_Jul13
2014/01/31 05:50:10
void* pixels
powei
2014/02/01 01:30:49
Done.
|
| + bool is_transient) { |
| + SkImageInfo info = {size.width(), size.height(), kPMColor_SkColorType, |
| + kPremul_SkAlphaType}; |
| + skia::RefPtr<SkMallocPixelRef> etc1_pixel_ref = |
| + skia::AdoptRef(SkMallocPixelRef::NewAllocate(info, 0, 0)); |
| + memcpy(etc1_pixel_ref->getAddr(), data, data_size); |
| + etc1_pixel_ref->setImmutable(); |
| + return GenerateUIResource(cc::UIResourceBitmap(etc1_pixel_ref), is_transient); |
| +} |
| + |
| 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); |
| } |
| -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; |
| -} |
| - |
| -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; |
| -} |
| - |
| -void CompositorImpl::DeleteTexture(GLuint texture_id) { |
| - gpu::gles2::GLES2Interface* gl = |
| - ImageTransportFactoryAndroid::GetInstance()->GetContextGL(); |
| - gl->DeleteTextures(1, &texture_id); |
| - gl->ShallowFlushCHROMIUM(); |
| -} |
| - |
| -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; |
| -} |
| - |
| static scoped_ptr<WebGraphicsContext3DCommandBufferImpl> |
| CreateGpuProcessViewContext( |
| const blink::WebGraphicsContext3D::Attributes attributes, |
| @@ -443,53 +439,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(); |
| } |