summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorpowei@chromium.org <powei@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-05 02:03:58 +0000
committerpowei@chromium.org <powei@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-05 02:03:58 +0000
commitf64e29fc677728bafac3291a2c909e8885b346ca (patch)
tree2f61242f93809f9ae0709c83aa909097ac3a9ce8 /content
parentd0e406165adf1ab1180e2f1b4b1536c540a9339f (diff)
downloadchromium_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')
-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
9 files changed, 177 insertions, 227 deletions
diff --git a/content/browser/android/content_startup_flags.cc b/content/browser/android/content_startup_flags.cc
index 3f1fd85..2015e98 100644
--- a/content/browser/android/content_startup_flags.cc
+++ b/content/browser/android/content_startup_flags.cc
@@ -86,6 +86,8 @@ 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 14a50be..725207c 100644
--- a/content/browser/android/content_view_core_impl.cc
+++ b/content/browser/android/content_view_core_impl.cc
@@ -701,14 +701,17 @@ void ContentViewCoreImpl::ShowPastePopup(int x_dip, int y_dip) {
static_cast<jint>(y_dip));
}
-unsigned int ContentViewCoreImpl::GetScaledContentTexture(
+void ContentViewCoreImpl::GetScaledContentBitmap(
float scale,
- gfx::Size* out_size) {
+ gfx::Size* out_size,
+ const base::Callback<void(bool, const SkBitmap&)>& result_callback) {
RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid();
- if (!view)
- return 0;
+ if (!view) {
+ result_callback.Run(false, SkBitmap());
+ return;
+ }
- return view->GetScaledContentTexture(scale, out_size);
+ view->GetScaledContentBitmap(scale, out_size, result_callback);
}
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 30e3b65..7464210 100644
--- a/content/browser/android/content_view_core_impl.h
+++ b/content/browser/android/content_view_core_impl.h
@@ -57,9 +57,11 @@ 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 unsigned int GetScaledContentTexture(
+ virtual void GetScaledContentBitmap(
float scale,
- gfx::Size* out_size) OVERRIDE;
+ gfx::Size* out_size,
+ const base::Callback<void(bool, const SkBitmap&)>& result_callback)
+ 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 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();
}
diff --git a/content/browser/renderer_host/compositor_impl_android.h b/content/browser/renderer_host/compositor_impl_android.h
index c5dfd27..ffbcd6e 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,18 +58,13 @@ class CONTENT_EXPORT CompositorImpl
virtual bool CompositeAndReadback(
void *pixels, const gfx::Rect& rect) OVERRIDE;
virtual void Composite() OVERRIDE;
- virtual cc::UIResourceId GenerateUIResource(
- const cc::UIResourceBitmap& bitmap) 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 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 {}
@@ -98,9 +93,9 @@ class CONTENT_EXPORT CompositorImpl
virtual void OnLostResources() OVERRIDE;
private:
- GLuint BuildBasicTexture();
- GLenum GetGLFormatForBitmap(gfx::JavaBitmap& bitmap);
- GLenum GetGLTypeForBitmap(gfx::JavaBitmap& bitmap);
+ cc::UIResourceId GenerateUIResourceFromUIResourceBitmap(
+ const cc::UIResourceBitmap& bitmap,
+ bool is_transient);
scoped_refptr<cc::Layer> root_layer_;
scoped_ptr<cc::LayerTreeHost> host_;
@@ -115,8 +110,8 @@ class CONTENT_EXPORT CompositorImpl
scoped_refptr<cc::ContextProvider> null_offscreen_context_provider_;
- typedef base::ScopedPtrHashMap<cc::UIResourceId, cc::ScopedUIResource>
- UIResourceMap;
+ typedef base::ScopedPtrHashMap<cc::UIResourceId, cc::UIResourceClient>
+ 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 07c4a2a..e8a67ae 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),
- are_layers_attached_(!widget_host->is_hidden()),
+ is_showing_(!widget_host->is_hidden()),
content_view_core_(NULL),
ime_adapter_android_(this),
cached_background_color_(SK_ColorWHITE),
@@ -259,31 +259,26 @@ void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) {
SetSize(rect.size());
}
-blink::WebGLId RenderWidgetHostViewAndroid::GetScaledContentTexture(
+void RenderWidgetHostViewAndroid::GetScaledContentBitmap(
float scale,
- 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* out_size,
+ const base::Callback<void(bool, const SkBitmap&)>& result_callback) {
+ if (!IsSurfaceAvailableForCopy()) {
+ result_callback.Run(false, SkBitmap());
+ return;
}
- 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);
+ 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);
}
bool RenderWidgetHostViewAndroid::PopulateBitmapWithContents(jobject jbitmap) {
@@ -323,6 +318,9 @@ 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;
@@ -387,22 +385,24 @@ bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const {
}
void RenderWidgetHostViewAndroid::Show() {
- if (are_layers_attached_)
+ if (is_showing_)
return;
- are_layers_attached_ = true;
- AttachLayers();
+ is_showing_ = true;
+ if (layer_)
+ layer_->SetHideLayerAndSubtree(false);
frame_evictor_->SetVisible(true);
WasShown();
}
void RenderWidgetHostViewAndroid::Hide() {
- if (!are_layers_attached_)
+ if (!is_showing_)
return;
- are_layers_attached_ = false;
- RemoveLayers();
+ is_showing_ = false;
+ if (layer_)
+ layer_->SetHideLayerAndSubtree(true);
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 are_layers_attached_ && content_view_core_;
+ return is_showing_ && content_view_core_;
}
void RenderWidgetHostViewAndroid::LockResources() {
@@ -739,8 +739,7 @@ void RenderWidgetHostViewAndroid::UnusedResourcesAreAvailable() {
}
void RenderWidgetHostViewAndroid::DestroyDelegatedContent() {
- if (are_layers_attached_)
- RemoveLayers();
+ RemoveLayers();
frame_provider_ = NULL;
delegated_renderer_layer_ = NULL;
layer_ = NULL;
@@ -776,15 +775,13 @@ void RenderWidgetHostViewAndroid::SwapDelegatedFrame(
}
if (!frame_provider_ ||
texture_size_in_layer_ != frame_provider_->frame_size()) {
- if (are_layers_attached_)
- RemoveLayers();
+ RemoveLayers();
frame_provider_ = new cc::DelegatedFrameProvider(
resource_collection_.get(), frame_data.Pass());
delegated_renderer_layer_ =
cc::DelegatedRendererLayer::Create(frame_provider_);
layer_ = delegated_renderer_layer_;
- if (are_layers_attached_)
- AttachLayers();
+ AttachLayers();
} else {
frame_provider_->SetFrameData(frame_data.Pass());
}
@@ -843,6 +840,7 @@ void RenderWidgetHostViewAndroid::OnSwapCompositorFrame(
ComputeContentsSize(frame->metadata);
SwapDelegatedFrame(output_surface_id, frame->delegated_frame_data.Pass());
+ frame_evictor_->SwappedFrame(!host_->is_hidden());
return;
}
@@ -995,6 +993,7 @@ void RenderWidgetHostViewAndroid::AttachLayers() {
content_view_core_->AttachLayer(layer_);
if (overscroll_effect_enabled_)
overscroll_effect_->Enable();
+ layer_->SetHideLayerAndSubtree(!is_showing_);
}
void RenderWidgetHostViewAndroid::RemoveLayers() {
@@ -1315,7 +1314,7 @@ SkColor RenderWidgetHostViewAndroid::GetCachedBackgroundColor() const {
void RenderWidgetHostViewAndroid::OnOverscrolled(
gfx::Vector2dF accumulated_overscroll,
gfx::Vector2dF current_fling_velocity) {
- if (!content_view_core_ || !are_layers_attached_)
+ if (!content_view_core_ || !layer_ || !is_showing_)
return;
if (overscroll_effect_->OnOverscrolled(content_view_core_->GetLayer(),
@@ -1335,9 +1334,7 @@ void RenderWidgetHostViewAndroid::SetContentViewCore(
ContentViewCoreImpl* content_view_core) {
RunAckCallbacks();
- if (are_layers_attached_)
- RemoveLayers();
-
+ RemoveLayers();
if (content_view_core_ && !using_synchronous_compositor_)
content_view_core_->GetWindowAndroid()->RemoveObserver(this);
@@ -1351,11 +1348,9 @@ void RenderWidgetHostViewAndroid::SetContentViewCore(
SetContentViewCore(obj);
}
- if (are_layers_attached_) {
- AttachLayers();
- if (content_view_core_ && !using_synchronous_compositor_)
- content_view_core_->GetWindowAndroid()->AddObserver(this);
- }
+ AttachLayers();
+ if (content_view_core_ && !using_synchronous_compositor_)
+ content_view_core_->GetWindowAndroid()->AddObserver(this);
}
void RenderWidgetHostViewAndroid::RunAckCallbacks() {
@@ -1395,7 +1390,6 @@ 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 c5aa524..fe7db5a 100644
--- a/content/browser/renderer_host/render_widget_host_view_android.h
+++ b/content/browser/renderer_host/render_widget_host_view_android.h
@@ -225,7 +225,10 @@ class RenderWidgetHostViewAndroid
void WasResized();
- blink::WebGLId GetScaledContentTexture(float scale, gfx::Size* out_size);
+ void GetScaledContentBitmap(
+ float scale,
+ gfx::Size* out_size,
+ const base::Callback<void(bool, const SkBitmap&)>& result_callback);
bool PopulateBitmapWithContents(jobject jbitmap);
bool HasValidFrame() const;
@@ -296,11 +299,7 @@ class RenderWidgetHostViewAndroid
// Used to track whether this render widget needs a BeginFrame.
bool needs_begin_frame_;
- // 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_;
+ bool is_showing_;
// 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 0a96af5..7cb73e2 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"
-#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
+class SkBitmap;
namespace cc {
class Layer;
@@ -72,38 +72,21 @@ class CONTENT_EXPORT Compositor {
// Composite immediately. Used in single-threaded mode.
virtual void Composite() = 0;
- // Generates a UIResource and returns a UIResourceId. May return 0.
- virtual cc::UIResourceId GenerateUIResource(
- const cc::UIResourceBitmap& bitmap) = 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;
// 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 85766ee..1113d79 100644
--- a/content/public/browser/android/content_view_core.h
+++ b/content/public/browser/android/content_view_core.h
@@ -12,6 +12,8 @@
#include "content/common/content_export.h"
#include "content/public/browser/navigation_controller.h"
+class SkBitmap;
+
namespace cc {
class Layer;
}
@@ -48,9 +50,15 @@ 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;
- virtual unsigned int GetScaledContentTexture(
+
+ // 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(
float scale,
- gfx::Size* out_size) = 0;
+ gfx::Size* out_size,
+ const base::Callback<void(bool, const SkBitmap&)>& result_callback) = 0;
virtual float GetDpiScale() const = 0;
virtual void RequestContentClipping(const gfx::Rect& clipping,
const gfx::Size& content_size) = 0;