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 10 matching lines...) Expand all Loading... | |
21 #include "SkTextBlobRunIterator.h" | 21 #include "SkTextBlobRunIterator.h" |
22 #include "SkTHash.h" | 22 #include "SkTHash.h" |
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_DRAWDEPTH "drawDepth" | |
31 #define SKDEBUGCANVAS_ATTRIBUTE_COORDS "coords" | 32 #define SKDEBUGCANVAS_ATTRIBUTE_COORDS "coords" |
32 #define SKDEBUGCANVAS_ATTRIBUTE_BOUNDS "bounds" | 33 #define SKDEBUGCANVAS_ATTRIBUTE_BOUNDS "bounds" |
33 #define SKDEBUGCANVAS_ATTRIBUTE_PAINT "paint" | 34 #define SKDEBUGCANVAS_ATTRIBUTE_PAINT "paint" |
34 #define SKDEBUGCANVAS_ATTRIBUTE_OUTER "outer" | 35 #define SKDEBUGCANVAS_ATTRIBUTE_OUTER "outer" |
35 #define SKDEBUGCANVAS_ATTRIBUTE_INNER "inner" | 36 #define SKDEBUGCANVAS_ATTRIBUTE_INNER "inner" |
36 #define SKDEBUGCANVAS_ATTRIBUTE_MODE "mode" | 37 #define SKDEBUGCANVAS_ATTRIBUTE_MODE "mode" |
37 #define SKDEBUGCANVAS_ATTRIBUTE_POINTS "points" | 38 #define SKDEBUGCANVAS_ATTRIBUTE_POINTS "points" |
38 #define SKDEBUGCANVAS_ATTRIBUTE_PATH "path" | 39 #define SKDEBUGCANVAS_ATTRIBUTE_PATH "path" |
39 #define SKDEBUGCANVAS_ATTRIBUTE_TEXT "text" | 40 #define SKDEBUGCANVAS_ATTRIBUTE_TEXT "text" |
40 #define SKDEBUGCANVAS_ATTRIBUTE_COLOR "color" | 41 #define SKDEBUGCANVAS_ATTRIBUTE_COLOR "color" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 case kDrawRRect_OpType: return "DrawRRect"; | 204 case kDrawRRect_OpType: return "DrawRRect"; |
204 case kDrawText_OpType: return "DrawText"; | 205 case kDrawText_OpType: return "DrawText"; |
205 case kDrawTextBlob_OpType: return "DrawTextBlob"; | 206 case kDrawTextBlob_OpType: return "DrawTextBlob"; |
206 case kDrawTextOnPath_OpType: return "DrawTextOnPath"; | 207 case kDrawTextOnPath_OpType: return "DrawTextOnPath"; |
207 case kDrawVertices_OpType: return "DrawVertices"; | 208 case kDrawVertices_OpType: return "DrawVertices"; |
208 case kEndDrawPicture_OpType: return "EndDrawPicture"; | 209 case kEndDrawPicture_OpType: return "EndDrawPicture"; |
209 case kRestore_OpType: return "Restore"; | 210 case kRestore_OpType: return "Restore"; |
210 case kSave_OpType: return "Save"; | 211 case kSave_OpType: return "Save"; |
211 case kSaveLayer_OpType: return "SaveLayer"; | 212 case kSaveLayer_OpType: return "SaveLayer"; |
212 case kSetMatrix_OpType: return "SetMatrix"; | 213 case kSetMatrix_OpType: return "SetMatrix"; |
214 case kSetZ_OpType: return "SetZ"; | |
213 default: | 215 default: |
214 SkDebugf("OpType error 0x%08x\n", type); | 216 SkDebugf("OpType error 0x%08x\n", type); |
215 SkASSERT(0); | 217 SkASSERT(0); |
216 break; | 218 break; |
217 } | 219 } |
218 SkDEBUGFAIL("DrawType UNUSED\n"); | 220 SkDEBUGFAIL("DrawType UNUSED\n"); |
219 return nullptr; | 221 return nullptr; |
220 } | 222 } |
221 | 223 |
222 SkString SkDrawCommand::toString() const { | 224 SkString SkDrawCommand::toString() const { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
259 INSTALL_FACTORY(DrawTextOnPath); | 261 INSTALL_FACTORY(DrawTextOnPath); |
260 INSTALL_FACTORY(DrawTextBlob); | 262 INSTALL_FACTORY(DrawTextBlob); |
261 | 263 |
262 INSTALL_FACTORY(DrawRect); | 264 INSTALL_FACTORY(DrawRect); |
263 INSTALL_FACTORY(DrawRRect); | 265 INSTALL_FACTORY(DrawRRect); |
264 INSTALL_FACTORY(DrawDRRect); | 266 INSTALL_FACTORY(DrawDRRect); |
265 INSTALL_FACTORY(DrawPatch); | 267 INSTALL_FACTORY(DrawPatch); |
266 INSTALL_FACTORY(Save); | 268 INSTALL_FACTORY(Save); |
267 INSTALL_FACTORY(SaveLayer); | 269 INSTALL_FACTORY(SaveLayer); |
268 INSTALL_FACTORY(SetMatrix); | 270 INSTALL_FACTORY(SetMatrix); |
271 | |
272 INSTALL_FACTORY(SetZ); | |
269 } | 273 } |
270 SkString name = SkString(command[SKDEBUGCANVAS_ATTRIBUTE_COMMAND].asCString( )); | 274 SkString name = SkString(command[SKDEBUGCANVAS_ATTRIBUTE_COMMAND].asCString( )); |
271 FROM_JSON* factory = factories.find(name); | 275 FROM_JSON* factory = factories.find(name); |
272 if (factory == nullptr) { | 276 if (factory == nullptr) { |
273 SkDebugf("no JSON factory for '%s'\n", name.c_str()); | 277 SkDebugf("no JSON factory for '%s'\n", name.c_str()); |
274 return nullptr; | 278 return nullptr; |
275 } | 279 } |
276 return (*factory)(command, urlDataManager); | 280 return (*factory)(command, urlDataManager); |
277 } | 281 } |
278 | 282 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
461 row2.append(Json::Value(matrix[5])); | 465 row2.append(Json::Value(matrix[5])); |
462 result.append(row2); | 466 result.append(row2); |
463 Json::Value row3(Json::arrayValue); | 467 Json::Value row3(Json::arrayValue); |
464 row3.append(Json::Value(matrix[6])); | 468 row3.append(Json::Value(matrix[6])); |
465 row3.append(Json::Value(matrix[7])); | 469 row3.append(Json::Value(matrix[7])); |
466 row3.append(Json::Value(matrix[8])); | 470 row3.append(Json::Value(matrix[8])); |
467 result.append(row3); | 471 result.append(row3); |
468 return result; | 472 return result; |
469 } | 473 } |
470 | 474 |
475 Json::Value SkDrawCommand::MakeJsonScalar(SkScalar z) { | |
476 Json::Value result(z); | |
477 return result; | |
478 } | |
479 | |
471 Json::Value SkDrawCommand::MakeJsonPath(const SkPath& path) { | 480 Json::Value SkDrawCommand::MakeJsonPath(const SkPath& path) { |
472 Json::Value result(Json::objectValue); | 481 Json::Value result(Json::objectValue); |
473 switch (path.getFillType()) { | 482 switch (path.getFillType()) { |
474 case SkPath::kWinding_FillType: | 483 case SkPath::kWinding_FillType: |
475 result[SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE] = SKDEBUGCANVAS_FILLTYPE_WI NDING; | 484 result[SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE] = SKDEBUGCANVAS_FILLTYPE_WI NDING; |
476 break; | 485 break; |
477 case SkPath::kEvenOdd_FillType: | 486 case SkPath::kEvenOdd_FillType: |
478 result[SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE] = SKDEBUGCANVAS_FILLTYPE_EV ENODD; | 487 result[SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE] = SKDEBUGCANVAS_FILLTYPE_EV ENODD; |
479 break; | 488 break; |
480 case SkPath::kInverseWinding_FillType: | 489 case SkPath::kInverseWinding_FillType: |
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1473 | 1482 |
1474 static void extract_json_matrix(Json::Value& matrix, SkMatrix* result) { | 1483 static void extract_json_matrix(Json::Value& matrix, SkMatrix* result) { |
1475 SkScalar values[] = { | 1484 SkScalar values[] = { |
1476 matrix[0][0].asFloat(), matrix[0][1].asFloat(), matrix[0][2].asFloat(), | 1485 matrix[0][0].asFloat(), matrix[0][1].asFloat(), matrix[0][2].asFloat(), |
1477 matrix[1][0].asFloat(), matrix[1][1].asFloat(), matrix[1][2].asFloat(), | 1486 matrix[1][0].asFloat(), matrix[1][1].asFloat(), matrix[1][2].asFloat(), |
1478 matrix[2][0].asFloat(), matrix[2][1].asFloat(), matrix[2][2].asFloat() | 1487 matrix[2][0].asFloat(), matrix[2][1].asFloat(), matrix[2][2].asFloat() |
1479 }; | 1488 }; |
1480 result->set9(values); | 1489 result->set9(values); |
1481 } | 1490 } |
1482 | 1491 |
1492 static void extract_json_scalar(Json::Value& scalar, SkScalar* result) { | |
1493 SkScalar value = scalar.asFloat(); | |
1494 *result = value; | |
1495 } | |
1496 | |
1483 static void extract_json_path(Json::Value& path, SkPath* result) { | 1497 static void extract_json_path(Json::Value& path, SkPath* result) { |
1484 const char* fillType = path[SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE].asCString(); | 1498 const char* fillType = path[SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE].asCString(); |
1485 if (!strcmp(fillType, SKDEBUGCANVAS_FILLTYPE_WINDING)) { | 1499 if (!strcmp(fillType, SKDEBUGCANVAS_FILLTYPE_WINDING)) { |
1486 result->setFillType(SkPath::kWinding_FillType); | 1500 result->setFillType(SkPath::kWinding_FillType); |
1487 } | 1501 } |
1488 else if (!strcmp(fillType, SKDEBUGCANVAS_FILLTYPE_EVENODD)) { | 1502 else if (!strcmp(fillType, SKDEBUGCANVAS_FILLTYPE_EVENODD)) { |
1489 result->setFillType(SkPath::kEvenOdd_FillType); | 1503 result->setFillType(SkPath::kEvenOdd_FillType); |
1490 } | 1504 } |
1491 else if (!strcmp(fillType, SKDEBUGCANVAS_FILLTYPE_INVERSEWINDING)) { | 1505 else if (!strcmp(fillType, SKDEBUGCANVAS_FILLTYPE_INVERSEWINDING)) { |
1492 result->setFillType(SkPath::kInverseWinding_FillType); | 1506 result->setFillType(SkPath::kInverseWinding_FillType); |
(...skipping 1724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3217 result[SKDEBUGCANVAS_ATTRIBUTE_MATRIX] = MakeJsonMatrix(fMatrix); | 3231 result[SKDEBUGCANVAS_ATTRIBUTE_MATRIX] = MakeJsonMatrix(fMatrix); |
3218 return result; | 3232 return result; |
3219 } | 3233 } |
3220 | 3234 |
3221 SkSetMatrixCommand* SkSetMatrixCommand::fromJSON(Json::Value& command, | 3235 SkSetMatrixCommand* SkSetMatrixCommand::fromJSON(Json::Value& command, |
3222 UrlDataManager& urlDataManager) { | 3236 UrlDataManager& urlDataManager) { |
3223 SkMatrix matrix; | 3237 SkMatrix matrix; |
3224 extract_json_matrix(command[SKDEBUGCANVAS_ATTRIBUTE_MATRIX], &matrix); | 3238 extract_json_matrix(command[SKDEBUGCANVAS_ATTRIBUTE_MATRIX], &matrix); |
3225 return new SkSetMatrixCommand(matrix); | 3239 return new SkSetMatrixCommand(matrix); |
3226 } | 3240 } |
3241 | |
3242 SkSetZCommand::SkSetZCommand(SkScalar z) | |
3243 : INHERITED(kSetZ_OpType) { | |
3244 fCurDrawDepth = z; | |
3245 fInfo.push(SkObjectParser::ScalarToString(z, "drawDepth")); | |
3246 } | |
3247 | |
3248 void SkSetZCommand::execute(SkCanvas* canvas) const { | |
3249 canvas->setZ(fCurDrawDepth); | |
3250 } | |
3251 | |
3252 Json::Value SkSetZCommand::toJSON(UrlDataManager& urlDataManager) const { | |
3253 Json::Value result = INHERITED::toJSON(urlDataManager); | |
3254 result[SKDEBUGCANVAS_ATTRIBUTE_DRAWDEPTH] = MakeJsonScalar(fCurDrawDepth); | |
3255 return result; | |
3256 } | |
3257 | |
3258 SkSetZCommand* SkSetZCommand::fromJSON(Json::Value& command, | |
robertphillips
2016/07/11 20:57:27
line this up with the prior parameter ?
vjiaoblack
2016/07/12 13:14:23
Done.
| |
3259 UrlDataManager& urlDataManager) { | |
3260 SkScalar z; | |
3261 extract_json_scalar(command[SKDEBUGCANVAS_ATTRIBUTE_DRAWDEPTH], &z); | |
3262 return new SkSetZCommand(z); | |
3263 } | |
OLD | NEW |