diff options
author | powei@chromium.org <powei@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-05 02:03:58 +0000 |
---|---|---|
committer | powei@chromium.org <powei@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-05 02:03:58 +0000 |
commit | f64e29fc677728bafac3291a2c909e8885b346ca (patch) | |
tree | 2f61242f93809f9ae0709c83aa909097ac3a9ce8 /content/browser/renderer_host/compositor_impl_android.cc | |
parent | d0e406165adf1ab1180e2f1b4b1536c540a9339f (diff) | |
download | chromium_src-f64e29fc677728bafac3291a2c909e8885b346ca.zip chromium_src-f64e29fc677728bafac3291a2c909e8885b346ca.tar.gz chromium_src-f64e29fc677728bafac3291a2c909e8885b346ca.tar.bz2 |
android: Migrate old content readback to use async readback (and delegated renderer)
This patch removes the use of a helper context for content readback. Instead,
we use the async readback API.
This patch is also setting delegated renderer as the default for android.
android= https://chrome-internal-review.googlesource.com/#/c/152377/
BUG=326363
TBR=sievers
NOTRY=true
Review URL: https://codereview.chromium.org/143803004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@248827 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/renderer_host/compositor_impl_android.cc')
-rw-r--r-- | content/browser/renderer_host/compositor_impl_android.cc | 204 |
1 files changed, 84 insertions, 120 deletions
diff --git a/content/browser/renderer_host/compositor_impl_android.cc b/content/browser/renderer_host/compositor_impl_android.cc index b85de07..7fe5fed 100644 --- a/content/browser/renderer_host/compositor_impl_android.cc +++ b/content/browser/renderer_host/compositor_impl_android.cc @@ -38,6 +38,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 +91,46 @@ 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 { + if (!retrieved_) { + cc::UIResourceBitmap old_bitmap(bitmap_); + + // Return a place holder for all following calls to GetBitmap. + SkBitmap tiny_bitmap; + SkCanvas canvas(tiny_bitmap); + tiny_bitmap.setConfig( + SkBitmap::kARGB_8888_Config, 1, 1, 0, kOpaque_SkAlphaType); + tiny_bitmap.allocPixels(); + canvas.drawColor(SK_ColorWHITE); + 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 @@ -266,90 +307,60 @@ bool CompositorImpl::CompositeAndReadback(void *pixels, const gfx::Rect& rect) { return false; } -cc::UIResourceId CompositorImpl::GenerateUIResource( - const cc::UIResourceBitmap& bitmap) { +cc::UIResourceId CompositorImpl::GenerateUIResourceFromUIResourceBitmap( + 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()); - 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); -} + 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(); + } -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; + ui_resource_map_.set(id, resource.Pass()); + return 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::UIResourceId CompositorImpl::GenerateUIResource(const SkBitmap& bitmap, + bool is_transient) { + return GenerateUIResourceFromUIResourceBitmap(cc::UIResourceBitmap(bitmap), + is_transient); } -void CompositorImpl::DeleteTexture(GLuint texture_id) { - gpu::gles2::GLES2Interface* gl = - ImageTransportFactoryAndroid::GetInstance()->GetContextGL(); - gl->DeleteTextures(1, &texture_id); - gl->ShallowFlushCHROMIUM(); -} +cc::UIResourceId CompositorImpl::GenerateCompressedUIResource( + const gfx::Size& size, + void* pixels, + bool is_transient) { + DCHECK_LT(0, size.width()); + DCHECK_LT(0, size.height()); + DCHECK_EQ(0, size.width() % 4); + DCHECK_EQ(0, size.height() % 4); -bool CompositorImpl::CopyTextureToBitmap(GLuint texture_id, - gfx::JavaBitmap& bitmap) { - return CopyTextureToBitmap(texture_id, gfx::Rect(bitmap.size()), bitmap); + size_t data_size = size.width() * size.height() / 2; + SkImageInfo info = {size.width(), size.height() / 2, kAlpha_8_SkColorType, + kPremul_SkAlphaType}; + skia::RefPtr<SkMallocPixelRef> etc1_pixel_ref = + skia::AdoptRef(SkMallocPixelRef::NewAllocate(info, 0, 0)); + memcpy(etc1_pixel_ref->getAddr(), pixels, data_size); + etc1_pixel_ref->setImmutable(); + return GenerateUIResourceFromUIResourceBitmap( + cc::UIResourceBitmap(etc1_pixel_ref, size), is_transient); } -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; +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); } static scoped_ptr<WebGraphicsContext3DCommandBufferImpl> @@ -443,53 +454,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(); } |