From d2501577f2df0764eda66614ddf429e230062562 Mon Sep 17 00:00:00 2001 From: enne Date: Thu, 9 Mar 2017 11:59:17 -0800 Subject: [PATCH] Make cc/paint have concrete types 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} --- ash/common/shelf/overflow_button.cc | 2 +- ash/common/shelf/shelf_button.cc | 4 +- cc/layers/painted_overlay_scrollbar_layer.cc | 14 +- cc/paint/BUILD.gn | 9 +- cc/paint/paint_canvas.cc | 44 +- cc/paint/paint_canvas.h | 434 +++++++++++++++++- cc/paint/paint_flags.h | 204 +++++++- cc/paint/paint_recorder.cc | 12 + cc/paint/paint_recorder.h | 61 ++- cc/paint/paint_shader.h | 3 +- cc/paint/paint_surface.cc | 14 + cc/paint/paint_surface.h | 49 +- .../child/browser_font_resource_trusted.cc | 9 +- .../gpu/gpu_benchmarking_extension.cc | 2 +- .../skcanvas_video_renderer_unittest.cc | 8 +- printing/pdf_metafile_skia.cc | 4 +- .../compositing/CompositedLayerMapping.cpp | 2 +- .../compositing/PaintLayerCompositor.cpp | 2 +- .../Source/core/paint/SVGShapePainter.cpp | 2 +- .../Source/core/svg/graphics/SVGImageTest.cpp | 2 +- .../Source/platform/exported/WebFont.cpp | 2 +- .../exported/WebScrollbarThemePainter.cpp | 20 +- .../platform/graphics/Canvas2DLayerBridge.cpp | 71 +-- .../platform/graphics/Canvas2DLayerBridge.h | 7 +- .../graphics/DeferredImageDecoderTest.cpp | 10 +- .../platform/graphics/GraphicsContext.cpp | 20 +- .../graphics/RecordingImageBufferSurface.cpp | 4 +- .../UnacceleratedImageBufferSurface.cpp | 20 +- .../UnacceleratedImageBufferSurface.h | 4 +- .../gpu/AcceleratedImageBufferSurface.cpp | 8 +- .../gpu/AcceleratedImageBufferSurface.h | 7 +- .../platform/graphics/paint/PaintCanvas.h | 1 - .../WebKit/Source/web/PageWidgetDelegate.cpp | 3 +- .../WebKit/Source/web/WebLocalFrameImpl.cpp | 4 +- ui/gfx/paint_vector_icon_unittest.cc | 11 +- 35 files changed, 931 insertions(+), 142 deletions(-) create mode 100644 cc/paint/paint_recorder.cc create mode 100644 cc/paint/paint_surface.cc diff --git a/ash/common/shelf/overflow_button.cc b/ash/common/shelf/overflow_button.cc index ccb585c6cc785a..b254012be91dc3 100644 --- a/ash/common/shelf/overflow_button.cc +++ b/ash/common/shelf/overflow_button.cc @@ -100,7 +100,7 @@ std::unique_ptr 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); } diff --git a/ash/common/shelf/shelf_button.cc b/ash/common/shelf/shelf_button.cc index d5d32ff71833d2..e77571e1e77cf2 100644 --- a/ash/common/shelf/shelf_button.cc +++ b/ash/common/shelf/shelf_button.cc @@ -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); } diff --git a/cc/layers/painted_overlay_scrollbar_layer.cc b/cc/layers/painted_overlay_scrollbar_layer.cc index ab8643ecac019f..eea22c63051043 100644 --- a/cc/layers/painted_overlay_scrollbar_layer.cc +++ b/cc/layers/painted_overlay_scrollbar_layer.cc @@ -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(); diff --git a/cc/paint/BUILD.gn b/cc/paint/BUILD.gn index a37d4a6dae577f..58cdaf410505e7 100644 --- a/cc/paint/BUILD.gn +++ b/cc/paint/BUILD.gn @@ -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", + ] } diff --git a/cc/paint/paint_canvas.cc b/cc/paint/paint_canvas.cc index 53dab8fb45b7af..d3a8b57183aaa1 100644 --- a/cc/paint/paint_canvas.cc +++ b/cc/paint/paint_canvas.cc @@ -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 { @@ -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; @@ -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 diff --git a/cc/paint/paint_canvas.h b/cc/paint/paint_canvas.h index 649096cf8ea9b8..f4379bcb580774 100644 --- a/cc/paint/paint_canvas.h +++ b/cc/paint/paint_canvas.h @@ -5,26 +5,430 @@ #ifndef CC_PAINT_PAINT_CANVAS_H_ #define CC_PAINT_PAINT_CANVAS_H_ +#include + +#include "base/compiler_specific.h" +#include "base/logging.h" +#include "base/macros.h" #include "build/build_config.h" #include "cc/paint/paint_export.h" +#include "cc/paint/paint_flags.h" +#include "cc/paint/paint_record.h" #include "third_party/skia/include/core/SkCanvas.h" -#include "third_party/skia/include/utils/SkNWayCanvas.h" #include "third_party/skia/include/utils/SkNoDrawCanvas.h" namespace cc { -using PaintCanvas = SkCanvas; -using PaintCanvasNoDraw = SkNoDrawCanvas; -using PaintCanvasAutoRestore = SkAutoCanvasRestore; +class PaintFlags; -class CC_PAINT_EXPORT PaintCanvasPassThrough : public SkNWayCanvas { +class CC_PAINT_EXPORT PaintCanvas { public: - explicit PaintCanvasPassThrough(SkCanvas* canvas); - PaintCanvasPassThrough(int width, int height); - ~PaintCanvasPassThrough() override; + // TODO(enne): remove all constructors but the one that takes an SkCanvas + // and a future one that will take a PaintOpBuffer to build a PaintRecord. + explicit PaintCanvas(SkCanvas* canvas); + explicit PaintCanvas(const SkBitmap& bitmap); + explicit PaintCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props); + ~PaintCanvas(); + + ALWAYS_INLINE SkMetaData& getMetaData() { return canvas_->getMetaData(); } + ALWAYS_INLINE SkImageInfo imageInfo() const { return canvas_->imageInfo(); } + ALWAYS_INLINE bool getProps(SkSurfaceProps* props) const { + return canvas_->getProps(props); + } + // TODO(enne): It would be nice to get rid of flush() entirely, as it + // doesn't really make sense for recording. However, this gets used by + // SkCanvasVideoRenderer which takes a PaintCanvas to paint both + // software and hardware video. This is super entangled with ImageBuffer + // and canvas/video painting in Blink where the same paths are used for + // both recording and gpu work. + ALWAYS_INLINE void flush() { canvas_->flush(); } + + ALWAYS_INLINE SkISize getBaseLayerSize() const { + return canvas_->getBaseLayerSize(); + } + ALWAYS_INLINE bool peekPixels(SkPixmap* pixmap) { + return canvas_->peekPixels(pixmap); + } + ALWAYS_INLINE bool readPixels(const SkImageInfo& dest_info, + void* dest_pixels, + size_t dest_row_bytes, + int src_x, + int src_y) { + return canvas_->readPixels(dest_info, dest_pixels, dest_row_bytes, src_x, + src_y); + } + ALWAYS_INLINE bool readPixels(SkBitmap* bitmap, int src_x, int src_y) { + return canvas_->readPixels(bitmap, src_x, src_y); + } + ALWAYS_INLINE bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap) { + return canvas_->readPixels(srcRect, bitmap); + } + ALWAYS_INLINE bool writePixels(const SkImageInfo& info, + const void* pixels, + size_t row_bytes, + int x, + int y) { + return canvas_->writePixels(info, pixels, row_bytes, x, y); + } + ALWAYS_INLINE int save() { return canvas_->save(); } + ALWAYS_INLINE int saveLayer(const SkRect* bounds, const PaintFlags* flags) { + return canvas_->saveLayer(bounds, ToSkPaint(flags)); + } + ALWAYS_INLINE int saveLayer(const SkRect& bounds, const PaintFlags* flags) { + return canvas_->saveLayer(bounds, ToSkPaint(flags)); + } + ALWAYS_INLINE int saveLayerPreserveLCDTextRequests(const SkRect* bounds, + const PaintFlags* flags) { + return canvas_->saveLayerPreserveLCDTextRequests(bounds, ToSkPaint(flags)); + } + ALWAYS_INLINE int saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { + return canvas_->saveLayerAlpha(bounds, alpha); + } + + ALWAYS_INLINE void restore() { canvas_->restore(); } + ALWAYS_INLINE int getSaveCount() const { return canvas_->getSaveCount(); } + ALWAYS_INLINE void restoreToCount(int save_count) { + canvas_->restoreToCount(save_count); + } + ALWAYS_INLINE void translate(SkScalar dx, SkScalar dy) { + canvas_->translate(dx, dy); + } + ALWAYS_INLINE void scale(SkScalar sx, SkScalar sy) { canvas_->scale(sx, sy); } + ALWAYS_INLINE void rotate(SkScalar degrees) { canvas_->rotate(degrees); } + ALWAYS_INLINE void rotate(SkScalar degrees, SkScalar px, SkScalar py) { + canvas_->rotate(degrees, px, py); + } + ALWAYS_INLINE void skew(SkScalar sx, SkScalar sy) { canvas_->skew(sx, sy); } + ALWAYS_INLINE void concat(const SkMatrix& matrix) { canvas_->concat(matrix); } + ALWAYS_INLINE void setMatrix(const SkMatrix& matrix) { + canvas_->setMatrix(matrix); + } + ALWAYS_INLINE void resetMatrix() { canvas_->resetMatrix(); } + ALWAYS_INLINE void clipRect(const SkRect& rect, + SkClipOp op, + bool do_anti_alias = false) { + canvas_->clipRect(rect, op, do_anti_alias); + } + ALWAYS_INLINE void clipRect(const SkRect& rect, bool do_anti_alias = false) { + canvas_->clipRect(rect, do_anti_alias); + } + ALWAYS_INLINE void clipRRect(const SkRRect& rrect, + SkClipOp op, + bool do_anti_alias) { + canvas_->clipRRect(rrect, op, do_anti_alias); + } + ALWAYS_INLINE void clipRRect(const SkRRect& rrect, SkClipOp op) { + canvas_->clipRRect(rrect, op); + } + ALWAYS_INLINE void clipRRect(const SkRRect& rrect, + bool do_anti_alias = false) { + canvas_->clipRRect(rrect, do_anti_alias); + } + ALWAYS_INLINE void clipPath(const SkPath& path, + SkClipOp op, + bool do_anti_alias) { + canvas_->clipPath(path, op, do_anti_alias); + } + ALWAYS_INLINE void clipPath(const SkPath& path, SkClipOp op) { + canvas_->clipPath(path, op); + } + ALWAYS_INLINE void clipPath(const SkPath& path, bool do_anti_alias = false) { + canvas_->clipPath(path, do_anti_alias); + } + ALWAYS_INLINE void clipRegion(const SkRegion& device_region, + SkClipOp op = SkClipOp::kIntersect) { + canvas_->clipRegion(device_region, op); + } + ALWAYS_INLINE bool quickReject(const SkRect& rect) const { + return canvas_->quickReject(rect); + } + ALWAYS_INLINE bool quickReject(const SkPath& path) const { + return canvas_->quickReject(path); + } + ALWAYS_INLINE SkRect getLocalClipBounds() const { + return canvas_->getLocalClipBounds(); + } + ALWAYS_INLINE bool getLocalClipBounds(SkRect* bounds) const { + return canvas_->getLocalClipBounds(bounds); + } + ALWAYS_INLINE SkIRect getDeviceClipBounds() const { + return canvas_->getDeviceClipBounds(); + } + ALWAYS_INLINE bool getDeviceClipBounds(SkIRect* bounds) const { + return canvas_->getDeviceClipBounds(bounds); + } + ALWAYS_INLINE void drawColor(SkColor color, + SkBlendMode mode = SkBlendMode::kSrcOver) { + canvas_->drawColor(color, mode); + } + ALWAYS_INLINE void clear(SkColor color) { canvas_->clear(color); } + ALWAYS_INLINE void discard() { canvas_->discard(); } + + ALWAYS_INLINE void drawLine(SkScalar x0, + SkScalar y0, + SkScalar x1, + SkScalar y1, + const PaintFlags& flags) { + canvas_->drawLine(x0, y0, x1, y1, ToSkPaint(flags)); + } + ALWAYS_INLINE void drawRect(const SkRect& rect, const PaintFlags& flags) { + canvas_->drawRect(rect, ToSkPaint(flags)); + } + ALWAYS_INLINE void drawIRect(const SkIRect& rect, const PaintFlags& flags) { + canvas_->drawIRect(rect, ToSkPaint(flags)); + } + ALWAYS_INLINE void drawOval(const SkRect& oval, const PaintFlags& flags) { + canvas_->drawOval(oval, ToSkPaint(flags)); + } + ALWAYS_INLINE void drawRRect(const SkRRect& rrect, const PaintFlags& flags) { + canvas_->drawRRect(rrect, ToSkPaint(flags)); + } + ALWAYS_INLINE void drawDRRect(const SkRRect& outer, + const SkRRect& inner, + const PaintFlags& flags) { + canvas_->drawDRRect(outer, inner, ToSkPaint(flags)); + } + ALWAYS_INLINE void drawCircle(SkScalar cx, + SkScalar cy, + SkScalar radius, + const PaintFlags& flags) { + canvas_->drawCircle(cx, cy, radius, ToSkPaint(flags)); + } + ALWAYS_INLINE void drawArc(const SkRect& oval, + SkScalar start_angle, + SkScalar sweep_angle, + bool use_center, + const PaintFlags& flags) { + canvas_->drawArc(oval, start_angle, sweep_angle, use_center, + ToSkPaint(flags)); + } + ALWAYS_INLINE void drawRoundRect(const SkRect& rect, + SkScalar rx, + SkScalar ry, + const PaintFlags& flags) { + canvas_->drawRoundRect(rect, rx, ry, ToSkPaint(flags)); + } + ALWAYS_INLINE void drawPath(const SkPath& path, const PaintFlags& flags) { + canvas_->drawPath(path, ToSkPaint(flags)); + } + ALWAYS_INLINE void drawImage(const SkImage* image, + SkScalar left, + SkScalar top, + const PaintFlags* flags = nullptr) { + canvas_->drawImage(image, left, top, ToSkPaint(flags)); + } + ALWAYS_INLINE void drawImage(const sk_sp& image, + SkScalar left, + SkScalar top, + const PaintFlags* flags = nullptr) { + canvas_->drawImage(image, left, top, ToSkPaint(flags)); + } + + enum SrcRectConstraint { + kStrict_SrcRectConstraint = SkCanvas::kStrict_SrcRectConstraint, + kFast_SrcRectConstraint = SkCanvas::kFast_SrcRectConstraint, + }; + + ALWAYS_INLINE void drawImageRect( + const SkImage* image, + const SkRect& src, + const SkRect& dst, + const PaintFlags* flags, + SrcRectConstraint constraint = kStrict_SrcRectConstraint) { + canvas_->drawImageRect( + image, src, dst, ToSkPaint(flags), + static_cast(constraint)); + } + ALWAYS_INLINE void drawImageRect( + const SkImage* image, + const SkIRect& isrc, + const SkRect& dst, + const PaintFlags* flags, + SrcRectConstraint constraint = kStrict_SrcRectConstraint) { + canvas_->drawImageRect( + image, isrc, dst, ToSkPaint(flags), + static_cast(constraint)); + } + ALWAYS_INLINE void drawImageRect( + const SkImage* image, + const SkRect& dst, + const PaintFlags* flags, + SrcRectConstraint constraint = kStrict_SrcRectConstraint) { + canvas_->drawImageRect( + image, dst, ToSkPaint(flags), + static_cast(constraint)); + } + ALWAYS_INLINE void drawImageRect( + const sk_sp& image, + const SkRect& src, + const SkRect& dst, + const PaintFlags* flags, + SrcRectConstraint constraint = kStrict_SrcRectConstraint) { + canvas_->drawImageRect( + image, src, dst, ToSkPaint(flags), + static_cast(constraint)); + } + ALWAYS_INLINE void drawImageRect( + const sk_sp& image, + const SkIRect& isrc, + const SkRect& dst, + const PaintFlags* flags, + SrcRectConstraint cons = kStrict_SrcRectConstraint) { + canvas_->drawImageRect(image, isrc, dst, ToSkPaint(flags), + static_cast(cons)); + } + ALWAYS_INLINE void drawImageRect( + const sk_sp& image, + const SkRect& dst, + const PaintFlags* flags, + SrcRectConstraint cons = kStrict_SrcRectConstraint) { + canvas_->drawImageRect(image, dst, ToSkPaint(flags), + static_cast(cons)); + } + ALWAYS_INLINE void drawBitmap(const SkBitmap& bitmap, + SkScalar left, + SkScalar top, + const PaintFlags* flags = nullptr) { + canvas_->drawBitmap(bitmap, left, top, ToSkPaint(flags)); + } + ALWAYS_INLINE void drawBitmapRect( + const SkBitmap& bitmap, + const SkRect& src, + const SkRect& dst, + const PaintFlags* flags, + SrcRectConstraint constraint = kStrict_SrcRectConstraint) { + canvas_->drawBitmapRect( + bitmap, src, dst, ToSkPaint(flags), + static_cast(constraint)); + } + ALWAYS_INLINE void drawBitmapRect( + const SkBitmap& bitmap, + const SkIRect& isrc, + const SkRect& dst, + const PaintFlags* flags, + SrcRectConstraint constraint = kStrict_SrcRectConstraint) { + canvas_->drawBitmapRect( + bitmap, isrc, dst, ToSkPaint(flags), + static_cast(constraint)); + } + ALWAYS_INLINE void drawBitmapRect( + const SkBitmap& bitmap, + const SkRect& dst, + const PaintFlags* flags, + SrcRectConstraint constraint = kStrict_SrcRectConstraint) { + canvas_->drawBitmapRect( + bitmap, dst, ToSkPaint(flags), + static_cast(constraint)); + } + + ALWAYS_INLINE void drawText(const void* text, + size_t byte_length, + SkScalar x, + SkScalar y, + const PaintFlags& flags) { + canvas_->drawText(text, byte_length, x, y, ToSkPaint(flags)); + } + ALWAYS_INLINE void drawPosText(const void* text, + size_t byte_length, + const SkPoint pos[], + const PaintFlags& flags) { + canvas_->drawPosText(text, byte_length, pos, ToSkPaint(flags)); + } + ALWAYS_INLINE void drawTextBlob(const SkTextBlob* blob, + SkScalar x, + SkScalar y, + const PaintFlags& flags) { + canvas_->drawTextBlob(blob, x, y, ToSkPaint(flags)); + } + ALWAYS_INLINE void drawTextBlob(const sk_sp& blob, + SkScalar x, + SkScalar y, + const PaintFlags& flags) { + canvas_->drawTextBlob(blob, x, y, ToSkPaint(flags)); + } + + ALWAYS_INLINE void drawPicture(const PaintRecord* record) { + canvas_->drawPicture(ToSkPicture(record)); + } + ALWAYS_INLINE void drawPicture(const PaintRecord* record, + const SkMatrix* matrix, + const PaintFlags* flags) { + canvas_->drawPicture(ToSkPicture(record), matrix, ToSkPaint(flags)); + } + ALWAYS_INLINE void drawPicture(sk_sp record) { + drawPicture(record.get()); + } + + ALWAYS_INLINE bool isClipEmpty() const { return canvas_->isClipEmpty(); } + ALWAYS_INLINE bool isClipRect() const { return canvas_->isClipRect(); } + ALWAYS_INLINE const SkMatrix& getTotalMatrix() const { + return canvas_->getTotalMatrix(); + } + + // For GraphicsContextCanvas only. Maybe this could be rewritten? + ALWAYS_INLINE void temporary_internal_describeTopLayer(SkMatrix* matrix, + SkIRect* clip_bounds) { + return canvas_->temporary_internal_describeTopLayer(matrix, clip_bounds); + } + + protected: + friend class PaintSurface; + friend class PaintRecorder; + friend CC_PAINT_EXPORT void PaintCanvasAnnotateRectWithURL( + PaintCanvas* canvas, + const SkRect& rect, + SkData* data); + friend CC_PAINT_EXPORT void PaintCanvasAnnotateNamedDestination( + PaintCanvas* canvas, + const SkPoint& point, + SkData* data); + friend CC_PAINT_EXPORT void PaintCanvasAnnotateLinkToDestination( + PaintCanvas* canvas, + const SkRect& rect, + SkData* data); + friend CC_PAINT_EXPORT bool ToPixmap(PaintCanvas* canvas, SkPixmap* output); + + private: + SkCanvas* canvas_; + std::unique_ptr owned_; + + DISALLOW_COPY_AND_ASSIGN(PaintCanvas); }; -// TODO(enne): Move all these functions into PaintCanvas. +class CC_PAINT_EXPORT PaintCanvasAutoRestore { + public: + ALWAYS_INLINE PaintCanvasAutoRestore(PaintCanvas* canvas, bool save) + : canvas_(canvas) { + if (canvas_) { + save_count_ = canvas_->getSaveCount(); + if (save) { + canvas_->save(); + } + } + } + + ALWAYS_INLINE ~PaintCanvasAutoRestore() { + if (canvas_) { + canvas_->restoreToCount(save_count_); + } + } + + ALWAYS_INLINE void restore() { + if (canvas_) { + canvas_->restoreToCount(save_count_); + canvas_ = nullptr; + } + } + + private: + PaintCanvas* canvas_ = nullptr; + int save_count_ = 0; +}; + +// TODO(enne): Move all these functions into PaintCanvas. These are only +// separate now to make the transition to concrete types easier by keeping +// the base PaintCanvas type equivalent to the SkCanvas interface and +// all these helper functions potentially operating on both. // PaintCanvas equivalent of skia::GetWritablePixels. CC_PAINT_EXPORT bool ToPixmap(PaintCanvas* canvas, SkPixmap* output); @@ -36,6 +440,18 @@ CC_PAINT_EXPORT void SetIsPreviewMetafile(PaintCanvas* canvas, bool is_preview); CC_PAINT_EXPORT bool IsPreviewMetafile(PaintCanvas* canvas); #endif +CC_PAINT_EXPORT void PaintCanvasAnnotateRectWithURL(PaintCanvas* canvas, + const SkRect& rect, + SkData* data); + +CC_PAINT_EXPORT void PaintCanvasAnnotateNamedDestination(PaintCanvas* canvas, + const SkPoint& point, + SkData* data); + +CC_PAINT_EXPORT void PaintCanvasAnnotateLinkToDestination(PaintCanvas* canvas, + const SkRect& rect, + SkData* data); + } // namespace cc #endif // CC_PAINT_PAINT_CANVAS_H_ diff --git a/cc/paint/paint_flags.h b/cc/paint/paint_flags.h index aa112452121ec0..b7e96c68e2ec48 100644 --- a/cc/paint/paint_flags.h +++ b/cc/paint/paint_flags.h @@ -5,14 +5,212 @@ #ifndef CC_PAINT_PAINT_FLAGS_H_ #define CC_PAINT_PAINT_FLAGS_H_ +#include "base/compiler_specific.h" +#include "cc/paint/paint_export.h" +#include "cc/paint/paint_shader.h" +#include "third_party/skia/include/core/SkCanvas.h" +#include "third_party/skia/include/core/SkColorFilter.h" +#include "third_party/skia/include/core/SkDrawLooper.h" +#include "third_party/skia/include/core/SkImageFilter.h" +#include "third_party/skia/include/core/SkMaskFilter.h" #include "third_party/skia/include/core/SkPaint.h" +#include "third_party/skia/include/core/SkPathEffect.h" +#include "third_party/skia/include/core/SkTypeface.h" namespace cc { -using PaintFlags = SkPaint; +class CC_PAINT_EXPORT PaintFlags { + public: + enum Style { + kFill_Style = SkPaint::kFill_Style, + kStroke_Style = SkPaint::kStroke_Style, + kStrokeAndFill_Style = SkPaint::kStrokeAndFill_Style, + }; + ALWAYS_INLINE Style getStyle() const { + return static_cast