summaryrefslogtreecommitdiffstats
path: root/content/browser/renderer_host/compositor_impl_android.cc
diff options
context:
space:
mode:
authorpasko@chromium.org <pasko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-05 13:21:01 +0000
committerpasko@chromium.org <pasko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-05 13:21:01 +0000
commit08f0d1067a3bfec8708c5c0218c37d333f787f1c (patch)
treee388659905ded56067d9500e7c8685cd56291aa3 /content/browser/renderer_host/compositor_impl_android.cc
parent0bf9082d2bece5f81191a1e9cdb66af794157f21 (diff)
downloadchromium_src-08f0d1067a3bfec8708c5c0218c37d333f787f1c.zip
chromium_src-08f0d1067a3bfec8708c5c0218c37d333f787f1c.tar.gz
chromium_src-08f0d1067a3bfec8708c5c0218c37d333f787f1c.tar.bz2
Revert 248827 "android: Migrate old content readback to use asyn..."
Breaks android ToT, and the pairing change downstream is not ready yet. > 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 TBR=powei@chromium.org Review URL: https://codereview.chromium.org/149653004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@248976 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.cc204
1 files changed, 120 insertions, 84 deletions
diff --git a/content/browser/renderer_host/compositor_impl_android.cc b/content/browser/renderer_host/compositor_impl_android.cc
index 7fe5fed..b85de07 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"
@@ -91,46 +90,6 @@ 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
@@ -307,60 +266,90 @@ bool CompositorImpl::CompositeAndReadback(void *pixels, const gfx::Rect& rect) {
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;
+ 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 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();
- }
+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);
+}
- ui_resource_map_.set(id, resource.Pass());
- return id;
+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;
}
-cc::UIResourceId CompositorImpl::GenerateUIResource(const SkBitmap& bitmap,
- bool is_transient) {
- return GenerateUIResourceFromUIResourceBitmap(cc::UIResourceBitmap(bitmap),
- is_transient);
+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::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);
+void CompositorImpl::DeleteTexture(GLuint texture_id) {
+ gpu::gles2::GLES2Interface* gl =
+ ImageTransportFactoryAndroid::GetInstance()->GetContextGL();
+ gl->DeleteTextures(1, &texture_id);
+ gl->ShallowFlushCHROMIUM();
+}
- 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,
+ gfx::JavaBitmap& bitmap) {
+ return CopyTextureToBitmap(texture_id, gfx::Rect(bitmap.size()), bitmap);
}
-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);
+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 @@ 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();
}