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 24 matching lines...) Expand all Loading... | |
35 #include "platform/graphics/LoggingCanvas.h" | 35 #include "platform/graphics/LoggingCanvas.h" |
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/SkPictureRecorder.h" | 46 #include "third_party/skia/include/core/SkPictureRecorder.h" |
46 #include "third_party/skia/include/core/SkStream.h" | 47 #include "third_party/skia/include/core/SkStream.h" |
47 #include "wtf/CurrentTime.h" | 48 #include "wtf/CurrentTime.h" |
48 #include "wtf/HexNumber.h" | 49 #include "wtf/HexNumber.h" |
49 #include "wtf/PtrUtil.h" | 50 #include "wtf/PtrUtil.h" |
50 #include "wtf/text/Base64.h" | 51 #include "wtf/text/Base64.h" |
51 #include "wtf/text/TextEncoding.h" | 52 #include "wtf/text/TextEncoding.h" |
52 #include <memory> | 53 #include <memory> |
53 | 54 |
54 namespace blink { | 55 namespace blink { |
55 | 56 |
56 PictureSnapshot::PictureSnapshot(PassRefPtr<const SkPicture> picture) | 57 PictureSnapshot::PictureSnapshot(PassRefPtr<const SkPicture> picture) |
57 : m_picture(picture) | 58 : m_picture(picture) |
58 { | 59 { |
59 } | 60 } |
60 | 61 |
61 static bool decodeBitmap(const void* data, size_t length, SkBitmap* result) | 62 class SkiaImageDecoder : public SkImageDeserializer { |
62 { | 63 public: |
63 std::unique_ptr<ImageDecoder> imageDecoder = ImageDecoder::create(ImageDecod er::determineImageType(static_cast<const char*>(data), length), | 64 sk_sp<SkImage> makeFromMemory(const void* data, size_t length, const SkIRect * subset) override |
64 ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgno red); | 65 { |
65 if (!imageDecoder) | 66 std::unique_ptr<ImageDecoder> imageDecoder = ImageDecoder::create(ImageD ecoder::determineImageType(static_cast<const char*>(data), length), |
66 return false; | 67 ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfile Ignored); |
68 if (!imageDecoder) | |
69 return nullptr; | |
67 | 70 |
68 // No need to copy the data; this decodes immediately. | 71 RefPtr<SegmentReader> segmentReader = SegmentReader::createFromSkData(Sk Data::MakeWithoutCopy(data, length)); |
69 RefPtr<SegmentReader> segmentReader = SegmentReader::createFromSkData(SkData ::MakeWithoutCopy(data, length)); | 72 imageDecoder->setData(segmentReader.release(), true); |
70 imageDecoder->setData(segmentReader.release(), true); | 73 ImageFrame* frame = imageDecoder->frameBufferAtIndex(0); |
71 ImageFrame* frame = imageDecoder->frameBufferAtIndex(0); | 74 if (!frame || imageDecoder->failed()) |
72 if (!frame) | 75 return nullptr; |
73 return true; | 76 return frame->finalizePixelsAndGetImage(); |
Peter Kasting
2016/09/22 21:44:08
Nit: Shorter:
return (frame && !imageDeco
aleksandar.stojiljkovic
2016/09/27 18:08:28
Done.
| |
74 *result = frame->bitmap(); | 77 } |
75 return true; | 78 sk_sp<SkImage> makeFromData(SkData* data, const SkIRect* subset) override |
76 } | 79 { |
80 return this->makeFromMemory(data->data(), data->size(), subset); | |
81 } | |
82 }; | |
77 | 83 |
78 PassRefPtr<PictureSnapshot> PictureSnapshot::load(const Vector<RefPtr<TilePictur eStream>>& tiles) | 84 PassRefPtr<PictureSnapshot> PictureSnapshot::load(const Vector<RefPtr<TilePictur eStream>>& tiles) |
79 { | 85 { |
80 ASSERT(!tiles.isEmpty()); | 86 ASSERT(!tiles.isEmpty()); |
81 Vector<sk_sp<SkPicture>> pictures; | 87 Vector<sk_sp<SkPicture>> pictures; |
82 pictures.reserveCapacity(tiles.size()); | 88 pictures.reserveCapacity(tiles.size()); |
83 FloatRect unionRect; | 89 FloatRect unionRect; |
84 for (const auto& tileStream : tiles) { | 90 for (const auto& tileStream : tiles) { |
85 SkMemoryStream stream(tileStream->data.begin(), tileStream->data.size()) ; | 91 SkMemoryStream stream(tileStream->data.begin(), tileStream->data.size()) ; |
86 sk_sp<SkPicture> picture = SkPicture::MakeFromStream(&stream, decodeBitm ap); | 92 SkiaImageDecoder factory; |
93 sk_sp<SkPicture> picture = SkPicture::MakeFromStream(&stream, &factory); | |
87 if (!picture) | 94 if (!picture) |
88 return nullptr; | 95 return nullptr; |
89 FloatRect cullRect(picture->cullRect()); | 96 FloatRect cullRect(picture->cullRect()); |
90 cullRect.moveBy(tileStream->layerOffset); | 97 cullRect.moveBy(tileStream->layerOffset); |
91 unionRect.unite(cullRect); | 98 unionRect.unite(cullRect); |
92 pictures.append(std::move(picture)); | 99 pictures.append(std::move(picture)); |
93 } | 100 } |
94 if (tiles.size() == 1) | 101 if (tiles.size() == 1) |
95 return adoptRef(new PictureSnapshot(fromSkSp(std::move(pictures[0])))); | 102 return adoptRef(new PictureSnapshot(fromSkSp(std::move(pictures[0])))); |
96 SkPictureRecorder recorder; | 103 SkPictureRecorder recorder; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 | 183 |
177 std::unique_ptr<JSONArray> PictureSnapshot::snapshotCommandLog() const | 184 std::unique_ptr<JSONArray> PictureSnapshot::snapshotCommandLog() const |
178 { | 185 { |
179 const SkIRect bounds = m_picture->cullRect().roundOut(); | 186 const SkIRect bounds = m_picture->cullRect().roundOut(); |
180 LoggingCanvas canvas(bounds.width(), bounds.height()); | 187 LoggingCanvas canvas(bounds.width(), bounds.height()); |
181 m_picture->playback(&canvas); | 188 m_picture->playback(&canvas); |
182 return canvas.log(); | 189 return canvas.log(); |
183 } | 190 } |
184 | 191 |
185 } // namespace blink | 192 } // namespace blink |
OLD | NEW |