summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpowei@chromium.org <powei@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-13 07:15:45 +0000
committerpowei@chromium.org <powei@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-13 07:15:45 +0000
commit4825cbfd9d1ffe09f93172893e73819ab9347546 (patch)
tree0f1394483574c1711acd8e32f62a6ff098521f9b
parent993c38816404ba88b532bbaef4aaf232cdcf1dea (diff)
downloadchromium_src-4825cbfd9d1ffe09f93172893e73819ab9347546.zip
chromium_src-4825cbfd9d1ffe09f93172893e73819ab9347546.tar.gz
chromium_src-4825cbfd9d1ffe09f93172893e73819ab9347546.tar.bz2
android: content::UIResourceProvider and content::UIResourceClientAndroid
We abstract out the allocation of UI resources into the UIResourceProvider. We add a client class that allows for callback from the provider when resources are invalidated (due to change in LayerTreeHost). android= https://chrome-internal-review.googlesource.com/#/c/164986 BUG= TBR=jam@chromium.org Review URL: https://codereview.chromium.org/287593002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@276955 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/browser/android/ui_resource_provider_impl.cc60
-rw-r--r--content/browser/android/ui_resource_provider_impl.h46
-rw-r--r--content/browser/renderer_host/compositor_impl_android.cc115
-rw-r--r--content/browser/renderer_host/compositor_impl_android.h15
-rw-r--r--content/content_browser.gypi4
-rw-r--r--content/public/browser/android/compositor.h19
-rw-r--r--content/public/browser/android/compositor_client.h6
-rw-r--r--content/public/browser/android/ui_resource_client_android.h30
-rw-r--r--content/public/browser/android/ui_resource_provider.h27
9 files changed, 182 insertions, 140 deletions
diff --git a/content/browser/android/ui_resource_provider_impl.cc b/content/browser/android/ui_resource_provider_impl.cc
new file mode 100644
index 0000000..f97975c
--- /dev/null
+++ b/content/browser/android/ui_resource_provider_impl.cc
@@ -0,0 +1,60 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/android/ui_resource_provider_impl.h"
+
+#include "cc/resources/ui_resource_client.h"
+#include "cc/trees/layer_tree_host.h"
+#include "content/public/browser/android/ui_resource_client_android.h"
+
+namespace content {
+
+UIResourceProviderImpl::UIResourceProviderImpl() : host_(NULL) {
+}
+
+UIResourceProviderImpl::~UIResourceProviderImpl() {
+ SetLayerTreeHost(NULL);
+}
+
+void UIResourceProviderImpl::SetLayerTreeHost(cc::LayerTreeHost* host) {
+ if (host_ == host)
+ return;
+ host_ = host;
+ UIResourcesAreInvalid();
+}
+
+void UIResourceProviderImpl::UIResourcesAreInvalid() {
+ UIResourceClientMap client_map = ui_resource_client_map_;
+ ui_resource_client_map_.clear();
+ for (UIResourceClientMap::iterator iter = client_map.begin();
+ iter != client_map.end();
+ iter++) {
+ iter->second->UIResourceIsInvalid();
+ }
+}
+
+cc::UIResourceId UIResourceProviderImpl::CreateUIResource(
+ UIResourceClientAndroid* client) {
+ if (!host_)
+ return 0;
+ cc::UIResourceId id = host_->CreateUIResource(client);
+ DCHECK(ui_resource_client_map_.find(id) == ui_resource_client_map_.end());
+
+ ui_resource_client_map_[id] = client;
+ return id;
+}
+
+void UIResourceProviderImpl::DeleteUIResource(cc::UIResourceId ui_resource_id) {
+ UIResourceClientMap::iterator iter =
+ ui_resource_client_map_.find(ui_resource_id);
+ DCHECK(iter != ui_resource_client_map_.end());
+
+ ui_resource_client_map_.erase(iter);
+
+ if (!host_)
+ return;
+ host_->DeleteUIResource(ui_resource_id);
+}
+
+} // namespace content
diff --git a/content/browser/android/ui_resource_provider_impl.h b/content/browser/android/ui_resource_provider_impl.h
new file mode 100644
index 0000000..79c2301
--- /dev/null
+++ b/content/browser/android/ui_resource_provider_impl.h
@@ -0,0 +1,46 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_ANDROID_UI_RESOURCE_PROVIDER_IMPL_H_
+#define CONTENT_BROWSER_ANDROID_UI_RESOURCE_PROVIDER_IMPL_H_
+
+#include "base/containers/hash_tables.h"
+#include "content/public/browser/android/ui_resource_provider.h"
+
+namespace cc {
+class LayerTreeHost;
+}
+
+namespace content {
+
+class UIResourceClientAndroid;
+
+class UIResourceProviderImpl : public UIResourceProvider {
+ public:
+ UIResourceProviderImpl();
+
+ virtual ~UIResourceProviderImpl();
+
+ void SetLayerTreeHost(cc::LayerTreeHost* host);
+
+ void UIResourcesAreInvalid();
+
+ virtual cc::UIResourceId CreateUIResource(
+ UIResourceClientAndroid* client) OVERRIDE;
+
+ virtual void DeleteUIResource(cc::UIResourceId resource_id) OVERRIDE;
+
+ private:
+ typedef base::hash_map<cc::UIResourceId, UIResourceClientAndroid*>
+ UIResourceClientMap;
+ UIResourceClientMap ui_resource_client_map_;
+
+ cc::LayerTreeHost* host_;
+
+ DISALLOW_COPY_AND_ASSIGN(UIResourceProviderImpl);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_ANDROID_UI_RESOURCE_PROVIDER_IMPL_H_
diff --git a/content/browser/renderer_host/compositor_impl_android.cc b/content/browser/renderer_host/compositor_impl_android.cc
index 60fedc8..6232bcd 100644
--- a/content/browser/renderer_host/compositor_impl_android.cc
+++ b/content/browser/renderer_host/compositor_impl_android.cc
@@ -24,8 +24,6 @@
#include "cc/output/compositor_frame.h"
#include "cc/output/context_provider.h"
#include "cc/output/output_surface.h"
-#include "cc/resources/scoped_ui_resource.h"
-#include "cc/resources/ui_resource_bitmap.h"
#include "cc/trees/layer_tree_host.h"
#include "content/browser/android/child_process_launcher_android.h"
#include "content/browser/gpu/browser_gpu_channel_host_factory.h"
@@ -44,17 +42,12 @@
#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"
#include "ui/gfx/frame_time.h"
#include "ui/gl/android/surface_texture.h"
#include "ui/gl/android/surface_texture_tracker.h"
#include "webkit/common/gpu/context_provider_in_process.h"
#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
-namespace gfx {
-class JavaBitmap;
-}
-
namespace {
const unsigned int kMaxSwapBuffers = 2U;
@@ -81,46 +74,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_;
-};
-
class SurfaceTextureTrackerImpl : public gfx::SurfaceTextureTracker {
public:
SurfaceTextureTrackerImpl() : next_surface_texture_id_(1) {
@@ -383,6 +336,10 @@ void CompositorImpl::OnGpuChannelEstablished() {
ScheduleComposite();
}
+UIResourceProvider& CompositorImpl::GetUIResourceProvider() {
+ return ui_resource_provider_;
+}
+
void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) {
root_layer_->RemoveAllChildren();
if (root_layer)
@@ -440,9 +397,8 @@ void CompositorImpl::SetVisible(bool visible) {
if (!visible) {
if (WillComposite())
CancelComposite();
- ui_resource_map_.clear();
+ ui_resource_provider_.SetLayerTreeHost(NULL);
host_.reset();
- client_->UIResourcesAreInvalid();
} else if (!host_) {
DCHECK(!WillComposite());
needs_composite_ = false;
@@ -471,9 +427,7 @@ void CompositorImpl::SetVisible(bool visible) {
host_->SetViewportSize(size_);
host_->set_has_transparent_background(has_transparent_background_);
host_->SetDeviceScaleFactor(device_scale_factor_);
- // Need to recreate the UI resources because a new LayerTreeHost has been
- // created.
- client_->DidLoseUIResources();
+ ui_resource_provider_.SetLayerTreeHost(host_.get());
}
}
@@ -508,62 +462,6 @@ void CompositorImpl::SetNeedsComposite() {
PostComposite(COMPOSITE_IMMEDIATELY);
}
-cc::UIResourceId CompositorImpl::GenerateUIResourceFromUIResourceBitmap(
- const cc::UIResourceBitmap& bitmap,
- bool is_transient) {
- 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());
- 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);
-}
-
static scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
CreateGpuProcessViewContext(
const scoped_refptr<GpuChannelHost>& gpu_channel_host,
@@ -633,6 +531,7 @@ scoped_ptr<cc::OutputSurface> CompositorImpl::CreateOutputSurface(
void CompositorImpl::OnLostResources() {
client_->DidLoseResources();
+ ui_resource_provider_.UIResourcesAreInvalid();
}
void CompositorImpl::ScheduleComposite() {
diff --git a/content/browser/renderer_host/compositor_impl_android.h b/content/browser/renderer_host/compositor_impl_android.h
index 360df36..61743af 100644
--- a/content/browser/renderer_host/compositor_impl_android.h
+++ b/content/browser/renderer_host/compositor_impl_android.h
@@ -14,6 +14,7 @@
#include "cc/resources/ui_resource_client.h"
#include "cc/trees/layer_tree_host_client.h"
#include "cc/trees/layer_tree_host_single_thread_client.h"
+#include "content/browser/android/ui_resource_provider_impl.h"
#include "content/browser/renderer_host/image_transport_factory_android.h"
#include "content/common/content_export.h"
#include "content/public/browser/android/compositor.h"
@@ -32,6 +33,7 @@ class LayerTreeHost;
namespace content {
class CompositorClient;
class GraphicsContext;
+class UIResourceProvider;
// -----------------------------------------------------------------------------
// Browser-side compositor that manages a tree of content and UI layers.
@@ -65,13 +67,7 @@ class CONTENT_EXPORT CompositorImpl
virtual void SetWindowBounds(const gfx::Size& size) OVERRIDE;
virtual void SetHasTransparentBackground(bool flag) OVERRIDE;
virtual void SetNeedsComposite() 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 UIResourceProvider& GetUIResourceProvider() OVERRIDE;
// LayerTreeHostClient implementation.
virtual void WillBeginMainFrame(int frame_id) OVERRIDE {}
@@ -140,6 +136,7 @@ class CONTENT_EXPORT CompositorImpl
scoped_refptr<cc::Layer> root_layer_;
scoped_ptr<cc::LayerTreeHost> host_;
+ content::UIResourceProviderImpl ui_resource_provider_;
gfx::Size size_;
bool has_transparent_background_;
@@ -150,10 +147,6 @@ class CONTENT_EXPORT CompositorImpl
CompositorClient* client_;
- typedef base::ScopedPtrHashMap<cc::UIResourceId, cc::UIResourceClient>
- UIResourceMap;
- UIResourceMap ui_resource_map_;
-
gfx::NativeWindow root_window_;
// Used locally to track whether a call to LTH::Composite() did result in
diff --git a/content/content_browser.gypi b/content/content_browser.gypi
index 69a3dc0..19a27a0 100644
--- a/content/content_browser.gypi
+++ b/content/content_browser.gypi
@@ -51,6 +51,8 @@
'public/browser/android/synchronous_compositor_client.h',
'public/browser/android/synchronous_compositor.cc',
'public/browser/android/synchronous_compositor.h',
+ 'public/browser/android/ui_resource_client_android.h',
+ 'public/browser/android/ui_resource_provider.h',
'public/browser/ax_event_notification_details.cc',
'public/browser/ax_event_notification_details.h',
'public/browser/blob_handle.h',
@@ -306,6 +308,8 @@
'browser/android/tracing_controller_android.h',
'browser/android/web_contents_observer_android.cc',
'browser/android/web_contents_observer_android.h',
+ 'browser/android/ui_resource_provider_impl.cc',
+ 'browser/android/ui_resource_provider_impl.h',
'browser/appcache/appcache_dispatcher_host.cc',
'browser/appcache/appcache_dispatcher_host.h',
'browser/appcache/appcache_frontend_proxy.cc',
diff --git a/content/public/browser/android/compositor.h b/content/public/browser/android/compositor.h
index 2d8126b..a8f734c 100644
--- a/content/public/browser/android/compositor.h
+++ b/content/public/browser/android/compositor.h
@@ -7,8 +7,8 @@
#include "base/callback.h"
#include "cc/resources/ui_resource_bitmap.h"
-#include "cc/resources/ui_resource_client.h"
#include "content/common/content_export.h"
+#include "content/public/browser/android/ui_resource_provider.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
@@ -25,6 +25,7 @@ class JavaBitmap;
namespace content {
class CompositorClient;
+class UIResourceProvider;
// An interface to the browser-side compositor.
class CONTENT_EXPORT Compositor {
@@ -68,20 +69,8 @@ class CONTENT_EXPORT Compositor {
// Composite *without* having modified the layer tree.
virtual void SetNeedsComposite() = 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;
+ // Returns the UI resource provider associated with the compositor.
+ virtual UIResourceProvider& GetUIResourceProvider() = 0;
protected:
Compositor() {}
diff --git a/content/public/browser/android/compositor_client.h b/content/public/browser/android/compositor_client.h
index 09a12e5..84a263e 100644
--- a/content/public/browser/android/compositor_client.h
+++ b/content/public/browser/android/compositor_client.h
@@ -20,12 +20,6 @@ class CONTENT_EXPORT CompositorClient {
// Tells the client that GL resources were lost and need to be reinitialized.
virtual void DidLoseResources() {}
- // Tells the client that UI resources were lost and need to be reinitialized.
- virtual void DidLoseUIResources() {}
-
- // Mark the UI Resources as being invalid for use.
- virtual void UIResourcesAreInvalid() {}
-
protected:
CompositorClient() {}
virtual ~CompositorClient() {}
diff --git a/content/public/browser/android/ui_resource_client_android.h b/content/public/browser/android/ui_resource_client_android.h
new file mode 100644
index 0000000..83228bd
--- /dev/null
+++ b/content/public/browser/android/ui_resource_client_android.h
@@ -0,0 +1,30 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_PUBLIC_BROWSER_ANDROID_UI_RESOURCE_CLIENT_ANDROID_H_
+#define CONTENT_PUBLIC_BROWSER_ANDROID_UI_RESOURCE_CLIENT_ANDROID_H_
+
+#include "cc/resources/ui_resource_client.h"
+#include "content/common/content_export.h"
+
+namespace content {
+
+class UIResourceProvider;
+
+// Android's UIResourceClient has one extra callback (UIResourceIsInvalid).
+// This signal is intended for the case when the LayerTreeHost is cleared and
+// the user needs to recreate their resources.
+// TODO(powei): This interface can be removed once crbug.com/374906 has been
+// addressed.
+class CONTENT_EXPORT UIResourceClientAndroid : public cc::UIResourceClient {
+ public:
+ // This method indicates that the UI resource the user holds is no longer
+ // valid. The user should not call DeleteUIResource on any resource generated
+ // before this signal.
+ virtual void UIResourceIsInvalid() = 0;
+};
+
+} // namespace content
+
+#endif // CONTENT_PUBLIC_BROWSER_ANDROID_UI_RESOURCE_CLIENT_ANDROID_H_
diff --git a/content/public/browser/android/ui_resource_provider.h b/content/public/browser/android/ui_resource_provider.h
new file mode 100644
index 0000000..38511e1
--- /dev/null
+++ b/content/public/browser/android/ui_resource_provider.h
@@ -0,0 +1,27 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_PUBLIC_BROWSER_ANDROID_UI_RESOURCE_PROVIDER_H_
+#define CONTENT_PUBLIC_BROWSER_ANDROID_UI_RESOURCE_PROVIDER_H_
+
+#include "cc/resources/ui_resource_client.h"
+#include "content/common/content_export.h"
+
+namespace content {
+
+class UIResourceClientAndroid;
+
+class CONTENT_EXPORT UIResourceProvider {
+ public:
+ virtual ~UIResourceProvider() {}
+
+ virtual cc::UIResourceId CreateUIResource(
+ UIResourceClientAndroid* client) = 0;
+
+ virtual void DeleteUIResource(cc::UIResourceId resource_id) = 0;
+};
+
+} // namespace content
+
+#endif // CONTENT_PUBLIC_BROWSER_ANDROID_UI_RESOURCE_PROVIDER_H_