summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ui/gfx/compositor/layer.cc7
-rw-r--r--ui/gfx/compositor/layer.h3
-rw-r--r--views/view.cc28
-rw-r--r--views/view.h14
4 files changed, 52 insertions, 0 deletions
diff --git a/ui/gfx/compositor/layer.cc b/ui/gfx/compositor/layer.cc
index b722c12..5779e52 100644
--- a/ui/gfx/compositor/layer.cc
+++ b/ui/gfx/compositor/layer.cc
@@ -39,6 +39,13 @@ void Layer::Remove(Layer* child) {
child->parent_ = NULL;
}
+void Layer::SetTexture(ui::Texture* texture) {
+ if (texture == NULL)
+ texture_ = compositor_->CreateTexture();
+ else
+ texture_ = texture;
+}
+
void Layer::SetBitmap(const SkBitmap& bitmap, const gfx::Point& origin) {
texture_->SetBitmap(bitmap, origin, bounds_.size());
}
diff --git a/ui/gfx/compositor/layer.h b/ui/gfx/compositor/layer.h
index 72faad1..5b2418c 100644
--- a/ui/gfx/compositor/layer.h
+++ b/ui/gfx/compositor/layer.h
@@ -55,6 +55,9 @@ class Layer {
const Compositor* compositor() const { return compositor_; }
Compositor* compositor() { return compositor_; }
+ // Passing NULL will cause the layer to get a texture from its compositor.
+ void SetTexture(ui::Texture* texture);
+
// Resets the bitmap of the texture.
void SetBitmap(const SkBitmap& bitmap, const gfx::Point& origin);
diff --git a/views/view.cc b/views/view.cc
index 0994639..84bb6ea 100644
--- a/views/view.cc
+++ b/views/view.cc
@@ -108,6 +108,7 @@ View::View()
needs_layout_(true),
flip_canvas_on_paint_for_rtl_ui_(false),
layer_needs_updating_(true),
+ layer_updated_externally_(false),
paint_to_layer_(false),
accelerator_registration_delayed_(false),
accelerator_focus_manager_(NULL),
@@ -1218,6 +1219,31 @@ void View::PaintToLayer(const gfx::Rect& dirty_region) {
void View::OnWillCompositeLayer() {
}
+bool View::SetExternalTexture(ui::Texture* texture) {
+ // A little heavy-handed -- it should be that each child has it's own layer.
+ // The desired use case is where there are no children.
+ DCHECK_EQ(child_count(), 0);
+
+ bool use_external = (texture != NULL);
+ if (use_external != paint_to_layer_)
+ SetPaintToLayer(use_external);
+ else if (use_external && !layer_.get())
+ CreateLayer();
+
+ if (use_external && !layer_.get())
+ return false;
+
+ layer_updated_externally_ = use_external;
+ layer_needs_updating_ = !use_external;
+ if (layer_.get())
+ layer_->SetTexture(texture);
+
+ if (IsVisible())
+ SchedulePaintInternal(GetLocalBounds());
+
+ return true;
+}
+
const ui::Compositor* View::GetCompositor() const {
return parent_ ? parent_->GetCompositor() : NULL;
}
@@ -1617,6 +1643,8 @@ bool View::ShouldPaintToLayer() const {
}
void View::MarkLayerDirty() {
+ if (layer_updated_externally_)
+ return;
View* owner = this;
while (!((owner->transform_.get() && owner->transform_->HasChange()) ||
owner->paint_to_layer_) && owner->parent_)
diff --git a/views/view.h b/views/view.h
index 24f9ca7..e510d53 100644
--- a/views/view.h
+++ b/views/view.h
@@ -34,6 +34,7 @@ namespace ui {
struct AccessibleViewState;
class Compositor;
class Layer;
+class Texture;
class ThemeProvider;
class Transform;
#if defined(TOUCH_UI)
@@ -965,6 +966,15 @@ class View : public AcceleratorTarget {
// layer is rendered by the compositor.
virtual void OnWillCompositeLayer();
+ // This creates a layer for the view, if one does not exist. It then
+ // passes the texture to a layer associated with the view. While an external
+ // texture is set, the view will not update the layer contents.
+ //
+ // Passing NULL resets to default behavior.
+ //
+ // Returns false if it cannot create a layer to which to assign the texture.
+ bool SetExternalTexture(ui::Texture* texture);
+
// Returns the Compositor.
virtual const ui::Compositor* GetCompositor() const;
virtual ui::Compositor* GetCompositor();
@@ -1370,6 +1380,10 @@ class View : public AcceleratorTarget {
// Is the layer out of date?
bool layer_needs_updating_;
+ // Is the texture backing the layer being updated externally?
+ // (i.e. by the GPU process when rendering 3D CSS)
+ bool layer_updated_externally_;
+
// Should we paint to a layer? See description above setter for details.
bool paint_to_layer_;