Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/PictureSnapshot.cpp

Issue 2155973002: Save a bitmap copy when advancing to dependent GIF and WebP animation frames (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DCHECK m_status in ImageFrame. Shortened commit message. Thanks kbr@. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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(sk_sp<const SkPicture> picture) 57 PictureSnapshot::PictureSnapshot(sk_sp<const SkPicture> picture)
57 : m_picture(std::move(picture)) 58 : m_picture(std::move(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 // No need to copy the data; this decodes immediately. 64 sk_sp<SkImage> makeFromMemory(const void* data, size_t length, const SkIRect * subset) override
64 RefPtr<SegmentReader> segmentReader = SegmentReader::createFromSkData(SkData ::MakeWithoutCopy(data, length)); 65 {
65 std::unique_ptr<ImageDecoder> imageDecoder = ImageDecoder::create(segmentRea der.release(), true, 66 // No need to copy the data; this decodes immediately.
66 ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgno red); 67 RefPtr<SegmentReader> segmentReader = SegmentReader::createFromSkData(Sk Data::MakeWithoutCopy(data, length));
67 if (!imageDecoder) 68 std::unique_ptr<ImageDecoder> imageDecoder = ImageDecoder::create(segmen tReader.release(), true,
68 return false; 69 ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfile Ignored);
70 if (!imageDecoder)
71 return nullptr;
69 72
70 ImageFrame* frame = imageDecoder->frameBufferAtIndex(0); 73 ImageFrame* frame = imageDecoder->frameBufferAtIndex(0);
71 if (!frame) 74 return (frame && !imageDecoder->failed()) ? frame->finalizePixelsAndGetI mage() : nullptr;
72 return true; 75 }
73 *result = frame->bitmap(); 76 sk_sp<SkImage> makeFromData(SkData* data, const SkIRect* subset) override
74 return true; 77 {
75 } 78 return this->makeFromMemory(data->data(), data->size(), subset);
79 }
80 };
76 81
77 PassRefPtr<PictureSnapshot> PictureSnapshot::load(const Vector<RefPtr<TilePictur eStream>>& tiles) 82 PassRefPtr<PictureSnapshot> PictureSnapshot::load(const Vector<RefPtr<TilePictur eStream>>& tiles)
78 { 83 {
79 ASSERT(!tiles.isEmpty()); 84 ASSERT(!tiles.isEmpty());
80 Vector<sk_sp<SkPicture>> pictures; 85 Vector<sk_sp<SkPicture>> pictures;
81 pictures.reserveCapacity(tiles.size()); 86 pictures.reserveCapacity(tiles.size());
82 FloatRect unionRect; 87 FloatRect unionRect;
83 for (const auto& tileStream : tiles) { 88 for (const auto& tileStream : tiles) {
84 SkMemoryStream stream(tileStream->data.begin(), tileStream->data.size()) ; 89 SkMemoryStream stream(tileStream->data.begin(), tileStream->data.size()) ;
85 sk_sp<SkPicture> picture = SkPicture::MakeFromStream(&stream, decodeBitm ap); 90 SkiaImageDecoder factory;
91 sk_sp<SkPicture> picture = SkPicture::MakeFromStream(&stream, &factory);
86 if (!picture) 92 if (!picture)
87 return nullptr; 93 return nullptr;
88 FloatRect cullRect(picture->cullRect()); 94 FloatRect cullRect(picture->cullRect());
89 cullRect.moveBy(tileStream->layerOffset); 95 cullRect.moveBy(tileStream->layerOffset);
90 unionRect.unite(cullRect); 96 unionRect.unite(cullRect);
91 pictures.append(std::move(picture)); 97 pictures.append(std::move(picture));
92 } 98 }
93 if (tiles.size() == 1) 99 if (tiles.size() == 1)
94 return adoptRef(new PictureSnapshot(std::move(pictures[0]))); 100 return adoptRef(new PictureSnapshot(std::move(pictures[0])));
95 SkPictureRecorder recorder; 101 SkPictureRecorder recorder;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 181
176 std::unique_ptr<JSONArray> PictureSnapshot::snapshotCommandLog() const 182 std::unique_ptr<JSONArray> PictureSnapshot::snapshotCommandLog() const
177 { 183 {
178 const SkIRect bounds = m_picture->cullRect().roundOut(); 184 const SkIRect bounds = m_picture->cullRect().roundOut();
179 LoggingCanvas canvas(bounds.width(), bounds.height()); 185 LoggingCanvas canvas(bounds.width(), bounds.height());
180 m_picture->playback(&canvas); 186 m_picture->playback(&canvas);
181 return canvas.log(); 187 return canvas.log();
182 } 188 }
183 189
184 } // namespace blink 190 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698