Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 bool DeferredImageDecoder::hasData() const | |
| 124 { | |
| 125 return static_cast<bool>(m_rwBuffer); | |
| 126 } | |
| 127 | |
| 128 PassRefPtr<SharedBuffer> DeferredImageDecoder::data() | |
| 129 { | |
| 130 if (!m_rwBuffer) | |
| 131 return nullptr; | |
| 132 RefPtr<SkROBuffer> roBuffer = adoptRef(m_rwBuffer->newRBufferSnapshot()); | |
| 133 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(); | |
| 134 SkROBuffer::Iter it(roBuffer.get()); | |
| 135 do { | |
| 136 sharedBuffer->append(static_cast<const char*>(it.data()), it.size()); | |
| 137 } while (it.next()); | |
| 138 return sharedBuffer; | |
|
haraken
2016/07/13 02:18:30
sharedBuffer.release()
hajimehoshi
2016/07/13 07:36:22
Done.
| |
| 139 } | |
| 140 | |
| 123 void DeferredImageDecoder::setData(SharedBuffer& data, bool allDataReceived) | 141 void DeferredImageDecoder::setData(SharedBuffer& data, bool allDataReceived) |
| 124 { | 142 { |
| 125 if (m_actualDecoder) { | 143 if (m_actualDecoder) { |
| 126 m_allDataReceived = allDataReceived; | 144 m_allDataReceived = allDataReceived; |
| 127 m_actualDecoder->setData(&data, allDataReceived); | 145 m_actualDecoder->setData(&data, allDataReceived); |
| 128 prepareLazyDecodedFrames(); | 146 prepareLazyDecodedFrames(); |
| 129 } | 147 } |
| 130 | 148 |
| 131 if (m_frameGenerator) { | 149 if (m_frameGenerator) { |
| 132 if (!m_rwBuffer) | 150 if (!m_rwBuffer) |
| 133 m_rwBuffer = wrapUnique(new SkRWBuffer(data.size())); | 151 m_rwBuffer = wrapUnique(new SkRWBuffer(data.size())); |
| 134 | 152 |
| 135 const char* segment = 0; | 153 const char* segment = 0; |
| 136 for (size_t length = data.getSomeData(segment, m_rwBuffer->size()); | 154 for (size_t length = data.getSomeData(segment, m_rwBuffer->size()); |
| 137 length; length = data.getSomeData(segment, m_rwBuffer->size())) | 155 length; length = data.getSomeData(segment, m_rwBuffer->size())) { |
| 138 m_rwBuffer->append(segment, length); | 156 m_rwBuffer->append(segment, length); |
| 157 } | |
| 139 } | 158 } |
| 140 } | 159 } |
| 141 | 160 |
| 142 bool DeferredImageDecoder::isSizeAvailable() | 161 bool DeferredImageDecoder::isSizeAvailable() |
| 143 { | 162 { |
| 144 // m_actualDecoder is 0 only if image decoding is deferred and that means | 163 // m_actualDecoder is 0 only if image decoding is deferred and that means |
| 145 // the image header decoded successfully and the size is available. | 164 // the image header decoded successfully and the size is available. |
| 146 return m_actualDecoder ? m_actualDecoder->isSizeAvailable() : true; | 165 return m_actualDecoder ? m_actualDecoder->isSizeAvailable() : true; |
| 147 } | 166 } |
| 148 | 167 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 } | 344 } |
| 326 | 345 |
| 327 } // namespace blink | 346 } // namespace blink |
| 328 | 347 |
| 329 namespace WTF { | 348 namespace WTF { |
| 330 template<> struct VectorTraits<blink::DeferredFrameData> : public SimpleClassVec torTraits<blink::DeferredFrameData> { | 349 template<> struct VectorTraits<blink::DeferredFrameData> : public SimpleClassVec torTraits<blink::DeferredFrameData> { |
| 331 STATIC_ONLY(VectorTraits); | 350 STATIC_ONLY(VectorTraits); |
| 332 static const bool canInitializeWithMemset = false; // Not all DeferredFrameD ata members initialize to 0. | 351 static const bool canInitializeWithMemset = false; // Not all DeferredFrameD ata members initialize to 0. |
| 333 }; | 352 }; |
| 334 } | 353 } |
| OLD | NEW |