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

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

Issue 2257513002: Refactor ImageDecoder factories (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup Created 4 years, 4 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 , m_uniqueID(DecodingImageGenerator::kNeedNewImageUniqueID) 50 , m_uniqueID(DecodingImageGenerator::kNeedNewImageUniqueID)
51 {} 51 {}
52 52
53 ImageOrientation m_orientation; 53 ImageOrientation m_orientation;
54 float m_duration; 54 float m_duration;
55 bool m_isComplete; 55 bool m_isComplete;
56 size_t m_frameBytes; 56 size_t m_frameBytes;
57 uint32_t m_uniqueID; 57 uint32_t m_uniqueID;
58 }; 58 };
59 59
60 std::unique_ptr<DeferredImageDecoder> DeferredImageDecoder::create(ImageDecoder: :SniffResult sniffResult, ImageDecoder::AlphaOption alphaOption, ImageDecoder::G ammaAndColorProfileOption colorOptions) 60 std::unique_ptr<DeferredImageDecoder> DeferredImageDecoder::create(PassRefPtr<Sh aredBuffer> passData,
61 bool dataComplete, ImageDecoder::AlphaOption alphaOption, ImageDecoder::Gamm aAndColorProfileOption colorOptions)
61 { 62 {
62 std::unique_ptr<ImageDecoder> actualDecoder = ImageDecoder::create(sniffResu lt, alphaOption, colorOptions); 63 RefPtr<SharedBuffer> data = passData;
64
65 std::unique_ptr<ImageDecoder> actualDecoder = ImageDecoder::create(data, dat aComplete, alphaOption, colorOptions);
63 66
64 if (!actualDecoder) 67 if (!actualDecoder)
65 return nullptr; 68 return nullptr;
66 69
67 return wrapUnique(new DeferredImageDecoder(std::move(actualDecoder))); 70 std::unique_ptr<DeferredImageDecoder> decoder = wrapUnique(new DeferredImage Decoder(std::move(actualDecoder)));
Peter Kasting 2016/08/19 23:04:58 Nit: Seems like the wrapUnique() call here doesn't
f(malita) 2016/08/22 01:51:15 Done.
71
72 // Since we've just instantiated a fresh decoder, there's no need to reset i ts data.
73 decoder->setDataInternal(data.release(), dataComplete, false);
74
75 return decoder;
68 } 76 }
69 77
70 std::unique_ptr<DeferredImageDecoder> DeferredImageDecoder::createForTesting(std ::unique_ptr<ImageDecoder> actualDecoder) 78 std::unique_ptr<DeferredImageDecoder> DeferredImageDecoder::createForTesting(std ::unique_ptr<ImageDecoder> actualDecoder)
71 { 79 {
72 return wrapUnique(new DeferredImageDecoder(std::move(actualDecoder))); 80 return wrapUnique(new DeferredImageDecoder(std::move(actualDecoder)));
73 } 81 }
74 82
75 DeferredImageDecoder::DeferredImageDecoder(std::unique_ptr<ImageDecoder> actualD ecoder) 83 DeferredImageDecoder::DeferredImageDecoder(std::unique_ptr<ImageDecoder> actualD ecoder)
76 : m_allDataReceived(false) 84 : m_allDataReceived(false)
77 , m_actualDecoder(std::move(actualDecoder)) 85 , m_actualDecoder(std::move(actualDecoder))
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 return nullptr; 134 return nullptr;
127 RefPtr<SkROBuffer> roBuffer = adoptRef(m_rwBuffer->newRBufferSnapshot()); 135 RefPtr<SkROBuffer> roBuffer = adoptRef(m_rwBuffer->newRBufferSnapshot());
128 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(); 136 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create();
129 SkROBuffer::Iter it(roBuffer.get()); 137 SkROBuffer::Iter it(roBuffer.get());
130 do { 138 do {
131 sharedBuffer->append(static_cast<const char*>(it.data()), it.size()); 139 sharedBuffer->append(static_cast<const char*>(it.data()), it.size());
132 } while (it.next()); 140 } while (it.next());
133 return sharedBuffer.release(); 141 return sharedBuffer.release();
134 } 142 }
135 143
136 void DeferredImageDecoder::setData(SharedBuffer& data, bool allDataReceived) 144 void DeferredImageDecoder::setData(PassRefPtr<SharedBuffer> data, bool allDataRe ceived)
137 { 145 {
146 setDataInternal(data, allDataReceived, true);
147 }
148
149 void DeferredImageDecoder::setDataInternal(PassRefPtr<SharedBuffer> passData, bo ol allDataReceived, bool pushDataToDecoder)
150 {
151 RefPtr<SharedBuffer> data = passData;
138 if (m_actualDecoder) { 152 if (m_actualDecoder) {
139 m_allDataReceived = allDataReceived; 153 m_allDataReceived = allDataReceived;
140 m_actualDecoder->setData(&data, allDataReceived); 154 if (pushDataToDecoder)
155 m_actualDecoder->setData(data, allDataReceived);
141 prepareLazyDecodedFrames(); 156 prepareLazyDecodedFrames();
142 } 157 }
143 158
144 if (m_frameGenerator) { 159 if (m_frameGenerator) {
145 if (!m_rwBuffer) 160 if (!m_rwBuffer)
146 m_rwBuffer = wrapUnique(new SkRWBuffer(data.size())); 161 m_rwBuffer = wrapUnique(new SkRWBuffer(data->size()));
147 162
148 const char* segment = 0; 163 const char* segment = 0;
149 for (size_t length = data.getSomeData(segment, m_rwBuffer->size()); 164 for (size_t length = data->getSomeData(segment, m_rwBuffer->size());
150 length; length = data.getSomeData(segment, m_rwBuffer->size())) { 165 length; length = data->getSomeData(segment, m_rwBuffer->size())) {
151 m_rwBuffer->append(segment, length); 166 m_rwBuffer->append(segment, length);
152 } 167 }
153 } 168 }
154 } 169 }
155 170
156 bool DeferredImageDecoder::isSizeAvailable() 171 bool DeferredImageDecoder::isSizeAvailable()
157 { 172 {
158 // m_actualDecoder is 0 only if image decoding is deferred and that means 173 // m_actualDecoder is 0 only if image decoding is deferred and that means
159 // the image header decoded successfully and the size is available. 174 // the image header decoded successfully and the size is available.
160 return m_actualDecoder ? m_actualDecoder->isSizeAvailable() : true; 175 return m_actualDecoder ? m_actualDecoder->isSizeAvailable() : true;
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 } 354 }
340 355
341 } // namespace blink 356 } // namespace blink
342 357
343 namespace WTF { 358 namespace WTF {
344 template<> struct VectorTraits<blink::DeferredFrameData> : public SimpleClassVec torTraits<blink::DeferredFrameData> { 359 template<> struct VectorTraits<blink::DeferredFrameData> : public SimpleClassVec torTraits<blink::DeferredFrameData> {
345 STATIC_ONLY(VectorTraits); 360 STATIC_ONLY(VectorTraits);
346 static const bool canInitializeWithMemset = false; // Not all DeferredFrameD ata members initialize to 0. 361 static const bool canInitializeWithMemset = false; // Not all DeferredFrameD ata members initialize to 0.
347 }; 362 };
348 } 363 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698