| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef SKY_ENGINE_CORE_PAINTING_CANVAS_H_ | 5 #ifndef SKY_ENGINE_CORE_PAINTING_CANVAS_H_ |
| 6 #define SKY_ENGINE_CORE_PAINTING_CANVAS_H_ | 6 #define SKY_ENGINE_CORE_PAINTING_CANVAS_H_ |
| 7 | 7 |
| 8 #include "sky/engine/bindings/exception_state.h" | 8 #include "sky/engine/bindings/exception_state.h" |
| 9 #include "sky/engine/core/painting/CanvasPath.h" | 9 #include "sky/engine/core/painting/CanvasPath.h" |
| 10 #include "sky/engine/core/painting/Drawable.h" | 10 #include "sky/engine/core/painting/Drawable.h" |
| 11 #include "sky/engine/core/painting/Offset.h" | 11 #include "sky/engine/core/painting/Offset.h" |
| 12 #include "sky/engine/core/painting/Paint.h" | 12 #include "sky/engine/core/painting/Paint.h" |
| 13 #include "sky/engine/core/painting/PaintingNode.h" |
| 13 #include "sky/engine/core/painting/Picture.h" | 14 #include "sky/engine/core/painting/Picture.h" |
| 14 #include "sky/engine/core/painting/PictureRecorder.h" | 15 #include "sky/engine/core/painting/PictureRecorder.h" |
| 15 #include "sky/engine/core/painting/Point.h" | 16 #include "sky/engine/core/painting/Point.h" |
| 16 #include "sky/engine/core/painting/RRect.h" | 17 #include "sky/engine/core/painting/RRect.h" |
| 17 #include "sky/engine/core/painting/Rect.h" | 18 #include "sky/engine/core/painting/Rect.h" |
| 18 #include "sky/engine/core/painting/Size.h" | 19 #include "sky/engine/core/painting/Size.h" |
| 19 #include "sky/engine/platform/graphics/DisplayList.h" | 20 #include "sky/engine/platform/graphics/DisplayList.h" |
| 20 #include "sky/engine/tonic/dart_wrappable.h" | 21 #include "sky/engine/tonic/dart_wrappable.h" |
| 21 #include "sky/engine/tonic/float32_list.h" | 22 #include "sky/engine/tonic/float32_list.h" |
| 22 #include "sky/engine/wtf/PassRefPtr.h" | 23 #include "sky/engine/wtf/PassRefPtr.h" |
| 23 #include "sky/engine/wtf/RefCounted.h" | 24 #include "sky/engine/wtf/RefCounted.h" |
| 24 #include "third_party/skia/include/core/SkCanvas.h" | 25 #include "third_party/skia/include/core/SkCanvas.h" |
| 25 | 26 |
| 26 namespace blink { | 27 namespace blink { |
| 27 class CanvasImage; | 28 class CanvasImage; |
| 28 | 29 |
| 29 class Canvas : public RefCounted<Canvas>, public DartWrappable { | 30 class Canvas : public RefCounted<Canvas>, public DartWrappable { |
| 30 DEFINE_WRAPPERTYPEINFO(); | 31 DEFINE_WRAPPERTYPEINFO(); |
| 31 public: | 32 public: |
| 32 static PassRefPtr<Canvas> create(SkCanvas* skCanvas) { | 33 static PassRefPtr<Canvas> create(SkCanvas* skCanvas) { |
| 33 ASSERT(skCanvas); | 34 ASSERT(skCanvas); |
| 34 return adoptRef(new Canvas(skCanvas)); | 35 return adoptRef(new Canvas(skCanvas)); |
| 35 } | 36 } |
| 36 | 37 |
| 37 static PassRefPtr<Canvas> create(PictureRecorder* recorder, | 38 static PassRefPtr<Canvas> create(PictureRecorder* recorder, |
| 38 Size& bounds, | 39 Rect& bounds, |
| 39 ExceptionState& es) { | 40 ExceptionState& es) { |
| 40 ASSERT(recorder); | 41 ASSERT(recorder); |
| 41 if (recorder->isRecording()) { | 42 if (recorder->isRecording()) { |
| 42 es.ThrowTypeError( | 43 es.ThrowTypeError( |
| 43 "You must call PictureRecorder.endRecording() before reusing a" | 44 "You must call PictureRecorder.endRecording() before reusing a" |
| 44 " PictureRecorder to create a new Canvas object."); | 45 " PictureRecorder to create a new Canvas object."); |
| 45 // TODO(iansf): We should return a nullptr here, I think, but doing | 46 // TODO(iansf): We should return a nullptr here, I think, but doing |
| 46 // so will require modifying the dart template code to | 47 // so will require modifying the dart template code to |
| 47 // to correctly handle constructors that throw | 48 // to correctly handle constructors that throw |
| 48 // exceptions. For now, just let it return a dart | 49 // exceptions. For now, just let it return a dart |
| 49 // object that may cause a crash later on -- if the | 50 // object that may cause a crash later on -- if the |
| 50 // dart code catches the error, it will leak a canvas | 51 // dart code catches the error, it will leak a canvas |
| 51 // but it won't crash. | 52 // but it won't crash. |
| 52 } | 53 } |
| 53 PassRefPtr<Canvas> canvas = create( | 54 PassRefPtr<Canvas> canvas = create(recorder->beginRecording(bounds)); |
| 54 recorder->beginRecording(bounds.sk_size.width(), bounds.sk_size.height
())); | |
| 55 recorder->set_canvas(canvas.get()); | 55 recorder->set_canvas(canvas.get()); |
| 56 return canvas; | 56 return canvas; |
| 57 } | 57 } |
| 58 | 58 |
| 59 ~Canvas() override; | 59 ~Canvas() override; |
| 60 | 60 |
| 61 void save(); | 61 void save(); |
| 62 void saveLayer(const Rect& bounds, const Paint* paint = nullptr); | 62 void saveLayer(const Rect& bounds, const Paint* paint = nullptr); |
| 63 void restore(); | 63 void restore(); |
| 64 | 64 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 76 void drawPaint(const Paint* paint); | 76 void drawPaint(const Paint* paint); |
| 77 void drawRect(const Rect& rect, const Paint* paint); | 77 void drawRect(const Rect& rect, const Paint* paint); |
| 78 void drawRRect(const RRect* rrect, const Paint* paint); | 78 void drawRRect(const RRect* rrect, const Paint* paint); |
| 79 void drawOval(const Rect& rect, const Paint* paint); | 79 void drawOval(const Rect& rect, const Paint* paint); |
| 80 void drawCircle(const Point& c, float radius, const Paint* paint); | 80 void drawCircle(const Point& c, float radius, const Paint* paint); |
| 81 void drawPath(const CanvasPath* path, const Paint* paint); | 81 void drawPath(const CanvasPath* path, const Paint* paint); |
| 82 void drawImage(const CanvasImage* image, const Point& p, const Paint* paint)
; | 82 void drawImage(const CanvasImage* image, const Point& p, const Paint* paint)
; |
| 83 void drawImageRect(const CanvasImage* image, Rect& src, Rect& dst, Paint* pa
int); | 83 void drawImageRect(const CanvasImage* image, Rect& src, Rect& dst, Paint* pa
int); |
| 84 void drawPicture(Picture* picture); | 84 void drawPicture(Picture* picture); |
| 85 void drawDrawable(Drawable* drawable); | 85 void drawDrawable(Drawable* drawable); |
| 86 void drawPaintingNode(PaintingNode* paintingNode, const Point& p); |
| 86 | 87 |
| 87 SkCanvas* skCanvas() { return m_canvas; } | 88 SkCanvas* skCanvas() { return m_canvas; } |
| 88 void clearSkCanvas() { m_canvas = nullptr; } | 89 void clearSkCanvas() { m_canvas = nullptr; } |
| 89 bool isRecording() const { return !!m_canvas; } | 90 bool isRecording() const { return !!m_canvas; } |
| 90 | 91 |
| 91 protected: | 92 protected: |
| 92 explicit Canvas(SkCanvas* skCanvas); | 93 explicit Canvas(SkCanvas* skCanvas); |
| 93 | 94 |
| 94 private: | 95 private: |
| 95 // The SkCanvas is supplied by a call to SkPictureRecorder::beginRecording, | 96 // The SkCanvas is supplied by a call to SkPictureRecorder::beginRecording, |
| 96 // which does not transfer ownership. For this reason, we hold a raw | 97 // which does not transfer ownership. For this reason, we hold a raw |
| 97 // pointer and manually set the SkCanvas to null in clearSkCanvas. | 98 // pointer and manually set the SkCanvas to null in clearSkCanvas. |
| 98 SkCanvas* m_canvas; | 99 SkCanvas* m_canvas; |
| 99 }; | 100 }; |
| 100 | 101 |
| 101 } // namespace blink | 102 } // namespace blink |
| 102 | 103 |
| 103 #endif // SKY_ENGINE_CORE_PAINTING_CANVAS_H_ | 104 #endif // SKY_ENGINE_CORE_PAINTING_CANVAS_H_ |
| OLD | NEW |