OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkDrawCommand.h" | 8 #include "SkDrawCommand.h" |
9 | 9 |
10 #include "SkBlurMaskFilter.h" | 10 #include "SkBlurMaskFilter.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "SkTypeface.h" | 23 #include "SkTypeface.h" |
24 #include "SkValidatingReadBuffer.h" | 24 #include "SkValidatingReadBuffer.h" |
25 #include "SkWriteBuffer.h" | 25 #include "SkWriteBuffer.h" |
26 #include "picture_utils.h" | 26 #include "picture_utils.h" |
27 | 27 |
28 #define SKDEBUGCANVAS_ATTRIBUTE_COMMAND "command" | 28 #define SKDEBUGCANVAS_ATTRIBUTE_COMMAND "command" |
29 #define SKDEBUGCANVAS_ATTRIBUTE_VISIBLE "visible" | 29 #define SKDEBUGCANVAS_ATTRIBUTE_VISIBLE "visible" |
30 #define SKDEBUGCANVAS_ATTRIBUTE_MATRIX "matrix" | 30 #define SKDEBUGCANVAS_ATTRIBUTE_MATRIX "matrix" |
31 #define SKDEBUGCANVAS_ATTRIBUTE_DRAWDEPTHTRANS "drawDepthTranslation" | 31 #define SKDEBUGCANVAS_ATTRIBUTE_DRAWDEPTHTRANS "drawDepthTranslation" |
32 #define SKDEBUGCANVAS_ATTRIBUTE_COORDS "coords" | 32 #define SKDEBUGCANVAS_ATTRIBUTE_COORDS "coords" |
| 33 #define SKDEBUGCANVAS_ATTRIBUTE_HINTING "hinting" |
33 #define SKDEBUGCANVAS_ATTRIBUTE_BOUNDS "bounds" | 34 #define SKDEBUGCANVAS_ATTRIBUTE_BOUNDS "bounds" |
34 #define SKDEBUGCANVAS_ATTRIBUTE_PAINT "paint" | 35 #define SKDEBUGCANVAS_ATTRIBUTE_PAINT "paint" |
35 #define SKDEBUGCANVAS_ATTRIBUTE_OUTER "outer" | 36 #define SKDEBUGCANVAS_ATTRIBUTE_OUTER "outer" |
36 #define SKDEBUGCANVAS_ATTRIBUTE_INNER "inner" | 37 #define SKDEBUGCANVAS_ATTRIBUTE_INNER "inner" |
37 #define SKDEBUGCANVAS_ATTRIBUTE_MODE "mode" | 38 #define SKDEBUGCANVAS_ATTRIBUTE_MODE "mode" |
38 #define SKDEBUGCANVAS_ATTRIBUTE_POINTS "points" | 39 #define SKDEBUGCANVAS_ATTRIBUTE_POINTS "points" |
39 #define SKDEBUGCANVAS_ATTRIBUTE_PATH "path" | 40 #define SKDEBUGCANVAS_ATTRIBUTE_PATH "path" |
40 #define SKDEBUGCANVAS_ATTRIBUTE_TEXT "text" | 41 #define SKDEBUGCANVAS_ATTRIBUTE_TEXT "text" |
41 #define SKDEBUGCANVAS_ATTRIBUTE_COLOR "color" | 42 #define SKDEBUGCANVAS_ATTRIBUTE_COLOR "color" |
42 #define SKDEBUGCANVAS_ATTRIBUTE_ALPHA "alpha" | 43 #define SKDEBUGCANVAS_ATTRIBUTE_ALPHA "alpha" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 | 155 |
155 #define SKDEBUGCANVAS_ALPHATYPE_OPAQUE "opaque" | 156 #define SKDEBUGCANVAS_ALPHATYPE_OPAQUE "opaque" |
156 #define SKDEBUGCANVAS_ALPHATYPE_PREMUL "premul" | 157 #define SKDEBUGCANVAS_ALPHATYPE_PREMUL "premul" |
157 #define SKDEBUGCANVAS_ALPHATYPE_UNPREMUL "unpremul" | 158 #define SKDEBUGCANVAS_ALPHATYPE_UNPREMUL "unpremul" |
158 | 159 |
159 #define SKDEBUGCANVAS_FILTERQUALITY_NONE "none" | 160 #define SKDEBUGCANVAS_FILTERQUALITY_NONE "none" |
160 #define SKDEBUGCANVAS_FILTERQUALITY_LOW "low" | 161 #define SKDEBUGCANVAS_FILTERQUALITY_LOW "low" |
161 #define SKDEBUGCANVAS_FILTERQUALITY_MEDIUM "medium" | 162 #define SKDEBUGCANVAS_FILTERQUALITY_MEDIUM "medium" |
162 #define SKDEBUGCANVAS_FILTERQUALITY_HIGH "high" | 163 #define SKDEBUGCANVAS_FILTERQUALITY_HIGH "high" |
163 | 164 |
| 165 #define SKDEBUGCANVAS_HINTING_NONE "none" |
| 166 #define SKDEBUGCANVAS_HINTING_SLIGHT "slight" |
| 167 #define SKDEBUGCANVAS_HINTING_NORMAL "normal" |
| 168 #define SKDEBUGCANVAS_HINTING_FULL "full" |
| 169 |
164 typedef SkDrawCommand* (*FROM_JSON)(Json::Value&, UrlDataManager&); | 170 typedef SkDrawCommand* (*FROM_JSON)(Json::Value&, UrlDataManager&); |
165 | 171 |
166 static SkString* str_append(SkString* str, const SkRect& r) { | 172 static SkString* str_append(SkString* str, const SkRect& r) { |
167 str->appendf(" [%g %g %g %g]", r.left(), r.top(), r.right(), r.bottom()); | 173 str->appendf(" [%g %g %g %g]", r.left(), r.top(), r.right(), r.bottom()); |
168 return str; | 174 return str; |
169 } | 175 } |
170 | 176 |
171 // TODO(chudy): Refactor into non subclass model. | 177 // TODO(chudy): Refactor into non subclass model. |
172 | 178 |
173 SkDrawCommand::SkDrawCommand(OpType type) | 179 SkDrawCommand::SkDrawCommand(OpType type) |
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 UrlDataManager& urlDataManager) { | 866 UrlDataManager& urlDataManager) { |
861 bitmap.lockPixels(); | 867 bitmap.lockPixels(); |
862 sk_sp<SkImage> image(SkImage::MakeFromBitmap(bitmap)); | 868 sk_sp<SkImage> image(SkImage::MakeFromBitmap(bitmap)); |
863 bitmap.unlockPixels(); | 869 bitmap.unlockPixels(); |
864 (*target)[SKDEBUGCANVAS_ATTRIBUTE_COLOR] = Json::Value(color_type_name(bitma
p.colorType())); | 870 (*target)[SKDEBUGCANVAS_ATTRIBUTE_COLOR] = Json::Value(color_type_name(bitma
p.colorType())); |
865 (*target)[SKDEBUGCANVAS_ATTRIBUTE_ALPHA] = Json::Value(alpha_type_name(bitma
p.alphaType())); | 871 (*target)[SKDEBUGCANVAS_ATTRIBUTE_ALPHA] = Json::Value(alpha_type_name(bitma
p.alphaType())); |
866 bool success = flatten(*image, target, urlDataManager); | 872 bool success = flatten(*image, target, urlDataManager); |
867 return success; | 873 return success; |
868 } | 874 } |
869 | 875 |
| 876 static void apply_paint_hinting(const SkPaint& paint, Json::Value* target) { |
| 877 SkPaint::Hinting hinting = paint.getHinting(); |
| 878 if (hinting != SkPaintDefaults_Hinting) { |
| 879 switch (hinting) { |
| 880 case SkPaint::kNo_Hinting: |
| 881 (*target)[SKDEBUGCANVAS_ATTRIBUTE_HINTING] = SKDEBUGCANVAS_HINTI
NG_NONE; |
| 882 break; |
| 883 case SkPaint::kSlight_Hinting: |
| 884 (*target)[SKDEBUGCANVAS_ATTRIBUTE_HINTING] = SKDEBUGCANVAS_HINTI
NG_SLIGHT; |
| 885 break; |
| 886 case SkPaint::kNormal_Hinting: |
| 887 (*target)[SKDEBUGCANVAS_ATTRIBUTE_HINTING] = SKDEBUGCANVAS_HINTI
NG_NORMAL; |
| 888 break; |
| 889 case SkPaint::kFull_Hinting: |
| 890 (*target)[SKDEBUGCANVAS_ATTRIBUTE_HINTING] = SKDEBUGCANVAS_HINTI
NG_FULL; |
| 891 break; |
| 892 } |
| 893 } |
| 894 } |
| 895 |
870 static void apply_paint_color(const SkPaint& paint, Json::Value* target) { | 896 static void apply_paint_color(const SkPaint& paint, Json::Value* target) { |
871 SkColor color = paint.getColor(); | 897 SkColor color = paint.getColor(); |
872 if (color != SK_ColorBLACK) { | 898 if (color != SK_ColorBLACK) { |
873 Json::Value colorValue(Json::arrayValue); | 899 Json::Value colorValue(Json::arrayValue); |
874 colorValue.append(Json::Value(SkColorGetA(color))); | 900 colorValue.append(Json::Value(SkColorGetA(color))); |
875 colorValue.append(Json::Value(SkColorGetR(color))); | 901 colorValue.append(Json::Value(SkColorGetR(color))); |
876 colorValue.append(Json::Value(SkColorGetG(color))); | 902 colorValue.append(Json::Value(SkColorGetG(color))); |
877 colorValue.append(Json::Value(SkColorGetB(color))); | 903 colorValue.append(Json::Value(SkColorGetB(color))); |
878 (*target)[SKDEBUGCANVAS_ATTRIBUTE_COLOR] = colorValue;; | 904 (*target)[SKDEBUGCANVAS_ATTRIBUTE_COLOR] = colorValue;; |
879 } | 905 } |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1121 Json::Value result(Json::objectValue); | 1147 Json::Value result(Json::objectValue); |
1122 store_scalar(&result, SKDEBUGCANVAS_ATTRIBUTE_STROKEWIDTH, paint.getStrokeWi
dth(), 0.0f); | 1148 store_scalar(&result, SKDEBUGCANVAS_ATTRIBUTE_STROKEWIDTH, paint.getStrokeWi
dth(), 0.0f); |
1123 store_scalar(&result, SKDEBUGCANVAS_ATTRIBUTE_STROKEMITER, paint.getStrokeMi
ter(), | 1149 store_scalar(&result, SKDEBUGCANVAS_ATTRIBUTE_STROKEMITER, paint.getStrokeMi
ter(), |
1124 SkPaintDefaults_MiterLimit); | 1150 SkPaintDefaults_MiterLimit); |
1125 store_bool(&result, SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS, paint.isAntiAlias(),
false); | 1151 store_bool(&result, SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS, paint.isAntiAlias(),
false); |
1126 store_bool(&result, SKDEBUGCANVAS_ATTRIBUTE_DITHER, paint.isDither(), false)
; | 1152 store_bool(&result, SKDEBUGCANVAS_ATTRIBUTE_DITHER, paint.isDither(), false)
; |
1127 store_scalar(&result, SKDEBUGCANVAS_ATTRIBUTE_TEXTSIZE, paint.getTextSize(), | 1153 store_scalar(&result, SKDEBUGCANVAS_ATTRIBUTE_TEXTSIZE, paint.getTextSize(), |
1128 SkPaintDefaults_TextSize); | 1154 SkPaintDefaults_TextSize); |
1129 store_scalar(&result, SKDEBUGCANVAS_ATTRIBUTE_TEXTSCALEX, paint.getTextScale
X(), SK_Scalar1); | 1155 store_scalar(&result, SKDEBUGCANVAS_ATTRIBUTE_TEXTSCALEX, paint.getTextScale
X(), SK_Scalar1); |
1130 store_scalar(&result, SKDEBUGCANVAS_ATTRIBUTE_TEXTSCALEX, paint.getTextSkewX
(), 0.0f); | 1156 store_scalar(&result, SKDEBUGCANVAS_ATTRIBUTE_TEXTSCALEX, paint.getTextSkewX
(), 0.0f); |
| 1157 apply_paint_hinting(paint, &result); |
1131 apply_paint_color(paint, &result); | 1158 apply_paint_color(paint, &result); |
1132 apply_paint_style(paint, &result); | 1159 apply_paint_style(paint, &result); |
1133 apply_paint_cap(paint, &result); | 1160 apply_paint_cap(paint, &result); |
1134 apply_paint_join(paint, &result); | 1161 apply_paint_join(paint, &result); |
1135 apply_paint_filterquality(paint, &result); | 1162 apply_paint_filterquality(paint, &result); |
1136 apply_paint_textalign(paint, &result); | 1163 apply_paint_textalign(paint, &result); |
1137 apply_paint_patheffect(paint, &result, urlDataManager); | 1164 apply_paint_patheffect(paint, &result, urlDataManager); |
1138 apply_paint_maskfilter(paint, &result, urlDataManager); | 1165 apply_paint_maskfilter(paint, &result, urlDataManager); |
1139 apply_paint_shader(paint, &result, urlDataManager); | 1166 apply_paint_shader(paint, &result, urlDataManager); |
1140 apply_paint_xfermode(paint, &result, urlDataManager); | 1167 apply_paint_xfermode(paint, &result, urlDataManager); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1246 if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_TYPEFACE)) { | 1273 if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_TYPEFACE)) { |
1247 Json::Value jsonTypeface = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_TYPEFACE]; | 1274 Json::Value jsonTypeface = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_TYPEFACE]; |
1248 Json::Value jsonData = jsonTypeface[SKDEBUGCANVAS_ATTRIBUTE_DATA]; | 1275 Json::Value jsonData = jsonTypeface[SKDEBUGCANVAS_ATTRIBUTE_DATA]; |
1249 const void* data; | 1276 const void* data; |
1250 Json::ArrayIndex length = decode_data(jsonData, urlDataManager, &data); | 1277 Json::ArrayIndex length = decode_data(jsonData, urlDataManager, &data); |
1251 SkMemoryStream buffer(data, length); | 1278 SkMemoryStream buffer(data, length); |
1252 target->setTypeface(SkTypeface::MakeDeserialize(&buffer)); | 1279 target->setTypeface(SkTypeface::MakeDeserialize(&buffer)); |
1253 } | 1280 } |
1254 } | 1281 } |
1255 | 1282 |
| 1283 static void extract_json_paint_hinting(Json::Value& jsonPaint, SkPaint* target)
{ |
| 1284 if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_HINTING)) { |
| 1285 const char* hinting = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_HINTING].asCStri
ng(); |
| 1286 if (!strcmp(hinting, SKDEBUGCANVAS_HINTING_NONE)) { |
| 1287 target->setHinting(SkPaint::kNo_Hinting); |
| 1288 } else if (!strcmp(hinting, SKDEBUGCANVAS_HINTING_SLIGHT)) { |
| 1289 target->setHinting(SkPaint::kSlight_Hinting); |
| 1290 } else if (!strcmp(hinting, SKDEBUGCANVAS_HINTING_NORMAL)) { |
| 1291 target->setHinting(SkPaint::kNormal_Hinting); |
| 1292 } else if (!strcmp(hinting, SKDEBUGCANVAS_HINTING_FULL)) { |
| 1293 target->setHinting(SkPaint::kFull_Hinting); |
| 1294 } |
| 1295 } |
| 1296 } |
| 1297 |
1256 static void extract_json_paint_style(Json::Value& jsonPaint, SkPaint* target) { | 1298 static void extract_json_paint_style(Json::Value& jsonPaint, SkPaint* target) { |
1257 if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_STYLE)) { | 1299 if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_STYLE)) { |
1258 const char* style = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_STYLE].asCString()
; | 1300 const char* style = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_STYLE].asCString()
; |
1259 if (!strcmp(style, SKDEBUGCANVAS_STYLE_FILL)) { | 1301 if (!strcmp(style, SKDEBUGCANVAS_STYLE_FILL)) { |
1260 target->setStyle(SkPaint::kFill_Style); | 1302 target->setStyle(SkPaint::kFill_Style); |
1261 } | 1303 } |
1262 else if (!strcmp(style, SKDEBUGCANVAS_STYLE_STROKE)) { | 1304 else if (!strcmp(style, SKDEBUGCANVAS_STYLE_STROKE)) { |
1263 target->setStyle(SkPaint::kStroke_Style); | 1305 target->setStyle(SkPaint::kStroke_Style); |
1264 } | 1306 } |
1265 else if (!strcmp(style, SKDEBUGCANVAS_STYLE_STROKEANDFILL)) { | 1307 else if (!strcmp(style, SKDEBUGCANVAS_STYLE_STROKEANDFILL)) { |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1435 | 1477 |
1436 static void extract_json_paint_textskewx(Json::Value& jsonPaint, SkPaint* target
) { | 1478 static void extract_json_paint_textskewx(Json::Value& jsonPaint, SkPaint* target
) { |
1437 if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_TEXTSKEWX)) { | 1479 if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_TEXTSKEWX)) { |
1438 float textSkewX = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_TEXTSKEWX].asFloat()
; | 1480 float textSkewX = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_TEXTSKEWX].asFloat()
; |
1439 target->setTextSkewX(textSkewX); | 1481 target->setTextSkewX(textSkewX); |
1440 } | 1482 } |
1441 } | 1483 } |
1442 | 1484 |
1443 static void extract_json_paint(Json::Value& paint, UrlDataManager& urlDataManage
r, | 1485 static void extract_json_paint(Json::Value& paint, UrlDataManager& urlDataManage
r, |
1444 SkPaint* result) { | 1486 SkPaint* result) { |
| 1487 extract_json_paint_hinting(paint, result); |
1445 extract_json_paint_color(paint, result); | 1488 extract_json_paint_color(paint, result); |
1446 extract_json_paint_shader(paint, urlDataManager, result); | 1489 extract_json_paint_shader(paint, urlDataManager, result); |
1447 extract_json_paint_patheffect(paint, urlDataManager, result); | 1490 extract_json_paint_patheffect(paint, urlDataManager, result); |
1448 extract_json_paint_maskfilter(paint, urlDataManager, result); | 1491 extract_json_paint_maskfilter(paint, urlDataManager, result); |
1449 extract_json_paint_colorfilter(paint, urlDataManager, result); | 1492 extract_json_paint_colorfilter(paint, urlDataManager, result); |
1450 extract_json_paint_xfermode(paint, urlDataManager, result); | 1493 extract_json_paint_xfermode(paint, urlDataManager, result); |
1451 extract_json_paint_looper(paint, urlDataManager, result); | 1494 extract_json_paint_looper(paint, urlDataManager, result); |
1452 extract_json_paint_imagefilter(paint, urlDataManager, result); | 1495 extract_json_paint_imagefilter(paint, urlDataManager, result); |
1453 extract_json_paint_typeface(paint, urlDataManager, result); | 1496 extract_json_paint_typeface(paint, urlDataManager, result); |
1454 extract_json_paint_style(paint, result); | 1497 extract_json_paint_style(paint, result); |
(...skipping 2027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3482 SkTranslateZCommand* SkTranslateZCommand::fromJSON(Json::Value& command, | 3525 SkTranslateZCommand* SkTranslateZCommand::fromJSON(Json::Value& command, |
3483 UrlDataManager& urlDataManager) { | 3526 UrlDataManager& urlDataManager) { |
3484 SkScalar z; | 3527 SkScalar z; |
3485 #ifdef SK_EXPERIMENTAL_SHADOWING | 3528 #ifdef SK_EXPERIMENTAL_SHADOWING |
3486 extract_json_scalar(command[SKDEBUGCANVAS_ATTRIBUTE_DRAWDEPTHTRANS], &z); | 3529 extract_json_scalar(command[SKDEBUGCANVAS_ATTRIBUTE_DRAWDEPTHTRANS], &z); |
3487 #else | 3530 #else |
3488 z = 0; | 3531 z = 0; |
3489 #endif | 3532 #endif |
3490 return new SkTranslateZCommand(z); | 3533 return new SkTranslateZCommand(z); |
3491 } | 3534 } |
OLD | NEW |