| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "sky/engine/core/painting/PaintingNode.h" |
| 6 #include "sky/engine/core/painting/Picture.h" |
| 7 |
| 8 namespace blink { |
| 9 |
| 10 class PaintingNodeDrawable : public SkDrawable { |
| 11 public: |
| 12 static PassRefPtr<PaintingNodeDrawable> create(PassRefPtr<SkDrawable> skDraw
able = nullptr); |
| 13 |
| 14 ~PaintingNodeDrawable() override; |
| 15 |
| 16 SkRect onGetBounds() override; |
| 17 void onDraw(SkCanvas* canvas) override; |
| 18 SkPicture* onNewPictureSnapshot() override; |
| 19 void set_drawable(PassRefPtr<SkDrawable> drawable) { m_drawable = drawable;
} |
| 20 |
| 21 private: |
| 22 PaintingNodeDrawable(); |
| 23 explicit PaintingNodeDrawable(PassRefPtr<SkDrawable> skDrawable); |
| 24 RefPtr<SkDrawable> m_drawable; |
| 25 }; |
| 26 |
| 27 // static |
| 28 PassRefPtr<PaintingNodeDrawable> PaintingNodeDrawable::create(PassRefPtr<SkDrawa
ble> skDrawable) |
| 29 { |
| 30 return adoptRef(new PaintingNodeDrawable(skDrawable)); |
| 31 } |
| 32 |
| 33 PaintingNodeDrawable::~PaintingNodeDrawable() {} |
| 34 |
| 35 |
| 36 PaintingNodeDrawable::PaintingNodeDrawable(PassRefPtr<SkDrawable> skDrawable) |
| 37 : m_drawable(skDrawable) |
| 38 { |
| 39 } |
| 40 |
| 41 SkPicture* PaintingNodeDrawable::onNewPictureSnapshot() |
| 42 { |
| 43 if (!m_drawable) |
| 44 return nullptr; |
| 45 return m_drawable->newPictureSnapshot(); |
| 46 } |
| 47 |
| 48 SkRect PaintingNodeDrawable::onGetBounds() |
| 49 { |
| 50 if (!m_drawable) |
| 51 return SkRect::MakeEmpty(); |
| 52 return m_drawable->getBounds(); |
| 53 } |
| 54 |
| 55 void PaintingNodeDrawable::onDraw(SkCanvas* canvas) |
| 56 { |
| 57 if (!m_drawable) |
| 58 return; |
| 59 return m_drawable->draw(canvas); |
| 60 } |
| 61 |
| 62 |
| 63 |
| 64 |
| 65 PassRefPtr<PaintingNode> PaintingNode::create() |
| 66 { |
| 67 return adoptRef(new PaintingNode()); |
| 68 } |
| 69 |
| 70 PaintingNode::PaintingNode() |
| 71 : m_paintingNodeDrawable(PaintingNodeDrawable::create()) |
| 72 { |
| 73 } |
| 74 |
| 75 void PaintingNode::setBackingDrawable(PassRefPtr<Drawable> drawable) |
| 76 { |
| 77 m_paintingNodeDrawable->set_drawable(drawable->toSkia()); |
| 78 } |
| 79 |
| 80 SkDrawable* PaintingNode::toSkia() |
| 81 { |
| 82 return m_paintingNodeDrawable.get(); |
| 83 } |
| 84 |
| 85 PassRefPtr<Picture> PaintingNode::newPictureSnapshot() |
| 86 { |
| 87 ASSERT(m_paintingNodeDrawable); |
| 88 return Picture::create( |
| 89 adoptRef(m_paintingNodeDrawable->newPictureSnapshot())); |
| 90 } |
| 91 |
| 92 PaintingNode::~PaintingNode() |
| 93 { |
| 94 } |
| 95 |
| 96 } // namespace blink |
| OLD | NEW |