| 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 | 8 |
| 9 #include "SkDrawCommand.h" | 9 #include "SkDrawCommand.h" |
| 10 | 10 |
| 11 #include "SkBlurMaskFilter.h" | 11 #include "SkBlurMaskFilter.h" |
| 12 #include "SkColorFilter.h" | 12 #include "SkColorFilter.h" |
| 13 #include "SkDashPathEffect.h" | 13 #include "SkDashPathEffect.h" |
| 14 #include "SkImageFilter.h" | 14 #include "SkImageFilter.h" |
| 15 #include "SkJsonWriteBuffer.h" |
| 15 #include "SkMaskFilter.h" | 16 #include "SkMaskFilter.h" |
| 16 #include "SkObjectParser.h" | 17 #include "SkObjectParser.h" |
| 17 #include "SkPaintDefaults.h" | 18 #include "SkPaintDefaults.h" |
| 18 #include "SkPathEffect.h" | 19 #include "SkPathEffect.h" |
| 19 #include "SkPicture.h" | 20 #include "SkPicture.h" |
| 20 #include "SkTextBlob.h" | 21 #include "SkTextBlob.h" |
| 21 #include "SkTextBlobRunIterator.h" | 22 #include "SkTextBlobRunIterator.h" |
| 22 #include "SkTHash.h" | 23 #include "SkTHash.h" |
| 23 #include "SkTypeface.h" | 24 #include "SkTypeface.h" |
| 24 #include "SkValidatingReadBuffer.h" | 25 #include "SkValidatingReadBuffer.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 #define SKDEBUGCANVAS_ATTRIBUTE_TEXTSIZE "textSize" | 57 #define SKDEBUGCANVAS_ATTRIBUTE_TEXTSIZE "textSize" |
| 57 #define SKDEBUGCANVAS_ATTRIBUTE_TEXTSCALEX "textScaleX" | 58 #define SKDEBUGCANVAS_ATTRIBUTE_TEXTSCALEX "textScaleX" |
| 58 #define SKDEBUGCANVAS_ATTRIBUTE_TEXTSKEWX "textSkewX" | 59 #define SKDEBUGCANVAS_ATTRIBUTE_TEXTSKEWX "textSkewX" |
| 59 #define SKDEBUGCANVAS_ATTRIBUTE_DASHING "dashing" | 60 #define SKDEBUGCANVAS_ATTRIBUTE_DASHING "dashing" |
| 60 #define SKDEBUGCANVAS_ATTRIBUTE_INTERVALS "intervals" | 61 #define SKDEBUGCANVAS_ATTRIBUTE_INTERVALS "intervals" |
| 61 #define SKDEBUGCANVAS_ATTRIBUTE_PHASE "phase" | 62 #define SKDEBUGCANVAS_ATTRIBUTE_PHASE "phase" |
| 62 #define SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE "fillType" | 63 #define SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE "fillType" |
| 63 #define SKDEBUGCANVAS_ATTRIBUTE_VERBS "verbs" | 64 #define SKDEBUGCANVAS_ATTRIBUTE_VERBS "verbs" |
| 64 #define SKDEBUGCANVAS_ATTRIBUTE_NAME "name" | 65 #define SKDEBUGCANVAS_ATTRIBUTE_NAME "name" |
| 65 #define SKDEBUGCANVAS_ATTRIBUTE_DATA "data" | 66 #define SKDEBUGCANVAS_ATTRIBUTE_DATA "data" |
| 67 #define SKDEBUGCANVAS_ATTRIBUTE_VALUES "values" |
| 66 #define SKDEBUGCANVAS_ATTRIBUTE_SHADER "shader" | 68 #define SKDEBUGCANVAS_ATTRIBUTE_SHADER "shader" |
| 67 #define SKDEBUGCANVAS_ATTRIBUTE_PATHEFFECT "pathEffect" | 69 #define SKDEBUGCANVAS_ATTRIBUTE_PATHEFFECT "pathEffect" |
| 68 #define SKDEBUGCANVAS_ATTRIBUTE_MASKFILTER "maskFilter" | 70 #define SKDEBUGCANVAS_ATTRIBUTE_MASKFILTER "maskFilter" |
| 69 #define SKDEBUGCANVAS_ATTRIBUTE_XFERMODE "xfermode" | 71 #define SKDEBUGCANVAS_ATTRIBUTE_XFERMODE "xfermode" |
| 70 #define SKDEBUGCANVAS_ATTRIBUTE_LOOPER "looper" | 72 #define SKDEBUGCANVAS_ATTRIBUTE_LOOPER "looper" |
| 71 #define SKDEBUGCANVAS_ATTRIBUTE_BACKDROP "backdrop" | 73 #define SKDEBUGCANVAS_ATTRIBUTE_BACKDROP "backdrop" |
| 72 #define SKDEBUGCANVAS_ATTRIBUTE_COLORFILTER "colorfilter" | 74 #define SKDEBUGCANVAS_ATTRIBUTE_COLORFILTER "colorfilter" |
| 73 #define SKDEBUGCANVAS_ATTRIBUTE_IMAGEFILTER "imagefilter" | 75 #define SKDEBUGCANVAS_ATTRIBUTE_IMAGEFILTER "imagefilter" |
| 74 #define SKDEBUGCANVAS_ATTRIBUTE_IMAGE "image" | 76 #define SKDEBUGCANVAS_ATTRIBUTE_IMAGE "image" |
| 75 #define SKDEBUGCANVAS_ATTRIBUTE_BITMAP "bitmap" | 77 #define SKDEBUGCANVAS_ATTRIBUTE_BITMAP "bitmap" |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 | 587 |
| 586 static void encode_data(const void* bytes, size_t count, const char* contentType
, | 588 static void encode_data(const void* bytes, size_t count, const char* contentType
, |
| 587 UrlDataManager& urlDataManager, Json::Value* target) { | 589 UrlDataManager& urlDataManager, Json::Value* target) { |
| 588 SkAutoTUnref<SkData> data(SkData::NewWithCopy(bytes, count)); | 590 SkAutoTUnref<SkData> data(SkData::NewWithCopy(bytes, count)); |
| 589 SkString url = urlDataManager.addData(data, contentType); | 591 SkString url = urlDataManager.addData(data, contentType); |
| 590 *target = Json::Value(url.c_str()); | 592 *target = Json::Value(url.c_str()); |
| 591 } | 593 } |
| 592 | 594 |
| 593 static void flatten(const SkFlattenable* flattenable, Json::Value* target, | 595 static void flatten(const SkFlattenable* flattenable, Json::Value* target, |
| 594 UrlDataManager& urlDataManager) { | 596 UrlDataManager& urlDataManager) { |
| 595 SkWriteBuffer buffer; | 597 SkBinaryWriteBuffer buffer; |
| 596 flattenable->flatten(buffer); | 598 flattenable->flatten(buffer); |
| 597 void* data = sk_malloc_throw(buffer.bytesWritten()); | 599 void* data = sk_malloc_throw(buffer.bytesWritten()); |
| 598 buffer.writeToMemory(data); | 600 buffer.writeToMemory(data); |
| 599 Json::Value jsonData; | 601 Json::Value jsonData; |
| 600 encode_data(data, buffer.bytesWritten(), "application/octet-stream", urlData
Manager, &jsonData); | 602 encode_data(data, buffer.bytesWritten(), "application/octet-stream", urlData
Manager, &jsonData); |
| 601 Json::Value jsonFlattenable; | 603 Json::Value jsonFlattenable; |
| 602 jsonFlattenable[SKDEBUGCANVAS_ATTRIBUTE_NAME] = Json::Value(flattenable->get
TypeName()); | 604 jsonFlattenable[SKDEBUGCANVAS_ATTRIBUTE_NAME] = Json::Value(flattenable->get
TypeName()); |
| 603 jsonFlattenable[SKDEBUGCANVAS_ATTRIBUTE_DATA] = jsonData; | 605 jsonFlattenable[SKDEBUGCANVAS_ATTRIBUTE_DATA] = jsonData; |
| 606 |
| 607 SkJsonWriteBuffer jsonBuffer(&urlDataManager); |
| 608 flattenable->flatten(jsonBuffer); |
| 609 jsonFlattenable[SKDEBUGCANVAS_ATTRIBUTE_VALUES] = jsonBuffer.getValue(); |
| 610 |
| 604 (*target) = jsonFlattenable; | 611 (*target) = jsonFlattenable; |
| 605 sk_free(data); | 612 sk_free(data); |
| 606 } | 613 } |
| 607 | 614 |
| 608 static void write_png_callback(png_structp png_ptr, png_bytep data, png_size_t l
ength) { | 615 static void write_png_callback(png_structp png_ptr, png_bytep data, png_size_t l
ength) { |
| 609 SkWStream* out = (SkWStream*) png_get_io_ptr(png_ptr); | 616 SkWStream* out = (SkWStream*) png_get_io_ptr(png_ptr); |
| 610 out->write(data, length); | 617 out->write(data, length); |
| 611 } | 618 } |
| 612 | 619 |
| 613 void SkDrawCommand::WritePNG(const png_bytep rgba, png_uint_32 width, png_uint_3
2 height, | 620 void SkDrawCommand::WritePNG(const png_bytep rgba, png_uint_32 width, png_uint_3
2 height, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 636 } | 643 } |
| 637 png_set_filter(png, 0, PNG_NO_FILTERS); | 644 png_set_filter(png, 0, PNG_NO_FILTERS); |
| 638 png_set_rows(png, info_ptr, &rows[0]); | 645 png_set_rows(png, info_ptr, &rows[0]); |
| 639 png_set_write_fn(png, &out, write_png_callback, NULL); | 646 png_set_write_fn(png, &out, write_png_callback, NULL); |
| 640 png_write_png(png, info_ptr, PNG_TRANSFORM_IDENTITY, NULL); | 647 png_write_png(png, info_ptr, PNG_TRANSFORM_IDENTITY, NULL); |
| 641 png_destroy_write_struct(&png, NULL); | 648 png_destroy_write_struct(&png, NULL); |
| 642 sk_free(rows); | 649 sk_free(rows); |
| 643 sk_free(pixels); | 650 sk_free(pixels); |
| 644 } | 651 } |
| 645 | 652 |
| 646 static bool SK_WARN_UNUSED_RESULT flatten(const SkImage& image, Json::Value* tar
get, | 653 bool SK_WARN_UNUSED_RESULT flatten(const SkImage& image, Json::Value* target, |
| 647 UrlDataManager& urlDataManager) { | 654 UrlDataManager& urlDataManager) { |
| 648 size_t rowBytes = 4 * image.width(); | 655 size_t rowBytes = 4 * image.width(); |
| 649 SkAutoFree buffer(sk_malloc_throw(rowBytes * image.height())); | 656 SkAutoFree buffer(sk_malloc_throw(rowBytes * image.height())); |
| 650 SkImageInfo dstInfo = SkImageInfo::Make(image.width(), image.height(), | 657 SkImageInfo dstInfo = SkImageInfo::Make(image.width(), image.height(), |
| 651 kN32_SkColorType, kPremul_SkAlphaTyp
e); | 658 kN32_SkColorType, kPremul_SkAlphaTyp
e); |
| 652 if (!image.readPixels(dstInfo, buffer.get(), rowBytes, 0, 0)) { | 659 if (!image.readPixels(dstInfo, buffer.get(), rowBytes, 0, 0)) { |
| 653 SkDebugf("readPixels failed\n"); | 660 SkDebugf("readPixels failed\n"); |
| 654 return false; | 661 return false; |
| 655 } | 662 } |
| 656 SkDynamicMemoryWStream out; | 663 SkDynamicMemoryWStream out; |
| 657 SkDrawCommand::WritePNG((png_bytep) buffer.get(), image.width(), image.heigh
t(), out); | 664 SkDrawCommand::WritePNG((png_bytep) buffer.get(), image.width(), image.heigh
t(), out); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 static sk_sp<SkImage> load_image(const Json::Value& jsonImage, UrlDataManager& u
rlDataManager) { | 815 static sk_sp<SkImage> load_image(const Json::Value& jsonImage, UrlDataManager& u
rlDataManager) { |
| 809 SkBitmap* bitmap = load_bitmap(jsonImage, urlDataManager); | 816 SkBitmap* bitmap = load_bitmap(jsonImage, urlDataManager); |
| 810 if (bitmap == nullptr) { | 817 if (bitmap == nullptr) { |
| 811 return nullptr; | 818 return nullptr; |
| 812 } | 819 } |
| 813 auto result = SkImage::MakeFromBitmap(*bitmap); | 820 auto result = SkImage::MakeFromBitmap(*bitmap); |
| 814 delete bitmap; | 821 delete bitmap; |
| 815 return result; | 822 return result; |
| 816 } | 823 } |
| 817 | 824 |
| 818 static bool SK_WARN_UNUSED_RESULT flatten(const SkBitmap& bitmap, Json::Value* t
arget, | 825 bool SK_WARN_UNUSED_RESULT flatten(const SkBitmap& bitmap, Json::Value* target, |
| 819 UrlDataManager& urlDataManager) { | 826 UrlDataManager& urlDataManager) { |
| 820 bitmap.lockPixels(); | 827 bitmap.lockPixels(); |
| 821 sk_sp<SkImage> image(SkImage::MakeFromBitmap(bitmap)); | 828 sk_sp<SkImage> image(SkImage::MakeFromBitmap(bitmap)); |
| 822 bitmap.unlockPixels(); | 829 bitmap.unlockPixels(); |
| 823 (*target)[SKDEBUGCANVAS_ATTRIBUTE_COLOR] = Json::Value(color_type_name(bitma
p.colorType())); | 830 (*target)[SKDEBUGCANVAS_ATTRIBUTE_COLOR] = Json::Value(color_type_name(bitma
p.colorType())); |
| 824 (*target)[SKDEBUGCANVAS_ATTRIBUTE_ALPHA] = Json::Value(alpha_type_name(bitma
p.alphaType())); | 831 (*target)[SKDEBUGCANVAS_ATTRIBUTE_ALPHA] = Json::Value(alpha_type_name(bitma
p.alphaType())); |
| 825 bool success = flatten(*image, target, urlDataManager); | 832 bool success = flatten(*image, target, urlDataManager); |
| 826 return success; | 833 return success; |
| 827 } | 834 } |
| 828 | 835 |
| 829 static void apply_paint_color(const SkPaint& paint, Json::Value* target) { | 836 static void apply_paint_color(const SkPaint& paint, Json::Value* target) { |
| (...skipping 2297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3127 result[SKDEBUGCANVAS_ATTRIBUTE_MATRIX] = MakeJsonMatrix(fMatrix); | 3134 result[SKDEBUGCANVAS_ATTRIBUTE_MATRIX] = MakeJsonMatrix(fMatrix); |
| 3128 return result; | 3135 return result; |
| 3129 } | 3136 } |
| 3130 | 3137 |
| 3131 SkSetMatrixCommand* SkSetMatrixCommand::fromJSON(Json::Value& command, | 3138 SkSetMatrixCommand* SkSetMatrixCommand::fromJSON(Json::Value& command, |
| 3132 UrlDataManager& urlDataManager)
{ | 3139 UrlDataManager& urlDataManager)
{ |
| 3133 SkMatrix matrix; | 3140 SkMatrix matrix; |
| 3134 extract_json_matrix(command[SKDEBUGCANVAS_ATTRIBUTE_MATRIX], &matrix); | 3141 extract_json_matrix(command[SKDEBUGCANVAS_ATTRIBUTE_MATRIX], &matrix); |
| 3135 return new SkSetMatrixCommand(matrix); | 3142 return new SkSetMatrixCommand(matrix); |
| 3136 } | 3143 } |
| OLD | NEW |