Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: sky/engine/core/painting/Canvas.cpp

Issue 1151673002: Sky: different tack for custom Rect type in the Canvas API. (Closed) Base URL: git@github.com:/domokit/mojo.git@master
Patch Set: Float32List Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/engine/core/painting/Canvas.h ('k') | sky/engine/core/painting/Canvas.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/PictureRecorder.h" 6 #include "sky/engine/core/painting/Canvas.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(const 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
24 Canvas::Canvas(const FloatSize& size) 16 Canvas::Canvas(const FloatSize& size)
25 : m_size(size) 17 : m_size(size)
26 { 18 {
27 m_displayList = adoptRef(new DisplayList); 19 m_displayList = adoptRef(new DisplayList);
28 m_canvas = m_displayList->beginRecording(expandedIntSize(m_size)); 20 m_canvas = m_displayList->beginRecording(expandedIntSize(m_size));
29 } 21 }
30 22
31 Canvas::~Canvas() 23 Canvas::~Canvas()
32 { 24 {
33 } 25 }
34 26
35 void Canvas::save() 27 void Canvas::save()
36 { 28 {
37 if (!m_canvas) 29 if (!m_canvas)
38 return; 30 return;
39 ASSERT(m_displayList->isRecording()); 31 ASSERT(m_displayList->isRecording());
40 m_canvas->save(); 32 m_canvas->save();
41 } 33 }
42 34
43 void Canvas::saveLayer(const Vector<float>& bounds, const Paint* paint) 35 void Canvas::saveLayer(const Rect& bounds, const Paint* paint)
44 { 36 {
45 if (!m_canvas) 37 if (!m_canvas)
46 return; 38 return;
47 ASSERT(m_displayList->isRecording()); 39 ASSERT(m_displayList->isRecording());
48 SkRect sk_bounds; 40 m_canvas->saveLayer(!bounds.is_null ? &bounds.sk_rect : nullptr,
49 if (!bounds.isEmpty())
50 sk_bounds = toSkRect(bounds);
51 m_canvas->saveLayer(!bounds.isEmpty() ? &sk_bounds : nullptr,
52 paint ? &paint->paint() : nullptr); 41 paint ? &paint->paint() : nullptr);
53 } 42 }
54 43
55 void Canvas::restore() 44 void Canvas::restore()
56 { 45 {
57 if (!m_canvas) 46 if (!m_canvas)
58 return; 47 return;
59 ASSERT(m_displayList->isRecording()); 48 ASSERT(m_displayList->isRecording());
60 m_canvas->restore(); 49 m_canvas->restore();
61 } 50 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 { 85 {
97 if (!m_canvas) 86 if (!m_canvas)
98 return; 87 return;
99 ASSERT(m_displayList->isRecording()); 88 ASSERT(m_displayList->isRecording());
100 ASSERT(matrix.size() == 9); 89 ASSERT(matrix.size() == 9);
101 SkMatrix sk_matrix; 90 SkMatrix sk_matrix;
102 sk_matrix.set9(matrix.data()); 91 sk_matrix.set9(matrix.data());
103 m_canvas->concat(sk_matrix); 92 m_canvas->concat(sk_matrix);
104 } 93 }
105 94
106 void Canvas::clipRect(const Vector<float>& rect) 95 void Canvas::clipRect(const Rect& rect)
107 { 96 {
108 if (!m_canvas) 97 if (!m_canvas)
109 return; 98 return;
110 ASSERT(m_displayList->isRecording()); 99 ASSERT(m_displayList->isRecording());
111 m_canvas->clipRect(toSkRect(rect)); 100 m_canvas->clipRect(rect.sk_rect);
112 } 101 }
113 102
114 void Canvas::drawPicture(Picture* picture) 103 void Canvas::drawPicture(Picture* picture)
115 { 104 {
116 if (!m_canvas) 105 if (!m_canvas)
117 return; 106 return;
118 ASSERT(picture); 107 ASSERT(picture);
119 ASSERT(m_displayList->isRecording()); 108 ASSERT(m_displayList->isRecording());
120 m_canvas->drawPicture(picture->displayList()->picture()); 109 m_canvas->drawPicture(picture->displayList()->picture());
121 } 110 }
122 111
123 void Canvas::drawPaint(const Paint* paint) 112 void Canvas::drawPaint(const Paint* paint)
124 { 113 {
125 if (!m_canvas) 114 if (!m_canvas)
126 return; 115 return;
127 ASSERT(paint); 116 ASSERT(paint);
128 ASSERT(m_displayList->isRecording()); 117 ASSERT(m_displayList->isRecording());
129 m_canvas->drawPaint(paint->paint()); 118 m_canvas->drawPaint(paint->paint());
130 } 119 }
131 120
132 void Canvas::drawRect(const Vector<float>& rect, const Paint* paint) 121 void Canvas::drawRect(const Rect& rect, const Paint* paint)
133 { 122 {
134 if (!m_canvas) 123 if (!m_canvas)
135 return; 124 return;
136 ASSERT(paint); 125 ASSERT(paint);
137 ASSERT(m_displayList->isRecording()); 126 ASSERT(m_displayList->isRecording());
138 m_canvas->drawRect(toSkRect(rect), paint->paint()); 127 m_canvas->drawRect(rect.sk_rect, paint->paint());
139 } 128 }
140 129
141 void Canvas::drawOval(const Vector<float>& rect, const Paint* paint) 130 void Canvas::drawOval(const Rect& rect, const Paint* paint)
142 { 131 {
143 if (!m_canvas) 132 if (!m_canvas)
144 return; 133 return;
145 ASSERT(paint); 134 ASSERT(paint);
146 ASSERT(m_displayList->isRecording()); 135 ASSERT(m_displayList->isRecording());
147 m_canvas->drawOval(toSkRect(rect), paint->paint()); 136 m_canvas->drawOval(rect.sk_rect, paint->paint());
148 } 137 }
149 138
150 void Canvas::drawCircle(float x, float y, float radius, const Paint* paint) 139 void Canvas::drawCircle(float x, float y, float radius, const Paint* paint)
151 { 140 {
152 if (!m_canvas) 141 if (!m_canvas)
153 return; 142 return;
154 ASSERT(paint); 143 ASSERT(paint);
155 ASSERT(m_displayList->isRecording()); 144 ASSERT(m_displayList->isRecording());
156 m_canvas->drawCircle(x, y, radius, paint->paint()); 145 m_canvas->drawCircle(x, y, radius, paint->paint());
157 } 146 }
158 147
159 PassRefPtr<DisplayList> Canvas::finishRecording() 148 PassRefPtr<DisplayList> Canvas::finishRecording()
160 { 149 {
161 if (!isRecording()) 150 if (!isRecording())
162 return nullptr; 151 return nullptr;
163 m_canvas = nullptr; 152 m_canvas = nullptr;
164 m_displayList->endRecording(); 153 m_displayList->endRecording();
165 return m_displayList.release(); 154 return m_displayList.release();
166 } 155 }
167 156
168 } // namespace blink 157 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/painting/Canvas.h ('k') | sky/engine/core/painting/Canvas.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698