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 25 matching lines...) Expand all Loading... |
36 #include "platform/graphics/ProfilingCanvas.h" | 36 #include "platform/graphics/ProfilingCanvas.h" |
37 #include "platform/graphics/ReplayingCanvas.h" | 37 #include "platform/graphics/ReplayingCanvas.h" |
38 #include "platform/graphics/skia/ImagePixelLocker.h" | 38 #include "platform/graphics/skia/ImagePixelLocker.h" |
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/SkImageDeserializer.h" | 45 #include "third_party/skia/include/core/SkImageDeserializer.h" |
46 #include "third_party/skia/include/core/SkPictureRecorder.h" | |
47 #include "third_party/skia/include/core/SkStream.h" | 46 #include "third_party/skia/include/core/SkStream.h" |
48 #include "wtf/CurrentTime.h" | 47 #include "wtf/CurrentTime.h" |
49 #include "wtf/HexNumber.h" | 48 #include "wtf/HexNumber.h" |
50 #include "wtf/PtrUtil.h" | 49 #include "wtf/PtrUtil.h" |
51 #include "wtf/text/Base64.h" | 50 #include "wtf/text/Base64.h" |
52 #include "wtf/text/TextEncoding.h" | 51 #include "wtf/text/TextEncoding.h" |
53 #include <memory> | 52 #include <memory> |
54 | 53 |
55 namespace blink { | 54 namespace blink { |
56 | 55 |
57 PictureSnapshot::PictureSnapshot(sk_sp<const SkPicture> picture) | 56 PictureSnapshot::PictureSnapshot(sk_sp<const PaintRecord> picture) |
58 : m_picture(std::move(picture)) {} | 57 : m_picture(std::move(picture)) {} |
59 | 58 |
60 class SkiaImageDecoder final : public SkImageDeserializer { | 59 class SkiaImageDecoder final : public SkImageDeserializer { |
61 public: | 60 public: |
62 sk_sp<SkImage> makeFromMemory(const void* data, | 61 sk_sp<SkImage> makeFromMemory(const void* data, |
63 size_t length, | 62 size_t length, |
64 const SkIRect* subset) override { | 63 const SkIRect* subset) override { |
65 // No need to copy the data; this decodes immediately. | 64 // No need to copy the data; this decodes immediately. |
66 RefPtr<SegmentReader> segmentReader = | 65 RefPtr<SegmentReader> segmentReader = |
67 SegmentReader::createFromSkData(SkData::MakeWithoutCopy(data, length)); | 66 SegmentReader::createFromSkData(SkData::MakeWithoutCopy(data, length)); |
68 std::unique_ptr<ImageDecoder> imageDecoder = ImageDecoder::create( | 67 std::unique_ptr<ImageDecoder> imageDecoder = ImageDecoder::create( |
69 std::move(segmentReader), true, ImageDecoder::AlphaPremultiplied, | 68 std::move(segmentReader), true, ImageDecoder::AlphaPremultiplied, |
70 ColorBehavior::ignore()); | 69 ColorBehavior::ignore()); |
71 if (!imageDecoder) | 70 if (!imageDecoder) |
72 return nullptr; | 71 return nullptr; |
73 | 72 |
74 ImageFrame* frame = imageDecoder->frameBufferAtIndex(0); | 73 ImageFrame* frame = imageDecoder->frameBufferAtIndex(0); |
75 return (frame && !imageDecoder->failed()) | 74 return (frame && !imageDecoder->failed()) |
76 ? frame->finalizePixelsAndGetImage() | 75 ? frame->finalizePixelsAndGetImage() |
77 : nullptr; | 76 : nullptr; |
78 } | 77 } |
79 sk_sp<SkImage> makeFromData(SkData* data, const SkIRect* subset) override { | 78 sk_sp<SkImage> makeFromData(SkData* data, const SkIRect* subset) override { |
80 return this->makeFromMemory(data->data(), data->size(), subset); | 79 return this->makeFromMemory(data->data(), data->size(), subset); |
81 } | 80 } |
82 }; | 81 }; |
83 | 82 |
84 PassRefPtr<PictureSnapshot> PictureSnapshot::load( | 83 PassRefPtr<PictureSnapshot> PictureSnapshot::load( |
85 const Vector<RefPtr<TilePictureStream>>& tiles) { | 84 const Vector<RefPtr<TilePictureStream>>& tiles) { |
86 ASSERT(!tiles.isEmpty()); | 85 ASSERT(!tiles.isEmpty()); |
87 Vector<sk_sp<SkPicture>> pictures; | 86 Vector<sk_sp<PaintRecord>> pictures; |
88 pictures.reserveCapacity(tiles.size()); | 87 pictures.reserveCapacity(tiles.size()); |
89 FloatRect unionRect; | 88 FloatRect unionRect; |
90 for (const auto& tileStream : tiles) { | 89 for (const auto& tileStream : tiles) { |
91 SkMemoryStream stream(tileStream->data.begin(), tileStream->data.size()); | 90 SkMemoryStream stream(tileStream->data.begin(), tileStream->data.size()); |
92 SkiaImageDecoder factory; | 91 SkiaImageDecoder factory; |
93 sk_sp<SkPicture> picture = SkPicture::MakeFromStream(&stream, &factory); | 92 sk_sp<PaintRecord> picture = PaintRecord::MakeFromStream(&stream, &factory); |
94 if (!picture) | 93 if (!picture) |
95 return nullptr; | 94 return nullptr; |
96 FloatRect cullRect(picture->cullRect()); | 95 FloatRect cullRect(picture->cullRect()); |
97 cullRect.moveBy(tileStream->layerOffset); | 96 cullRect.moveBy(tileStream->layerOffset); |
98 unionRect.unite(cullRect); | 97 unionRect.unite(cullRect); |
99 pictures.push_back(std::move(picture)); | 98 pictures.push_back(std::move(picture)); |
100 } | 99 } |
101 if (tiles.size() == 1) | 100 if (tiles.size() == 1) |
102 return adoptRef(new PictureSnapshot(std::move(pictures[0]))); | 101 return adoptRef(new PictureSnapshot(std::move(pictures[0]))); |
103 SkPictureRecorder recorder; | 102 PaintRecorder recorder; |
104 SkCanvas* canvas = | 103 PaintCanvas* canvas = |
105 recorder.beginRecording(unionRect.width(), unionRect.height(), 0, 0); | 104 recorder.beginRecording(unionRect.width(), unionRect.height(), 0, 0); |
106 for (size_t i = 0; i < pictures.size(); ++i) { | 105 for (size_t i = 0; i < pictures.size(); ++i) { |
107 canvas->save(); | 106 canvas->save(); |
108 canvas->translate(tiles[i]->layerOffset.x() - unionRect.x(), | 107 canvas->translate(tiles[i]->layerOffset.x() - unionRect.x(), |
109 tiles[i]->layerOffset.y() - unionRect.y()); | 108 tiles[i]->layerOffset.y() - unionRect.y()); |
110 pictures[i]->playback(canvas, 0); | 109 pictures[i]->playback(canvas, 0); |
111 canvas->restore(); | 110 canvas->restore(); |
112 } | 111 } |
113 return adoptRef(new PictureSnapshot(recorder.finishRecordingAsPicture())); | 112 return adoptRef(new PictureSnapshot(recorder.finishRecordingAsPicture())); |
114 } | 113 } |
(...skipping 18 matching lines...) Expand all Loading... |
133 ReplayingCanvas canvas(bitmap, fromStep, toStep); | 132 ReplayingCanvas canvas(bitmap, fromStep, toStep); |
134 // Disable LCD text preemptively, because the picture opacity is unknown. | 133 // Disable LCD text preemptively, because the picture opacity is unknown. |
135 // The canonical API involves SkSurface props, but since we're not | 134 // The canonical API involves SkSurface props, but since we're not |
136 // SkSurface-based at this point (see TODO above) we (ab)use saveLayer for | 135 // SkSurface-based at this point (see TODO above) we (ab)use saveLayer for |
137 // this purpose. | 136 // this purpose. |
138 SkAutoCanvasRestore autoRestore(&canvas, false); | 137 SkAutoCanvasRestore autoRestore(&canvas, false); |
139 canvas.saveLayer(nullptr, nullptr); | 138 canvas.saveLayer(nullptr, nullptr); |
140 | 139 |
141 canvas.scale(scale, scale); | 140 canvas.scale(scale, scale); |
142 canvas.resetStepCount(); | 141 canvas.resetStepCount(); |
143 m_picture->playback(&canvas, &canvas); | 142 |
| 143 // TODO(enne): Handle this abort callback in PaintRecord::playback. |
| 144 PaintCanvasPassThrough passthrough(&canvas); |
| 145 m_picture->playback(&passthrough, &canvas); |
144 } | 146 } |
145 std::unique_ptr<Vector<char>> base64Data = WTF::makeUnique<Vector<char>>(); | 147 std::unique_ptr<Vector<char>> base64Data = WTF::makeUnique<Vector<char>>(); |
146 Vector<char> encodedImage; | 148 Vector<char> encodedImage; |
147 | 149 |
148 sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); | 150 sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
149 if (!image) | 151 if (!image) |
150 return nullptr; | 152 return nullptr; |
151 | 153 |
152 ImagePixelLocker pixelLocker(image, kUnpremul_SkAlphaType, | 154 ImagePixelLocker pixelLocker(image, kUnpremul_SkAlphaType, |
153 kRGBA_8888_SkColorType); | 155 kRGBA_8888_SkColorType); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 canvas.setTimings(currentTimings); | 193 canvas.setTimings(currentTimings); |
192 m_picture->playback(&canvas); | 194 m_picture->playback(&canvas); |
193 now = WTF::monotonicallyIncreasingTime(); | 195 now = WTF::monotonicallyIncreasingTime(); |
194 } | 196 } |
195 return timings; | 197 return timings; |
196 } | 198 } |
197 | 199 |
198 std::unique_ptr<JSONArray> PictureSnapshot::snapshotCommandLog() const { | 200 std::unique_ptr<JSONArray> PictureSnapshot::snapshotCommandLog() const { |
199 const SkIRect bounds = m_picture->cullRect().roundOut(); | 201 const SkIRect bounds = m_picture->cullRect().roundOut(); |
200 LoggingCanvas canvas(bounds.width(), bounds.height()); | 202 LoggingCanvas canvas(bounds.width(), bounds.height()); |
201 m_picture->playback(&canvas); | 203 PaintCanvasPassThrough passthrough(&canvas); |
| 204 m_picture->playback(&passthrough); |
202 return canvas.log(); | 205 return canvas.log(); |
203 } | 206 } |
204 | 207 |
205 } // namespace blink | 208 } // namespace blink |
OLD | NEW |