Index: ui/compositor/paint_context.h |
diff --git a/ui/compositor/paint_context.h b/ui/compositor/paint_context.h |
index bc17c50f46bd3b00cee3ce9e83229b04704d12a9..affbc28468f4fe9d06b0c7ec2ef45071eda3a24d 100644 |
--- a/ui/compositor/paint_context.h |
+++ b/ui/compositor/paint_context.h |
@@ -25,14 +25,29 @@ class TransformRecorder; |
class COMPOSITOR_EXPORT PaintContext { |
public: |
- // Construct a PaintContext that may only re-paint the area in the |
- // |invalidation|. |
+ enum class 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, |
danakj
2017/07/19 17:00:59
enums should be kFoo style now
malaykeshav
2017/07/21 00:12:33
Done
|
+ |
+ // Scales the context based on the effective dsf. This may lead to minor |
+ // distortion during scaling due to edge snapping. |
+ 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. |
+ PaintContext(const PaintContext& other, |
+ const gfx::Rect& bounds, |
+ const gfx::Rect& parent_bounds, |
+ ScaleType 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 |paint_recording_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(paint_recording_bounds_); |
} |
#if DCHECK_IS_ON() |
@@ -60,11 +74,26 @@ class COMPOSITOR_EXPORT PaintContext { |
root_visited_ = visited; |
} |
void* RootVisited() const { return root_visited_; } |
- const gfx::Vector2d& PaintOffset() const { return offset_; } |
+ const gfx::Point& PaintOffset() const { |
+ return paint_recording_bounds_.origin(); |
+ } |
#endif |
const gfx::Rect& InvalidationForTesting() const { return invalidation_; } |
+ bool IsPixelCanvas() const; |
+ |
+ const gfx::Size& paint_recording_size() const { |
+ return paint_recording_bounds_.size(); |
+ } |
+ const gfx::Rect& paint_recording_bounds() const { |
+ return paint_recording_bounds_; |
+ } |
+ |
+ gfx::PointF paint_recording_scale() const { |
+ return gfx::PointF(paint_recording_scale_x_, paint_recording_scale_y_); |
+ } |
+ |
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 |
@@ -81,19 +110,36 @@ class COMPOSITOR_EXPORT PaintContext { |
// containing layer. |
gfx::Rect ToLayerSpaceBounds(const gfx::Size& size_in_context) const; |
- // Returns the given rect translated by the layer space offset. |
- gfx::Rect ToLayerSpaceRect(const gfx::Rect& rect) const; |
+ // Given the DIP |size|, this function updates the paint recording scales. |
+ void ComputePaintRecordingScales(const gfx::Size& size); |
+ |
+ // Scales the |child_bounds| to its recording bounds based on the |
+ // |device_scale_factor_|. The recording bounds are snapped to the |
+ // |parent bound|'s right and/or bottom edge if required. |
danakj
2017/07/19 17:00:59
|parent_bounds|'
malaykeshav
2017/07/21 00:12:33
Done
|
+ // This function returns |child_bounds| as is if pixel canvas is disabled. |
danakj
2017/07/19 17:00:59
"as is if" reads a bit awkward, maybe reorder thin
malaykeshav
2017/07/21 00:12:33
Done
|
+ gfx::Rect GetSnappedRecordingBounds(const gfx::Rect& parent_bounds, |
+ 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_; |
+ // The scale at which the paint commands are recorded at. Due to the decimal |
+ // rounding and snapping to edges during scaling operations, the effective |
+ // paint recording scale may end up being slightly different between the x and |
+ // y axis. |
+ float paint_recording_scale_x_; |
+ float paint_recording_scale_y_; |
// 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_; |
- // Offset from the PaintContext to the space of the paint root and the |
- // |invalidation_|. |
- gfx::Vector2d offset_; |
+ // Paint Recording bounds for this paint context. The offset is relative to |
+ // the paint root. |
+ const gfx::Rect paint_recording_bounds_; |
+ // The |scale_type| tells the context how it needs to perform scaling when |
+ // pixel canvas is enabled. |
+ ScaleType scale_type_ = ScaleType::SCALE_TO_SCALE_FACTOR; |
#if DCHECK_IS_ON() |
// Used to verify that the |invalidation_| is only used to compare against |