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

Side by Side Diff: runtime/embedders/openglui/common/canvas_context.h

Issue 12186002: Canvas API. There are still a number of things to do: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 #ifndef EMBEDDERS_OPENGLUI_COMMON_CANVAS_CONTEXT_H_
6 #define EMBEDDERS_OPENGLUI_COMMON_CANVAS_CONTEXT_H_
7
8 #include "embedders/openglui/common/canvas_state.h"
9 #include "embedders/openglui/common/graphics_handler.h"
10 #include "embedders/openglui/common/log.h"
11 #include "embedders/openglui/common/opengl.h"
12 #include "embedders/openglui/common/support.h"
13
14 typedef struct ImageData {
15 int width;
16 int height;
17 GLubyte* pixels;
18
19 ImageData(int wp, int hp, GLubyte* pp)
20 : width(wp), height(hp), pixels(pp) {
21 }
22 ImageData() {}
vsm 2013/02/04 18:18:41 Initialize 0/NULL on empty constructor?
gram 2013/02/04 22:02:28 Done.
23 } ImageData;
24
25 class CanvasContext {
26 protected:
27 SkCanvas* canvas_;
28
29 int16_t width_, height_;
30
31 bool imageSmoothingEnabled_;
32
33 CanvasState* state_;
34
35 inline float Radians2Degrees(float angle) {
vsm 2013/02/04 18:18:41 Can make static to avoid implicit this argument.
gram 2013/02/04 22:02:28 Done.
36 return 180.0 * angle / M_PI;
37 }
38
39 inline void NotImplemented(const char* method) {
40 LOGE("Method CanvasContext::%s is not yet implemented", method);
41 }
42
43 public:
44 CanvasContext(int16_t width, int16_t height);
45 virtual ~CanvasContext();
46
47 inline void setGlobalAlpha(float alpha) {
48 state_->setGlobalAlpha(alpha);
49 }
50
51 inline void setFillColor(const char* color) {
52 state_->setFillColor(color);
53 }
54
55 inline void setStrokeColor(const char* color) {
56 state_->setStrokeColor(color);
57 }
58
59 inline void setShadowBlur(float blur) {
60 state_->setShadowBlur(blur);
61 }
62
63 inline void setShadowColor(const char* color) {
64 state_->setShadowColor(color);
65 }
66
67 inline void setShadowOffsetX(float offset) {
68 state_->setShadowOffsetX(offset);
69 }
70
71 inline void setShadowOffsetY(float offset) {
72 state_->setShadowOffsetY(offset);
73 }
74
75 // For now, we don't allow resizing.
76 // TODO(gram): fix this or remove these.
77 inline int setWidth(int widthp) {
78 return width_;
79 }
80
81 inline int setHeight(int heightp) {
82 return height_;
83 }
84
85 inline bool imageSmoothingEnabled() {
86 return imageSmoothingEnabled_;
87 }
88
89 inline void setImageSmoothingEnabled(bool enabled) {
90 // TODO(gram): We're not actually doing anything with this yet.
91 imageSmoothingEnabled_ = enabled;
92 }
93
94 inline void setGlobalCompositeOperation(const char* op) {
95 state_->setGlobalCompositeOperation(op);
96 }
97
98 inline void Save() {
99 state_ = state_->Save();
100 }
101
102 inline void Restore() {
103 CanvasState* popped_state = state_;
104 state_ = state_->Restore();
105 if (state_ != popped_state) {
vsm 2013/02/04 18:18:41 Not sure I understand the model here. Is it possi
gram 2013/02/04 22:02:28 I'm not sure on the exact semantics of Canvas if y
106 delete popped_state;
107 }
108 }
109
110 inline void Rotate(float angle) {
111 canvas_->rotate(Radians2Degrees(angle));
112 }
113
114 inline void Translate(float x, float y) {
115 canvas_->translate(x, y);
116 }
117
118 inline void Scale(float x, float y) {
119 canvas_->scale(x, y);
120 }
121
122 inline void Transform(float a, float b,
123 float c, float d,
124 float e, float f) {
125 SkMatrix t;
126 // Our params are for a 3 x 2 matrix in column order:
127 //
128 // a c e
129 // b d f
130 //
131 // We need to turn this into a 3x3 matrix:
132 //
133 // a c e
134 // b d f
135 // 0 0 1
136 //
137 // and pass the params in row order:
138 t.setAll(a, c, e, b, d, f, 0, 0, 1);
139 canvas_->concat(t);
140 }
141
142 inline void setTransform(float a, float b,
143 float c, float d,
144 float e, float f) {
145 SkMatrix t;
146 t.setAll(a, c, e, b, d, f, 0, 0, 1);
147 canvas_->setMatrix(t);
148 }
149
150 ImageData* GetImageData(float sx, float sy, float sw, float sh) {
151 NotImplemented("GetImageData");
152 return NULL;
153 }
154
155 void PutImageData(ImageData* imageData, float dx, float dy) {
156 NotImplemented("PutImageData");
157 }
158
159 void DrawImage(const char* src_url,
160 int sx, int sy, bool has_src_dimensions, int sw, int sh,
161 int dx, int dy, bool has_dst_dimensions, int dw, int dh);
162
163 inline void Clear() {
164 canvas_->drawColor(0xFFFFFFFF);
165 }
166
167 void ClearRect(float left, float top, float width, float height);
168
169 inline void FillRect(float left, float top, float width, float height) {
170 // Does not affect the path.
171 state_->FillRect(left, top, width, height);
172 }
173
174 inline void StrokeRect(float left, float top, float width, float height) {
175 // Does not affect the path.
176 state_->StrokeRect(left, top, width, height);
177 }
178
179 inline void BeginPath() {
180 state_->BeginPath();
181 }
182
183 inline void Fill() {
184 state_->Fill();
185 }
186
187 inline void Stroke() {
188 state_->Stroke();
189 }
190
191 inline void ClosePath() {
192 state_->ClosePath();
193 }
194
195 inline void MoveTo(float x, float y) {
196 state_->MoveTo(x, y);
197 }
198
199 inline void LineTo(float x, float y) {
200 state_->LineTo(x, y);
201 }
202
203 inline void QuadraticCurveTo(float cpx, float cpy, float x, float y) {
204 state_->QuadraticCurveTo(cpx, cpy, x, y);
205 }
206
207 inline void BezierCurveTo(float cp1x, float cp1y, float cp2x, float cp2y,
208 float x, float y) {
209 state_->BezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
210 }
211
212 inline void ArcTo(float x1, float y1, float x2, float y2, float radius) {
213 state_->ArcTo(x1, y1, x2, y2, radius);
214 }
215
216 inline void Rect(float x, float y, float w, float h) {
217 state_->Rect(x, y, w, h);
218 }
219
220 inline void Arc(float x, float y, float radius,
221 float startAngle, float endAngle,
222 bool antiClockwise) {
223 state_->Arc(x, y, radius, startAngle, endAngle, antiClockwise);
224 }
225
226 inline void setLineWidth(double w) {
227 state_->setLineWidth(w);
228 }
229
230 inline void setLineCap(const char* lc) {
231 state_->setLineCap(lc);
232 }
233
234 inline void setLineDash(float* dashes, int len) {
235 state_->setLineDash(dashes, len);
236 }
237
238 inline void setLineDashOffset(float offset) {
239 state_->setLineDashOffset(offset);
240 }
241
242 inline void setLineJoin(const char* lj) {
243 state_->setLineJoin(lj);
244 }
245
246 inline void setMiterLimit(float limit) {
247 state_->setMiterLimit(limit);
248 }
249
250 inline const char* setFont(const char* font) {
251 return state_->setFont(font);
252 }
253
254 inline const char* setTextAlign(const char* align) {
255 return state_->setTextAlign(align);
256 }
257
258 const char* setTextBaseline(const char* baseline) {
259 return state_->setTextBaseline(baseline);
260 }
261
262 inline const char* setDirection(const char* direction) {
263 return state_->setTextDirection(direction);
264 }
265
266 inline void FillText(const char* text, float x, float y,
267 float maxWidth = -1) {
268 state_->FillText(text, x, y, maxWidth);
269 }
270
271 inline void StrokeText(const char* text, float x, float y,
272 float maxWidth = -1) {
273 state_->StrokeText(text, x, y, maxWidth);
274 }
275
276 inline float MeasureText(const char *text) {
277 return state_->MeasureText(text);
278 }
279
280 inline void Clip() {
281 state_->Clip();
282 }
283
284 inline void ResetClip() {
285 // TODO(gram): Check this. Is it affected by the transform?
286 canvas_->clipRect(SkRect::MakeLTRB(0, 0, width_, height_),
287 SkRegion::kReplace_Op);
288 }
289
290 virtual void Flush() {
291 canvas_->flush();
292 graphics->Flush();
293 }
294
295 void Create();
296 };
297
298 #endif // EMBEDDERS_OPENGLUI_COMMON_CANVAS_CONTEXT_H_
299
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698