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 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 DeferredImageDecoder::setEnabled(true); | 76 DeferredImageDecoder::setEnabled(true); |
77 m_data = SharedBuffer::create(whitePNG, sizeof(whitePNG)); | 77 m_data = SharedBuffer::create(whitePNG, sizeof(whitePNG)); |
78 OwnPtr<MockImageDecoder> decoder = MockImageDecoder::create(this); | 78 OwnPtr<MockImageDecoder> decoder = MockImageDecoder::create(this); |
79 m_actualDecoder = decoder.get(); | 79 m_actualDecoder = decoder.get(); |
80 m_actualDecoder->setSize(1, 1); | 80 m_actualDecoder->setSize(1, 1); |
81 m_lazyDecoder = DeferredImageDecoder::createForTesting(decoder.release()
); | 81 m_lazyDecoder = DeferredImageDecoder::createForTesting(decoder.release()
); |
82 m_canvas.reset(createRasterCanvas(100, 100)); | 82 m_canvas.reset(createRasterCanvas(100, 100)); |
83 m_frameBufferRequestCount = 0; | 83 m_frameBufferRequestCount = 0; |
84 m_frameCount = 1; | 84 m_frameCount = 1; |
85 m_repetitionCount = cAnimationNone; | 85 m_repetitionCount = cAnimationNone; |
86 m_frameStatus = ImageFrame::FrameComplete; | 86 m_status = ImageFrame::FrameComplete; |
87 m_frameDuration = 0; | 87 m_frameDuration = 0; |
88 } | 88 } |
89 | 89 |
90 virtual void TearDown() | 90 virtual void TearDown() |
91 { | 91 { |
92 ImageDecodingStore::shutdown(); | 92 ImageDecodingStore::shutdown(); |
93 } | 93 } |
94 | 94 |
95 virtual void decoderBeingDestroyed() | 95 virtual void decoderBeingDestroyed() |
96 { | 96 { |
97 m_actualDecoder = 0; | 97 m_actualDecoder = 0; |
98 } | 98 } |
99 | 99 |
100 virtual void frameBufferRequested() | 100 virtual void frameBufferRequested() |
101 { | 101 { |
102 ++m_frameBufferRequestCount; | 102 ++m_frameBufferRequestCount; |
103 } | 103 } |
104 | 104 |
105 virtual size_t frameCount() | 105 virtual size_t frameCount() |
106 { | 106 { |
107 return m_frameCount; | 107 return m_frameCount; |
108 } | 108 } |
109 | 109 |
110 virtual int repetitionCount() const | 110 virtual int repetitionCount() const |
111 { | 111 { |
112 return m_repetitionCount; | 112 return m_repetitionCount; |
113 } | 113 } |
114 | 114 |
115 virtual ImageFrame::FrameStatus frameStatus() | 115 virtual ImageFrame::Status status() |
116 { | 116 { |
117 return m_frameStatus; | 117 return m_status; |
118 } | 118 } |
119 | 119 |
120 virtual float frameDuration() const | 120 virtual float frameDuration() const |
121 { | 121 { |
122 return m_frameDuration; | 122 return m_frameDuration; |
123 } | 123 } |
124 | 124 |
125 protected: | 125 protected: |
126 // Don't own this but saves the pointer to query states. | 126 // Don't own this but saves the pointer to query states. |
127 MockImageDecoder* m_actualDecoder; | 127 MockImageDecoder* m_actualDecoder; |
128 OwnPtr<DeferredImageDecoder> m_lazyDecoder; | 128 OwnPtr<DeferredImageDecoder> m_lazyDecoder; |
129 SkPicture m_picture; | 129 SkPicture m_picture; |
130 SkAutoTUnref<SkCanvas> m_canvas; | 130 SkAutoTUnref<SkCanvas> m_canvas; |
131 int m_frameBufferRequestCount; | 131 int m_frameBufferRequestCount; |
132 RefPtr<SharedBuffer> m_data; | 132 RefPtr<SharedBuffer> m_data; |
133 size_t m_frameCount; | 133 size_t m_frameCount; |
134 int m_repetitionCount; | 134 int m_repetitionCount; |
135 ImageFrame::FrameStatus m_frameStatus; | 135 ImageFrame::Status m_status; |
136 float m_frameDuration; | 136 float m_frameDuration; |
137 }; | 137 }; |
138 | 138 |
139 TEST_F(DeferredImageDecoderTest, drawIntoSkPicture) | 139 TEST_F(DeferredImageDecoderTest, drawIntoSkPicture) |
140 { | 140 { |
141 m_lazyDecoder->setData(m_data.get(), true); | 141 m_lazyDecoder->setData(m_data.get(), true); |
142 RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewN
ativeImage(); | 142 RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewN
ativeImage(); |
143 EXPECT_EQ(1, image->bitmap().width()); | 143 EXPECT_EQ(1, image->bitmap().width()); |
144 EXPECT_EQ(1, image->bitmap().height()); | 144 EXPECT_EQ(1, image->bitmap().height()); |
145 EXPECT_FALSE(image->bitmap().isNull()); | 145 EXPECT_FALSE(image->bitmap().isNull()); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 | 217 |
218 SkBitmap canvasBitmap; | 218 SkBitmap canvasBitmap; |
219 canvasBitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 219 canvasBitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); |
220 ASSERT_TRUE(m_canvas->readPixels(&canvasBitmap, 0, 0)); | 220 ASSERT_TRUE(m_canvas->readPixels(&canvasBitmap, 0, 0)); |
221 SkAutoLockPixels autoLock(canvasBitmap); | 221 SkAutoLockPixels autoLock(canvasBitmap); |
222 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); | 222 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); |
223 } | 223 } |
224 | 224 |
225 TEST_F(DeferredImageDecoderTest, singleFrameImageLoading) | 225 TEST_F(DeferredImageDecoderTest, singleFrameImageLoading) |
226 { | 226 { |
227 m_frameStatus = ImageFrame::FramePartial; | 227 m_status = ImageFrame::FramePartial; |
228 m_lazyDecoder->setData(m_data.get(), false); | 228 m_lazyDecoder->setData(m_data.get(), false); |
229 EXPECT_FALSE(m_lazyDecoder->frameIsCompleteAtIndex(0)); | 229 EXPECT_FALSE(m_lazyDecoder->frameIsCompleteAtIndex(0)); |
230 ImageFrame* frame = m_lazyDecoder->frameBufferAtIndex(0); | 230 ImageFrame* frame = m_lazyDecoder->frameBufferAtIndex(0); |
231 EXPECT_EQ(ImageFrame::FramePartial, frame->status()); | 231 EXPECT_EQ(ImageFrame::FramePartial, frame->status()); |
232 EXPECT_TRUE(m_actualDecoder); | 232 EXPECT_TRUE(m_actualDecoder); |
233 | 233 |
234 m_frameStatus = ImageFrame::FrameComplete; | 234 m_status = ImageFrame::FrameComplete; |
235 m_lazyDecoder->setData(m_data.get(), true); | 235 m_lazyDecoder->setData(m_data.get(), true); |
236 EXPECT_FALSE(m_actualDecoder); | 236 EXPECT_FALSE(m_actualDecoder); |
237 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(0)); | 237 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(0)); |
238 frame = m_lazyDecoder->frameBufferAtIndex(0); | 238 frame = m_lazyDecoder->frameBufferAtIndex(0); |
239 EXPECT_EQ(ImageFrame::FrameComplete, frame->status()); | 239 EXPECT_EQ(ImageFrame::FrameComplete, frame->status()); |
240 EXPECT_FALSE(m_frameBufferRequestCount); | 240 EXPECT_FALSE(m_frameBufferRequestCount); |
241 } | 241 } |
242 | 242 |
243 TEST_F(DeferredImageDecoderTest, multiFrameImageLoading) | 243 TEST_F(DeferredImageDecoderTest, multiFrameImageLoading) |
244 { | 244 { |
245 m_repetitionCount = 10; | 245 m_repetitionCount = 10; |
246 m_frameCount = 1; | 246 m_frameCount = 1; |
247 m_frameDuration = 10; | 247 m_frameDuration = 10; |
248 m_frameStatus = ImageFrame::FramePartial; | 248 m_status = ImageFrame::FramePartial; |
249 m_lazyDecoder->setData(m_data.get(), false); | 249 m_lazyDecoder->setData(m_data.get(), false); |
250 EXPECT_EQ(ImageFrame::FramePartial, m_lazyDecoder->frameBufferAtIndex(0)->st
atus()); | 250 EXPECT_EQ(ImageFrame::FramePartial, m_lazyDecoder->frameBufferAtIndex(0)->st
atus()); |
251 EXPECT_FALSE(m_lazyDecoder->frameIsCompleteAtIndex(0)); | 251 EXPECT_FALSE(m_lazyDecoder->frameIsCompleteAtIndex(0)); |
252 EXPECT_EQ(10.0f, m_lazyDecoder->frameBufferAtIndex(0)->duration()); | 252 EXPECT_EQ(10.0f, m_lazyDecoder->frameBufferAtIndex(0)->duration()); |
253 EXPECT_EQ(10.0f, m_lazyDecoder->frameDurationAtIndex(0)); | 253 EXPECT_EQ(10.0f, m_lazyDecoder->frameDurationAtIndex(0)); |
254 | 254 |
255 m_frameCount = 2; | 255 m_frameCount = 2; |
256 m_frameDuration = 20; | 256 m_frameDuration = 20; |
257 m_frameStatus = ImageFrame::FrameComplete; | 257 m_status = ImageFrame::FrameComplete; |
258 m_lazyDecoder->setData(m_data.get(), false); | 258 m_lazyDecoder->setData(m_data.get(), false); |
259 EXPECT_EQ(ImageFrame::FrameComplete, m_lazyDecoder->frameBufferAtIndex(0)->s
tatus()); | 259 EXPECT_EQ(ImageFrame::FrameComplete, m_lazyDecoder->frameBufferAtIndex(0)->s
tatus()); |
260 EXPECT_EQ(ImageFrame::FrameComplete, m_lazyDecoder->frameBufferAtIndex(1)->s
tatus()); | 260 EXPECT_EQ(ImageFrame::FrameComplete, m_lazyDecoder->frameBufferAtIndex(1)->s
tatus()); |
261 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(0)); | 261 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(0)); |
262 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(1)); | 262 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(1)); |
263 EXPECT_EQ(20.0f, m_lazyDecoder->frameDurationAtIndex(1)); | 263 EXPECT_EQ(20.0f, m_lazyDecoder->frameDurationAtIndex(1)); |
264 EXPECT_EQ(10.0f, m_lazyDecoder->frameBufferAtIndex(0)->duration()); | 264 EXPECT_EQ(10.0f, m_lazyDecoder->frameBufferAtIndex(0)->duration()); |
265 EXPECT_EQ(20.0f, m_lazyDecoder->frameBufferAtIndex(1)->duration()); | 265 EXPECT_EQ(20.0f, m_lazyDecoder->frameBufferAtIndex(1)->duration()); |
266 EXPECT_TRUE(m_actualDecoder); | 266 EXPECT_TRUE(m_actualDecoder); |
267 | 267 |
268 m_frameCount = 3; | 268 m_frameCount = 3; |
269 m_frameDuration = 30; | 269 m_frameDuration = 30; |
270 m_frameStatus = ImageFrame::FrameComplete; | 270 m_status = ImageFrame::FrameComplete; |
271 m_lazyDecoder->setData(m_data.get(), true); | 271 m_lazyDecoder->setData(m_data.get(), true); |
272 EXPECT_FALSE(m_actualDecoder); | 272 EXPECT_FALSE(m_actualDecoder); |
273 EXPECT_EQ(ImageFrame::FrameComplete, m_lazyDecoder->frameBufferAtIndex(0)->s
tatus()); | 273 EXPECT_EQ(ImageFrame::FrameComplete, m_lazyDecoder->frameBufferAtIndex(0)->s
tatus()); |
274 EXPECT_EQ(ImageFrame::FrameComplete, m_lazyDecoder->frameBufferAtIndex(1)->s
tatus()); | 274 EXPECT_EQ(ImageFrame::FrameComplete, m_lazyDecoder->frameBufferAtIndex(1)->s
tatus()); |
275 EXPECT_EQ(ImageFrame::FrameComplete, m_lazyDecoder->frameBufferAtIndex(2)->s
tatus()); | 275 EXPECT_EQ(ImageFrame::FrameComplete, m_lazyDecoder->frameBufferAtIndex(2)->s
tatus()); |
276 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(0)); | 276 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(0)); |
277 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(1)); | 277 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(1)); |
278 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(2)); | 278 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(2)); |
279 EXPECT_EQ(10.0f, m_lazyDecoder->frameDurationAtIndex(0)); | 279 EXPECT_EQ(10.0f, m_lazyDecoder->frameDurationAtIndex(0)); |
280 EXPECT_EQ(20.0f, m_lazyDecoder->frameDurationAtIndex(1)); | 280 EXPECT_EQ(20.0f, m_lazyDecoder->frameDurationAtIndex(1)); |
281 EXPECT_EQ(30.0f, m_lazyDecoder->frameDurationAtIndex(2)); | 281 EXPECT_EQ(30.0f, m_lazyDecoder->frameDurationAtIndex(2)); |
282 EXPECT_EQ(10.0f, m_lazyDecoder->frameBufferAtIndex(0)->duration()); | 282 EXPECT_EQ(10.0f, m_lazyDecoder->frameBufferAtIndex(0)->duration()); |
283 EXPECT_EQ(20.0f, m_lazyDecoder->frameBufferAtIndex(1)->duration()); | 283 EXPECT_EQ(20.0f, m_lazyDecoder->frameBufferAtIndex(1)->duration()); |
284 EXPECT_EQ(30.0f, m_lazyDecoder->frameBufferAtIndex(2)->duration()); | 284 EXPECT_EQ(30.0f, m_lazyDecoder->frameBufferAtIndex(2)->duration()); |
285 EXPECT_EQ(10, m_lazyDecoder->repetitionCount()); | 285 EXPECT_EQ(10, m_lazyDecoder->repetitionCount()); |
286 } | 286 } |
287 | 287 |
288 } // namespace | 288 } // namespace |
OLD | NEW |