| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 ImageFrame::Status m_status; | 121 ImageFrame::Status m_status; |
| 122 ImageFrame::Status m_nextFrameStatus; | 122 ImageFrame::Status m_nextFrameStatus; |
| 123 size_t m_frameCount; | 123 size_t m_frameCount; |
| 124 }; | 124 }; |
| 125 | 125 |
| 126 TEST_F(ImageFrameGeneratorTest, incompleteDecode) | 126 TEST_F(ImageFrameGeneratorTest, incompleteDecode) |
| 127 { | 127 { |
| 128 setFrameStatus(ImageFrame::FramePartial); | 128 setFrameStatus(ImageFrame::FramePartial); |
| 129 | 129 |
| 130 char buffer[100 * 100 * 4]; | 130 char buffer[100 * 100 * 4]; |
| 131 m_generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4); | 131 m_generator->decodeAndScale(0, imageInfo(), buffer, 100 * 4); |
| 132 EXPECT_EQ(1, m_decodeRequestCount); | 132 EXPECT_EQ(1, m_decodeRequestCount); |
| 133 | 133 |
| 134 addNewData(); | 134 addNewData(); |
| 135 m_generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4); | 135 m_generator->decodeAndScale(0, imageInfo(), buffer, 100 * 4); |
| 136 EXPECT_EQ(2, m_decodeRequestCount); | 136 EXPECT_EQ(2, m_decodeRequestCount); |
| 137 EXPECT_EQ(0, m_decodersDestroyed); | 137 EXPECT_EQ(0, m_decodersDestroyed); |
| 138 } | 138 } |
| 139 | 139 |
| 140 TEST_F(ImageFrameGeneratorTest, incompleteDecodeBecomesComplete) | 140 TEST_F(ImageFrameGeneratorTest, incompleteDecodeBecomesComplete) |
| 141 { | 141 { |
| 142 setFrameStatus(ImageFrame::FramePartial); | 142 setFrameStatus(ImageFrame::FramePartial); |
| 143 | 143 |
| 144 char buffer[100 * 100 * 4]; | 144 char buffer[100 * 100 * 4]; |
| 145 m_generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4); | 145 m_generator->decodeAndScale(0, imageInfo(), buffer, 100 * 4); |
| 146 EXPECT_EQ(1, m_decodeRequestCount); | 146 EXPECT_EQ(1, m_decodeRequestCount); |
| 147 EXPECT_EQ(0, m_decodersDestroyed); | 147 EXPECT_EQ(0, m_decodersDestroyed); |
| 148 | 148 |
| 149 setFrameStatus(ImageFrame::FrameComplete); | 149 setFrameStatus(ImageFrame::FrameComplete); |
| 150 addNewData(); | 150 addNewData(); |
| 151 | 151 |
| 152 m_generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4); | 152 m_generator->decodeAndScale(0, imageInfo(), buffer, 100 * 4); |
| 153 EXPECT_EQ(2, m_decodeRequestCount); | 153 EXPECT_EQ(2, m_decodeRequestCount); |
| 154 EXPECT_EQ(1, m_decodersDestroyed); | 154 EXPECT_EQ(1, m_decodersDestroyed); |
| 155 | 155 |
| 156 // Decoder created again. | 156 // Decoder created again. |
| 157 m_generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4); | 157 m_generator->decodeAndScale(0, imageInfo(), buffer, 100 * 4); |
| 158 EXPECT_EQ(3, m_decodeRequestCount); | 158 EXPECT_EQ(3, m_decodeRequestCount); |
| 159 } | 159 } |
| 160 | 160 |
| 161 static void decodeThreadMain(ImageFrameGenerator* generator) | 161 static void decodeThreadMain(ImageFrameGenerator* generator) |
| 162 { | 162 { |
| 163 char buffer[100 * 100 * 4]; | 163 char buffer[100 * 100 * 4]; |
| 164 generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4); | 164 generator->decodeAndScale(0, imageInfo(), buffer, 100 * 4); |
| 165 } | 165 } |
| 166 | 166 |
| 167 static void decodeThreadWithRefEncodedMain(ImageFrameGenerator* generator) | 167 static void decodeThreadWithRefEncodedMain(ImageFrameGenerator* generator) |
| 168 { | 168 { |
| 169 // Image must be complete - refEncodedData otherwise returns null. | 169 // Image must be complete - refEncodedData otherwise returns null. |
| 170 char buffer[100 * 100 * 4]; | 170 char buffer[100 * 100 * 4]; |
| 171 SkData* data = generator->refEncodedData(); | 171 SkData* data = generator->refEncodedData(); |
| 172 generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4); | 172 generator->decodeAndScale(0, imageInfo(), buffer, 100 * 4); |
| 173 data->unref(); | 173 data->unref(); |
| 174 } | 174 } |
| 175 | 175 |
| 176 TEST_F(ImageFrameGeneratorTest, incompleteDecodeBecomesCompleteMultiThreaded) | 176 TEST_F(ImageFrameGeneratorTest, incompleteDecodeBecomesCompleteMultiThreaded) |
| 177 { | 177 { |
| 178 setFrameStatus(ImageFrame::FramePartial); | 178 setFrameStatus(ImageFrame::FramePartial); |
| 179 | 179 |
| 180 char buffer[100 * 100 * 4]; | 180 char buffer[100 * 100 * 4]; |
| 181 m_generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4); | 181 m_generator->decodeAndScale(0, imageInfo(), buffer, 100 * 4); |
| 182 EXPECT_EQ(1, m_decodeRequestCount); | 182 EXPECT_EQ(1, m_decodeRequestCount); |
| 183 EXPECT_EQ(0, m_decodersDestroyed); | 183 EXPECT_EQ(0, m_decodersDestroyed); |
| 184 SkData* data = m_generator->refEncodedData(); | 184 SkData* data = m_generator->refEncodedData(); |
| 185 EXPECT_EQ(nullptr, data); | 185 EXPECT_EQ(nullptr, data); |
| 186 | 186 |
| 187 // LocalFrame can now be decoded completely. | 187 // LocalFrame can now be decoded completely. |
| 188 setFrameStatus(ImageFrame::FrameComplete); | 188 setFrameStatus(ImageFrame::FrameComplete); |
| 189 addNewData(); | 189 addNewData(); |
| 190 // addNewData is calling m_generator->setData with allDataReceived == false,
which means that | 190 // addNewData is calling m_generator->setData with allDataReceived == false,
which means that |
| 191 // refEncodedData should return null. | 191 // refEncodedData should return null. |
| 192 data = m_generator->refEncodedData(); | 192 data = m_generator->refEncodedData(); |
| 193 EXPECT_EQ(nullptr, data); | 193 EXPECT_EQ(nullptr, data); |
| 194 OwnPtr<WebThread> thread = adoptPtr(Platform::current()->createThread("Decod
eThread")); | 194 OwnPtr<WebThread> thread = adoptPtr(Platform::current()->createThread("Decod
eThread")); |
| 195 thread->taskRunner()->postTask(BLINK_FROM_HERE, new Task(threadSafeBind(&dec
odeThreadMain, AllowCrossThreadAccess(m_generator.get())))); | 195 thread->taskRunner()->postTask(BLINK_FROM_HERE, new Task(threadSafeBind(&dec
odeThreadMain, AllowCrossThreadAccess(m_generator.get())))); |
| 196 thread.clear(); | 196 thread.clear(); |
| 197 EXPECT_EQ(2, m_decodeRequestCount); | 197 EXPECT_EQ(2, m_decodeRequestCount); |
| 198 EXPECT_EQ(1, m_decodersDestroyed); | 198 EXPECT_EQ(1, m_decodersDestroyed); |
| 199 | 199 |
| 200 // Decoder created again. | 200 // Decoder created again. |
| 201 m_generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4); | 201 m_generator->decodeAndScale(0, imageInfo(), buffer, 100 * 4); |
| 202 EXPECT_EQ(3, m_decodeRequestCount); | 202 EXPECT_EQ(3, m_decodeRequestCount); |
| 203 | 203 |
| 204 addNewData(true); | 204 addNewData(true); |
| 205 data = m_generator->refEncodedData(); | 205 data = m_generator->refEncodedData(); |
| 206 ASSERT_TRUE(data); | 206 ASSERT_TRUE(data); |
| 207 // To prevent data writting, SkData::unique() should be false. | 207 // To prevent data writting, SkData::unique() should be false. |
| 208 ASSERT_TRUE(!data->unique()); | 208 ASSERT_TRUE(!data->unique()); |
| 209 | 209 |
| 210 // Thread will also ref and unref the data. | 210 // Thread will also ref and unref the data. |
| 211 thread = adoptPtr(Platform::current()->createThread("RefEncodedDataThread"))
; | 211 thread = adoptPtr(Platform::current()->createThread("RefEncodedDataThread"))
; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 224 m_generator = nullptr; | 224 m_generator = nullptr; |
| 225 ASSERT_TRUE(data->unique()); | 225 ASSERT_TRUE(data->unique()); |
| 226 data->unref(); | 226 data->unref(); |
| 227 } | 227 } |
| 228 | 228 |
| 229 TEST_F(ImageFrameGeneratorTest, frameHasAlpha) | 229 TEST_F(ImageFrameGeneratorTest, frameHasAlpha) |
| 230 { | 230 { |
| 231 setFrameStatus(ImageFrame::FramePartial); | 231 setFrameStatus(ImageFrame::FramePartial); |
| 232 | 232 |
| 233 char buffer[100 * 100 * 4]; | 233 char buffer[100 * 100 * 4]; |
| 234 m_generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4); | 234 m_generator->decodeAndScale(0, imageInfo(), buffer, 100 * 4); |
| 235 EXPECT_TRUE(m_generator->hasAlpha(0)); | 235 EXPECT_TRUE(m_generator->hasAlpha(0)); |
| 236 EXPECT_EQ(1, m_decodeRequestCount); | 236 EXPECT_EQ(1, m_decodeRequestCount); |
| 237 | 237 |
| 238 ImageDecoder* tempDecoder = 0; | 238 ImageDecoder* tempDecoder = 0; |
| 239 EXPECT_TRUE(ImageDecodingStore::instance().lockDecoder(m_generator.get(), fu
llSize(), &tempDecoder)); | 239 EXPECT_TRUE(ImageDecodingStore::instance().lockDecoder(m_generator.get(), fu
llSize(), &tempDecoder)); |
| 240 ASSERT_TRUE(tempDecoder); | 240 ASSERT_TRUE(tempDecoder); |
| 241 tempDecoder->frameBufferAtIndex(0)->setHasAlpha(false); | 241 tempDecoder->frameBufferAtIndex(0)->setHasAlpha(false); |
| 242 ImageDecodingStore::instance().unlockDecoder(m_generator.get(), tempDecoder)
; | 242 ImageDecodingStore::instance().unlockDecoder(m_generator.get(), tempDecoder)
; |
| 243 EXPECT_EQ(2, m_decodeRequestCount); | 243 EXPECT_EQ(2, m_decodeRequestCount); |
| 244 | 244 |
| 245 setFrameStatus(ImageFrame::FrameComplete); | 245 setFrameStatus(ImageFrame::FrameComplete); |
| 246 m_generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4); | 246 m_generator->decodeAndScale(0, imageInfo(), buffer, 100 * 4); |
| 247 EXPECT_EQ(3, m_decodeRequestCount); | 247 EXPECT_EQ(3, m_decodeRequestCount); |
| 248 EXPECT_FALSE(m_generator->hasAlpha(0)); | 248 EXPECT_FALSE(m_generator->hasAlpha(0)); |
| 249 } | 249 } |
| 250 | 250 |
| 251 TEST_F(ImageFrameGeneratorTest, removeMultiFrameDecoder) | 251 TEST_F(ImageFrameGeneratorTest, removeMultiFrameDecoder) |
| 252 { | 252 { |
| 253 setFrameCount(3); | 253 setFrameCount(3); |
| 254 setFrameStatus(ImageFrame::FrameComplete); | 254 setFrameStatus(ImageFrame::FrameComplete); |
| 255 | 255 |
| 256 char buffer[100 * 100 * 4]; | 256 char buffer[100 * 100 * 4]; |
| 257 m_generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4); | 257 m_generator->decodeAndScale(0, imageInfo(), buffer, 100 * 4); |
| 258 EXPECT_EQ(1, m_decodeRequestCount); | 258 EXPECT_EQ(1, m_decodeRequestCount); |
| 259 EXPECT_EQ(0, m_decodersDestroyed); | 259 EXPECT_EQ(0, m_decodersDestroyed); |
| 260 | 260 |
| 261 setFrameStatus(ImageFrame::FrameComplete); | 261 setFrameStatus(ImageFrame::FrameComplete); |
| 262 | 262 |
| 263 m_generator->decodeAndScale(imageInfo(), 1, buffer, 100 * 4); | 263 m_generator->decodeAndScale(1, imageInfo(), buffer, 100 * 4); |
| 264 EXPECT_EQ(2, m_decodeRequestCount); | 264 EXPECT_EQ(2, m_decodeRequestCount); |
| 265 EXPECT_EQ(0, m_decodersDestroyed); | 265 EXPECT_EQ(0, m_decodersDestroyed); |
| 266 | 266 |
| 267 setFrameStatus(ImageFrame::FrameComplete); | 267 setFrameStatus(ImageFrame::FrameComplete); |
| 268 | 268 |
| 269 // Multi frame decoder should be removed. | 269 // Multi frame decoder should be removed. |
| 270 m_generator->decodeAndScale(imageInfo(), 2, buffer, 100 * 4); | 270 m_generator->decodeAndScale(2, imageInfo(), buffer, 100 * 4); |
| 271 EXPECT_EQ(3, m_decodeRequestCount); | 271 EXPECT_EQ(3, m_decodeRequestCount); |
| 272 EXPECT_EQ(1, m_decodersDestroyed); | 272 EXPECT_EQ(1, m_decodersDestroyed); |
| 273 } | 273 } |
| 274 | 274 |
| 275 } // namespace blink | 275 } // namespace blink |
| OLD | NEW |