Commit 533d7341 authored by danakj's avatar danakj Committed by Commit bot

ui: Use a PaintRecorder to access the Canvas for painting.

Don't use the canvas() from the PaintContext so that we can have the
PaintContext be backed by a DisplayItemList instead in the future.
Access to the Canvas should be done through a PaintRecorder.

R=sadrul
BUG=466426

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

Cr-Commit-Position: refs/heads/master@{#324137}
parent 2c1f7765
......@@ -29,7 +29,7 @@
#include "ui/compositor/compositor_observer.h"
#include "ui/compositor/debug_utils.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/paint_context.h"
#include "ui/compositor/paint_recorder.h"
#include "ui/compositor/test/in_process_context_factory.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/rect.h"
......@@ -63,7 +63,8 @@ class ColoredLayer : public Layer, public LayerDelegate {
// Overridden from LayerDelegate:
void OnPaintLayer(const ui::PaintContext& context) override {
if (draw_) {
context.canvas()->DrawColor(color_);
ui::PaintRecorder recorder(context);
recorder.canvas()->DrawColor(color_);
}
}
......
......@@ -19,7 +19,7 @@
#include "ui/aura/window_delegate.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/hit_test.h"
#include "ui/compositor/paint_context.h"
#include "ui/compositor/paint_recorder.h"
#include "ui/compositor/test/in_process_context_factory.h"
#include "ui/events/event.h"
#include "ui/gfx/canvas.h"
......@@ -64,15 +64,15 @@ class DemoWindowDelegate : public aura::WindowDelegate {
bool CanFocus() override { return true; }
void OnCaptureLost() override {}
void OnPaint(const ui::PaintContext& context) override {
gfx::Canvas* canvas = context.canvas();
canvas->DrawColor(color_, SkXfermode::kSrc_Mode);
ui::PaintRecorder recorder(context);
recorder.canvas()->DrawColor(color_, SkXfermode::kSrc_Mode);
gfx::Rect r;
canvas->GetClipBounds(&r);
recorder.canvas()->GetClipBounds(&r);
// Fill with a non-solid color so that the compositor will exercise its
// texture upload path.
while (!r.IsEmpty()) {
r.Inset(2, 2);
canvas->FillRect(r, color_, SkXfermode::kXor_Mode);
recorder.canvas()->FillRect(r, color_, SkXfermode::kXor_Mode);
}
}
void OnDeviceScaleFactorChanged(float device_scale_factor) override {}
......
......@@ -7,7 +7,7 @@
#include "base/strings/stringprintf.h"
#include "ui/aura/window.h"
#include "ui/base/hit_test.h"
#include "ui/compositor/paint_context.h"
#include "ui/compositor/paint_recorder.h"
#include "ui/events/event.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/path.h"
......@@ -122,7 +122,8 @@ void ColorTestWindowDelegate::OnWindowDestroyed(Window* window) {
}
void ColorTestWindowDelegate::OnPaint(const ui::PaintContext& context) {
context.canvas()->DrawColor(color_, SkXfermode::kSrc_Mode);
ui::PaintRecorder recorder(context);
recorder.canvas()->DrawColor(color_, SkXfermode::kSrc_Mode);
}
////////////////////////////////////////////////////////////////////////////////
......
......@@ -31,7 +31,6 @@
#include "ui/base/hit_test.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_animation_observer.h"
#include "ui/compositor/paint_context.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/compositor/test/test_layers.h"
......@@ -2841,47 +2840,6 @@ TEST_F(WindowTest, OnWindowHierarchyChange) {
namespace {
// Tracks the number of times paint is invoked along with what the clip and
// translate was.
class PaintWindowDelegate : public TestWindowDelegate {
public:
PaintWindowDelegate() : paint_count_(0) {}
~PaintWindowDelegate() override {}
const gfx::Rect& most_recent_paint_clip_bounds() const {
return most_recent_paint_clip_bounds_;
}
const gfx::Vector2d& most_recent_paint_matrix_offset() const {
return most_recent_paint_matrix_offset_;
}
void clear_paint_count() { paint_count_ = 0; }
int paint_count() const { return paint_count_; }
// TestWindowDelegate::
void OnPaint(const ui::PaintContext& context) override {
gfx::Canvas* canvas = context.canvas();
paint_count_++;
canvas->GetClipBounds(&most_recent_paint_clip_bounds_);
const SkMatrix& matrix = canvas->sk_canvas()->getTotalMatrix();
most_recent_paint_matrix_offset_ = gfx::Vector2d(
SkScalarFloorToInt(matrix.getTranslateX()),
SkScalarFloorToInt(matrix.getTranslateY()));
}
private:
int paint_count_;
gfx::Rect most_recent_paint_clip_bounds_;
gfx::Vector2d most_recent_paint_matrix_offset_;
DISALLOW_COPY_AND_ASSIGN(PaintWindowDelegate);
};
} // namespace
namespace {
class TestLayerAnimationObserver : public ui::LayerAnimationObserver {
public:
TestLayerAnimationObserver()
......
......@@ -16,6 +16,7 @@
'../../skia/skia.gyp:skia',
'../aura/aura.gyp:aura',
'../base/ui_base.gyp:ui_base',
'../compositor/compositor.gyp:compositor',
'../events/events.gyp:events',
'../gfx/gfx.gyp:gfx',
'../gfx/gfx.gyp:gfx_geometry',
......
......@@ -7,7 +7,7 @@
#include "ui/base/cursor/cursor.h"
#include "ui/base/hit_test.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/paint_context.h"
#include "ui/compositor/paint_recorder.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
......@@ -71,13 +71,15 @@ void ImageWindowDelegate::OnCaptureLost() {
}
void ImageWindowDelegate::OnPaint(const ui::PaintContext& context) {
gfx::Canvas* canvas = context.canvas();
ui::PaintRecorder recorder(context);
if (background_color_ != SK_ColorTRANSPARENT &&
(image_.IsEmpty() || size_mismatch_ || !offset_.IsZero())) {
canvas->DrawColor(background_color_);
recorder.canvas()->DrawColor(background_color_);
}
if (!image_.IsEmpty()) {
recorder.canvas()->DrawImageInt(image_.AsImageSkia(), offset_.x(),
offset_.y());
}
if (!image_.IsEmpty())
canvas->DrawImageInt(image_.AsImageSkia(), offset_.x(), offset_.y());
}
void ImageWindowDelegate::OnDeviceScaleFactorChanged(float scale_factor) {
......
......@@ -15,7 +15,7 @@
#include "ui/aura/window_event_dispatcher.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/paint_context.h"
#include "ui/compositor/paint_recorder.h"
#include "ui/compositor/test/context_factories_for_test.h"
#include "ui/compositor/test/draw_waiter_for_test.h"
#include "ui/gfx/canvas.h"
......@@ -44,10 +44,11 @@ class TestPaintingWindowDelegate : public aura::test::TestWindowDelegate {
~TestPaintingWindowDelegate() override {}
void OnPaint(const ui::PaintContext& context) override {
ui::PaintRecorder recorder(context);
for (int y = 0; y < window_size_.height(); ++y) {
for (int x = 0; x < window_size_.width(); ++x) {
context.canvas()->FillRect(gfx::Rect(x, y, 1, 1),
GetExpectedColorForPoint(x, y));
recorder.canvas()->FillRect(gfx::Rect(x, y, 1, 1),
GetExpectedColorForPoint(x, y));
}
}
}
......
......@@ -15,7 +15,7 @@
#include "ui/aura/window.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_delegate.h"
#include "ui/compositor/paint_context.h"
#include "ui/compositor/paint_recorder.h"
#include "ui/events/event.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/insets.h"
......@@ -206,11 +206,12 @@ TrayBubbleContentMask::~TrayBubbleContentMask() {
}
void TrayBubbleContentMask::OnPaintLayer(const ui::PaintContext& context) {
ui::PaintRecorder recorder(context);
SkPaint paint;
paint.setAlpha(255);
paint.setStyle(SkPaint::kFill_Style);
gfx::Rect rect(layer()->bounds().size());
context.canvas()->DrawRoundRect(rect, corner_radius_, paint);
recorder.canvas()->DrawRoundRect(rect, corner_radius_, paint);
}
void TrayBubbleContentMask::OnDeviceScaleFactorChanged(
......
......@@ -1459,8 +1459,10 @@ void View::UpdateChildLayerBounds(const gfx::Vector2d& offset) {
}
void View::OnPaintLayer(const ui::PaintContext& context) {
if (!layer()->fills_bounds_opaquely())
context.canvas()->DrawColor(SK_ColorBLACK, SkXfermode::kClear_Mode);
if (!layer()->fills_bounds_opaquely()) {
ui::PaintRecorder recorder(context);
recorder.canvas()->DrawColor(SK_ColorBLACK, SkXfermode::kClear_Mode);
}
if (!visible_)
return;
Paint(context);
......
......@@ -9,7 +9,7 @@
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkXfermode.h"
#include "ui/compositor/dip_util.h"
#include "ui/compositor/paint_context.h"
#include "ui/compositor/paint_recorder.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_conversions.h"
......@@ -268,9 +268,10 @@ void ImageGrid::ImagePainter::SetClipRect(const gfx::Rect& clip_rect,
}
void ImageGrid::ImagePainter::OnPaintLayer(const ui::PaintContext& context) {
ui::PaintRecorder recorder(context);
if (!clip_rect_.IsEmpty())
context.canvas()->ClipRect(clip_rect_);
context.canvas()->DrawImageInt(image_, 0, 0);
recorder.canvas()->ClipRect(clip_rect_);
recorder.canvas()->DrawImageInt(image_, 0, 0);
}
void ImageGrid::ImagePainter::OnDelegatedFrameDamage(
......
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