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

Unified Diff: ui/views/paint_info.h

Issue 2877483003: Implements core logic for Pixel Canvas (Closed)
Patch Set: Sync with ToT Created 3 years, 4 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
« no previous file with comments | « ui/views/controls/textfield/textfield.cc ('k') | ui/views/paint_info.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/paint_info.h
diff --git a/ui/views/paint_info.h b/ui/views/paint_info.h
new file mode 100644
index 0000000000000000000000000000000000000000..8545f04e959ac36045852c756c49018ccd9e1777
--- /dev/null
+++ b/ui/views/paint_info.h
@@ -0,0 +1,119 @@
+// Copyright 2017 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_VIEWS_PAINT_INFO_H_
+#define UI_VIEWS_PAINT_INFO_H_
+
+#include "ui/compositor/paint_context.h"
+#include "ui/gfx/geometry/rect.h"
+#include "ui/views/views_export.h"
+
+namespace views {
+
+// This class manages the context required during View::Paint(). It is
+// responsible for setting the paint recording size and the paint recording
+// scale factors for an individual View.
+// Each PaintInfo instance has paint recording offset relative to a root
+// PaintInfo.
+// All coordinates are in paint recording space. If pixel canvas is enabled this
+// essentially becomes pixel coordinate space.
+class VIEWS_EXPORT PaintInfo {
+ public:
+ enum class ScaleType {
+ // Scale the recordings by the default dsf. Use this if you don't want any
+ // form of distortion during scaling.
+ kScaleToScaleFactor = 0,
+
+ // Scale the recordings based on the effective dsf. This may lead to minor
+ // distortion during scaling due to edge snapping.
+ kScaleToFit
+ };
+
+ // Instantiates a root PaintInfo. This should only be initialized at the Paint
+ // root, ie., a layer or the root of a widget.
+ static PaintInfo CreateRootPaintInfo(const ui::PaintContext& root_context,
+ const gfx::Size& size);
+
+ // Instantiate a child PaintInfo instance. All bounds for this object are
+ // relative to its root PaintInfo.
+ static PaintInfo CreateChildPaintInfo(const PaintInfo& parent_paint_info,
+ const gfx::Rect& bounds,
+ const gfx::Size& parent_size,
+ ScaleType scale_type);
+
+ // Clones a given paint info, |other|, without the invalidation from its
+ // PaintContext.
+ static PaintInfo ClonePaintInfo(const PaintInfo& other);
+
+ PaintInfo(const PaintInfo& other);
+ ~PaintInfo();
+
+ // Returns true if all paint commands are recorded at pixel size.
+ bool IsPixelCanvas() const;
+
+ const ui::PaintContext& context() const {
+ return root_context_ ? *root_context_ : context_;
+ }
+
+ gfx::Vector2d offset_from_root() const {
+ return paint_recording_bounds_.OffsetFromOrigin();
+ }
+
+ const gfx::Vector2d& offset_from_parent() const {
+ return offset_from_parent_;
+ }
+
+ float paint_recording_scale_x() const { return paint_recording_scale_x_; }
+
+ float paint_recording_scale_y() const { return paint_recording_scale_y_; }
+
+ const gfx::Size& paint_recording_size() const {
+ return paint_recording_bounds_.size();
+ }
+
+ const gfx::Rect& paint_recording_bounds() const {
+ return paint_recording_bounds_;
+ }
+
+ private:
+ friend class PaintInfoTest;
+
+ PaintInfo(const ui::PaintContext& root_context, const gfx::Size& size);
+ PaintInfo(const PaintInfo& parent_paint_info,
+ const gfx::Rect& bounds,
+ const gfx::Size& parent_size,
+ ScaleType scale_type);
+ PaintInfo(const PaintInfo& other,
+ ui::PaintContext::CloneWithoutInvalidation c);
+
+ // Scales the |child_bounds| to its recording bounds based on the
+ // |context.device_scale_factor()|. The recording bounds are snapped to the
+ // parent's right and/or bottom edge if required.
+ // If pixel canvas is disabled, this function returns |child_bounds| as is.
+ gfx::Rect GetSnappedRecordingBounds(const gfx::Size& parent_size,
+ const gfx::Rect& child_bounds) const;
+
+ // The scale at which the paint commands are recorded at. Due to the decimal
+ // rounding and snapping to edges during the scale operation, 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_;
+
+ // Paint Recording bounds of the view. The offset is relative to the root
+ // PaintInfo.
+ const gfx::Rect paint_recording_bounds_;
+
+ // Offset relative to the parent view's paint recording bounds. Returns 0
+ // offset if this is the root.
+ gfx::Vector2d offset_from_parent_;
+
+ // Compositor PaintContext associated with the view this object belongs to.
+ ui::PaintContext context_;
+ const ui::PaintContext* root_context_;
+};
+
+} // namespace views
+
+#endif // UI_VIEWS_PAINT_INFO_H_
« no previous file with comments | « ui/views/controls/textfield/textfield.cc ('k') | ui/views/paint_info.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698