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

chromeos: 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=oshima
BUG=466426

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

Cr-Commit-Position: refs/heads/master@{#324115}
parent 703c89a1
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/compositor/layer.h" #include "ui/compositor/layer.h"
#include "ui/compositor/paint_context.h" #include "ui/compositor/paint_recorder.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
namespace chromeos { namespace chromeos {
...@@ -117,18 +117,20 @@ void OverscanCalibrator::UpdateInsets(const gfx::Insets& insets) { ...@@ -117,18 +117,20 @@ void OverscanCalibrator::UpdateInsets(const gfx::Insets& insets) {
} }
void OverscanCalibrator::OnPaintLayer(const ui::PaintContext& context) { void OverscanCalibrator::OnPaintLayer(const ui::PaintContext& context) {
gfx::Canvas* canvas = context.canvas(); ui::PaintRecorder recorder(context);
static const SkColor kTransparent = SkColorSetARGB(0, 0, 0, 0); static const SkColor kTransparent = SkColorSetARGB(0, 0, 0, 0);
gfx::Rect full_bounds = calibration_layer_->bounds(); gfx::Rect full_bounds = calibration_layer_->bounds();
gfx::Rect inner_bounds = full_bounds; gfx::Rect inner_bounds = full_bounds;
inner_bounds.Inset(insets_); inner_bounds.Inset(insets_);
canvas->FillRect(full_bounds, SK_ColorBLACK); recorder.canvas()->FillRect(full_bounds, SK_ColorBLACK);
canvas->FillRect(inner_bounds, kTransparent, SkXfermode::kClear_Mode); recorder.canvas()->FillRect(inner_bounds, kTransparent,
SkXfermode::kClear_Mode);
gfx::Point center = inner_bounds.CenterPoint(); gfx::Point center = inner_bounds.CenterPoint();
int vertical_offset = inner_bounds.height() / 2 - kArrowGapWidth; int vertical_offset = inner_bounds.height() / 2 - kArrowGapWidth;
int horizontal_offset = inner_bounds.width() / 2 - kArrowGapWidth; int horizontal_offset = inner_bounds.width() / 2 - kArrowGapWidth;
gfx::Canvas* canvas = recorder.canvas();
DrawTriangle(center.x(), center.y() + vertical_offset, 0, canvas); DrawTriangle(center.x(), center.y() + vertical_offset, 0, canvas);
DrawTriangle(center.x(), center.y() - vertical_offset, 180, canvas); DrawTriangle(center.x(), center.y() - vertical_offset, 180, canvas);
DrawTriangle(center.x() - horizontal_offset, center.y(), 90, canvas); DrawTriangle(center.x() - horizontal_offset, center.y(), 90, canvas);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/compositor/layer.h" #include "ui/compositor/layer.h"
#include "ui/compositor/paint_context.h" #include "ui/compositor/paint_recorder.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
namespace chromeos { namespace chromeos {
...@@ -112,16 +112,15 @@ void AccessibilityFocusRingLayer::Set(const AccessibilityFocusRing& ring) { ...@@ -112,16 +112,15 @@ void AccessibilityFocusRingLayer::Set(const AccessibilityFocusRing& ring) {
void AccessibilityFocusRingLayer::OnPaintLayer( void AccessibilityFocusRingLayer::OnPaintLayer(
const ui::PaintContext& context) { const ui::PaintContext& context) {
gfx::Vector2d offset = layer()->bounds().OffsetFromOrigin(); ui::PaintRecorder recorder(context);
SkPaint paint; SkPaint paint;
paint.setFlags(SkPaint::kAntiAlias_Flag); paint.setFlags(SkPaint::kAntiAlias_Flag);
paint.setStyle(SkPaint::kStroke_Style); paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(2); paint.setStrokeWidth(2);
gfx::Canvas* canvas = context.canvas();
SkPath path; SkPath path;
gfx::Vector2d offset = layer()->bounds().OffsetFromOrigin();
const int w = kGradientWidth; const int w = kGradientWidth;
for (int i = 0; i < w; ++i) { for (int i = 0; i < w; ++i) {
paint.setColor( paint.setColor(
...@@ -129,7 +128,7 @@ void AccessibilityFocusRingLayer::OnPaintLayer( ...@@ -129,7 +128,7 @@ void AccessibilityFocusRingLayer::OnPaintLayer(
255 * (w - i) * (w - i) / (w * w), 255 * (w - i) * (w - i) / (w * w),
kFocusRingColorRed, kFocusRingColorGreen, kFocusRingColorBlue)); kFocusRingColorRed, kFocusRingColorGreen, kFocusRingColorBlue));
path = MakePath(ring_, i, offset); path = MakePath(ring_, i, offset);
canvas->DrawPath(path, paint); recorder.canvas()->DrawPath(path, paint);
} }
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/compositor/layer.h" #include "ui/compositor/layer.h"
#include "ui/compositor/paint_context.h" #include "ui/compositor/paint_recorder.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
namespace chromeos { namespace chromeos {
...@@ -61,20 +61,22 @@ void FocusRingLayer::OnPaintLayer(const ui::PaintContext& context) { ...@@ -61,20 +61,22 @@ void FocusRingLayer::OnPaintLayer(const ui::PaintContext& context) {
if (!root_window_ || focus_ring_.IsEmpty()) if (!root_window_ || focus_ring_.IsEmpty())
return; return;
gfx::Canvas* canvas = context.canvas(); ui::PaintRecorder recorder(context);
gfx::Rect bounds = focus_ring_ - layer_->bounds().OffsetFromOrigin();
SkPaint paint; SkPaint paint;
paint.setColor(kShadowColor); paint.setColor(kShadowColor);
paint.setFlags(SkPaint::kAntiAlias_Flag); paint.setFlags(SkPaint::kAntiAlias_Flag);
paint.setStyle(SkPaint::kStroke_Style); paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(2); paint.setStrokeWidth(2);
gfx::Rect bounds = focus_ring_ - layer_->bounds().OffsetFromOrigin();
int r = kShadowRadius; int r = kShadowRadius;
for (int i = 0; i < r; i++) { for (int i = 0; i < r; i++) {
// Fade out alpha quadratically. // Fade out alpha quadratically.
paint.setAlpha((kShadowAlpha * (r - i) * (r - i)) / (r * r)); paint.setAlpha((kShadowAlpha * (r - i) * (r - i)) / (r * r));
gfx::Rect outsetRect = bounds; gfx::Rect outsetRect = bounds;
outsetRect.Inset(-i, -i, -i, -i); outsetRect.Inset(-i, -i, -i, -i);
canvas->DrawRect(outsetRect, paint); recorder.canvas()->DrawRect(outsetRect, paint);
} }
} }
......
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