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

Side by Side Diff: runtime/embedders/openglui/common/canvas_state.cc

Issue 13042015: Various OpenGLUI changes: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 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
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "embedders/openglui/common/canvas_state.h" 5 #include "embedders/openglui/common/canvas_state.h"
6 6
7 #include <ctype.h> 7 #include <ctype.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include "embedders/openglui/common/support.h" 10 #include "embedders/openglui/common/support.h"
(...skipping 29 matching lines...) Expand all
40 while (pos < len && !isdigit(s[pos])) { 40 while (pos < len && !isdigit(s[pos])) {
41 ++pos; 41 ++pos;
42 } 42 }
43 while (pos < len && isdigit(s[pos])) { 43 while (pos < len && isdigit(s[pos])) {
44 rtn = rtn * 10 + s[pos] - '0'; 44 rtn = rtn * 10 + s[pos] - '0';
45 ++pos; 45 ++pos;
46 } 46 }
47 return rtn; 47 return rtn;
48 } 48 }
49 49
50 CanvasState* CanvasState::Restore() {
51 if (next_ != NULL) {
52 // If the state we are popping has a non-empty path,
53 // apply the state's transform to the path, then
54 // add the path to the previous state's path.
55 if (path_->countPoints() > 0) {
56 path_->transform(canvas_->getTotalMatrix());
57 next_->path_->addPath(*path_);
58 }
59 canvas_->restore();
60 return next_;
61 }
62 canvas_->restore();
63 return next_; // TODO(gram): Should we assert/throw?
64 }
65
50 void CanvasState::setLineCap(const char* lc) { 66 void CanvasState::setLineCap(const char* lc) {
51 if (strcmp(lc, "round") == 0) { 67 if (strcmp(lc, "round") == 0) {
52 paint_.setStrokeCap(SkPaint::kRound_Cap); 68 paint_.setStrokeCap(SkPaint::kRound_Cap);
53 } else if (strcmp(lc, "square") == 0) { 69 } else if (strcmp(lc, "square") == 0) {
54 paint_.setStrokeCap(SkPaint::kSquare_Cap); 70 paint_.setStrokeCap(SkPaint::kSquare_Cap);
55 } else { 71 } else {
56 paint_.setStrokeCap(SkPaint::kButt_Cap); 72 paint_.setStrokeCap(SkPaint::kButt_Cap);
57 } 73 }
58 } 74 }
59 75
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 } else if (strcmp(baseline, "ideographic") == 0) { 146 } else if (strcmp(baseline, "ideographic") == 0) {
131 } 147 }
132 return baseline; 148 return baseline;
133 } 149 }
134 150
135 const char* CanvasState::setTextDirection(const char* direction) { 151 const char* CanvasState::setTextDirection(const char* direction) {
136 // TODO(gram): Add support for this if Skia does. 152 // TODO(gram): Add support for this if Skia does.
137 return direction; 153 return direction;
138 } 154 }
139 155
156 void CanvasState::setMode(SkPaint::Style style, ColorRGBA color,
157 SkShader* shader) {
158 paint_.setStyle(style);
159 paint_.setColor(color.v);
160 paint_.setShader(shader);
161 uint8_t alpha = static_cast<uint8_t>(
162 globalAlpha_ * static_cast<float>(color.alpha()));
163 paint_.setAlpha(alpha);
164 bool drawShadow = (shadowOffsetX_ != 0 ||
165 shadowOffsetY_ != 0 ||
166 shadowBlur_ != 0) &&
167 shadowColor_.alpha() > 0;
168 if (drawShadow) {
169 // TODO(gram): should we mult shadowColor by globalAlpha?
170 paint_.setLooper(new SkBlurDrawLooper(SkFloatToScalar(shadowBlur_),
171 SkFloatToScalar(shadowOffsetX_),
172 SkFloatToScalar(shadowOffsetY_),
173 shadowColor_.v))->unref();
174 } else {
175 paint_.setLooper(NULL);
176 }
177 }
178
140 void CanvasState::setGlobalCompositeOperation(const char* op) { 179 void CanvasState::setGlobalCompositeOperation(const char* op) {
141 SkXfermode::Mode mode; 180 SkXfermode::Mode mode;
142 static const struct CompositOpToXfermodeMode { 181 static const struct CompositOpToXfermodeMode {
143 const char* mCompositOp; 182 const char* mCompositOp;
144 uint8_t m_xfermodeMode; 183 uint8_t m_xfermodeMode;
145 } gMapCompositOpsToXfermodeModes[] = { 184 } gMapCompositOpsToXfermodeModes[] = {
146 { "clear", SkXfermode::kClear_Mode }, 185 { "clear", SkXfermode::kClear_Mode },
147 { "copy", SkXfermode::kSrc_Mode }, 186 { "copy", SkXfermode::kSrc_Mode },
148 { "source-over", SkXfermode::kSrcOver_Mode }, 187 { "source-over", SkXfermode::kSrcOver_Mode },
149 { "source-in", SkXfermode::kSrcIn_Mode }, 188 { "source-in", SkXfermode::kSrcIn_Mode },
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 if (sw < 0) sw = bm.width(); 328 if (sw < 0) sw = bm.width();
290 if (dw < 0) dw = bm.width(); 329 if (dw < 0) dw = bm.width();
291 if (sh < 0) sh = bm.height(); 330 if (sh < 0) sh = bm.height();
292 if (dh < 0) dh = bm.height(); 331 if (dh < 0) dh = bm.height();
293 SkIRect src = SkIRect::MakeXYWH(sx, sy, sw, sh); 332 SkIRect src = SkIRect::MakeXYWH(sx, sy, sw, sh);
294 SkRect dst = SkRect::MakeXYWH(dx, dy, dw, dh); 333 SkRect dst = SkRect::MakeXYWH(dx, dy, dw, dh);
295 LOGI("DrawImage(_,%d,%d,%d,%d,%d,%d,%d,%d)", sx, sy, sw, sh, dx, dy, dw, dh); 334 LOGI("DrawImage(_,%d,%d,%d,%d,%d,%d,%d,%d)", sx, sy, sw, sh, dx, dy, dw, dh);
296 canvas_->drawBitmapRect(bm, &src, dst); 335 canvas_->drawBitmapRect(bm, &src, dst);
297 } 336 }
298 337
338 void CanvasState::SetFillGradient(bool is_radial,
339 double x0, double y0, double r0,
340 double x1, double y1, double r1,
341 int stops, float* positions, char** colors) {
342 if (fillShader_ != NULL) {
343 fillShader_->unref();
344 }
345 if (is_radial) {
346 fillShader_ = CreateRadialGradient(x0, y0, r0, x1, y1, r1,
347 stops, positions, colors);
348 } else {
349 fillShader_ = CreateLinearGradient(x0, y0, x1, y1,
350 stops, positions, colors);
351 }
352 fillShader_->validate();
353 }
354
355 void CanvasState::SetStrokeGradient(bool is_radial,
356 double x0, double y0, double r0,
357 double x1, double y1, double r1,
358 int stops, float* positions, char** colors) {
359 if (strokeShader_ != NULL) {
360 strokeShader_->unref();
361 }
362 if (is_radial) {
363 strokeShader_ = CreateRadialGradient(x0, y0, r0, x1, y1, r1,
364 stops, positions, colors);
365 } else {
366 strokeShader_ = CreateLinearGradient(x0, y0, x1, y1,
367 stops, positions, colors);
368 }
369 strokeShader_->validate();
370 }
371
372 SkShader* CanvasState::CreateRadialGradient(
373 double x0, double y0, double r0,
374 double x1, double y1, double r1,
375 int stops, float* positions, char** colors) {
376 SkScalar* p = new SkScalar[stops];
377 SkColor* c = new SkColor[stops];
378 for (int i = 0; i < stops; i++) {
379 p[i] = positions[i];
380 c[i] = GetColor(colors[i]).v;
381 }
382 LOGI("CreateRadialGradient(%f,%f,%f,%f,%f,%f,%d,[%f,%f],[%s,%s]",
383 x0, y0, r0, x1, y1, r1, stops, positions[0], positions[1],
384 colors[0], colors[1]);
385 SkShader* shader = SkGradientShader::CreateTwoPointRadial(
386 SkPoint::Make(x0, y0), r0, SkPoint::Make(x1, y1), r1,
387 c, p, stops, SkShader::kClamp_TileMode);
388 delete[] c;
389 delete[] p;
390 return shader;
391 }
392
393 SkShader* CanvasState::CreateLinearGradient(
394 double x0, double y0, double x1, double y1,
395 int stops, float* positions, char** colors) {
396 SkScalar* p = new SkScalar[stops];
397 SkColor* c = new SkColor[stops];
398 for (int i = 0; i < stops; i++) {
399 p[i] = positions[i];
400 c[i] = GetColor(colors[i]).v;
401 }
402 SkPoint pts[2];
403 pts[0] = SkPoint::Make(x0, y0);
404 pts[1] = SkPoint::Make(x1, y1);
405 SkShader* shader = SkGradientShader::CreateLinear(pts, c, p, stops,
406 SkShader::kClamp_TileMode);
407 delete[] c;
408 delete[] p;
409 return shader;
410 }
411
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698