| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "SkDrawCommand.h" | 10 #include "SkDrawCommand.h" |
| (...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 } | 747 } |
| 748 | 748 |
| 749 // caller is responsible for freeing return value | 749 // caller is responsible for freeing return value |
| 750 static SkBitmap* load_bitmap(const Json::Value& jsonBitmap, UrlDataManager& urlD
ataManager) { | 750 static SkBitmap* load_bitmap(const Json::Value& jsonBitmap, UrlDataManager& urlD
ataManager) { |
| 751 if (!jsonBitmap.isMember(SKDEBUGCANVAS_ATTRIBUTE_DATA)) { | 751 if (!jsonBitmap.isMember(SKDEBUGCANVAS_ATTRIBUTE_DATA)) { |
| 752 SkDebugf("invalid bitmap\n"); | 752 SkDebugf("invalid bitmap\n"); |
| 753 return nullptr; | 753 return nullptr; |
| 754 } | 754 } |
| 755 const void* data; | 755 const void* data; |
| 756 int size = decode_data(jsonBitmap[SKDEBUGCANVAS_ATTRIBUTE_DATA], urlDataMana
ger, &data); | 756 int size = decode_data(jsonBitmap[SKDEBUGCANVAS_ATTRIBUTE_DATA], urlDataMana
ger, &data); |
| 757 SkMemoryStream stream(data, size); | 757 SkAutoTUnref<SkData> encoded(SkData::NewWithoutCopy(data, size)); |
| 758 SkImageDecoder* decoder = SkImageDecoder::Factory(&stream); | 758 SkAutoTDelete<SkImage> image(SkImage::NewFromEncoded(encoded, nullptr)); |
| 759 SkBitmap* bitmap = new SkBitmap(); | 759 |
| 760 SkImageDecoder::Result result = decoder->decode(&stream, bitmap, | 760 SkAutoTDelete<SkBitmap> bitmap(new SkBitmap()); |
| 761 SkImageDecoder::kDecodePixel
s_Mode); | 761 if (nullptr != image) { |
| 762 sk_free(decoder); | 762 if (!image->asLegacyBitmap(bitmap, SkImage::kRW_LegacyBitmapMode)) { |
| 763 if (result != SkImageDecoder::kFailure) { | 763 SkDebugf("image decode failed\n"); |
| 764 return nullptr; |
| 765 } |
| 766 |
| 764 if (jsonBitmap.isMember(SKDEBUGCANVAS_ATTRIBUTE_COLOR)) { | 767 if (jsonBitmap.isMember(SKDEBUGCANVAS_ATTRIBUTE_COLOR)) { |
| 765 const char* ctName = jsonBitmap[SKDEBUGCANVAS_ATTRIBUTE_COLOR].asCSt
ring(); | 768 const char* ctName = jsonBitmap[SKDEBUGCANVAS_ATTRIBUTE_COLOR].asCSt
ring(); |
| 766 SkColorType ct = colortype_from_name(ctName); | 769 SkColorType ct = colortype_from_name(ctName); |
| 767 if (ct != kIndex_8_SkColorType) { | 770 if (ct != kIndex_8_SkColorType) { |
| 768 bitmap = convert_colortype(bitmap, ct); | 771 bitmap.reset(convert_colortype(bitmap.detach(), ct)); |
| 769 } | 772 } |
| 770 } | 773 } |
| 771 return bitmap; | 774 return bitmap.detach(); |
| 772 } | 775 } |
| 773 SkDebugf("image decode failed\n"); | 776 SkDebugf("image decode failed\n"); |
| 774 return nullptr; | 777 return nullptr; |
| 775 } | 778 } |
| 776 | 779 |
| 777 static SkImage* load_image(const Json::Value& jsonImage, UrlDataManager& urlData
Manager) { | 780 static SkImage* load_image(const Json::Value& jsonImage, UrlDataManager& urlData
Manager) { |
| 778 SkBitmap* bitmap = load_bitmap(jsonImage, urlDataManager); | 781 SkBitmap* bitmap = load_bitmap(jsonImage, urlDataManager); |
| 779 if (bitmap == nullptr) { | 782 if (bitmap == nullptr) { |
| 780 return nullptr; | 783 return nullptr; |
| 781 } | 784 } |
| (...skipping 2289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3071 result[SKDEBUGCANVAS_ATTRIBUTE_MATRIX] = MakeJsonMatrix(fMatrix); | 3074 result[SKDEBUGCANVAS_ATTRIBUTE_MATRIX] = MakeJsonMatrix(fMatrix); |
| 3072 return result; | 3075 return result; |
| 3073 } | 3076 } |
| 3074 | 3077 |
| 3075 SkSetMatrixCommand* SkSetMatrixCommand::fromJSON(Json::Value& command, | 3078 SkSetMatrixCommand* SkSetMatrixCommand::fromJSON(Json::Value& command, |
| 3076 UrlDataManager& urlDataManager)
{ | 3079 UrlDataManager& urlDataManager)
{ |
| 3077 SkMatrix matrix; | 3080 SkMatrix matrix; |
| 3078 extract_json_matrix(command[SKDEBUGCANVAS_ATTRIBUTE_MATRIX], &matrix); | 3081 extract_json_matrix(command[SKDEBUGCANVAS_ATTRIBUTE_MATRIX], &matrix); |
| 3079 return new SkSetMatrixCommand(matrix); | 3082 return new SkSetMatrixCommand(matrix); |
| 3080 } | 3083 } |
| OLD | NEW |