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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 ImageFrameGenerator::~ImageFrameGenerator() | 110 ImageFrameGenerator::~ImageFrameGenerator() |
111 { | 111 { |
112 ImageDecodingStore::instance().removeCacheIndexedByGenerator(this); | 112 ImageDecodingStore::instance().removeCacheIndexedByGenerator(this); |
113 } | 113 } |
114 | 114 |
115 void ImageFrameGenerator::setData(PassRefPtr<SharedBuffer> data, bool allDataRec eived) | 115 void ImageFrameGenerator::setData(PassRefPtr<SharedBuffer> data, bool allDataRec eived) |
116 { | 116 { |
117 m_data.setData(data.get(), allDataReceived); | 117 m_data.setData(data.get(), allDataReceived); |
118 } | 118 } |
119 | 119 |
120 void ImageFrameGenerator::copyData(RefPtr<SharedBuffer>* data, bool* allDataRece ived) | 120 static void sharedBufSkDataReleaseProc(const void* addr, void* ctx) |
121 { | 121 { |
122 SharedBuffer* buffer = static_cast<SharedBuffer*>(ctx); | |
123 ASSERT(buffer && buffer->data() == addr); | |
124 // Deref SharedBuffer shared with m_data. | |
125 buffer->deref(); | |
Stephen White
2015/12/02 16:15:14
Are we 100% sure this is thread-safe? Does this ca
chrishtr
2015/12/02 16:44:28
It's not clear to me why removing the RefPtr for t
Stephen White
2015/12/02 18:25:47
There's an explicit call to ref() in refSkData() b
chrishtr
2015/12/02 18:26:44
Ah I see, thanks.
| |
126 } | |
127 | |
128 SkData* ImageFrameGenerator::refSkData() | |
129 { | |
130 // Every SkData instance and SharedBuffer need to keep buffer->data() refcou nted. | |
131 // Both SkData and m_data.m_readBuffer are having separate ref counting impl ementations. | |
132 // | |
133 // SkData's SkData::NewWithProc is designed with similar use case in mind, | |
134 // unmapping wrapped shmem data once all SkData instances are disposed. | |
135 // in this case, sharedBufSkDataReleaseProc would just need to deref (since m_data.m_readBuffer | |
136 // might still hold a reference) and that is happening in sharedBufSkDataRel easeProc. | |
137 // | |
138 // If m_data gets disposed, SkData would still need to hold the ref to Share dBuffer, | |
139 // and that is why SharedBuffer (accompanying returned SkData) is passed to client of this | |
140 // call - by contract they need to call SkData unref that would end up in sh aredBufSkDataReleaseProc | |
141 // releasing the ref to SharedBuffer. | |
142 // | |
143 // A note about allDataReceived: | |
144 // Client side use case is valid only for full image (encoded) data download ed, | |
145 // but, incidentally, this is in line with current Chromium implementation, where | |
146 // DeferredImageDecoder::setData is called only once with allDataReceived an d after | |
147 // that m_data.m_readBuffer.data() is not changed. For the sake of not leavi ng loose ends, | |
148 // ThreadSafeDataTransport::data is checking if there is new data added afte r AllDataReceived | |
149 // was set to true. | |
122 SharedBuffer* buffer = 0; | 150 SharedBuffer* buffer = 0; |
123 m_data.data(&buffer, allDataReceived); | 151 bool allDataReceived = false; |
124 if (buffer) | 152 m_data.data(&buffer, &allDataReceived); |
125 *data = buffer->copy(); | 153 if (!allDataReceived) |
154 return nullptr; | |
155 | |
156 buffer->ref(); | |
aleksandar.stojiljkovic
2015/12/02 16:58:24
I'll cover this with comment that the buffer->ref(
| |
157 return SkData::NewWithProc(buffer->data(), buffer->size(), sharedBufSkDataRe leaseProc, buffer); | |
126 } | 158 } |
127 | 159 |
128 bool ImageFrameGenerator::decodeAndScale(const SkImageInfo& info, size_t index, void* pixels, size_t rowBytes) | 160 bool ImageFrameGenerator::decodeAndScale(const SkImageInfo& info, size_t index, void* pixels, size_t rowBytes) |
129 { | 161 { |
130 // This method is called to populate a discardable memory owned by Skia. | 162 // This method is called to populate a discardable memory owned by Skia. |
131 | 163 |
132 // Prevents concurrent decode or scale operations on the same image data. | 164 // Prevents concurrent decode or scale operations on the same image data. |
133 MutexLocker lock(m_decodeMutex); | 165 MutexLocker lock(m_decodeMutex); |
134 | 166 |
135 // This implementation does not support scaling so check the requested size. | 167 // This implementation does not support scaling so check the requested size. |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
373 | 405 |
374 // Setting a dummy ImagePlanes object signals to the decoder that we want to do YUV decoding. | 406 // Setting a dummy ImagePlanes object signals to the decoder that we want to do YUV decoding. |
375 decoder->setData(data, allDataReceived); | 407 decoder->setData(data, allDataReceived); |
376 OwnPtr<ImagePlanes> dummyImagePlanes = adoptPtr(new ImagePlanes); | 408 OwnPtr<ImagePlanes> dummyImagePlanes = adoptPtr(new ImagePlanes); |
377 decoder->setImagePlanes(dummyImagePlanes.release()); | 409 decoder->setImagePlanes(dummyImagePlanes.release()); |
378 | 410 |
379 return updateYUVComponentSizes(decoder.get(), componentSizes, ImageDecoder:: SizeForMemoryAllocation); | 411 return updateYUVComponentSizes(decoder.get(), componentSizes, ImageDecoder:: SizeForMemoryAllocation); |
380 } | 412 } |
381 | 413 |
382 } // namespace blink | 414 } // namespace blink |
OLD | NEW |