summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--cc/resources/ui_resource_bitmap.cc17
-rw-r--r--cc/resources/ui_resource_bitmap.h3
-rw-r--r--cc/trees/layer_tree_host_impl_unittest.cc8
-rw-r--r--content/browser/android/content_startup_flags.cc2
-rw-r--r--content/browser/android/content_view_core_impl.cc13
-rw-r--r--content/browser/android/content_view_core_impl.h6
-rw-r--r--content/browser/renderer_host/compositor_impl_android.cc204
-rw-r--r--content/browser/renderer_host/compositor_impl_android.h29
-rw-r--r--content/browser/renderer_host/render_widget_host_view_android.cc86
-rw-r--r--content/browser/renderer_host/render_widget_host_view_android.h11
-rw-r--r--content/public/browser/android/compositor.h41
-rw-r--r--content/public/browser/android/content_view_core.h12
12 files changed, 237 insertions, 195 deletions
diff --git a/cc/resources/ui_resource_bitmap.cc b/cc/resources/ui_resource_bitmap.cc
index 562e13a..b84eb8e 100644
--- a/cc/resources/ui_resource_bitmap.cc
+++ b/cc/resources/ui_resource_bitmap.cc
@@ -13,14 +13,14 @@
namespace cc {
void UIResourceBitmap::Create(const skia::RefPtr<SkPixelRef>& pixel_ref,
- gfx::Size size,
UIResourceFormat format) {
- DCHECK(size.width());
- DCHECK(size.height());
+ const SkImageInfo& info = pixel_ref->info();
+ DCHECK(info.fWidth);
+ DCHECK(info.fHeight);
DCHECK(pixel_ref);
DCHECK(pixel_ref->isImmutable());
format_ = format;
- size_ = size;
+ size_ = gfx::Size(info.fWidth, info.fHeight);
pixel_ref_ = pixel_ref;
// Default values for secondary parameters.
@@ -34,16 +34,13 @@ UIResourceBitmap::UIResourceBitmap(const SkBitmap& skbitmap) {
DCHECK(skbitmap.isImmutable());
skia::RefPtr<SkPixelRef> pixel_ref = skia::SharePtr(skbitmap.pixelRef());
- const SkImageInfo& info = pixel_ref->info();
- Create(
- pixel_ref, gfx::Size(info.fWidth, info.fHeight), UIResourceBitmap::RGBA8);
+ Create(pixel_ref, UIResourceBitmap::RGBA8);
SetOpaque(skbitmap.isOpaque());
}
-UIResourceBitmap::UIResourceBitmap(const skia::RefPtr<SkPixelRef>& pixel_ref,
- gfx::Size size) {
- Create(pixel_ref, size, UIResourceBitmap::ETC1);
+UIResourceBitmap::UIResourceBitmap(const skia::RefPtr<SkPixelRef>& pixel_ref) {
+ Create(pixel_ref, UIResourceBitmap::ETC1);
}
UIResourceBitmap::~UIResourceBitmap() {}
diff --git a/cc/resources/ui_resource_bitmap.h b/cc/resources/ui_resource_bitmap.h
index 2cce0b3..64e962c 100644
--- a/cc/resources/ui_resource_bitmap.h
+++ b/cc/resources/ui_resource_bitmap.h
@@ -44,14 +44,13 @@ class CC_EXPORT UIResourceBitmap {
// User must ensure that |skbitmap| is immutable. The SkBitmap Format should
// be 32-bit RGBA.
explicit UIResourceBitmap(const SkBitmap& skbitmap);
- UIResourceBitmap(const skia::RefPtr<SkPixelRef>& pixel_ref, gfx::Size size);
+ explicit UIResourceBitmap(const skia::RefPtr<SkPixelRef>& pixel_ref);
~UIResourceBitmap();
private:
friend class AutoLockUIResourceBitmap;
void Create(const skia::RefPtr<SkPixelRef>& pixel_ref,
- gfx::Size size,
UIResourceFormat format);
skia::RefPtr<SkPixelRef> pixel_ref_;
diff --git a/cc/trees/layer_tree_host_impl_unittest.cc b/cc/trees/layer_tree_host_impl_unittest.cc
index 6c13418..b8120dd 100644
--- a/cc/trees/layer_tree_host_impl_unittest.cc
+++ b/cc/trees/layer_tree_host_impl_unittest.cc
@@ -5453,16 +5453,12 @@ TEST_F(LayerTreeHostImplTest, CreateETC1UIResource) {
EXPECT_EQ(0u, context3d->NumTextures());
- gfx::Size size(4, 4);
- // SkImageInfo has no support for ETC1. The |info| below contains the right
- // total pixel size for the bitmap but not the right height and width. The
- // correct width/height are passed directly to UIResourceBitmap.
SkImageInfo info =
- SkImageInfo::Make(4, 2, kAlpha_8_SkColorType, kPremul_SkAlphaType);
+ SkImageInfo::Make(4, 4, kPMColor_SkColorType, kPremul_SkAlphaType);
skia::RefPtr<SkPixelRef> pixel_ref =
skia::AdoptRef(SkMallocPixelRef::NewAllocate(info, 0, 0));
pixel_ref->setImmutable();
- UIResourceBitmap bitmap(pixel_ref, size);
+ UIResourceBitmap bitmap(pixel_ref);
UIResourceId ui_resource_id = 1;
host_impl_->CreateUIResource(ui_resource_id, bitmap);
EXPECT_EQ(1u, context3d->NumTextures());
diff --git a/content/browser/android/content_startup_flags.cc b/content/browser/android/content_startup_flags.cc
index 2015e98..3f1fd85 100644
--- a/content/browser/android/content_startup_flags.cc
+++ b/content/browser/android/content_startup_flags.cc
@@ -86,8 +86,6 @@ void SetContentCommandLineFlags(int max_render_process_count,
parsed_command_line->AppendSwitch(switches::kUIPrioritizeInGpuProcess);
- parsed_command_line->AppendSwitch(switches::kEnableDelegatedRenderer);
-
if (!plugin_descriptor.empty()) {
parsed_command_line->AppendSwitchNative(
switches::kRegisterPepperPlugins, plugin_descriptor);
diff --git a/content/browser/android/content_view_core_impl.cc b/content/browser/android/content_view_core_impl.cc
index 725207c..14a50be 100644
--- a/content/browser/android/content_view_core_impl.cc
+++ b/content/browser/android/content_view_core_impl.cc
@@ -701,17 +701,14 @@ void ContentViewCoreImpl::ShowPastePopup(int x_dip, int y_dip) {
static_cast<jint>(y_dip));
}
-void ContentViewCoreImpl::GetScaledContentBitmap(
+unsigned int ContentViewCoreImpl::GetScaledContentTexture(
float scale,
- gfx::Size* out_size,
- const base::Callback<void(bool, const SkBitmap&)>& result_callback) {
+ gfx::Size* out_size) {
RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid();
- if (!view) {
- result_callback.Run(false, SkBitmap());
- return;
- }
+ if (!view)
+ return 0;
- view->GetScaledContentBitmap(scale, out_size, result_callback);
+ return view->GetScaledContentTexture(scale, out_size);
}
void ContentViewCoreImpl::StartContentIntent(const GURL& content_url) {
diff --git a/content/browser/android/content_view_core_impl.h b/content/browser/android/content_view_core_impl.h
index 7464210..30e3b65 100644
--- a/content/browser/android/content_view_core_impl.h
+++ b/content/browser/android/content_view_core_impl.h
@@ -57,11 +57,9 @@ class ContentViewCoreImpl : public ContentViewCore,
virtual void LoadUrl(NavigationController::LoadURLParams& params) OVERRIDE;
virtual jint GetCurrentRenderProcessId(JNIEnv* env, jobject obj) OVERRIDE;
virtual void ShowPastePopup(int x, int y) OVERRIDE;
- virtual void GetScaledContentBitmap(
+ virtual unsigned int GetScaledContentTexture(
float scale,
- gfx::Size* out_size,
- const base::Callback<void(bool, const SkBitmap&)>& result_callback)
- OVERRIDE;
+ gfx::Size* out_size) OVERRIDE;
virtual float GetDpiScale() const OVERRIDE;
virtual void RequestContentClipping(const gfx::Rect& clipping,
const gfx::Size& content_size) OVERRIDE;
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();
}
diff --git a/content/browser/renderer_host/compositor_impl_android.h b/content/browser/renderer_host/compositor_impl_android.h
index d5bbf88..21e5e9a 100644
--- a/content/browser/renderer_host/compositor_impl_android.h
+++ b/content/browser/renderer_host/compositor_impl_android.h
@@ -17,13 +17,13 @@
#include "content/public/browser/android/compositor.h"
#include "third_party/khronos/GLES2/gl2.h"
-class SkBitmap;
struct ANativeWindow;
namespace cc {
class InputHandlerClient;
class Layer;
class LayerTreeHost;
+class ScopedUIResource;
}
namespace content {
@@ -58,13 +58,18 @@ class CONTENT_EXPORT CompositorImpl
virtual bool CompositeAndReadback(
void *pixels, const gfx::Rect& rect) OVERRIDE;
virtual void Composite() OVERRIDE;
- virtual cc::UIResourceId GenerateUIResource(const SkBitmap& bitmap,
- bool is_transient) OVERRIDE;
- virtual cc::UIResourceId GenerateCompressedUIResource(const gfx::Size& size,
- void* pixels,
- bool is_transient)
- OVERRIDE;
+ virtual cc::UIResourceId GenerateUIResource(
+ const cc::UIResourceBitmap& bitmap) OVERRIDE;
virtual void DeleteUIResource(cc::UIResourceId resource_id) OVERRIDE;
+ virtual GLuint GenerateTexture(gfx::JavaBitmap& bitmap) OVERRIDE;
+ virtual GLuint GenerateCompressedTexture(
+ gfx::Size& size, int data_size, void* data) OVERRIDE;
+ virtual void DeleteTexture(GLuint texture_id) OVERRIDE;
+ virtual bool CopyTextureToBitmap(GLuint texture_id,
+ gfx::JavaBitmap& bitmap) OVERRIDE;
+ virtual bool CopyTextureToBitmap(GLuint texture_id,
+ const gfx::Rect& sub_rect,
+ gfx::JavaBitmap& bitmap) OVERRIDE;
// LayerTreeHostClient implementation.
virtual void WillBeginMainFrame(int frame_id) OVERRIDE {}
@@ -93,9 +98,9 @@ class CONTENT_EXPORT CompositorImpl
virtual void OnLostResources() OVERRIDE;
private:
- cc::UIResourceId GenerateUIResourceFromUIResourceBitmap(
- const cc::UIResourceBitmap& bitmap,
- bool is_transient);
+ GLuint BuildBasicTexture();
+ GLenum GetGLFormatForBitmap(gfx::JavaBitmap& bitmap);
+ GLenum GetGLTypeForBitmap(gfx::JavaBitmap& bitmap);
scoped_refptr<cc::Layer> root_layer_;
scoped_ptr<cc::LayerTreeHost> host_;
@@ -110,8 +115,8 @@ class CONTENT_EXPORT CompositorImpl
scoped_refptr<cc::ContextProvider> null_offscreen_context_provider_;
- typedef base::ScopedPtrHashMap<cc::UIResourceId, cc::UIResourceClient>
- UIResourceMap;
+ typedef base::ScopedPtrHashMap<cc::UIResourceId, cc::ScopedUIResource>
+ UIResourceMap;
UIResourceMap ui_resource_map_;
gfx::NativeWindow root_window_;
diff --git a/content/browser/renderer_host/render_widget_host_view_android.cc b/content/browser/renderer_host/render_widget_host_view_android.cc
index 32d94bf..394707f 100644
--- a/content/browser/renderer_host/render_widget_host_view_android.cc
+++ b/content/browser/renderer_host/render_widget_host_view_android.cc
@@ -139,7 +139,7 @@ RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid(
ContentViewCoreImpl* content_view_core)
: host_(widget_host),
needs_begin_frame_(false),
- is_showing_(!widget_host->is_hidden()),
+ are_layers_attached_(!widget_host->is_hidden()),
content_view_core_(NULL),
ime_adapter_android_(this),
cached_background_color_(SK_ColorWHITE),
@@ -259,26 +259,31 @@ void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) {
SetSize(rect.size());
}
-void RenderWidgetHostViewAndroid::GetScaledContentBitmap(
+blink::WebGLId RenderWidgetHostViewAndroid::GetScaledContentTexture(
float scale,
- gfx::Size* out_size,
- const base::Callback<void(bool, const SkBitmap&)>& result_callback) {
- if (!IsSurfaceAvailableForCopy()) {
- result_callback.Run(false, SkBitmap());
- return;
+ gfx::Size* out_size) {
+ gfx::Size size(gfx::ToCeiledSize(
+ gfx::ScaleSize(texture_size_in_layer_, scale)));
+
+ if (!CompositorImpl::IsInitialized() ||
+ texture_id_in_layer_ == 0 ||
+ texture_size_in_layer_.IsEmpty() ||
+ size.IsEmpty()) {
+ if (out_size)
+ out_size->SetSize(0, 0);
+
+ return 0;
}
- gfx::Size bounds = layer_->bounds();
- gfx::Rect src_subrect(bounds);
- const gfx::Display& display =
- gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
- float device_scale_factor = display.device_scale_factor();
- DCHECK_GT(device_scale_factor, 0);
- gfx::Size dst_size(
- gfx::ToCeiledSize(gfx::ScaleSize(bounds, scale / device_scale_factor)));
- *out_size = dst_size;
- CopyFromCompositingSurface(
- src_subrect, dst_size, result_callback, SkBitmap::kARGB_8888_Config);
+ if (out_size)
+ *out_size = size;
+
+ GLHelper* helper = ImageTransportFactoryAndroid::GetInstance()->GetGLHelper();
+ return helper->CopyAndScaleTexture(texture_id_in_layer_,
+ texture_size_in_layer_,
+ size,
+ true,
+ GLHelper::SCALER_QUALITY_FAST);
}
bool RenderWidgetHostViewAndroid::PopulateBitmapWithContents(jobject jbitmap) {
@@ -318,9 +323,6 @@ bool RenderWidgetHostViewAndroid::PopulateBitmapWithContents(jobject jbitmap) {
bool RenderWidgetHostViewAndroid::HasValidFrame() const {
if (!content_view_core_)
return false;
- if (!layer_)
- return false;
-
if (texture_size_in_layer_.IsEmpty())
return false;
@@ -385,24 +387,22 @@ bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const {
}
void RenderWidgetHostViewAndroid::Show() {
- if (is_showing_)
+ if (are_layers_attached_)
return;
- is_showing_ = true;
- if (layer_)
- layer_->SetHideLayerAndSubtree(false);
+ are_layers_attached_ = true;
+ AttachLayers();
frame_evictor_->SetVisible(true);
WasShown();
}
void RenderWidgetHostViewAndroid::Hide() {
- if (!is_showing_)
+ if (!are_layers_attached_)
return;
- is_showing_ = false;
- if (layer_)
- layer_->SetHideLayerAndSubtree(true);
+ are_layers_attached_ = false;
+ RemoveLayers();
frame_evictor_->SetVisible(false);
WasHidden();
@@ -412,7 +412,7 @@ bool RenderWidgetHostViewAndroid::IsShowing() {
// ContentViewCoreImpl represents the native side of the Java
// ContentViewCore. It being NULL means that it is not attached
// to the View system yet, so we treat this RWHVA as hidden.
- return is_showing_ && content_view_core_;
+ return are_layers_attached_ && content_view_core_;
}
void RenderWidgetHostViewAndroid::LockResources() {
@@ -756,7 +756,8 @@ void RenderWidgetHostViewAndroid::UnusedResourcesAreAvailable() {
}
void RenderWidgetHostViewAndroid::DestroyDelegatedContent() {
- RemoveLayers();
+ if (are_layers_attached_)
+ RemoveLayers();
frame_provider_ = NULL;
delegated_renderer_layer_ = NULL;
layer_ = NULL;
@@ -791,13 +792,15 @@ void RenderWidgetHostViewAndroid::SwapDelegatedFrame(
}
if (!frame_provider_ ||
texture_size_in_layer_ != frame_provider_->frame_size()) {
- RemoveLayers();
+ if (are_layers_attached_)
+ RemoveLayers();
frame_provider_ = new cc::DelegatedFrameProvider(
resource_collection_.get(), frame_data.Pass());
delegated_renderer_layer_ =
cc::DelegatedRendererLayer::Create(frame_provider_);
layer_ = delegated_renderer_layer_;
- AttachLayers();
+ if (are_layers_attached_)
+ AttachLayers();
} else {
frame_provider_->SetFrameData(frame_data.Pass());
}
@@ -856,7 +859,6 @@ void RenderWidgetHostViewAndroid::OnSwapCompositorFrame(
ComputeContentsSize(frame->metadata);
SwapDelegatedFrame(output_surface_id, frame->delegated_frame_data.Pass());
- frame_evictor_->SwappedFrame(!host_->is_hidden());
return;
}
@@ -1009,7 +1011,6 @@ void RenderWidgetHostViewAndroid::AttachLayers() {
content_view_core_->AttachLayer(layer_);
if (overscroll_effect_enabled_)
overscroll_effect_->Enable();
- layer_->SetHideLayerAndSubtree(!is_showing_);
}
void RenderWidgetHostViewAndroid::RemoveLayers() {
@@ -1330,7 +1331,7 @@ SkColor RenderWidgetHostViewAndroid::GetCachedBackgroundColor() const {
void RenderWidgetHostViewAndroid::OnOverscrolled(
gfx::Vector2dF accumulated_overscroll,
gfx::Vector2dF current_fling_velocity) {
- if (!content_view_core_ || !layer_ || !is_showing_)
+ if (!content_view_core_ || !are_layers_attached_)
return;
if (overscroll_effect_->OnOverscrolled(content_view_core_->GetLayer(),
@@ -1350,7 +1351,9 @@ void RenderWidgetHostViewAndroid::SetContentViewCore(
ContentViewCoreImpl* content_view_core) {
RunAckCallbacks();
- RemoveLayers();
+ if (are_layers_attached_)
+ RemoveLayers();
+
if (content_view_core_ && !using_synchronous_compositor_)
content_view_core_->GetWindowAndroid()->RemoveObserver(this);
@@ -1364,9 +1367,11 @@ void RenderWidgetHostViewAndroid::SetContentViewCore(
SetContentViewCore(obj);
}
- AttachLayers();
- if (content_view_core_ && !using_synchronous_compositor_)
- content_view_core_->GetWindowAndroid()->AddObserver(this);
+ if (are_layers_attached_) {
+ AttachLayers();
+ if (content_view_core_ && !using_synchronous_compositor_)
+ content_view_core_->GetWindowAndroid()->AddObserver(this);
+ }
}
void RenderWidgetHostViewAndroid::RunAckCallbacks() {
@@ -1402,6 +1407,7 @@ void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult(
const base::TimeTicks& start_time,
const base::Callback<void(bool, const SkBitmap&)>& callback,
scoped_ptr<cc::CopyOutputResult> result) {
+ DCHECK(result->HasTexture());
base::ScopedClosureRunner scoped_callback_runner(
base::Bind(callback, false, SkBitmap()));
diff --git a/content/browser/renderer_host/render_widget_host_view_android.h b/content/browser/renderer_host/render_widget_host_view_android.h
index 5f20ebf..a119ef9 100644
--- a/content/browser/renderer_host/render_widget_host_view_android.h
+++ b/content/browser/renderer_host/render_widget_host_view_android.h
@@ -224,10 +224,7 @@ class RenderWidgetHostViewAndroid
void WasResized();
- void GetScaledContentBitmap(
- float scale,
- gfx::Size* out_size,
- const base::Callback<void(bool, const SkBitmap&)>& result_callback);
+ blink::WebGLId GetScaledContentTexture(float scale, gfx::Size* out_size);
bool PopulateBitmapWithContents(jobject jbitmap);
bool HasValidFrame() const;
@@ -299,7 +296,11 @@ class RenderWidgetHostViewAndroid
// Used to track whether this render widget needs a BeginFrame.
bool needs_begin_frame_;
- bool is_showing_;
+ // Whether or not this widget is potentially attached to the view hierarchy.
+ // This view may not actually be attached if this is true, but it should be
+ // treated as such, because as soon as a ContentViewCore is set the layer
+ // will be attached automatically.
+ bool are_layers_attached_;
// ContentViewCoreImpl is our interface to the view system.
ContentViewCoreImpl* content_view_core_;
diff --git a/content/public/browser/android/compositor.h b/content/public/browser/android/compositor.h
index 7cb73e2..0a96af5 100644
--- a/content/public/browser/android/compositor.h
+++ b/content/public/browser/android/compositor.h
@@ -13,7 +13,7 @@
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
-class SkBitmap;
+#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
namespace cc {
class Layer;
@@ -72,21 +72,38 @@ class CONTENT_EXPORT Compositor {
// Composite immediately. Used in single-threaded mode.
virtual void Composite() = 0;
- // Generates a UIResource and returns a UIResourceId. |is_transient|
- // indicates whether or not to release the resource once the bitmap
- // has been uploaded. May return 0.
- virtual cc::UIResourceId GenerateUIResource(const SkBitmap& bitmap,
- bool is_transient) = 0;
-
- // Generates an ETC1 compressed UIResource. See above for |is_transient|.
- // May return 0.
- virtual cc::UIResourceId GenerateCompressedUIResource(const gfx::Size& size,
- void* pixels,
- bool is_transient) = 0;
+ // Generates a UIResource and returns a UIResourceId. May return 0.
+ virtual cc::UIResourceId GenerateUIResource(
+ const cc::UIResourceBitmap& bitmap) = 0;
// Deletes a UIResource.
virtual void DeleteUIResource(cc::UIResourceId resource_id) = 0;
+ // Generates an OpenGL texture and returns a texture handle. May return 0
+ // if the current context is lost.
+ virtual blink::WebGLId GenerateTexture(gfx::JavaBitmap& bitmap) = 0;
+
+ // Generates an OpenGL compressed texture and returns a texture handle. May
+ // return 0 if the current context is lost.
+ virtual blink::WebGLId GenerateCompressedTexture(gfx::Size& size,
+ int data_size,
+ void* data) = 0;
+
+ // Deletes an OpenGL texture.
+ virtual void DeleteTexture(blink::WebGLId texture_id) = 0;
+
+ // Grabs a copy of |texture_id| and saves it into |bitmap|. No scaling is
+ // done. It is assumed that the texture size matches that of the bitmap.
+ virtual bool CopyTextureToBitmap(blink::WebGLId texture_id,
+ gfx::JavaBitmap& bitmap) = 0;
+
+ // Grabs a copy of |texture_id| and saves it into |bitmap|. No scaling is
+ // done. |src_rect| allows the caller to specify which rect of |texture_id|
+ // to copy to |bitmap|. It needs to match the size of |bitmap|. Returns
+ // true if the |texture_id| was copied into |bitmap|, false if not.
+ virtual bool CopyTextureToBitmap(blink::WebGLId texture_id,
+ const gfx::Rect& src_rect,
+ gfx::JavaBitmap& bitmap) = 0;
protected:
Compositor() {}
};
diff --git a/content/public/browser/android/content_view_core.h b/content/public/browser/android/content_view_core.h
index 1113d79..85766ee 100644
--- a/content/public/browser/android/content_view_core.h
+++ b/content/public/browser/android/content_view_core.h
@@ -12,8 +12,6 @@
#include "content/common/content_export.h"
#include "content/public/browser/navigation_controller.h"
-class SkBitmap;
-
namespace cc {
class Layer;
}
@@ -50,15 +48,9 @@ class CONTENT_EXPORT ContentViewCore {
virtual void LoadUrl(NavigationController::LoadURLParams& params) = 0;
virtual jint GetCurrentRenderProcessId(JNIEnv* env, jobject obj) = 0;
virtual void ShowPastePopup(int x, int y) = 0;
-
- // Request a scaled content readback. The result is passed through the
- // callback. The boolean parameter indicates whether the readback was a
- // success or not. The content is passed through the SkBitmap parameter.
- // |out_size| is returned with the size of the content.
- virtual void GetScaledContentBitmap(
+ virtual unsigned int GetScaledContentTexture(
float scale,
- gfx::Size* out_size,
- const base::Callback<void(bool, const SkBitmap&)>& result_callback) = 0;
+ gfx::Size* out_size) = 0;
virtual float GetDpiScale() const = 0;
virtual void RequestContentClipping(const gfx::Rect& clipping,
const gfx::Size& content_size) = 0;