Skip to content

Commit

Permalink
Make cc/paint have concrete types
Browse files Browse the repository at this point in the history
This changes PaintCanvas, PaintFlags, PaintSurface, and PaintRecorder
to all be real types (that forward to Skia types internally).  PaintShader
is left as-is for now.  This will force callers to use the correct
types in the rest of Chromium as the internals of these classes are
rewritten in future patches.

This code also changes a number of callers elsewhere in the codebase
that want to wrap an SkCanvas in a PaintCanvas.  As SkCanvas has no
constructor that takes an SkCanvas*, this change had to wait for this
final conversion patch.

In general, if code wants to raster directly into a bitmap with local
code, it should use Skia directly.  If code wants to raster into a bitmap
with paint callers, it can wrap that bitmap in a PaintCanvas.  Similarly,
if code wants to go into an accelerated SkSurface, it should wrap that
surface's canvas in a PaintCanvas (as blink html canvas code does).

BUG=671433

CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2

Review-Url: https://codereview.chromium.org/2690583002
Cr-Commit-Position: refs/heads/master@{#455840}
  • Loading branch information
quisquous authored and Commit bot committed Mar 9, 2017
1 parent 3e8277d commit d250157
Show file tree
Hide file tree
Showing 35 changed files with 931 additions and 142 deletions.
2 changes: 1 addition & 1 deletion ash/common/shelf/overflow_button.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ std::unique_ptr<views::InkDropMask> OverflowButton::CreateInkDropMask() const {
void OverflowButton::PaintBackground(gfx::Canvas* canvas,
const gfx::Rect& bounds) {
cc::PaintFlags flags;
flags.setFlags(cc::PaintFlags::kAntiAlias_Flag);
flags.setAntiAlias(true);
flags.setColor(background_color_);
canvas->DrawRoundRect(bounds, kOverflowButtonCornerRadius, flags);
}
Expand Down
4 changes: 2 additions & 2 deletions ash/common/shelf/shelf_button.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ class ShelfButton::AppStatusIndicatorView
// Fill the center.
cc::PaintFlags flags;
flags.setColor(kIndicatorColor);
flags.setFlags(cc::PaintFlags::kAntiAlias_Flag);
flags.setAntiAlias(true);
canvas->DrawCircle(center, dsf * kIndicatorRadiusDip - kStrokeWidthPx,
flags);

// Stroke the border.
flags.setColor(SkColorSetA(SK_ColorBLACK, 0x4D));
flags.setStyle(SkPaint::kStroke_Style);
flags.setStyle(cc::PaintFlags::kStroke_Style);
canvas->DrawCircle(
center, dsf * kIndicatorRadiusDip - kStrokeWidthPx / 2.0f, flags);
}
Expand Down
14 changes: 7 additions & 7 deletions cc/layers/painted_overlay_scrollbar_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,16 @@ bool PaintedOverlayScrollbarLayer::PaintThumbIfNeeded() {

SkBitmap skbitmap;
skbitmap.allocN32Pixels(paint_rect.width(), paint_rect.height());
SkCanvas skcanvas(skbitmap);
PaintCanvas canvas(skbitmap);

SkRect content_skrect = RectToSkRect(paint_rect);
SkPaint paint;
paint.setAntiAlias(false);
paint.setBlendMode(SkBlendMode::kClear);
skcanvas.drawRect(content_skrect, paint);
skcanvas.clipRect(content_skrect);
PaintFlags flags;
flags.setAntiAlias(false);
flags.setBlendMode(SkBlendMode::kClear);
canvas.drawRect(content_skrect, flags);
canvas.clipRect(content_skrect);

scrollbar_->PaintPart(&skcanvas, THUMB, paint_rect);
scrollbar_->PaintPart(&canvas, THUMB, paint_rect);
// Make sure that the pixels are no longer mutable to unavoid unnecessary
// allocation and copying.
skbitmap.setImmutable();
Expand Down
9 changes: 8 additions & 1 deletion cc/paint/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,23 @@ cc_component("paint") {
"paint_export.h",
"paint_flags.h",
"paint_record.h",
"paint_recorder.cc",
"paint_recorder.h",
"paint_shader.h",
"paint_surface.cc",
"paint_surface.h",
]

defines = [ "CC_PAINT_IMPLEMENTATION=1" ]

# cc/paint is intended to be a separate component from cc that can be
# included in Blink. This component should never include //base.
# included in Blink. This component should never publicly include
# anything that Blink core wouldn't include (e.g. base).
public_deps = [
"//skia",
]

deps = [
"//base",
]
}
44 changes: 31 additions & 13 deletions cc/paint/paint_canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

#include "cc/paint/paint_canvas.h"

#include "base/memory/ptr_util.h"
#include "cc/paint/paint_record.h"
#include "cc/paint/paint_recorder.h"
#include "third_party/skia/include/core/SkAnnotation.h"
#include "third_party/skia/include/core/SkMetaData.h"
#include "third_party/skia/include/utils/SkNWayCanvas.h"

#if defined(OS_MACOSX)
namespace {
Expand All @@ -14,25 +19,20 @@ const char kIsPreviewMetafileKey[] = "CrIsPreviewMetafile";

namespace cc {

PaintCanvasPassThrough::PaintCanvasPassThrough(SkCanvas* canvas)
: SkNWayCanvas(canvas->getBaseLayerSize().width(),
canvas->getBaseLayerSize().height()) {
SkIRect raster_bounds;
canvas->getDeviceClipBounds(&raster_bounds);
clipRect(SkRect::MakeFromIRect(raster_bounds));
setMatrix(canvas->getTotalMatrix());
addCanvas(canvas);
}
PaintCanvas::PaintCanvas(SkCanvas* canvas) : canvas_(canvas) {}

PaintCanvas::PaintCanvas(const SkBitmap& bitmap)
: canvas_(new SkCanvas(bitmap)), owned_(canvas_) {}

PaintCanvasPassThrough::PaintCanvasPassThrough(int width, int height)
: SkNWayCanvas(width, height) {}
PaintCanvas::PaintCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props)
: canvas_(new SkCanvas(bitmap, props)), owned_(canvas_) {}

PaintCanvasPassThrough::~PaintCanvasPassThrough() = default;
PaintCanvas::~PaintCanvas() = default;

bool ToPixmap(PaintCanvas* canvas, SkPixmap* output) {
SkImageInfo info;
size_t row_bytes;
void* pixels = canvas->accessTopLayerPixels(&info, &row_bytes);
void* pixels = canvas->canvas_->accessTopLayerPixels(&info, &row_bytes);
if (!pixels) {
output->reset();
return false;
Expand All @@ -57,4 +57,22 @@ bool IsPreviewMetafile(PaintCanvas* canvas) {
}
#endif

void PaintCanvasAnnotateRectWithURL(PaintCanvas* canvas,
const SkRect& rect,
SkData* data) {
SkAnnotateRectWithURL(canvas->canvas_, rect, data);
}

void PaintCanvasAnnotateNamedDestination(PaintCanvas* canvas,
const SkPoint& point,
SkData* data) {
SkAnnotateNamedDestination(canvas->canvas_, point, data);
}

void PaintCanvasAnnotateLinkToDestination(PaintCanvas* canvas,
const SkRect& rect,
SkData* data) {
SkAnnotateLinkToDestination(canvas->canvas_, rect, data);
}

} // namespace cc
Loading

0 comments on commit d250157

Please sign in to comment.