Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Unified Diff: ui/compositor/paint_context.h

Issue 2877483003: Implements core logic for Pixel Canvas (Closed)
Patch Set: nits Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/compositor/paint_context.h
diff --git a/ui/compositor/paint_context.h b/ui/compositor/paint_context.h
index bc17c50f46bd3b00cee3ce9e83229b04704d12a9..78e5e1209c07f11ea9c2f89709974409636efe43 100644
--- a/ui/compositor/paint_context.h
+++ b/ui/compositor/paint_context.h
@@ -9,6 +9,7 @@
#include "base/logging.h"
#include "base/macros.h"
+#include "cc/paint/display_item_list.h"
#include "cc/paint/paint_recorder.h"
#include "ui/compositor/compositor_export.h"
#include "ui/gfx/geometry/rect.h"
@@ -25,14 +26,28 @@ class TransformRecorder;
class COMPOSITOR_EXPORT PaintContext {
public:
- // Construct a PaintContext that may only re-paint the area in the
- // |invalidation|.
+ enum ScaleType {
+ // Scales the context by the default dsf. Use this if you dont want any form
+ // of distortion during scaling.
+ SCALE_TO_SCALE_FACTOR = 0,
+
+ // Scales the context based on the effective dsf. This may lead to minor
+ // distortion during scaling.
+ SCALE_TO_FIT
+ };
+
+ // Construct a PaintContext of given size that may only re-paint the area in
+ // the |invalidation|.
PaintContext(cc::DisplayItemList* list,
float device_scale_factor,
- const gfx::Rect& invalidation);
+ const gfx::Rect& invalidation,
+ const gfx::Size& size);
- // Clone a PaintContext with an additional |offset|.
- PaintContext(const PaintContext& other, const gfx::Vector2d& offset);
+ // Clone a PaintContext with different |bounds| that has some offset from its
+ // parent. |scale_type| should be from |ScaleType|.
+ PaintContext(const PaintContext& other,
+ const gfx::Rect& bounds,
+ int scale_type);
// Clone a PaintContext that has no consideration for invalidation.
enum CloneWithoutInvalidation {
@@ -42,16 +57,15 @@ class COMPOSITOR_EXPORT PaintContext {
~PaintContext();
- // When true, IsRectInvalid() can be called, otherwise its result would be
+ // When true, ShouldRepaint() can be called, otherwise its result would be
// invalid.
- bool CanCheckInvalid() 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 IsRectInvalid(const gfx::Rect& bounds) const {
- DCHECK(CanCheckInvalid());
- return invalidation_.Intersects(bounds + offset_);
+ bool CanCheckRepaint() const { return !invalidation_.IsEmpty(); }
+
+ // When true, the |pixel_bounds_| touches an invalidated area, so should be
+ // re-painted. When false, re-painting can be skipped.
+ bool ShouldRepaint() const {
+ DCHECK(CanCheckRepaint());
+ return invalidation_.Intersects(gfx::Rect(pixel_size()) + offset_);
}
#if DCHECK_IS_ON()
@@ -65,6 +79,23 @@ class COMPOSITOR_EXPORT PaintContext {
const gfx::Rect& InvalidationForTesting() const { return invalidation_; }
+ bool IsPixelCanvas() const { return list_ && list_->pixel_canvas_enabled(); }
+
+ // Due to decimal rounding during scaling operations the effective device
+ // scale factor ends up being different from |device_scale_factor_|. To
+ // convert any DIP measurement to its corresponding measurement on the canvas,
+ // the following scales must be used.
+ float effective_scale_factor_x() const;
+ float effective_scale_factor_y() const;
+
+ const gfx::Size& pixel_size() const { return pixel_bounds_.size(); }
+ const gfx::Rect& pixel_bounds() const { return pixel_bounds_; }
+
+ // Scales the given DIP measurement to their corresponding canvas measurement
+ // using the effective scale factors and corner point scaling logic.
+ // Returns the measurements as is, if pixel canvas is disabled.
+ gfx::Size ScaleToCorneredPixelSize(const gfx::Size& size) const;
+
private:
// The Recorder classes need access to the internal canvas and friends, but we
// don't want to expose them on this class so that people must go through the
@@ -84,16 +115,31 @@ class COMPOSITOR_EXPORT PaintContext {
// Returns the given rect translated by the layer space offset.
gfx::Rect ToLayerSpaceRect(const gfx::Rect& rect) const;
+ // Scales the |child_bounds| to its pixel bounds based on the
+ // |device_scale_factor_|. The pixel bounds are snapped to the parent bound's
+ // right and/or bottom edge if required.
+ // This function returns |child_bounds| as is if pixel canvas is disabled.
+ gfx::Rect GetSnappedPixelBounds(const gfx::Rect& child_bounds) const;
+
cc::DisplayItemList* list_;
// The device scale of the frame being painted. Used to determine which bitmap
// resources to use in the frame.
float device_scale_factor_;
// Invalidation in the space of the paint root (ie the space of the layer
- // backing the paint taking place).
+ // backing the paint taking place). This is in pixel size if pixel canvas is
+ // enabled.
gfx::Rect invalidation_;
+ // Bounds of the paint context.
+ gfx::Rect bounds_;
+ // Bounds of paint context in exact pixel size. This will have the same value
+ // as |bounds_| if pixel canvas is disabled.
+ gfx::Rect pixel_bounds_;
// Offset from the PaintContext to the space of the paint root and the
- // |invalidation_|.
+ // |invalidation_|. This is in pixels if pixel canvas is enabled.
gfx::Vector2d offset_;
+ // The |scale_type| tells the context how it needs to perform scaling when
+ // pixel canvas is enabled.
+ int scale_type_ = SCALE_TO_SCALE_FACTOR;
#if DCHECK_IS_ON()
// Used to verify that the |invalidation_| is only used to compare against

Powered by Google App Engine
This is Rietveld 408576698