Commit a3084d7e authored by danakj's avatar danakj Committed by Commit bot

views: Use ClipTransformRecorder to access canvas in ProfileChooserView

Go through a recorder instead of getting the canvas() from the
PaintContext, so this will continue to work when the PaintContext
is backed by a DisplayItemList instead of a canvas.

R=sky
BUG=466426

Review URL: https://codereview.chromium.org/1062813004

Cr-Commit-Position: refs/heads/master@{#323965}
parent edc54e0f
......@@ -43,6 +43,7 @@
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/compositor/clip_transform_recorder.h"
#include "ui/compositor/paint_context.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/image/image.h"
......@@ -260,7 +261,8 @@ class EditableProfilePhoto : public views::LabelButton {
void PaintChildren(const ui::PaintContext& context) override {
// Display any children (the "change photo" overlay) as a circle.
context.canvas()->ClipPath(circular_mask_, true);
ui::ClipTransformRecorder clip_transform_recorder(context);
clip_transform_recorder.ClipPathWithAntiAliasing(circular_mask_);
View::PaintChildren(context);
}
......
......@@ -7,35 +7,37 @@
#include "ui/compositor/paint_context.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/path.h"
#include "ui/gfx/transform.h"
namespace ui {
ClipTransformRecorder::ClipTransformRecorder(const PaintContext& context,
const gfx::Rect& clip_rect)
ClipTransformRecorder::ClipTransformRecorder(const PaintContext& context)
: canvas_(context.canvas()) {
canvas_->Save();
canvas_->ClipRect(clip_rect);
}
ClipTransformRecorder::ClipTransformRecorder(const PaintContext& context,
const gfx::Transform& transform)
: canvas_(context.canvas()) {
canvas_->Save();
canvas_->Transform(transform);
ClipTransformRecorder::~ClipTransformRecorder() {
canvas_->Restore();
}
ClipTransformRecorder::ClipTransformRecorder(const PaintContext& context,
const gfx::Rect& clip_rect,
const gfx::Transform& transform)
: canvas_(context.canvas()) {
canvas_->Save();
void ClipTransformRecorder::ClipRect(const gfx::Rect& clip_rect) {
canvas_->ClipRect(clip_rect);
canvas_->Transform(transform);
}
ClipTransformRecorder::~ClipTransformRecorder() {
canvas_->Restore();
void ClipTransformRecorder::ClipPath(const gfx::Path& clip_path) {
bool anti_alias = false;
canvas_->ClipPath(clip_path, anti_alias);
}
void ClipTransformRecorder::ClipPathWithAntiAliasing(
const gfx::Path& clip_path) {
bool anti_alias = true;
canvas_->ClipPath(clip_path, anti_alias);
}
void ClipTransformRecorder::Transform(const gfx::Transform& transform) {
canvas_->Transform(transform);
}
} // namespace ui
......@@ -10,6 +10,7 @@
namespace gfx {
class Canvas;
class Path;
class Rect;
class Transform;
}
......@@ -24,15 +25,14 @@ class PaintContext;
// be clipped/transformed.
class COMPOSITOR_EXPORT ClipTransformRecorder {
public:
ClipTransformRecorder(const PaintContext& context,
const gfx::Rect& clip_rect);
ClipTransformRecorder(const PaintContext& context,
const gfx::Transform& transform);
ClipTransformRecorder(const PaintContext& context,
const gfx::Rect& clip_rect,
const gfx::Transform& transform);
explicit ClipTransformRecorder(const PaintContext& context);
~ClipTransformRecorder();
void ClipRect(const gfx::Rect& clip_rect);
void ClipPath(const gfx::Path& clip_path);
void ClipPathWithAntiAliasing(const gfx::Path& clip_path);
void Transform(const gfx::Transform& transform);
private:
gfx::Canvas* canvas_;
......
......@@ -780,6 +780,8 @@ void View::Paint(const ui::PaintContext& parent_context) {
// rather than relative to its parent.
scoped_ptr<ui::ClipTransformRecorder> clip_transform_recorder;
if (!layer()) {
clip_transform_recorder.reset(new ui::ClipTransformRecorder(context));
// Set the clip rect to the bounds of this View. Note that the X (or left)
// position we pass to ClipRect takes into consideration whether or not the
// View uses a right-to-left layout so that we paint the View in its
......@@ -789,6 +791,7 @@ void View::Paint(const ui::PaintContext& parent_context) {
if (parent_)
clip_rect_in_parent.set_x(
parent_->GetMirroredXForRect(clip_rect_in_parent));
clip_transform_recorder->ClipRect(clip_rect_in_parent);
// Translate the graphics such that 0,0 corresponds to where
// this View is located relative to its parent.
......@@ -797,9 +800,7 @@ void View::Paint(const ui::PaintContext& parent_context) {
transform_from_parent.Translate(offset_from_parent.x(),
offset_from_parent.y());
transform_from_parent.PreconcatTransform(GetTransform());
clip_transform_recorder = make_scoped_ptr(new ui::ClipTransformRecorder(
context, clip_rect_in_parent, transform_from_parent));
clip_transform_recorder->Transform(transform_from_parent);
}
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment