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 22 matching lines...) Expand all Loading... | |
33 #include <memory> | 33 #include <memory> |
34 #include "platform/geometry/IntSize.h" | 34 #include "platform/geometry/IntSize.h" |
35 #include "platform/graphics/ImageBuffer.h" | 35 #include "platform/graphics/ImageBuffer.h" |
36 #include "platform/graphics/LoggingCanvas.h" | 36 #include "platform/graphics/LoggingCanvas.h" |
37 #include "platform/graphics/ProfilingCanvas.h" | 37 #include "platform/graphics/ProfilingCanvas.h" |
38 #include "platform/graphics/ReplayingCanvas.h" | 38 #include "platform/graphics/ReplayingCanvas.h" |
39 #include "platform/graphics/skia/ImagePixelLocker.h" | 39 #include "platform/graphics/skia/ImagePixelLocker.h" |
40 #include "platform/image-decoders/ImageDecoder.h" | 40 #include "platform/image-decoders/ImageDecoder.h" |
41 #include "platform/image-decoders/ImageFrame.h" | 41 #include "platform/image-decoders/ImageFrame.h" |
42 #include "platform/image-decoders/SegmentReader.h" | 42 #include "platform/image-decoders/SegmentReader.h" |
43 #include "platform/image-encoders/PNGImageEncoder.h" | 43 #include "platform/image-encoders/ImageEncoder.h" |
44 #include "platform/wtf/CurrentTime.h" | 44 #include "platform/wtf/CurrentTime.h" |
45 #include "platform/wtf/HexNumber.h" | 45 #include "platform/wtf/HexNumber.h" |
46 #include "platform/wtf/PtrUtil.h" | 46 #include "platform/wtf/PtrUtil.h" |
47 #include "platform/wtf/text/Base64.h" | 47 #include "platform/wtf/text/Base64.h" |
48 #include "platform/wtf/text/TextEncoding.h" | 48 #include "platform/wtf/text/TextEncoding.h" |
49 #include "third_party/skia/include/core/SkData.h" | 49 #include "third_party/skia/include/core/SkData.h" |
50 #include "third_party/skia/include/core/SkImage.h" | 50 #include "third_party/skia/include/core/SkImage.h" |
51 #include "third_party/skia/include/core/SkImageDeserializer.h" | 51 #include "third_party/skia/include/core/SkImageDeserializer.h" |
52 #include "third_party/skia/include/core/SkPictureRecorder.h" | 52 #include "third_party/skia/include/core/SkPictureRecorder.h" |
53 #include "third_party/skia/include/core/SkStream.h" | 53 #include "third_party/skia/include/core/SkStream.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 SkAutoCanvasRestore auto_restore(&canvas, false); | 138 SkAutoCanvasRestore auto_restore(&canvas, false); |
139 canvas.saveLayer(nullptr, nullptr); | 139 canvas.saveLayer(nullptr, nullptr); |
140 | 140 |
141 canvas.scale(scale, scale); | 141 canvas.scale(scale, scale); |
142 canvas.ResetStepCount(); | 142 canvas.ResetStepCount(); |
143 picture_->playback(&canvas, &canvas); | 143 picture_->playback(&canvas, &canvas); |
144 } | 144 } |
145 std::unique_ptr<Vector<char>> base64_data = WTF::MakeUnique<Vector<char>>(); | 145 std::unique_ptr<Vector<char>> base64_data = WTF::MakeUnique<Vector<char>>(); |
146 Vector<char> encoded_image; | 146 Vector<char> encoded_image; |
147 | 147 |
148 sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); | 148 SkPixmap src; |
149 if (!image) | 149 bool peekResult = bitmap.peekPixels(&src); |
150 DCHECK(peekResult); | |
151 | |
152 SkPngEncoder::Options options; | |
scroggo_chromium
2017/05/22 13:35:04
Both LoggingCanvas.cpp and this one use the same v
msarett1
2017/05/22 15:33:56
Arguably kIgnore should be the default - but I'm t
| |
153 options.fFilterFlags = SkPngEncoder::FilterFlag::kSub; | |
154 options.fZLibLevel = 3; | |
155 options.fUnpremulBehavior = SkTransferFunctionBehavior::kIgnore; | |
156 if (!ImageEncoder::Encode( | |
157 reinterpret_cast<Vector<unsigned char>*>(&encoded_image), src, | |
158 options)) { | |
150 return nullptr; | 159 return nullptr; |
151 | 160 } |
152 ImagePixelLocker pixel_locker(image, kUnpremul_SkAlphaType, | |
153 kRGBA_8888_SkColorType); | |
154 ImageDataBuffer image_data( | |
155 IntSize(image->width(), image->height()), | |
156 static_cast<const unsigned char*>(pixel_locker.Pixels())); | |
157 if (!PNGImageEncoder::Encode( | |
158 image_data, reinterpret_cast<Vector<unsigned char>*>(&encoded_image))) | |
159 return nullptr; | |
160 | 161 |
161 Base64Encode(encoded_image, *base64_data); | 162 Base64Encode(encoded_image, *base64_data); |
162 return base64_data; | 163 return base64_data; |
163 } | 164 } |
164 | 165 |
165 std::unique_ptr<PictureSnapshot::Timings> PictureSnapshot::Profile( | 166 std::unique_ptr<PictureSnapshot::Timings> PictureSnapshot::Profile( |
166 unsigned min_repeat_count, | 167 unsigned min_repeat_count, |
167 double min_duration, | 168 double min_duration, |
168 const FloatRect* clip_rect) const { | 169 const FloatRect* clip_rect) const { |
169 std::unique_ptr<PictureSnapshot::Timings> timings = | 170 std::unique_ptr<PictureSnapshot::Timings> timings = |
(...skipping 27 matching lines...) Expand all Loading... | |
197 } | 198 } |
198 | 199 |
199 std::unique_ptr<JSONArray> PictureSnapshot::SnapshotCommandLog() const { | 200 std::unique_ptr<JSONArray> PictureSnapshot::SnapshotCommandLog() const { |
200 const SkIRect bounds = picture_->cullRect().roundOut(); | 201 const SkIRect bounds = picture_->cullRect().roundOut(); |
201 LoggingCanvas canvas(bounds.width(), bounds.height()); | 202 LoggingCanvas canvas(bounds.width(), bounds.height()); |
202 picture_->playback(&canvas); | 203 picture_->playback(&canvas); |
203 return canvas.Log(); | 204 return canvas.Log(); |
204 } | 205 } |
205 | 206 |
206 } // namespace blink | 207 } // namespace blink |
OLD | NEW |