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

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

Issue 2054643003: Remove duplication of encoded image data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: (rebase) Created 4 years, 5 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 if (!m_actualDecoder || m_actualDecoder->failed()) 113 if (!m_actualDecoder || m_actualDecoder->failed())
114 return nullptr; 114 return nullptr;
115 115
116 ImageFrame* frame = m_actualDecoder->frameBufferAtIndex(index); 116 ImageFrame* frame = m_actualDecoder->frameBufferAtIndex(index);
117 if (!frame || frame->getStatus() == ImageFrame::FrameEmpty) 117 if (!frame || frame->getStatus() == ImageFrame::FrameEmpty)
118 return nullptr; 118 return nullptr;
119 119
120 return fromSkSp(SkImage::MakeFromBitmap(frame->bitmap())); 120 return fromSkSp(SkImage::MakeFromBitmap(frame->bitmap()));
121 } 121 }
122 122
123 PassRefPtr<SharedBuffer> DeferredImageDecoder::data()
124 {
125 if (!m_rwBuffer)
126 return nullptr;
127 RefPtr<SkROBuffer> roBuffer = adoptRef(m_rwBuffer->newRBufferSnapshot());
128 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create();
129 SkROBuffer::Iter it(roBuffer.get());
130 do {
131 sharedBuffer->append(static_cast<const char*>(it.data()), it.size());
132 } while (it.next());
133 return sharedBuffer.release();
134 }
135
123 void DeferredImageDecoder::setData(SharedBuffer& data, bool allDataReceived) 136 void DeferredImageDecoder::setData(SharedBuffer& data, bool allDataReceived)
124 { 137 {
125 if (m_actualDecoder) { 138 if (m_actualDecoder) {
126 m_allDataReceived = allDataReceived; 139 m_allDataReceived = allDataReceived;
127 m_actualDecoder->setData(&data, allDataReceived); 140 m_actualDecoder->setData(&data, allDataReceived);
128 prepareLazyDecodedFrames(); 141 prepareLazyDecodedFrames();
129 } 142 }
130 143
131 if (m_frameGenerator) { 144 if (m_frameGenerator) {
132 if (!m_rwBuffer) 145 if (!m_rwBuffer)
133 m_rwBuffer = wrapUnique(new SkRWBuffer(data.size())); 146 m_rwBuffer = wrapUnique(new SkRWBuffer(data.size()));
134 147
135 const char* segment = 0; 148 const char* segment = 0;
136 for (size_t length = data.getSomeData(segment, m_rwBuffer->size()); 149 for (size_t length = data.getSomeData(segment, m_rwBuffer->size());
137 length; length = data.getSomeData(segment, m_rwBuffer->size())) 150 length; length = data.getSomeData(segment, m_rwBuffer->size())) {
138 m_rwBuffer->append(segment, length); 151 m_rwBuffer->append(segment, length);
152 }
139 } 153 }
140 } 154 }
141 155
142 bool DeferredImageDecoder::isSizeAvailable() 156 bool DeferredImageDecoder::isSizeAvailable()
143 { 157 {
144 // m_actualDecoder is 0 only if image decoding is deferred and that means 158 // m_actualDecoder is 0 only if image decoding is deferred and that means
145 // the image header decoded successfully and the size is available. 159 // the image header decoded successfully and the size is available.
146 return m_actualDecoder ? m_actualDecoder->isSizeAvailable() : true; 160 return m_actualDecoder ? m_actualDecoder->isSizeAvailable() : true;
147 } 161 }
148 162
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 } 339 }
326 340
327 } // namespace blink 341 } // namespace blink
328 342
329 namespace WTF { 343 namespace WTF {
330 template<> struct VectorTraits<blink::DeferredFrameData> : public SimpleClassVec torTraits<blink::DeferredFrameData> { 344 template<> struct VectorTraits<blink::DeferredFrameData> : public SimpleClassVec torTraits<blink::DeferredFrameData> {
331 STATIC_ONLY(VectorTraits); 345 STATIC_ONLY(VectorTraits);
332 static const bool canInitializeWithMemset = false; // Not all DeferredFrameD ata members initialize to 0. 346 static const bool canInitializeWithMemset = false; // Not all DeferredFrameD ata members initialize to 0.
333 }; 347 };
334 } 348 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698