summaryrefslogtreecommitdiffstats
path: root/ui/compositor
diff options
context:
space:
mode:
authordanakj <danakj@chromium.org>2015-04-03 12:11:29 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-03 19:11:55 +0000
commitaea775fbda5267c73941aa44a8c08eea015eadc7 (patch)
treeb4d6db0fa97a795ec73b1ec19b731c16a16cae11 /ui/compositor
parent968100467a776d8b6881966fa19caef5e1dee944 (diff)
downloadchromium_src-aea775fbda5267c73941aa44a8c08eea015eadc7.zip
chromium_src-aea775fbda5267c73941aa44a8c08eea015eadc7.tar.gz
chromium_src-aea775fbda5267c73941aa44a8c08eea015eadc7.tar.bz2
Move PaintContext from views::View to ui::.
This will let LayerDelegate take a ui::PaintContext instead of a gfx::Canvas. R=sky BUG=466426 Review URL: https://codereview.chromium.org/1058663002 Cr-Commit-Position: refs/heads/master@{#323789}
Diffstat (limited to 'ui/compositor')
-rw-r--r--ui/compositor/BUILD.gn1
-rw-r--r--ui/compositor/compositor.gyp1
-rw-r--r--ui/compositor/paint_context.h97
3 files changed, 99 insertions, 0 deletions
diff --git a/ui/compositor/BUILD.gn b/ui/compositor/BUILD.gn
index d76b3af..f9a7785 100644
--- a/ui/compositor/BUILD.gn
+++ b/ui/compositor/BUILD.gn
@@ -43,6 +43,7 @@ component("compositor") {
"layer_tree_owner.cc",
"layer_tree_owner.h",
"layer_type.h",
+ "paint_context.h",
"reflector.cc",
"reflector.h",
"scoped_animation_duration_scale_mode.cc",
diff --git a/ui/compositor/compositor.gyp b/ui/compositor/compositor.gyp
index 5cb11da..fa0d768 100644
--- a/ui/compositor/compositor.gyp
+++ b/ui/compositor/compositor.gyp
@@ -61,6 +61,7 @@
'layer_tree_owner.cc',
'layer_tree_owner.h',
'layer_type.h',
+ 'paint_context.h',
'reflector.cc',
'reflector.h',
'scoped_animation_duration_scale_mode.cc',
diff --git a/ui/compositor/paint_context.h b/ui/compositor/paint_context.h
new file mode 100644
index 0000000..ceb5d25
--- /dev/null
+++ b/ui/compositor/paint_context.h
@@ -0,0 +1,97 @@
+// Copyright 2015 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 UI_COMPOSITOR_PAINT_CONTEXT_H_
+#define UI_COMPOSITOR_PAINT_CONTEXT_H_
+
+#include "base/logging.h"
+#include "ui/gfx/geometry/rect.h"
+
+namespace gfx {
+class Canvas;
+}
+
+namespace ui {
+
+class PaintContext {
+ public:
+ // Construct a PaintContext that can only re-paint the area in the
+ // |invalidation|.
+ PaintContext(gfx::Canvas* canvas, const gfx::Rect& invalidation)
+ : canvas_(canvas), invalidation_(invalidation) {
+#if DCHECK_IS_ON()
+ root_visited_ = nullptr;
+#endif
+ }
+
+ // Construct a PaintContext that will re-paint everything (no consideration
+ // for invalidation).
+ explicit PaintContext(gfx::Canvas* canvas)
+ : PaintContext(canvas, gfx::Rect()) {}
+
+ ~PaintContext() {}
+
+ // Clone a PaintContext with an additional |offset|.
+ PaintContext CloneWithPaintOffset(const gfx::Vector2d& offset) const {
+ return PaintContext(*this, offset);
+ }
+
+ // Clone a PaintContext that has no consideration for invalidation.
+ PaintContext CloneWithoutInvalidation() const {
+ return PaintContext(canvas_);
+ }
+
+ // TODO(danakj): Remove this once everything is painting to display lists.
+ gfx::Canvas* canvas() const { return canvas_; }
+
+ // When true, IsRectInvalidated() can be called, otherwise its result would be
+ // invalid.
+ bool CanCheckInvalidated() const { return !invalidation_.IsEmpty(); }
+
+ // When true, the |bounds| touches an invalidated area, so should be
+ // re-painted. When false, re-painting can be skipped. Bounds should be in
+ // the local space with offsets up to the painting root in the PaintContext.
+ bool IsRectInvalidated(const gfx::Rect& bounds) const {
+ DCHECK(CanCheckInvalidated());
+ return invalidation_.Intersects(bounds + offset_);
+ }
+
+#if DCHECK_IS_ON()
+ void Visited(void* visited) const {
+ if (!root_visited_)
+ root_visited_ = visited;
+ }
+ void* RootVisited() const { return root_visited_; }
+ const gfx::Vector2d& PaintOffset() const { return offset_; }
+#endif
+
+ private:
+ // Clone a PaintContext with an additional |offset|.
+ PaintContext(const PaintContext& other, const gfx::Vector2d& offset)
+ : canvas_(other.canvas_),
+ invalidation_(other.invalidation_),
+ offset_(other.offset_ + offset) {
+#if DCHECK_IS_ON()
+ root_visited_ = other.root_visited_;
+#endif
+ }
+
+ gfx::Canvas* canvas_;
+ // Invalidation in the space of the paint root (ie the space of the layer
+ // backing the paint taking place).
+ gfx::Rect invalidation_;
+ // Offset from the PaintContext to the space of the paint root and the
+ // |invalidation_|.
+ gfx::Vector2d offset_;
+
+#if DCHECK_IS_ON()
+ // Used to verify that the |invalidation_| is only used to compare against
+ // rects in the same space.
+ mutable void* root_visited_;
+#endif
+};
+
+} // namespace ui
+
+#endif // UI_COMPOSITOR_PAINT_CONTEXT_H_