| 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 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| 11 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
| 12 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
| 13 * | 13 * |
| 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "platform/graphics/ImageFrameGenerator.h" | 26 #include "platform/graphics/ImageFrameGenerator.h" |
| 27 | 27 |
| 28 #include "platform/SharedBuffer.h" | 28 #include "platform/SharedBuffer.h" |
| 29 #include "platform/Task.h" | |
| 30 #include "platform/ThreadSafeFunctional.h" | 29 #include "platform/ThreadSafeFunctional.h" |
| 31 #include "platform/graphics/ImageDecodingStore.h" | 30 #include "platform/graphics/ImageDecodingStore.h" |
| 32 #include "platform/graphics/test/MockImageDecoder.h" | 31 #include "platform/graphics/test/MockImageDecoder.h" |
| 33 #include "public/platform/Platform.h" | 32 #include "public/platform/Platform.h" |
| 33 #include "public/platform/WebTaskRunner.h" |
| 34 #include "public/platform/WebThread.h" | 34 #include "public/platform/WebThread.h" |
| 35 #include "public/platform/WebTraceLocation.h" | 35 #include "public/platform/WebTraceLocation.h" |
| 36 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
| 37 | 37 |
| 38 namespace blink { | 38 namespace blink { |
| 39 | 39 |
| 40 namespace { | 40 namespace { |
| 41 | 41 |
| 42 // Helper methods to generate standard sizes. | 42 // Helper methods to generate standard sizes. |
| 43 SkISize fullSize() { return SkISize::Make(100, 100); } | 43 SkISize fullSize() { return SkISize::Make(100, 100); } |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 EXPECT_EQ(nullptr, data); | 191 EXPECT_EQ(nullptr, data); |
| 192 | 192 |
| 193 // LocalFrame can now be decoded completely. | 193 // LocalFrame can now be decoded completely. |
| 194 setFrameStatus(ImageFrame::FrameComplete); | 194 setFrameStatus(ImageFrame::FrameComplete); |
| 195 addNewData(); | 195 addNewData(); |
| 196 // addNewData is calling m_generator->setData with allDataReceived == false,
which means that | 196 // addNewData is calling m_generator->setData with allDataReceived == false,
which means that |
| 197 // refEncodedData should return null. | 197 // refEncodedData should return null. |
| 198 data = m_generator->refEncodedData(); | 198 data = m_generator->refEncodedData(); |
| 199 EXPECT_EQ(nullptr, data); | 199 EXPECT_EQ(nullptr, data); |
| 200 OwnPtr<WebThread> thread = adoptPtr(Platform::current()->createThread("Decod
eThread")); | 200 OwnPtr<WebThread> thread = adoptPtr(Platform::current()->createThread("Decod
eThread")); |
| 201 thread->taskRunner()->postTask(BLINK_FROM_HERE, new Task(threadSafeBind(&dec
odeThreadMain, AllowCrossThreadAccess(m_generator.get())))); | 201 thread->taskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(&decodeThread
Main, AllowCrossThreadAccess(m_generator.get()))); |
| 202 thread.clear(); | 202 thread.clear(); |
| 203 EXPECT_EQ(2, m_decodeRequestCount); | 203 EXPECT_EQ(2, m_decodeRequestCount); |
| 204 EXPECT_EQ(1, m_decodersDestroyed); | 204 EXPECT_EQ(1, m_decodersDestroyed); |
| 205 | 205 |
| 206 // Decoder created again. | 206 // Decoder created again. |
| 207 m_generator->decodeAndScale(0, imageInfo(), buffer, 100 * 4); | 207 m_generator->decodeAndScale(0, imageInfo(), buffer, 100 * 4); |
| 208 EXPECT_EQ(3, m_decodeRequestCount); | 208 EXPECT_EQ(3, m_decodeRequestCount); |
| 209 | 209 |
| 210 addNewData(true); | 210 addNewData(true); |
| 211 data = m_generator->refEncodedData(); | 211 data = m_generator->refEncodedData(); |
| 212 ASSERT_TRUE(data); | 212 ASSERT_TRUE(data); |
| 213 // To prevent data writting, SkData::unique() should be false. | 213 // To prevent data writting, SkData::unique() should be false. |
| 214 ASSERT_TRUE(!data->unique()); | 214 ASSERT_TRUE(!data->unique()); |
| 215 | 215 |
| 216 // Thread will also ref and unref the data. | 216 // Thread will also ref and unref the data. |
| 217 thread = adoptPtr(Platform::current()->createThread("RefEncodedDataThread"))
; | 217 thread = adoptPtr(Platform::current()->createThread("RefEncodedDataThread"))
; |
| 218 thread->taskRunner()->postTask(BLINK_FROM_HERE, new Task(threadSafeBind(&dec
odeThreadWithRefEncodedMain, AllowCrossThreadAccess(m_generator.get())))); | 218 thread->taskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(&decodeThread
WithRefEncodedMain, AllowCrossThreadAccess(m_generator.get()))); |
| 219 thread.clear(); | 219 thread.clear(); |
| 220 EXPECT_EQ(4, m_decodeRequestCount); | 220 EXPECT_EQ(4, m_decodeRequestCount); |
| 221 | 221 |
| 222 data->unref(); | 222 data->unref(); |
| 223 // m_generator is holding the only reference to SkData now. | 223 // m_generator is holding the only reference to SkData now. |
| 224 ASSERT_TRUE(data->unique()); | 224 ASSERT_TRUE(data->unique()); |
| 225 | 225 |
| 226 data = m_generator->refEncodedData(); | 226 data = m_generator->refEncodedData(); |
| 227 ASSERT_TRUE(data && !data->unique()); | 227 ASSERT_TRUE(data && !data->unique()); |
| 228 | 228 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 // Decoding the last frame of a multi-frame images should trigger clearing | 277 // Decoding the last frame of a multi-frame images should trigger clearing |
| 278 // all the frame data, but not destroying the decoder. See comments in | 278 // all the frame data, but not destroying the decoder. See comments in |
| 279 // ImageFrameGenerator::tryToResumeDecode(). | 279 // ImageFrameGenerator::tryToResumeDecode(). |
| 280 m_generator->decodeAndScale(2, imageInfo(), buffer, 100 * 4); | 280 m_generator->decodeAndScale(2, imageInfo(), buffer, 100 * 4); |
| 281 EXPECT_EQ(3, m_decodeRequestCount); | 281 EXPECT_EQ(3, m_decodeRequestCount); |
| 282 EXPECT_EQ(0, m_decodersDestroyed); | 282 EXPECT_EQ(0, m_decodersDestroyed); |
| 283 EXPECT_EQ(kNotFound, m_requestedClearExceptFrame); | 283 EXPECT_EQ(kNotFound, m_requestedClearExceptFrame); |
| 284 } | 284 } |
| 285 | 285 |
| 286 } // namespace blink | 286 } // namespace blink |
| OLD | NEW |