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 #include "sky/engine/config.h" | 5 #include "sky/engine/config.h" |
6 #include "sky/engine/core/painting/PaintingContext.h" | 6 #include "sky/engine/core/painting/PaintingContext.h" |
7 | 7 |
8 #include "sky/engine/core/dom/Document.h" | 8 #include "sky/engine/core/dom/Document.h" |
9 #include "sky/engine/core/dom/Element.h" | 9 #include "sky/engine/core/dom/Element.h" |
10 #include "sky/engine/core/painting/PaintingTasks.h" | 10 #include "sky/engine/core/painting/PaintingTasks.h" |
11 #include "sky/engine/platform/geometry/IntRect.h" | 11 #include "sky/engine/platform/geometry/IntRect.h" |
12 #include "third_party/skia/include/core/SkCanvas.h" | 12 #include "third_party/skia/include/core/SkCanvas.h" |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
| 16 SkRect toSkRect(Vector<float> rect) |
| 17 { |
| 18 ASSERT(rect.size() == 4); |
| 19 SkRect sk_rect; |
| 20 sk_rect.set(rect[0], rect[1], rect[2], rect[3]); |
| 21 return sk_rect; |
| 22 } |
| 23 |
16 PassRefPtr<PaintingContext> PaintingContext::create(PassRefPtr<Element> element,
const FloatSize& size) | 24 PassRefPtr<PaintingContext> PaintingContext::create(PassRefPtr<Element> element,
const FloatSize& size) |
17 { | 25 { |
18 return adoptRef(new PaintingContext(element, size)); | 26 return adoptRef(new PaintingContext(element, size)); |
19 } | 27 } |
20 | 28 |
21 PaintingContext::PaintingContext(PassRefPtr<Element> element, const FloatSize& s
ize) | 29 PaintingContext::PaintingContext(PassRefPtr<Element> element, const FloatSize& s
ize) |
22 : m_element(element) | 30 : m_element(element) |
23 , m_size(size) | 31 , m_size(size) |
24 { | 32 { |
25 m_displayList = adoptRef(new DisplayList); | 33 m_displayList = adoptRef(new DisplayList); |
26 m_canvas = m_displayList->beginRecording(expandedIntSize(m_size)); | 34 m_canvas = m_displayList->beginRecording(expandedIntSize(m_size)); |
27 } | 35 } |
28 | 36 |
29 PaintingContext::~PaintingContext() | 37 PaintingContext::~PaintingContext() |
30 { | 38 { |
31 } | 39 } |
32 | 40 |
| 41 void PaintingContext::save() |
| 42 { |
| 43 if (!m_canvas) |
| 44 return; |
| 45 ASSERT(m_displayList->isRecording()); |
| 46 m_canvas->save(); |
| 47 } |
| 48 |
| 49 void PaintingContext::saveLayer(Vector<float> bounds, Paint* paint) |
| 50 { |
| 51 if (!m_canvas) |
| 52 return; |
| 53 ASSERT(m_displayList->isRecording()); |
| 54 SkRect sk_bounds; |
| 55 if (bounds.size() != 0) |
| 56 sk_bounds = toSkRect(bounds); |
| 57 m_canvas->saveLayer(bounds.size() != 0 ? &sk_bounds : nullptr, |
| 58 paint ? &paint->paint() : nullptr); |
| 59 } |
| 60 |
| 61 void PaintingContext::restore() |
| 62 { |
| 63 if (!m_canvas) |
| 64 return; |
| 65 ASSERT(m_displayList->isRecording()); |
| 66 m_canvas->restore(); |
| 67 } |
| 68 |
| 69 void PaintingContext::translate(float dx, float dy) |
| 70 { |
| 71 if (!m_canvas) |
| 72 return; |
| 73 ASSERT(m_displayList->isRecording()); |
| 74 m_canvas->translate(dx, dy); |
| 75 } |
| 76 |
| 77 void PaintingContext::scale(float sx, float sy) |
| 78 { |
| 79 if (!m_canvas) |
| 80 return; |
| 81 ASSERT(m_displayList->isRecording()); |
| 82 m_canvas->scale(sx, sy); |
| 83 } |
| 84 |
| 85 void PaintingContext::rotate(float degrees) |
| 86 { |
| 87 if (!m_canvas) |
| 88 return; |
| 89 ASSERT(m_displayList->isRecording()); |
| 90 m_canvas->rotate(degrees); |
| 91 } |
| 92 |
| 93 void PaintingContext::skew(float sx, float sy) |
| 94 { |
| 95 if (!m_canvas) |
| 96 return; |
| 97 ASSERT(m_displayList->isRecording()); |
| 98 m_canvas->skew(sx, sy); |
| 99 } |
| 100 |
| 101 void PaintingContext::concat(Vector<float> matrix) |
| 102 { |
| 103 if (!m_canvas) |
| 104 return; |
| 105 ASSERT(m_displayList->isRecording()); |
| 106 ASSERT(matrix.size() == 9); |
| 107 SkMatrix sk_matrix; |
| 108 sk_matrix.set9(matrix.data()); |
| 109 m_canvas->concat(sk_matrix); |
| 110 } |
| 111 |
| 112 void PaintingContext::clipRect(Vector<float> rect) |
| 113 { |
| 114 if (!m_canvas) |
| 115 return; |
| 116 ASSERT(m_displayList->isRecording()); |
| 117 m_canvas->clipRect(toSkRect(rect)); |
| 118 } |
| 119 |
| 120 void PaintingContext::drawPaint(Paint* paint) |
| 121 { |
| 122 if (!m_canvas) |
| 123 return; |
| 124 ASSERT(paint); |
| 125 ASSERT(m_displayList->isRecording()); |
| 126 m_canvas->drawPaint(paint->paint()); |
| 127 } |
| 128 |
| 129 void PaintingContext::drawOval(Vector<float> rect, Paint* paint) |
| 130 { |
| 131 if (!m_canvas) |
| 132 return; |
| 133 ASSERT(paint); |
| 134 ASSERT(m_displayList->isRecording()); |
| 135 m_canvas->drawOval(toSkRect(rect), paint->paint()); |
| 136 } |
| 137 |
| 138 void PaintingContext::drawRect(Vector<float> rect, Paint* paint) |
| 139 { |
| 140 if (!m_canvas) |
| 141 return; |
| 142 ASSERT(paint); |
| 143 ASSERT(m_displayList->isRecording()); |
| 144 m_canvas->drawRect(toSkRect(rect), paint->paint()); |
| 145 } |
| 146 |
33 void PaintingContext::drawCircle(double x, double y, double radius, Paint* paint
) | 147 void PaintingContext::drawCircle(double x, double y, double radius, Paint* paint
) |
34 { | 148 { |
35 if (!m_canvas) | 149 if (!m_canvas) |
36 return; | 150 return; |
37 ASSERT(paint); | 151 ASSERT(paint); |
38 ASSERT(m_displayList->isRecording()); | 152 ASSERT(m_displayList->isRecording()); |
39 m_canvas->drawCircle(x, y, radius, paint->paint()); | 153 m_canvas->drawCircle(x, y, radius, paint->paint()); |
40 } | 154 } |
41 | 155 |
42 void PaintingContext::commit() | 156 void PaintingContext::commit() |
43 { | 157 { |
44 if (!m_canvas) | 158 if (!m_canvas) |
45 return; | 159 return; |
46 m_displayList->endRecording(); | 160 m_displayList->endRecording(); |
47 m_canvas = nullptr; | 161 m_canvas = nullptr; |
48 PaintingTasks::enqueueCommit(m_element, m_displayList.release()); | 162 PaintingTasks::enqueueCommit(m_element, m_displayList.release()); |
49 m_element->document().scheduleVisualUpdate(); | 163 m_element->document().scheduleVisualUpdate(); |
50 } | 164 } |
51 | 165 |
52 } // namespace blink | 166 } // namespace blink |
OLD | NEW |