| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/paint/paint_canvas.h" | 5 #include "cc/paint/paint_canvas.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "cc/paint/paint_record.h" | 8 #include "cc/paint/paint_record.h" |
| 9 #include "cc/paint/paint_recorder.h" | 9 #include "cc/paint/paint_recorder.h" |
| 10 #include "third_party/skia/include/core/SkAnnotation.h" | 10 #include "third_party/skia/include/core/SkAnnotation.h" |
| 11 #include "third_party/skia/include/core/SkMetaData.h" | 11 #include "third_party/skia/include/core/SkMetaData.h" |
| 12 #include "third_party/skia/include/utils/SkNWayCanvas.h" | |
| 13 | 12 |
| 14 #if defined(OS_MACOSX) | 13 #if defined(OS_MACOSX) |
| 15 namespace { | 14 namespace { |
| 16 const char kIsPreviewMetafileKey[] = "CrIsPreviewMetafile"; | 15 const char kIsPreviewMetafileKey[] = "CrIsPreviewMetafile"; |
| 17 } | 16 } |
| 18 #endif | 17 #endif |
| 19 | 18 |
| 20 namespace cc { | 19 namespace cc { |
| 21 | 20 |
| 22 PaintCanvas::PaintCanvas(SkCanvas* canvas) : canvas_(canvas) {} | |
| 23 | |
| 24 PaintCanvas::PaintCanvas(const SkBitmap& bitmap) | |
| 25 : canvas_(new SkCanvas(bitmap)), owned_(canvas_) {} | |
| 26 | |
| 27 PaintCanvas::PaintCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props) | |
| 28 : canvas_(new SkCanvas(bitmap, props)), owned_(canvas_) {} | |
| 29 | |
| 30 PaintCanvas::~PaintCanvas() = default; | |
| 31 | |
| 32 bool ToPixmap(PaintCanvas* canvas, SkPixmap* output) { | 21 bool ToPixmap(PaintCanvas* canvas, SkPixmap* output) { |
| 33 SkImageInfo info; | 22 return canvas->ToPixmap(output); |
| 34 size_t row_bytes; | |
| 35 void* pixels = canvas->canvas_->accessTopLayerPixels(&info, &row_bytes); | |
| 36 if (!pixels) { | |
| 37 output->reset(); | |
| 38 return false; | |
| 39 } | |
| 40 | |
| 41 output->reset(info, pixels, row_bytes); | |
| 42 return true; | |
| 43 } | 23 } |
| 44 | 24 |
| 45 #if defined(OS_MACOSX) | 25 #if defined(OS_MACOSX) |
| 46 void SetIsPreviewMetafile(PaintCanvas* canvas, bool is_preview) { | 26 void SetIsPreviewMetafile(PaintCanvas* canvas, bool is_preview) { |
| 47 SkMetaData& meta = canvas->getMetaData(); | 27 SkMetaData& meta = canvas->getMetaData(); |
| 48 meta.setBool(kIsPreviewMetafileKey, is_preview); | 28 meta.setBool(kIsPreviewMetafileKey, is_preview); |
| 49 } | 29 } |
| 50 | 30 |
| 51 bool IsPreviewMetafile(PaintCanvas* canvas) { | 31 bool IsPreviewMetafile(PaintCanvas* canvas) { |
| 52 bool value; | 32 bool value; |
| 53 SkMetaData& meta = canvas->getMetaData(); | 33 SkMetaData& meta = canvas->getMetaData(); |
| 54 if (!meta.findBool(kIsPreviewMetafileKey, &value)) | 34 if (!meta.findBool(kIsPreviewMetafileKey, &value)) |
| 55 value = false; | 35 value = false; |
| 56 return value; | 36 return value; |
| 57 } | 37 } |
| 58 #endif | 38 #endif |
| 59 | 39 |
| 60 void PaintCanvasAnnotateRectWithURL(PaintCanvas* canvas, | 40 void PaintCanvasAnnotateRectWithURL(PaintCanvas* canvas, |
| 61 const SkRect& rect, | 41 const SkRect& rect, |
| 62 SkData* data) { | 42 SkData* data) { |
| 63 SkAnnotateRectWithURL(canvas->canvas_, rect, data); | 43 canvas->AnnotateRectWithURL(rect, data); |
| 64 } | 44 } |
| 65 | 45 |
| 66 void PaintCanvasAnnotateNamedDestination(PaintCanvas* canvas, | 46 void PaintCanvasAnnotateNamedDestination(PaintCanvas* canvas, |
| 67 const SkPoint& point, | 47 const SkPoint& point, |
| 68 SkData* data) { | 48 SkData* data) { |
| 69 SkAnnotateNamedDestination(canvas->canvas_, point, data); | 49 canvas->AnnotateNamedDestination(point, data); |
| 70 } | 50 } |
| 71 | 51 |
| 72 void PaintCanvasAnnotateLinkToDestination(PaintCanvas* canvas, | 52 void PaintCanvasAnnotateLinkToDestination(PaintCanvas* canvas, |
| 73 const SkRect& rect, | 53 const SkRect& rect, |
| 74 SkData* data) { | 54 SkData* data) { |
| 75 SkAnnotateLinkToDestination(canvas->canvas_, rect, data); | 55 canvas->AnnotateLinkToDestination(rect, data); |
| 76 } | 56 } |
| 77 | 57 |
| 78 } // namespace cc | 58 } // namespace cc |
| OLD | NEW |