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 28 matching lines...) Expand all Loading... |
39 #include "platform/image-decoders/ImageDecoder.h" | 39 #include "platform/image-decoders/ImageDecoder.h" |
40 #include "platform/image-decoders/ImageFrame.h" | 40 #include "platform/image-decoders/ImageFrame.h" |
41 #include "platform/image-decoders/SegmentReader.h" | 41 #include "platform/image-decoders/SegmentReader.h" |
42 #include "platform/image-encoders/PNGImageEncoder.h" | 42 #include "platform/image-encoders/PNGImageEncoder.h" |
43 #include "third_party/skia/include/core/SkData.h" | 43 #include "third_party/skia/include/core/SkData.h" |
44 #include "third_party/skia/include/core/SkImage.h" | 44 #include "third_party/skia/include/core/SkImage.h" |
45 #include "third_party/skia/include/core/SkPictureRecorder.h" | 45 #include "third_party/skia/include/core/SkPictureRecorder.h" |
46 #include "third_party/skia/include/core/SkStream.h" | 46 #include "third_party/skia/include/core/SkStream.h" |
47 #include "wtf/CurrentTime.h" | 47 #include "wtf/CurrentTime.h" |
48 #include "wtf/HexNumber.h" | 48 #include "wtf/HexNumber.h" |
| 49 #include "wtf/PtrUtil.h" |
49 #include "wtf/text/Base64.h" | 50 #include "wtf/text/Base64.h" |
50 #include "wtf/text/TextEncoding.h" | 51 #include "wtf/text/TextEncoding.h" |
| 52 #include <memory> |
51 | 53 |
52 namespace blink { | 54 namespace blink { |
53 | 55 |
54 PictureSnapshot::PictureSnapshot(PassRefPtr<const SkPicture> picture) | 56 PictureSnapshot::PictureSnapshot(PassRefPtr<const SkPicture> picture) |
55 : m_picture(picture) | 57 : m_picture(picture) |
56 { | 58 { |
57 } | 59 } |
58 | 60 |
59 static bool decodeBitmap(const void* data, size_t length, SkBitmap* result) | 61 static bool decodeBitmap(const void* data, size_t length, SkBitmap* result) |
60 { | 62 { |
61 OwnPtr<ImageDecoder> imageDecoder = ImageDecoder::create(static_cast<const c
har*>(data), length, | 63 std::unique_ptr<ImageDecoder> imageDecoder = ImageDecoder::create(static_cas
t<const char*>(data), length, |
62 ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgno
red); | 64 ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgno
red); |
63 if (!imageDecoder) | 65 if (!imageDecoder) |
64 return false; | 66 return false; |
65 | 67 |
66 // No need to copy the data; this decodes immediately. | 68 // No need to copy the data; this decodes immediately. |
67 RefPtr<SegmentReader> segmentReader = SegmentReader::createFromSkData(adoptR
ef(SkData::NewWithoutCopy(data, length))); | 69 RefPtr<SegmentReader> segmentReader = SegmentReader::createFromSkData(adoptR
ef(SkData::NewWithoutCopy(data, length))); |
68 imageDecoder->setData(segmentReader.release(), true); | 70 imageDecoder->setData(segmentReader.release(), true); |
69 ImageFrame* frame = imageDecoder->frameBufferAtIndex(0); | 71 ImageFrame* frame = imageDecoder->frameBufferAtIndex(0); |
70 if (!frame) | 72 if (!frame) |
71 return true; | 73 return true; |
(...skipping 28 matching lines...) Expand all Loading... |
100 canvas->restore(); | 102 canvas->restore(); |
101 } | 103 } |
102 return adoptRef(new PictureSnapshot(fromSkSp(recorder.finishRecordingAsPictu
re()))); | 104 return adoptRef(new PictureSnapshot(fromSkSp(recorder.finishRecordingAsPictu
re()))); |
103 } | 105 } |
104 | 106 |
105 bool PictureSnapshot::isEmpty() const | 107 bool PictureSnapshot::isEmpty() const |
106 { | 108 { |
107 return m_picture->cullRect().isEmpty(); | 109 return m_picture->cullRect().isEmpty(); |
108 } | 110 } |
109 | 111 |
110 PassOwnPtr<Vector<char>> PictureSnapshot::replay(unsigned fromStep, unsigned toS
tep, double scale) const | 112 std::unique_ptr<Vector<char>> PictureSnapshot::replay(unsigned fromStep, unsigne
d toStep, double scale) const |
111 { | 113 { |
112 const SkIRect bounds = m_picture->cullRect().roundOut(); | 114 const SkIRect bounds = m_picture->cullRect().roundOut(); |
113 | 115 |
114 // TODO(fmalita): convert this to SkSurface/SkImage, drop the intermediate S
kBitmap. | 116 // TODO(fmalita): convert this to SkSurface/SkImage, drop the intermediate S
kBitmap. |
115 SkBitmap bitmap; | 117 SkBitmap bitmap; |
116 bitmap.allocPixels(SkImageInfo::MakeN32Premul(bounds.width(), bounds.height(
))); | 118 bitmap.allocPixels(SkImageInfo::MakeN32Premul(bounds.width(), bounds.height(
))); |
117 bitmap.eraseARGB(0, 0, 0, 0); | 119 bitmap.eraseARGB(0, 0, 0, 0); |
118 { | 120 { |
119 ReplayingCanvas canvas(bitmap, fromStep, toStep); | 121 ReplayingCanvas canvas(bitmap, fromStep, toStep); |
120 // Disable LCD text preemptively, because the picture opacity is unknown
. | 122 // Disable LCD text preemptively, because the picture opacity is unknown
. |
121 // The canonical API involves SkSurface props, but since we're not SkSur
face-based | 123 // The canonical API involves SkSurface props, but since we're not SkSur
face-based |
122 // at this point (see TODO above) we (ab)use saveLayer for this purpose. | 124 // at this point (see TODO above) we (ab)use saveLayer for this purpose. |
123 SkAutoCanvasRestore autoRestore(&canvas, false); | 125 SkAutoCanvasRestore autoRestore(&canvas, false); |
124 canvas.saveLayer(nullptr, nullptr); | 126 canvas.saveLayer(nullptr, nullptr); |
125 | 127 |
126 canvas.scale(scale, scale); | 128 canvas.scale(scale, scale); |
127 canvas.resetStepCount(); | 129 canvas.resetStepCount(); |
128 m_picture->playback(&canvas, &canvas); | 130 m_picture->playback(&canvas, &canvas); |
129 } | 131 } |
130 OwnPtr<Vector<char>> base64Data = adoptPtr(new Vector<char>()); | 132 std::unique_ptr<Vector<char>> base64Data = wrapUnique(new Vector<char>()); |
131 Vector<char> encodedImage; | 133 Vector<char> encodedImage; |
132 | 134 |
133 RefPtr<SkImage> image = fromSkSp(SkImage::MakeFromBitmap(bitmap)); | 135 RefPtr<SkImage> image = fromSkSp(SkImage::MakeFromBitmap(bitmap)); |
134 if (!image) | 136 if (!image) |
135 return nullptr; | 137 return nullptr; |
136 | 138 |
137 ImagePixelLocker pixelLocker(image, kUnpremul_SkAlphaType, kRGBA_8888_SkColo
rType); | 139 ImagePixelLocker pixelLocker(image, kUnpremul_SkAlphaType, kRGBA_8888_SkColo
rType); |
138 ImageDataBuffer imageData(IntSize(image->width(), image->height()), | 140 ImageDataBuffer imageData(IntSize(image->width(), image->height()), |
139 static_cast<const unsigned char*>(pixelLocker.pixels())); | 141 static_cast<const unsigned char*>(pixelLocker.pixels())); |
140 if (!PNGImageEncoder::encode(imageData, reinterpret_cast<Vector<unsigned cha
r>*>(&encodedImage))) | 142 if (!PNGImageEncoder::encode(imageData, reinterpret_cast<Vector<unsigned cha
r>*>(&encodedImage))) |
141 return nullptr; | 143 return nullptr; |
142 | 144 |
143 base64Encode(encodedImage, *base64Data); | 145 base64Encode(encodedImage, *base64Data); |
144 return base64Data; | 146 return base64Data; |
145 } | 147 } |
146 | 148 |
147 PassOwnPtr<PictureSnapshot::Timings> PictureSnapshot::profile(unsigned minRepeat
Count, double minDuration, const FloatRect* clipRect) const | 149 std::unique_ptr<PictureSnapshot::Timings> PictureSnapshot::profile(unsigned minR
epeatCount, double minDuration, const FloatRect* clipRect) const |
148 { | 150 { |
149 OwnPtr<PictureSnapshot::Timings> timings = adoptPtr(new PictureSnapshot::Tim
ings()); | 151 std::unique_ptr<PictureSnapshot::Timings> timings = wrapUnique(new PictureSn
apshot::Timings()); |
150 timings->reserveCapacity(minRepeatCount); | 152 timings->reserveCapacity(minRepeatCount); |
151 const SkIRect bounds = m_picture->cullRect().roundOut(); | 153 const SkIRect bounds = m_picture->cullRect().roundOut(); |
152 SkBitmap bitmap; | 154 SkBitmap bitmap; |
153 bitmap.allocPixels(SkImageInfo::MakeN32Premul(bounds.width(), bounds.height(
))); | 155 bitmap.allocPixels(SkImageInfo::MakeN32Premul(bounds.width(), bounds.height(
))); |
154 bitmap.eraseARGB(0, 0, 0, 0); | 156 bitmap.eraseARGB(0, 0, 0, 0); |
155 | 157 |
156 double now = WTF::monotonicallyIncreasingTime(); | 158 double now = WTF::monotonicallyIncreasingTime(); |
157 double stopTime = now + minDuration; | 159 double stopTime = now + minDuration; |
158 for (unsigned step = 0; step < minRepeatCount || now < stopTime; ++step) { | 160 for (unsigned step = 0; step < minRepeatCount || now < stopTime; ++step) { |
159 timings->append(Vector<double>()); | 161 timings->append(Vector<double>()); |
(...skipping 14 matching lines...) Expand all Loading... |
174 | 176 |
175 PassRefPtr<JSONArray> PictureSnapshot::snapshotCommandLog() const | 177 PassRefPtr<JSONArray> PictureSnapshot::snapshotCommandLog() const |
176 { | 178 { |
177 const SkIRect bounds = m_picture->cullRect().roundOut(); | 179 const SkIRect bounds = m_picture->cullRect().roundOut(); |
178 LoggingCanvas canvas(bounds.width(), bounds.height()); | 180 LoggingCanvas canvas(bounds.width(), bounds.height()); |
179 m_picture->playback(&canvas); | 181 m_picture->playback(&canvas); |
180 return canvas.log(); | 182 return canvas.log(); |
181 } | 183 } |
182 | 184 |
183 } // namespace blink | 185 } // namespace blink |
OLD | NEW |