summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ui/gfx/compositor/layer.h1
-rw-r--r--views/layer_helper.cc3
-rw-r--r--views/layer_helper.h6
-rw-r--r--views/view.cc12
-rw-r--r--views/view_unittest.cc29
5 files changed, 48 insertions, 3 deletions
diff --git a/ui/gfx/compositor/layer.h b/ui/gfx/compositor/layer.h
index 5b2418c..00574cc 100644
--- a/ui/gfx/compositor/layer.h
+++ b/ui/gfx/compositor/layer.h
@@ -57,6 +57,7 @@ class Layer {
// Passing NULL will cause the layer to get a texture from its compositor.
void SetTexture(ui::Texture* texture);
+ const ui::Texture* texture() const { return texture_.get(); }
// Resets the bitmap of the texture.
void SetBitmap(const SkBitmap& bitmap, const gfx::Point& origin);
diff --git a/views/layer_helper.cc b/views/layer_helper.cc
index e6b03ce..46cf791 100644
--- a/views/layer_helper.cc
+++ b/views/layer_helper.cc
@@ -16,7 +16,8 @@ LayerHelper::LayerHelper()
: bitmap_needs_updating_(true),
layer_updated_externally_(false),
paint_to_layer_(false),
- property_setter_explicitly_set_(false) {
+ property_setter_explicitly_set_(false),
+ needs_paint_all_(true) {
}
LayerHelper::~LayerHelper() {
diff --git a/views/layer_helper.h b/views/layer_helper.h
index bc6a177..fa26170 100644
--- a/views/layer_helper.h
+++ b/views/layer_helper.h
@@ -73,6 +73,10 @@ class LayerHelper {
}
bool layer_updated_externally() const { return layer_updated_externally_; }
+ // If true the complete bounds of the view needs to be painted.
+ void set_needs_paint_all(bool value) { needs_paint_all_ = value; }
+ bool needs_paint_all() const { return needs_paint_all_; }
+
// Returns true if the layer needs to be used.
bool ShouldPaintToLayer() const;
@@ -101,6 +105,8 @@ class LayerHelper {
bool property_setter_explicitly_set_;
+ bool needs_paint_all_;
+
DISALLOW_COPY_AND_ASSIGN(LayerHelper);
};
diff --git a/views/view.cc b/views/view.cc
index bb9f641..eca7c75 100644
--- a/views/view.cc
+++ b/views/view.cc
@@ -1198,7 +1198,10 @@ void View::PaintToLayer(const gfx::Rect& dirty_region) {
return;
if (layer() && layer_helper_->bitmap_needs_updating()) {
- layer_helper_->set_clip_rect(dirty_region);
+ if (!layer_helper_->needs_paint_all())
+ layer_helper_->set_clip_rect(dirty_region);
+ else
+ layer_helper_->set_needs_paint_all(false);
Paint(NULL);
layer_helper_->set_clip_rect(gfx::Rect());
} else {
@@ -1493,6 +1496,12 @@ void View::BoundsChanged(const gfx::Rect& previous_bounds) {
} else {
layer_helper_->property_setter()->SetBounds(layer(), bounds_);
}
+ if (previous_bounds.size() != bounds_.size() &&
+ !layer_helper_->layer_updated_externally()) {
+ // If our bounds have changed then we need to update the complete
+ // texture.
+ layer_helper_->set_needs_paint_all(true);
+ }
} else if (GetCompositor()) {
// If our bounds have changed, then any descendant layer bounds may
// have changed. Update them accordingly.
@@ -1687,6 +1696,7 @@ void View::CreateLayer() {
if (ancestor_with_layer)
ancestor_with_layer->layer()->Add(layer());
layer_helper_->set_bitmap_needs_updating(true);
+ layer_helper_->set_needs_paint_all(true);
for (int i = 0, count = child_count(); i < count; ++i)
GetChildViewAt(i)->MoveLayerToParent(layer(), gfx::Point());
diff --git a/views/view_unittest.cc b/views/view_unittest.cc
index 29b312f..bd6a030 100644
--- a/views/view_unittest.cc
+++ b/views/view_unittest.cc
@@ -2267,22 +2267,36 @@ class TestTexture : public ui::Texture {
static void reset_live_count() { live_count_ = 0; }
static int live_count() { return live_count_; }
+ // Bounds of the last bitmap passed to SetBitmap.
+ const gfx::Rect& bounds_of_last_paint() const {
+ return bounds_of_last_paint_;
+ }
+
// ui::Texture
virtual void SetBitmap(const SkBitmap& bitmap,
const gfx::Point& origin,
- const gfx::Size& overall_size) OVERRIDE {}
+ const gfx::Size& overall_size) OVERRIDE;
virtual void Draw(const ui::Transform& transform) OVERRIDE {}
private:
// Number of live instances.
static int live_count_;
+ gfx::Rect bounds_of_last_paint_;
+
DISALLOW_COPY_AND_ASSIGN(TestTexture);
};
// static
int TestTexture::live_count_ = 0;
+void TestTexture::SetBitmap(const SkBitmap& bitmap,
+ const gfx::Point& origin,
+ const gfx::Size& overall_size) {
+ bounds_of_last_paint_.SetRect(
+ origin.x(), origin.y(), bitmap.width(), bitmap.height());
+}
+
class TestCompositor : public ui::Compositor {
public:
TestCompositor() {}
@@ -2536,6 +2550,19 @@ TEST_F(ViewLayerTest, ToggleVisibilityWithTransform) {
EXPECT_EQ(2.0f, view->GetTransform().matrix()[0]);
}
+// Verifies that the complete bounds of a texture are updated if the texture
+// needs to be refreshed and paint with a clip is invoked.
+TEST_F(ViewLayerTest, PaintAll) {
+ View* view = widget()->GetRootView();
+ view->SetBounds(0, 0, 200, 200);
+ widget()->OnNativeWidgetPaintAccelerated(gfx::Rect(0, 0, 1, 1));
+ ASSERT_TRUE(view->layer() != NULL);
+ const TestTexture* texture =
+ static_cast<const TestTexture*>(view->layer()->texture());
+ ASSERT_TRUE(texture != NULL);
+ EXPECT_EQ(view->GetLocalBounds(), texture->bounds_of_last_paint());
+}
+
#endif // VIEWS_COMPOSITOR || TOUCH_UI
} // namespace views