| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "platform/graphics/LoggingCanvas.h" | 31 #include "platform/graphics/LoggingCanvas.h" |
| 32 | 32 |
| 33 #include "platform/geometry/IntSize.h" | 33 #include "platform/geometry/IntSize.h" |
| 34 #include "platform/graphics/ImageBuffer.h" | 34 #include "platform/graphics/ImageBuffer.h" |
| 35 #include "platform/graphics/skia/ImagePixelLocker.h" | 35 #include "platform/graphics/skia/ImagePixelLocker.h" |
| 36 #include "platform/graphics/skia/SkiaUtils.h" | 36 #include "platform/graphics/skia/SkiaUtils.h" |
| 37 #include "platform/image-encoders/PNGImageEncoder.h" | 37 #include "platform/image-encoders/ImageEncoder.h" |
| 38 #include "platform/wtf/HexNumber.h" | 38 #include "platform/wtf/HexNumber.h" |
| 39 #include "platform/wtf/text/Base64.h" | 39 #include "platform/wtf/text/Base64.h" |
| 40 #include "platform/wtf/text/TextEncoding.h" | 40 #include "platform/wtf/text/TextEncoding.h" |
| 41 #include "third_party/skia/include/core/SkImage.h" | 41 #include "third_party/skia/include/core/SkImage.h" |
| 42 #include "third_party/skia/include/core/SkImageInfo.h" | 42 #include "third_party/skia/include/core/SkImageInfo.h" |
| 43 #include "third_party/skia/include/core/SkPaint.h" | 43 #include "third_party/skia/include/core/SkPaint.h" |
| 44 #include "third_party/skia/include/core/SkPath.h" | 44 #include "third_party/skia/include/core/SkPath.h" |
| 45 #include "third_party/skia/include/core/SkRRect.h" | 45 #include "third_party/skia/include/core/SkRRect.h" |
| 46 #include "third_party/skia/include/core/SkRect.h" | 46 #include "third_party/skia/include/core/SkRect.h" |
| 47 | 47 |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 return "ARGB8888"; | 259 return "ARGB8888"; |
| 260 default: | 260 default: |
| 261 NOTREACHED(); | 261 NOTREACHED(); |
| 262 return "?"; | 262 return "?"; |
| 263 }; | 263 }; |
| 264 } | 264 } |
| 265 | 265 |
| 266 std::unique_ptr<JSONObject> ObjectForBitmapData(const SkBitmap& bitmap) { | 266 std::unique_ptr<JSONObject> ObjectForBitmapData(const SkBitmap& bitmap) { |
| 267 Vector<unsigned char> output; | 267 Vector<unsigned char> output; |
| 268 | 268 |
| 269 if (sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap)) { | 269 SkPixmap src; |
| 270 ImagePixelLocker pixel_locker(image, kUnpremul_SkAlphaType, | 270 bool peekResult = bitmap.peekPixels(&src); |
| 271 kRGBA_8888_SkColorType); | 271 DCHECK(peekResult); |
| 272 ImageDataBuffer image_data( | |
| 273 IntSize(image->width(), image->height()), | |
| 274 static_cast<const unsigned char*>(pixel_locker.Pixels())); | |
| 275 | 272 |
| 276 PNGImageEncoder::Encode(image_data, &output); | 273 SkPngEncoder::Options options; |
| 274 options.fFilterFlags = SkPngEncoder::FilterFlag::kSub; |
| 275 options.fZLibLevel = 3; |
| 276 options.fUnpremulBehavior = SkTransferFunctionBehavior::kIgnore; |
| 277 if (!ImageEncoder::Encode(&output, src, options)) { |
| 278 return nullptr; |
| 277 } | 279 } |
| 278 | 280 |
| 279 std::unique_ptr<JSONObject> data_item = JSONObject::Create(); | 281 std::unique_ptr<JSONObject> data_item = JSONObject::Create(); |
| 280 data_item->SetString( | 282 data_item->SetString( |
| 281 "base64", | 283 "base64", |
| 282 WTF::Base64Encode(reinterpret_cast<char*>(output.data()), output.size())); | 284 WTF::Base64Encode(reinterpret_cast<char*>(output.data()), output.size())); |
| 283 data_item->SetString("mimeType", "image/png"); | 285 data_item->SetString("mimeType", "image/png"); |
| 284 return data_item; | 286 return data_item; |
| 285 } | 287 } |
| 286 | 288 |
| (...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 record_as_json->SetArray("operations", canvas.Log()); | 916 record_as_json->SetArray("operations", canvas.Log()); |
| 915 return record_as_json->ToPrettyJSONString(); | 917 return record_as_json->ToPrettyJSONString(); |
| 916 } | 918 } |
| 917 | 919 |
| 918 void ShowPaintRecord(const PaintRecord* record) { | 920 void ShowPaintRecord(const PaintRecord* record) { |
| 919 WTFLogAlways("%s\n", RecordAsDebugString(record).Utf8().data()); | 921 WTFLogAlways("%s\n", RecordAsDebugString(record).Utf8().data()); |
| 920 } | 922 } |
| 921 #endif | 923 #endif |
| 922 | 924 |
| 923 } // namespace blink | 925 } // namespace blink |
| OLD | NEW |