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

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

Issue 2202473002: DO NOT COMMIT: Experimental removal of encoded image data Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: (rebase) Created 4 years, 3 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) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 return wrapUnique(new DeferredImageDecoder(std::move(actualDecoder))); 80 return wrapUnique(new DeferredImageDecoder(std::move(actualDecoder)));
81 } 81 }
82 82
83 DeferredImageDecoder::DeferredImageDecoder(std::unique_ptr<ImageDecoder> actualD ecoder) 83 DeferredImageDecoder::DeferredImageDecoder(std::unique_ptr<ImageDecoder> actualD ecoder)
84 : m_allDataReceived(false) 84 : m_allDataReceived(false)
85 , m_actualDecoder(std::move(actualDecoder)) 85 , m_actualDecoder(std::move(actualDecoder))
86 , m_repetitionCount(cAnimationNone) 86 , m_repetitionCount(cAnimationNone)
87 , m_hasColorProfile(false) 87 , m_hasColorProfile(false)
88 , m_canYUVDecode(false) 88 , m_canYUVDecode(false)
89 , m_hasHotSpot(false) 89 , m_hasHotSpot(false)
90 , m_isBufferCleared(false)
90 { 91 {
91 } 92 }
92 93
93 DeferredImageDecoder::~DeferredImageDecoder() 94 DeferredImageDecoder::~DeferredImageDecoder()
94 { 95 {
95 } 96 }
96 97
97 String DeferredImageDecoder::filenameExtension() const 98 String DeferredImageDecoder::filenameExtension() const
98 { 99 {
99 return m_actualDecoder ? m_actualDecoder->filenameExtension() : m_filenameEx tension; 100 return m_actualDecoder ? m_actualDecoder->filenameExtension() : m_filenameEx tension;
(...skipping 21 matching lines...) Expand all
121 if (!m_actualDecoder || m_actualDecoder->failed()) 122 if (!m_actualDecoder || m_actualDecoder->failed())
122 return nullptr; 123 return nullptr;
123 124
124 ImageFrame* frame = m_actualDecoder->frameBufferAtIndex(index); 125 ImageFrame* frame = m_actualDecoder->frameBufferAtIndex(index);
125 if (!frame || frame->getStatus() == ImageFrame::FrameEmpty) 126 if (!frame || frame->getStatus() == ImageFrame::FrameEmpty)
126 return nullptr; 127 return nullptr;
127 128
128 return SkImage::MakeFromBitmap(frame->bitmap()); 129 return SkImage::MakeFromBitmap(frame->bitmap());
129 } 130 }
130 131
132 bool DeferredImageDecoder::clear()
133 {
134 if (!m_rwBuffer)
135 return false;
136 m_rwBuffer.reset();
137 m_isBufferCleared = true;
138 return true;
139 }
140
131 PassRefPtr<SharedBuffer> DeferredImageDecoder::data() 141 PassRefPtr<SharedBuffer> DeferredImageDecoder::data()
132 { 142 {
133 if (!m_rwBuffer) 143 if (!m_rwBuffer)
134 return nullptr; 144 return nullptr;
135 sk_sp<SkROBuffer> roBuffer(m_rwBuffer->newRBufferSnapshot()); 145 sk_sp<SkROBuffer> roBuffer(m_rwBuffer->newRBufferSnapshot());
136 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(); 146 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create();
137 SkROBuffer::Iter it(roBuffer.get()); 147 SkROBuffer::Iter it(roBuffer.get());
138 do { 148 do {
139 sharedBuffer->append(static_cast<const char*>(it.data()), it.size()); 149 sharedBuffer->append(static_cast<const char*>(it.data()), it.size());
140 } while (it.next()); 150 } while (it.next());
(...skipping 17 matching lines...) Expand all
158 168
159 if (m_frameGenerator) { 169 if (m_frameGenerator) {
160 if (!m_rwBuffer) 170 if (!m_rwBuffer)
161 m_rwBuffer = wrapUnique(new SkRWBuffer(data->size())); 171 m_rwBuffer = wrapUnique(new SkRWBuffer(data->size()));
162 172
163 const char* segment = 0; 173 const char* segment = 0;
164 for (size_t length = data->getSomeData(segment, m_rwBuffer->size()); 174 for (size_t length = data->getSomeData(segment, m_rwBuffer->size());
165 length; length = data->getSomeData(segment, m_rwBuffer->size())) { 175 length; length = data->getSomeData(segment, m_rwBuffer->size())) {
166 m_rwBuffer->append(segment, length); 176 m_rwBuffer->append(segment, length);
167 } 177 }
178 m_isBufferCleared = false;
168 } 179 }
169 } 180 }
170 181
171 bool DeferredImageDecoder::isSizeAvailable() 182 bool DeferredImageDecoder::isSizeAvailable()
172 { 183 {
173 // m_actualDecoder is 0 only if image decoding is deferred and that means 184 // m_actualDecoder is 0 only if image decoding is deferred and that means
174 // the image header decoded successfully and the size is available. 185 // the image header decoded successfully and the size is available.
175 return m_actualDecoder ? m_actualDecoder->isSizeAvailable() : true; 186 return m_actualDecoder ? m_actualDecoder->isSizeAvailable() : true;
176 } 187 }
177 188
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 { 328 {
318 return SkImageInfo::MakeN32(decodedSize.width(), decodedSize.height(), known ToBeOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); 329 return SkImageInfo::MakeN32(decodedSize.width(), decodedSize.height(), known ToBeOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
319 } 330 }
320 331
321 sk_sp<SkImage> DeferredImageDecoder::createFrameImageAtIndex(size_t index, bool knownToBeOpaque) 332 sk_sp<SkImage> DeferredImageDecoder::createFrameImageAtIndex(size_t index, bool knownToBeOpaque)
322 { 333 {
323 const SkISize& decodedSize = m_frameGenerator->getFullSize(); 334 const SkISize& decodedSize = m_frameGenerator->getFullSize();
324 ASSERT(decodedSize.width() > 0); 335 ASSERT(decodedSize.width() > 0);
325 ASSERT(decodedSize.height() > 0); 336 ASSERT(decodedSize.height() > 0);
326 337
338 DCHECK(!m_isBufferCleared);
327 sk_sp<SkROBuffer> roBuffer(m_rwBuffer->newRBufferSnapshot()); 339 sk_sp<SkROBuffer> roBuffer(m_rwBuffer->newRBufferSnapshot());
328 RefPtr<SegmentReader> segmentReader = SegmentReader::createFromSkROBuffer(st d::move(roBuffer)); 340 RefPtr<SegmentReader> segmentReader = SegmentReader::createFromSkROBuffer(st d::move(roBuffer));
329 DecodingImageGenerator* generator = new DecodingImageGenerator(m_frameGenera tor, imageInfoFrom(decodedSize, knownToBeOpaque), segmentReader.release(), m_all DataReceived, index, m_frameData[index].m_uniqueID); 341 DecodingImageGenerator* generator = new DecodingImageGenerator(m_frameGenera tor, imageInfoFrom(decodedSize, knownToBeOpaque), segmentReader.release(), m_all DataReceived, index, m_frameData[index].m_uniqueID);
330 sk_sp<SkImage> image = SkImage::MakeFromGenerator(generator); // SkImage tak es ownership of the generator. 342 sk_sp<SkImage> image = SkImage::MakeFromGenerator(generator); // SkImage tak es ownership of the generator.
331 if (!image) 343 if (!image)
332 return nullptr; 344 return nullptr;
333 345
334 // We can consider decoded bitmap constant and reuse uniqueID only after all 346 // We can consider decoded bitmap constant and reuse uniqueID only after all
335 // data is received. We reuse it also for multiframe images when image data 347 // data is received. We reuse it also for multiframe images when image data
336 // is partially received but the frame data is fully received. 348 // is partially received but the frame data is fully received.
(...skipping 17 matching lines...) Expand all
354 } 366 }
355 367
356 } // namespace blink 368 } // namespace blink
357 369
358 namespace WTF { 370 namespace WTF {
359 template<> struct VectorTraits<blink::DeferredFrameData> : public SimpleClassVec torTraits<blink::DeferredFrameData> { 371 template<> struct VectorTraits<blink::DeferredFrameData> : public SimpleClassVec torTraits<blink::DeferredFrameData> {
360 STATIC_ONLY(VectorTraits); 372 STATIC_ONLY(VectorTraits);
361 static const bool canInitializeWithMemset = false; // Not all DeferredFrameD ata members initialize to 0. 373 static const bool canInitializeWithMemset = false; // Not all DeferredFrameD ata members initialize to 0.
362 }; 374 };
363 } 375 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698