| 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_DRAWDEPTHTRANS "drawDepthTranslation" | |
| 32 #define SKDEBUGCANVAS_ATTRIBUTE_COORDS "coords" | 31 #define SKDEBUGCANVAS_ATTRIBUTE_COORDS "coords" |
| 33 #define SKDEBUGCANVAS_ATTRIBUTE_BOUNDS "bounds" | 32 #define SKDEBUGCANVAS_ATTRIBUTE_BOUNDS "bounds" |
| 34 #define SKDEBUGCANVAS_ATTRIBUTE_PAINT "paint" | 33 #define SKDEBUGCANVAS_ATTRIBUTE_PAINT "paint" |
| 35 #define SKDEBUGCANVAS_ATTRIBUTE_OUTER "outer" | 34 #define SKDEBUGCANVAS_ATTRIBUTE_OUTER "outer" |
| 36 #define SKDEBUGCANVAS_ATTRIBUTE_INNER "inner" | 35 #define SKDEBUGCANVAS_ATTRIBUTE_INNER "inner" |
| 37 #define SKDEBUGCANVAS_ATTRIBUTE_MODE "mode" | 36 #define SKDEBUGCANVAS_ATTRIBUTE_MODE "mode" |
| 38 #define SKDEBUGCANVAS_ATTRIBUTE_POINTS "points" | 37 #define SKDEBUGCANVAS_ATTRIBUTE_POINTS "points" |
| 39 #define SKDEBUGCANVAS_ATTRIBUTE_PATH "path" | 38 #define SKDEBUGCANVAS_ATTRIBUTE_PATH "path" |
| 40 #define SKDEBUGCANVAS_ATTRIBUTE_TEXT "text" | 39 #define SKDEBUGCANVAS_ATTRIBUTE_TEXT "text" |
| 41 #define SKDEBUGCANVAS_ATTRIBUTE_COLOR "color" | 40 #define SKDEBUGCANVAS_ATTRIBUTE_COLOR "color" |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 case kDrawText_OpType: return "DrawText"; | 204 case kDrawText_OpType: return "DrawText"; |
| 206 case kDrawTextBlob_OpType: return "DrawTextBlob"; | 205 case kDrawTextBlob_OpType: return "DrawTextBlob"; |
| 207 case kDrawTextOnPath_OpType: return "DrawTextOnPath"; | 206 case kDrawTextOnPath_OpType: return "DrawTextOnPath"; |
| 208 case kDrawTextRSXform_OpType: return "DrawTextRSXform"; | 207 case kDrawTextRSXform_OpType: return "DrawTextRSXform"; |
| 209 case kDrawVertices_OpType: return "DrawVertices"; | 208 case kDrawVertices_OpType: return "DrawVertices"; |
| 210 case kEndDrawPicture_OpType: return "EndDrawPicture"; | 209 case kEndDrawPicture_OpType: return "EndDrawPicture"; |
| 211 case kRestore_OpType: return "Restore"; | 210 case kRestore_OpType: return "Restore"; |
| 212 case kSave_OpType: return "Save"; | 211 case kSave_OpType: return "Save"; |
| 213 case kSaveLayer_OpType: return "SaveLayer"; | 212 case kSaveLayer_OpType: return "SaveLayer"; |
| 214 case kSetMatrix_OpType: return "SetMatrix"; | 213 case kSetMatrix_OpType: return "SetMatrix"; |
| 215 case kTranslateZ_OpType: return "TranslateZ"; | |
| 216 default: | 214 default: |
| 217 SkDebugf("OpType error 0x%08x\n", type); | 215 SkDebugf("OpType error 0x%08x\n", type); |
| 218 SkASSERT(0); | 216 SkASSERT(0); |
| 219 break; | 217 break; |
| 220 } | 218 } |
| 221 SkDEBUGFAIL("DrawType UNUSED\n"); | 219 SkDEBUGFAIL("DrawType UNUSED\n"); |
| 222 return nullptr; | 220 return nullptr; |
| 223 } | 221 } |
| 224 | 222 |
| 225 SkString SkDrawCommand::toString() const { | 223 SkString SkDrawCommand::toString() const { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 INSTALL_FACTORY(DrawTextRSXform); | 261 INSTALL_FACTORY(DrawTextRSXform); |
| 264 INSTALL_FACTORY(DrawTextBlob); | 262 INSTALL_FACTORY(DrawTextBlob); |
| 265 | 263 |
| 266 INSTALL_FACTORY(DrawRect); | 264 INSTALL_FACTORY(DrawRect); |
| 267 INSTALL_FACTORY(DrawRRect); | 265 INSTALL_FACTORY(DrawRRect); |
| 268 INSTALL_FACTORY(DrawDRRect); | 266 INSTALL_FACTORY(DrawDRRect); |
| 269 INSTALL_FACTORY(DrawPatch); | 267 INSTALL_FACTORY(DrawPatch); |
| 270 INSTALL_FACTORY(Save); | 268 INSTALL_FACTORY(Save); |
| 271 INSTALL_FACTORY(SaveLayer); | 269 INSTALL_FACTORY(SaveLayer); |
| 272 INSTALL_FACTORY(SetMatrix); | 270 INSTALL_FACTORY(SetMatrix); |
| 273 | |
| 274 INSTALL_FACTORY(TranslateZ); | |
| 275 } | 271 } |
| 276 SkString name = SkString(command[SKDEBUGCANVAS_ATTRIBUTE_COMMAND].asCString(
)); | 272 SkString name = SkString(command[SKDEBUGCANVAS_ATTRIBUTE_COMMAND].asCString(
)); |
| 277 FROM_JSON* factory = factories.find(name); | 273 FROM_JSON* factory = factories.find(name); |
| 278 if (factory == nullptr) { | 274 if (factory == nullptr) { |
| 279 SkDebugf("no JSON factory for '%s'\n", name.c_str()); | 275 SkDebugf("no JSON factory for '%s'\n", name.c_str()); |
| 280 return nullptr; | 276 return nullptr; |
| 281 } | 277 } |
| 282 return (*factory)(command, urlDataManager); | 278 return (*factory)(command, urlDataManager); |
| 283 } | 279 } |
| 284 | 280 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 row2.append(Json::Value(matrix[5])); | 463 row2.append(Json::Value(matrix[5])); |
| 468 result.append(row2); | 464 result.append(row2); |
| 469 Json::Value row3(Json::arrayValue); | 465 Json::Value row3(Json::arrayValue); |
| 470 row3.append(Json::Value(matrix[6])); | 466 row3.append(Json::Value(matrix[6])); |
| 471 row3.append(Json::Value(matrix[7])); | 467 row3.append(Json::Value(matrix[7])); |
| 472 row3.append(Json::Value(matrix[8])); | 468 row3.append(Json::Value(matrix[8])); |
| 473 result.append(row3); | 469 result.append(row3); |
| 474 return result; | 470 return result; |
| 475 } | 471 } |
| 476 | 472 |
| 477 Json::Value SkDrawCommand::MakeJsonScalar(SkScalar z) { | |
| 478 Json::Value result(z); | |
| 479 return result; | |
| 480 } | |
| 481 | |
| 482 Json::Value SkDrawCommand::MakeJsonPath(const SkPath& path) { | 473 Json::Value SkDrawCommand::MakeJsonPath(const SkPath& path) { |
| 483 Json::Value result(Json::objectValue); | 474 Json::Value result(Json::objectValue); |
| 484 switch (path.getFillType()) { | 475 switch (path.getFillType()) { |
| 485 case SkPath::kWinding_FillType: | 476 case SkPath::kWinding_FillType: |
| 486 result[SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE] = SKDEBUGCANVAS_FILLTYPE_WI
NDING; | 477 result[SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE] = SKDEBUGCANVAS_FILLTYPE_WI
NDING; |
| 487 break; | 478 break; |
| 488 case SkPath::kEvenOdd_FillType: | 479 case SkPath::kEvenOdd_FillType: |
| 489 result[SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE] = SKDEBUGCANVAS_FILLTYPE_EV
ENODD; | 480 result[SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE] = SKDEBUGCANVAS_FILLTYPE_EV
ENODD; |
| 490 break; | 481 break; |
| 491 case SkPath::kInverseWinding_FillType: | 482 case SkPath::kInverseWinding_FillType: |
| (...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1484 | 1475 |
| 1485 static void extract_json_matrix(Json::Value& matrix, SkMatrix* result) { | 1476 static void extract_json_matrix(Json::Value& matrix, SkMatrix* result) { |
| 1486 SkScalar values[] = { | 1477 SkScalar values[] = { |
| 1487 matrix[0][0].asFloat(), matrix[0][1].asFloat(), matrix[0][2].asFloat(), | 1478 matrix[0][0].asFloat(), matrix[0][1].asFloat(), matrix[0][2].asFloat(), |
| 1488 matrix[1][0].asFloat(), matrix[1][1].asFloat(), matrix[1][2].asFloat(), | 1479 matrix[1][0].asFloat(), matrix[1][1].asFloat(), matrix[1][2].asFloat(), |
| 1489 matrix[2][0].asFloat(), matrix[2][1].asFloat(), matrix[2][2].asFloat() | 1480 matrix[2][0].asFloat(), matrix[2][1].asFloat(), matrix[2][2].asFloat() |
| 1490 }; | 1481 }; |
| 1491 result->set9(values); | 1482 result->set9(values); |
| 1492 } | 1483 } |
| 1493 | 1484 |
| 1494 static void extract_json_scalar(Json::Value& scalar, SkScalar* result) { | |
| 1495 SkScalar value = scalar.asFloat(); | |
| 1496 *result = value; | |
| 1497 } | |
| 1498 | |
| 1499 static void extract_json_path(Json::Value& path, SkPath* result) { | 1485 static void extract_json_path(Json::Value& path, SkPath* result) { |
| 1500 const char* fillType = path[SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE].asCString(); | 1486 const char* fillType = path[SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE].asCString(); |
| 1501 if (!strcmp(fillType, SKDEBUGCANVAS_FILLTYPE_WINDING)) { | 1487 if (!strcmp(fillType, SKDEBUGCANVAS_FILLTYPE_WINDING)) { |
| 1502 result->setFillType(SkPath::kWinding_FillType); | 1488 result->setFillType(SkPath::kWinding_FillType); |
| 1503 } | 1489 } |
| 1504 else if (!strcmp(fillType, SKDEBUGCANVAS_FILLTYPE_EVENODD)) { | 1490 else if (!strcmp(fillType, SKDEBUGCANVAS_FILLTYPE_EVENODD)) { |
| 1505 result->setFillType(SkPath::kEvenOdd_FillType); | 1491 result->setFillType(SkPath::kEvenOdd_FillType); |
| 1506 } | 1492 } |
| 1507 else if (!strcmp(fillType, SKDEBUGCANVAS_FILLTYPE_INVERSEWINDING)) { | 1493 else if (!strcmp(fillType, SKDEBUGCANVAS_FILLTYPE_INVERSEWINDING)) { |
| 1508 result->setFillType(SkPath::kInverseWinding_FillType); | 1494 result->setFillType(SkPath::kInverseWinding_FillType); |
| (...skipping 1793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3302 result[SKDEBUGCANVAS_ATTRIBUTE_MATRIX] = MakeJsonMatrix(fMatrix); | 3288 result[SKDEBUGCANVAS_ATTRIBUTE_MATRIX] = MakeJsonMatrix(fMatrix); |
| 3303 return result; | 3289 return result; |
| 3304 } | 3290 } |
| 3305 | 3291 |
| 3306 SkSetMatrixCommand* SkSetMatrixCommand::fromJSON(Json::Value& command, | 3292 SkSetMatrixCommand* SkSetMatrixCommand::fromJSON(Json::Value& command, |
| 3307 UrlDataManager& urlDataManager)
{ | 3293 UrlDataManager& urlDataManager)
{ |
| 3308 SkMatrix matrix; | 3294 SkMatrix matrix; |
| 3309 extract_json_matrix(command[SKDEBUGCANVAS_ATTRIBUTE_MATRIX], &matrix); | 3295 extract_json_matrix(command[SKDEBUGCANVAS_ATTRIBUTE_MATRIX], &matrix); |
| 3310 return new SkSetMatrixCommand(matrix); | 3296 return new SkSetMatrixCommand(matrix); |
| 3311 } | 3297 } |
| 3312 | |
| 3313 SkTranslateZCommand::SkTranslateZCommand(SkScalar z) | |
| 3314 : INHERITED(kTranslateZ_OpType) { | |
| 3315 fZTranslate = z; | |
| 3316 fInfo.push(SkObjectParser::ScalarToString(fZTranslate, "drawDepthTranslation
")); | |
| 3317 } | |
| 3318 | |
| 3319 void SkTranslateZCommand::execute(SkCanvas* canvas) const { | |
| 3320 canvas->translateZ(fZTranslate); | |
| 3321 } | |
| 3322 | |
| 3323 Json::Value SkTranslateZCommand::toJSON(UrlDataManager& urlDataManager) const { | |
| 3324 Json::Value result = INHERITED::toJSON(urlDataManager); | |
| 3325 result[SKDEBUGCANVAS_ATTRIBUTE_DRAWDEPTHTRANS] = MakeJsonScalar(fZTranslate)
; | |
| 3326 return result; | |
| 3327 } | |
| 3328 | |
| 3329 SkTranslateZCommand* SkTranslateZCommand::fromJSON(Json::Value& command, | |
| 3330 UrlDataManager& urlDataManager) { | |
| 3331 SkScalar z; | |
| 3332 extract_json_scalar(command[SKDEBUGCANVAS_ATTRIBUTE_DRAWDEPTHTRANS], &z); | |
| 3333 return new SkTranslateZCommand(z); | |
| 3334 } | |
| OLD | NEW |