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

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: Address on hiroshige's review Created 4 years, 6 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 if (!m_actualDecoder || m_actualDecoder->failed()) 110 if (!m_actualDecoder || m_actualDecoder->failed())
111 return nullptr; 111 return nullptr;
112 112
113 ImageFrame* frame = m_actualDecoder->frameBufferAtIndex(index); 113 ImageFrame* frame = m_actualDecoder->frameBufferAtIndex(index);
114 if (!frame || frame->getStatus() == ImageFrame::FrameEmpty) 114 if (!frame || frame->getStatus() == ImageFrame::FrameEmpty)
115 return nullptr; 115 return nullptr;
116 116
117 return adoptRef(SkImage::NewFromBitmap(frame->bitmap())); 117 return adoptRef(SkImage::NewFromBitmap(frame->bitmap()));
118 } 118 }
119 119
120 bool DeferredImageDecoder::hasData() const
121 {
122 return static_cast<bool>(m_rwBuffer);
123 }
124
125 PassRefPtr<SharedBuffer> DeferredImageDecoder::data()
scroggo_chromium 2016/06/20 19:00:43 This method can be slow, especially if it's called
hajimehoshi 2016/06/22 09:42:29 IIUC this is not called often: Resource::resourceB
126 {
127 if (!m_rwBuffer)
128 return nullptr;
129 RefPtr<SkROBuffer> roBuffer = adoptRef(m_rwBuffer->newRBufferSnapshot());
130 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(roBuffer->size());
131 SkROBuffer::Iter it(roBuffer.get());
132 do {
133 sharedBuffer->append(static_cast<const char*>(it.data()), it.size());
134 } while (it.next());
135 return sharedBuffer;
136 }
137
120 void DeferredImageDecoder::setData(SharedBuffer& data, bool allDataReceived) 138 void DeferredImageDecoder::setData(SharedBuffer& data, bool allDataReceived)
121 { 139 {
122 if (m_actualDecoder) { 140 if (m_actualDecoder) {
123 m_allDataReceived = allDataReceived; 141 m_allDataReceived = allDataReceived;
124 m_actualDecoder->setData(&data, allDataReceived); 142 m_actualDecoder->setData(&data, allDataReceived);
125 prepareLazyDecodedFrames(); 143 prepareLazyDecodedFrames();
126 } 144 }
127 145
128 if (m_frameGenerator) { 146 if (m_frameGenerator) {
129 if (!m_rwBuffer) 147 if (!m_rwBuffer)
130 m_rwBuffer = adoptPtr(new SkRWBuffer(data.size())); 148 m_rwBuffer = adoptPtr(new SkRWBuffer(data.size()));
131 149
132 const char* segment = 0; 150 const char* segment = 0;
133 for (size_t length = data.getSomeData(segment, m_rwBuffer->size()); 151 for (size_t length = data.getSomeData(segment, m_rwBuffer->size());
134 length; length = data.getSomeData(segment, m_rwBuffer->size())) 152 length; length = data.getSomeData(segment, m_rwBuffer->size())) {
135 m_rwBuffer->append(segment, length); 153 m_rwBuffer->append(segment, length);
154 }
136 } 155 }
137 } 156 }
138 157
139 bool DeferredImageDecoder::isSizeAvailable() 158 bool DeferredImageDecoder::isSizeAvailable()
140 { 159 {
141 // m_actualDecoder is 0 only if image decoding is deferred and that means 160 // m_actualDecoder is 0 only if image decoding is deferred and that means
142 // the image header decoded successfully and the size is available. 161 // the image header decoded successfully and the size is available.
143 return m_actualDecoder ? m_actualDecoder->isSizeAvailable() : true; 162 return m_actualDecoder ? m_actualDecoder->isSizeAvailable() : true;
144 } 163 }
145 164
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 } 338 }
320 339
321 } // namespace blink 340 } // namespace blink
322 341
323 namespace WTF { 342 namespace WTF {
324 template<> struct VectorTraits<blink::DeferredFrameData> : public SimpleClassVec torTraits<blink::DeferredFrameData> { 343 template<> struct VectorTraits<blink::DeferredFrameData> : public SimpleClassVec torTraits<blink::DeferredFrameData> {
325 STATIC_ONLY(VectorTraits); 344 STATIC_ONLY(VectorTraits);
326 static const bool canInitializeWithMemset = false; // Not all DeferredFrameD ata members initialize to 0. 345 static const bool canInitializeWithMemset = false; // Not all DeferredFrameD ata members initialize to 0.
327 }; 346 };
328 } 347 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698