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 7fe5fed2651507d79b2ecf5e8e64086440466ca3..b85de07a858272d6ce8e1a523530c228c6e47a45 100644 |
--- a/content/browser/renderer_host/compositor_impl_android.cc |
+++ b/content/browser/renderer_host/compositor_impl_android.cc |
@@ -38,7 +38,6 @@ |
#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" |
@@ -89,46 +88,6 @@ |
OutputSurface::SwapBuffers(frame); |
} |
-}; |
- |
-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; |
@@ -307,60 +266,90 @@ |
return false; |
} |
-cc::UIResourceId CompositorImpl::GenerateUIResourceFromUIResourceBitmap( |
- const cc::UIResourceBitmap& bitmap, |
- bool is_transient) { |
+cc::UIResourceId CompositorImpl::GenerateUIResource( |
+ const cc::UIResourceBitmap& bitmap) { |
if (!host_) |
return 0; |
- |
- 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()); |
+ 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; |
-} |
- |
-cc::UIResourceId CompositorImpl::GenerateUIResource(const SkBitmap& bitmap, |
- bool is_transient) { |
- return GenerateUIResourceFromUIResourceBitmap(cc::UIResourceBitmap(bitmap), |
- is_transient); |
-} |
- |
-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); |
- |
- 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); |
} |
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> |
@@ -454,6 +443,53 @@ |
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(); |
} |