| 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 156 |
| 157 TEST_F(DeferredImageDecoderTest, drawIntoPaintRecord) { | 157 TEST_F(DeferredImageDecoderTest, drawIntoPaintRecord) { |
| 158 lazy_decoder_->SetData(data_, true); | 158 lazy_decoder_->SetData(data_, true); |
| 159 sk_sp<SkImage> image = lazy_decoder_->CreateFrameAtIndex(0); | 159 sk_sp<SkImage> image = lazy_decoder_->CreateFrameAtIndex(0); |
| 160 ASSERT_TRUE(image); | 160 ASSERT_TRUE(image); |
| 161 EXPECT_EQ(1, image->width()); | 161 EXPECT_EQ(1, image->width()); |
| 162 EXPECT_EQ(1, image->height()); | 162 EXPECT_EQ(1, image->height()); |
| 163 | 163 |
| 164 PaintRecorder recorder; | 164 PaintRecorder recorder; |
| 165 PaintCanvas* temp_canvas = recorder.beginRecording(100, 100); | 165 PaintCanvas* temp_canvas = recorder.beginRecording(100, 100); |
| 166 temp_canvas->drawImage( | 166 temp_canvas->drawImage(PaintImage(std::move(image)), 0, 0); |
| 167 PaintImage(std::move(image), PaintImage::AnimationType::STATIC, | |
| 168 PaintImage::CompletionState::DONE), | |
| 169 0, 0); | |
| 170 sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture(); | 167 sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture(); |
| 171 EXPECT_EQ(0, decode_request_count_); | 168 EXPECT_EQ(0, decode_request_count_); |
| 172 | 169 |
| 173 canvas_->drawPicture(record); | 170 canvas_->drawPicture(record); |
| 174 EXPECT_EQ(0, decode_request_count_); | 171 EXPECT_EQ(0, decode_request_count_); |
| 175 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), bitmap_.getColor(0, 0)); | 172 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), bitmap_.getColor(0, 0)); |
| 176 } | 173 } |
| 177 | 174 |
| 178 TEST_F(DeferredImageDecoderTest, drawIntoPaintRecordProgressive) { | 175 TEST_F(DeferredImageDecoderTest, drawIntoPaintRecordProgressive) { |
| 179 RefPtr<SharedBuffer> partial_data = | 176 RefPtr<SharedBuffer> partial_data = |
| 180 SharedBuffer::Create(data_->Data(), data_->size() - 10); | 177 SharedBuffer::Create(data_->Data(), data_->size() - 10); |
| 181 | 178 |
| 182 // Received only half the file. | 179 // Received only half the file. |
| 183 lazy_decoder_->SetData(partial_data, false); | 180 lazy_decoder_->SetData(partial_data, false); |
| 184 sk_sp<SkImage> image = lazy_decoder_->CreateFrameAtIndex(0); | 181 sk_sp<SkImage> image = lazy_decoder_->CreateFrameAtIndex(0); |
| 185 ASSERT_TRUE(image); | 182 ASSERT_TRUE(image); |
| 186 PaintRecorder recorder; | 183 PaintRecorder recorder; |
| 187 PaintCanvas* temp_canvas = recorder.beginRecording(100, 100); | 184 PaintCanvas* temp_canvas = recorder.beginRecording(100, 100); |
| 188 temp_canvas->drawImage( | 185 temp_canvas->drawImage( |
| 189 PaintImage(std::move(image), PaintImage::AnimationType::STATIC, | 186 PaintImage(std::move(image), PaintImage::AnimationType::STATIC, |
| 190 PaintImage::CompletionState::PARTIALLY_DONE), | 187 PaintImage::CompletionState::PARTIALLY_DONE), |
| 191 0, 0); | 188 0, 0); |
| 192 canvas_->drawPicture(recorder.finishRecordingAsPicture()); | 189 canvas_->drawPicture(recorder.finishRecordingAsPicture()); |
| 193 | 190 |
| 194 // Fully received the file and draw the PaintRecord again. | 191 // Fully received the file and draw the PaintRecord again. |
| 195 lazy_decoder_->SetData(data_, true); | 192 lazy_decoder_->SetData(data_, true); |
| 196 image = lazy_decoder_->CreateFrameAtIndex(0); | 193 image = lazy_decoder_->CreateFrameAtIndex(0); |
| 197 ASSERT_TRUE(image); | 194 ASSERT_TRUE(image); |
| 198 temp_canvas = recorder.beginRecording(100, 100); | 195 temp_canvas = recorder.beginRecording(100, 100); |
| 199 temp_canvas->drawImage( | 196 temp_canvas->drawImage(PaintImage(std::move(image)), 0, 0); |
| 200 PaintImage(std::move(image), PaintImage::AnimationType::STATIC, | |
| 201 PaintImage::CompletionState::DONE), | |
| 202 0, 0); | |
| 203 canvas_->drawPicture(recorder.finishRecordingAsPicture()); | 197 canvas_->drawPicture(recorder.finishRecordingAsPicture()); |
| 204 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), bitmap_.getColor(0, 0)); | 198 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), bitmap_.getColor(0, 0)); |
| 205 } | 199 } |
| 206 | 200 |
| 207 static void RasterizeMain(PaintCanvas* canvas, sk_sp<PaintRecord> record) { | 201 static void RasterizeMain(PaintCanvas* canvas, sk_sp<PaintRecord> record) { |
| 208 canvas->drawPicture(record); | 202 canvas->drawPicture(record); |
| 209 } | 203 } |
| 210 | 204 |
| 211 TEST_F(DeferredImageDecoderTest, decodeOnOtherThread) { | 205 TEST_F(DeferredImageDecoderTest, decodeOnOtherThread) { |
| 212 lazy_decoder_->SetData(data_, true); | 206 lazy_decoder_->SetData(data_, true); |
| 213 sk_sp<SkImage> image = lazy_decoder_->CreateFrameAtIndex(0); | 207 sk_sp<SkImage> image = lazy_decoder_->CreateFrameAtIndex(0); |
| 214 ASSERT_TRUE(image); | 208 ASSERT_TRUE(image); |
| 215 EXPECT_EQ(1, image->width()); | 209 EXPECT_EQ(1, image->width()); |
| 216 EXPECT_EQ(1, image->height()); | 210 EXPECT_EQ(1, image->height()); |
| 217 | 211 |
| 218 PaintRecorder recorder; | 212 PaintRecorder recorder; |
| 219 PaintCanvas* temp_canvas = recorder.beginRecording(100, 100); | 213 PaintCanvas* temp_canvas = recorder.beginRecording(100, 100); |
| 220 temp_canvas->drawImage( | 214 temp_canvas->drawImage(PaintImage(std::move(image)), 0, 0); |
| 221 PaintImage(std::move(image), PaintImage::AnimationType::STATIC, | |
| 222 PaintImage::CompletionState::DONE), | |
| 223 0, 0); | |
| 224 sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture(); | 215 sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture(); |
| 225 EXPECT_EQ(0, decode_request_count_); | 216 EXPECT_EQ(0, decode_request_count_); |
| 226 | 217 |
| 227 // Create a thread to rasterize PaintRecord. | 218 // Create a thread to rasterize PaintRecord. |
| 228 std::unique_ptr<WebThread> thread = | 219 std::unique_ptr<WebThread> thread = |
| 229 WTF::WrapUnique(Platform::Current()->CreateThread("RasterThread")); | 220 WTF::WrapUnique(Platform::Current()->CreateThread("RasterThread")); |
| 230 thread->GetWebTaskRunner()->PostTask( | 221 thread->GetWebTaskRunner()->PostTask( |
| 231 BLINK_FROM_HERE, | 222 BLINK_FROM_HERE, |
| 232 CrossThreadBind(&RasterizeMain, CrossThreadUnretained(canvas_.get()), | 223 CrossThreadBind(&RasterizeMain, CrossThreadUnretained(canvas_.get()), |
| 233 record)); | 224 record)); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 sk_sp<SkImage> image = lazy_decoder_->CreateFrameAtIndex(0); | 298 sk_sp<SkImage> image = lazy_decoder_->CreateFrameAtIndex(0); |
| 308 ASSERT_TRUE(image); | 299 ASSERT_TRUE(image); |
| 309 EXPECT_EQ(decoded_size_.Width(), image->width()); | 300 EXPECT_EQ(decoded_size_.Width(), image->width()); |
| 310 EXPECT_EQ(decoded_size_.Height(), image->height()); | 301 EXPECT_EQ(decoded_size_.Height(), image->height()); |
| 311 | 302 |
| 312 UseMockImageDecoderFactory(); | 303 UseMockImageDecoderFactory(); |
| 313 | 304 |
| 314 // The following code should not fail any assert. | 305 // The following code should not fail any assert. |
| 315 PaintRecorder recorder; | 306 PaintRecorder recorder; |
| 316 PaintCanvas* temp_canvas = recorder.beginRecording(100, 100); | 307 PaintCanvas* temp_canvas = recorder.beginRecording(100, 100); |
| 317 temp_canvas->drawImage( | 308 temp_canvas->drawImage(PaintImage(std::move(image)), 0, 0); |
| 318 PaintImage(std::move(image), PaintImage::AnimationType::STATIC, | |
| 319 PaintImage::CompletionState::DONE), | |
| 320 0, 0); | |
| 321 sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture(); | 309 sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture(); |
| 322 EXPECT_EQ(0, decode_request_count_); | 310 EXPECT_EQ(0, decode_request_count_); |
| 323 canvas_->drawPicture(record); | 311 canvas_->drawPicture(record); |
| 324 EXPECT_EQ(1, decode_request_count_); | 312 EXPECT_EQ(1, decode_request_count_); |
| 325 } | 313 } |
| 326 | 314 |
| 327 TEST_F(DeferredImageDecoderTest, smallerFrameCount) { | 315 TEST_F(DeferredImageDecoderTest, smallerFrameCount) { |
| 328 frame_count_ = 1; | 316 frame_count_ = 1; |
| 329 lazy_decoder_->SetData(data_, false); | 317 lazy_decoder_->SetData(data_, false); |
| 330 EXPECT_EQ(frame_count_, lazy_decoder_->FrameCount()); | 318 EXPECT_EQ(frame_count_, lazy_decoder_->FrameCount()); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 SharedBuffer::Create(data_->Data(), data_->size()); | 383 SharedBuffer::Create(data_->Data(), data_->size()); |
| 396 EXPECT_EQ(original_data->size(), data_->size()); | 384 EXPECT_EQ(original_data->size(), data_->size()); |
| 397 lazy_decoder_->SetData(original_data, false); | 385 lazy_decoder_->SetData(original_data, false); |
| 398 RefPtr<SharedBuffer> new_data = lazy_decoder_->Data(); | 386 RefPtr<SharedBuffer> new_data = lazy_decoder_->Data(); |
| 399 EXPECT_EQ(original_data->size(), new_data->size()); | 387 EXPECT_EQ(original_data->size(), new_data->size()); |
| 400 EXPECT_EQ(0, std::memcmp(original_data->Data(), new_data->Data(), | 388 EXPECT_EQ(0, std::memcmp(original_data->Data(), new_data->Data(), |
| 401 new_data->size())); | 389 new_data->size())); |
| 402 } | 390 } |
| 403 | 391 |
| 404 } // namespace blink | 392 } // namespace blink |
| OLD | NEW |