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

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

Powered by Google App Engine
This is Rietveld 408576698