| 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 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 #include "platform/graphics/DeferredImageDecoder.h" | 26 #include "platform/graphics/DeferredImageDecoder.h" |
| 27 | 27 |
| 28 #include <memory> | 28 #include <memory> |
| 29 #include "platform/CrossThreadFunctional.h" | 29 #include "platform/CrossThreadFunctional.h" |
| 30 #include "platform/SharedBuffer.h" | 30 #include "platform/SharedBuffer.h" |
| 31 #include "platform/WebTaskRunner.h" | 31 #include "platform/WebTaskRunner.h" |
| 32 #include "platform/graphics/ImageDecodingStore.h" | 32 #include "platform/graphics/ImageDecodingStore.h" |
| 33 #include "platform/graphics/ImageFrameGenerator.h" | 33 #include "platform/graphics/ImageFrameGenerator.h" |
| 34 #include "platform/graphics/paint/PaintCanvas.h" | 34 #include "platform/graphics/paint/PaintCanvas.h" |
| 35 #include "platform/graphics/paint/PaintImage.h" |
| 35 #include "platform/graphics/paint/PaintRecord.h" | 36 #include "platform/graphics/paint/PaintRecord.h" |
| 36 #include "platform/graphics/paint/PaintRecorder.h" | 37 #include "platform/graphics/paint/PaintRecorder.h" |
| 37 #include "platform/graphics/test/MockImageDecoder.h" | 38 #include "platform/graphics/test/MockImageDecoder.h" |
| 38 #include "platform/wtf/PassRefPtr.h" | 39 #include "platform/wtf/PassRefPtr.h" |
| 39 #include "platform/wtf/PtrUtil.h" | 40 #include "platform/wtf/PtrUtil.h" |
| 40 #include "platform/wtf/RefPtr.h" | 41 #include "platform/wtf/RefPtr.h" |
| 41 #include "public/platform/Platform.h" | 42 #include "public/platform/Platform.h" |
| 42 #include "public/platform/WebThread.h" | 43 #include "public/platform/WebThread.h" |
| 43 #include "public/platform/WebTraceLocation.h" | 44 #include "public/platform/WebTraceLocation.h" |
| 44 #include "testing/gtest/include/gtest/gtest.h" | 45 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 156 |
| 156 TEST_F(DeferredImageDecoderTest, drawIntoPaintRecord) { | 157 TEST_F(DeferredImageDecoderTest, drawIntoPaintRecord) { |
| 157 lazy_decoder_->SetData(data_, true); | 158 lazy_decoder_->SetData(data_, true); |
| 158 sk_sp<SkImage> image = lazy_decoder_->CreateFrameAtIndex(0); | 159 sk_sp<SkImage> image = lazy_decoder_->CreateFrameAtIndex(0); |
| 159 ASSERT_TRUE(image); | 160 ASSERT_TRUE(image); |
| 160 EXPECT_EQ(1, image->width()); | 161 EXPECT_EQ(1, image->width()); |
| 161 EXPECT_EQ(1, image->height()); | 162 EXPECT_EQ(1, image->height()); |
| 162 | 163 |
| 163 PaintRecorder recorder; | 164 PaintRecorder recorder; |
| 164 PaintCanvas* temp_canvas = recorder.beginRecording(100, 100); | 165 PaintCanvas* temp_canvas = recorder.beginRecording(100, 100); |
| 165 temp_canvas->drawImage(image, 0, 0); | 166 temp_canvas->drawImage( |
| 167 PaintImage(std::move(image), PaintImage::AnimationType::STATIC, |
| 168 PaintImage::CompletionState::DONE), |
| 169 0, 0); |
| 166 sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture(); | 170 sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture(); |
| 167 EXPECT_EQ(0, decode_request_count_); | 171 EXPECT_EQ(0, decode_request_count_); |
| 168 | 172 |
| 169 canvas_->drawPicture(record); | 173 canvas_->drawPicture(record); |
| 170 EXPECT_EQ(0, decode_request_count_); | 174 EXPECT_EQ(0, decode_request_count_); |
| 171 | 175 |
| 172 SkAutoLockPixels auto_lock(bitmap_); | 176 SkAutoLockPixels auto_lock(bitmap_); |
| 173 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), bitmap_.getColor(0, 0)); | 177 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), bitmap_.getColor(0, 0)); |
| 174 } | 178 } |
| 175 | 179 |
| 176 TEST_F(DeferredImageDecoderTest, drawIntoPaintRecordProgressive) { | 180 TEST_F(DeferredImageDecoderTest, drawIntoPaintRecordProgressive) { |
| 177 RefPtr<SharedBuffer> partial_data = | 181 RefPtr<SharedBuffer> partial_data = |
| 178 SharedBuffer::Create(data_->Data(), data_->size() - 10); | 182 SharedBuffer::Create(data_->Data(), data_->size() - 10); |
| 179 | 183 |
| 180 // Received only half the file. | 184 // Received only half the file. |
| 181 lazy_decoder_->SetData(partial_data, false); | 185 lazy_decoder_->SetData(partial_data, false); |
| 182 sk_sp<SkImage> image = lazy_decoder_->CreateFrameAtIndex(0); | 186 sk_sp<SkImage> image = lazy_decoder_->CreateFrameAtIndex(0); |
| 183 ASSERT_TRUE(image); | 187 ASSERT_TRUE(image); |
| 184 PaintRecorder recorder; | 188 PaintRecorder recorder; |
| 185 PaintCanvas* temp_canvas = recorder.beginRecording(100, 100); | 189 PaintCanvas* temp_canvas = recorder.beginRecording(100, 100); |
| 186 temp_canvas->drawImage(std::move(image), 0, 0); | 190 temp_canvas->drawImage( |
| 191 PaintImage(std::move(image), PaintImage::AnimationType::STATIC, |
| 192 PaintImage::CompletionState::PARTIALLY_DONE), |
| 193 0, 0); |
| 187 canvas_->drawPicture(recorder.finishRecordingAsPicture()); | 194 canvas_->drawPicture(recorder.finishRecordingAsPicture()); |
| 188 | 195 |
| 189 // Fully received the file and draw the PaintRecord again. | 196 // Fully received the file and draw the PaintRecord again. |
| 190 lazy_decoder_->SetData(data_, true); | 197 lazy_decoder_->SetData(data_, true); |
| 191 image = lazy_decoder_->CreateFrameAtIndex(0); | 198 image = lazy_decoder_->CreateFrameAtIndex(0); |
| 192 ASSERT_TRUE(image); | 199 ASSERT_TRUE(image); |
| 193 temp_canvas = recorder.beginRecording(100, 100); | 200 temp_canvas = recorder.beginRecording(100, 100); |
| 194 temp_canvas->drawImage(std::move(image), 0, 0); | 201 temp_canvas->drawImage( |
| 202 PaintImage(std::move(image), PaintImage::AnimationType::STATIC, |
| 203 PaintImage::CompletionState::DONE), |
| 204 0, 0); |
| 195 canvas_->drawPicture(recorder.finishRecordingAsPicture()); | 205 canvas_->drawPicture(recorder.finishRecordingAsPicture()); |
| 196 | 206 |
| 197 SkAutoLockPixels auto_lock(bitmap_); | 207 SkAutoLockPixels auto_lock(bitmap_); |
| 198 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), bitmap_.getColor(0, 0)); | 208 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), bitmap_.getColor(0, 0)); |
| 199 } | 209 } |
| 200 | 210 |
| 201 static void RasterizeMain(PaintCanvas* canvas, sk_sp<PaintRecord> record) { | 211 static void RasterizeMain(PaintCanvas* canvas, sk_sp<PaintRecord> record) { |
| 202 canvas->drawPicture(record); | 212 canvas->drawPicture(record); |
| 203 } | 213 } |
| 204 | 214 |
| 205 TEST_F(DeferredImageDecoderTest, decodeOnOtherThread) { | 215 TEST_F(DeferredImageDecoderTest, decodeOnOtherThread) { |
| 206 lazy_decoder_->SetData(data_, true); | 216 lazy_decoder_->SetData(data_, true); |
| 207 sk_sp<SkImage> image = lazy_decoder_->CreateFrameAtIndex(0); | 217 sk_sp<SkImage> image = lazy_decoder_->CreateFrameAtIndex(0); |
| 208 ASSERT_TRUE(image); | 218 ASSERT_TRUE(image); |
| 209 EXPECT_EQ(1, image->width()); | 219 EXPECT_EQ(1, image->width()); |
| 210 EXPECT_EQ(1, image->height()); | 220 EXPECT_EQ(1, image->height()); |
| 211 | 221 |
| 212 PaintRecorder recorder; | 222 PaintRecorder recorder; |
| 213 PaintCanvas* temp_canvas = recorder.beginRecording(100, 100); | 223 PaintCanvas* temp_canvas = recorder.beginRecording(100, 100); |
| 214 temp_canvas->drawImage(std::move(image), 0, 0); | 224 temp_canvas->drawImage( |
| 225 PaintImage(std::move(image), PaintImage::AnimationType::STATIC, |
| 226 PaintImage::CompletionState::DONE), |
| 227 0, 0); |
| 215 sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture(); | 228 sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture(); |
| 216 EXPECT_EQ(0, decode_request_count_); | 229 EXPECT_EQ(0, decode_request_count_); |
| 217 | 230 |
| 218 // Create a thread to rasterize PaintRecord. | 231 // Create a thread to rasterize PaintRecord. |
| 219 std::unique_ptr<WebThread> thread = | 232 std::unique_ptr<WebThread> thread = |
| 220 WTF::WrapUnique(Platform::Current()->CreateThread("RasterThread")); | 233 WTF::WrapUnique(Platform::Current()->CreateThread("RasterThread")); |
| 221 thread->GetWebTaskRunner()->PostTask( | 234 thread->GetWebTaskRunner()->PostTask( |
| 222 BLINK_FROM_HERE, | 235 BLINK_FROM_HERE, |
| 223 CrossThreadBind(&RasterizeMain, CrossThreadUnretained(canvas_.get()), | 236 CrossThreadBind(&RasterizeMain, CrossThreadUnretained(canvas_.get()), |
| 224 record)); | 237 record)); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 sk_sp<SkImage> image = lazy_decoder_->CreateFrameAtIndex(0); | 313 sk_sp<SkImage> image = lazy_decoder_->CreateFrameAtIndex(0); |
| 301 ASSERT_TRUE(image); | 314 ASSERT_TRUE(image); |
| 302 EXPECT_EQ(decoded_size_.Width(), image->width()); | 315 EXPECT_EQ(decoded_size_.Width(), image->width()); |
| 303 EXPECT_EQ(decoded_size_.Height(), image->height()); | 316 EXPECT_EQ(decoded_size_.Height(), image->height()); |
| 304 | 317 |
| 305 UseMockImageDecoderFactory(); | 318 UseMockImageDecoderFactory(); |
| 306 | 319 |
| 307 // The following code should not fail any assert. | 320 // The following code should not fail any assert. |
| 308 PaintRecorder recorder; | 321 PaintRecorder recorder; |
| 309 PaintCanvas* temp_canvas = recorder.beginRecording(100, 100); | 322 PaintCanvas* temp_canvas = recorder.beginRecording(100, 100); |
| 310 temp_canvas->drawImage(std::move(image), 0, 0); | 323 temp_canvas->drawImage( |
| 324 PaintImage(std::move(image), PaintImage::AnimationType::STATIC, |
| 325 PaintImage::CompletionState::DONE), |
| 326 0, 0); |
| 311 sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture(); | 327 sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture(); |
| 312 EXPECT_EQ(0, decode_request_count_); | 328 EXPECT_EQ(0, decode_request_count_); |
| 313 canvas_->drawPicture(record); | 329 canvas_->drawPicture(record); |
| 314 EXPECT_EQ(1, decode_request_count_); | 330 EXPECT_EQ(1, decode_request_count_); |
| 315 } | 331 } |
| 316 | 332 |
| 317 TEST_F(DeferredImageDecoderTest, smallerFrameCount) { | 333 TEST_F(DeferredImageDecoderTest, smallerFrameCount) { |
| 318 frame_count_ = 1; | 334 frame_count_ = 1; |
| 319 lazy_decoder_->SetData(data_, false); | 335 lazy_decoder_->SetData(data_, false); |
| 320 EXPECT_EQ(frame_count_, lazy_decoder_->FrameCount()); | 336 EXPECT_EQ(frame_count_, lazy_decoder_->FrameCount()); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 SharedBuffer::Create(data_->Data(), data_->size()); | 401 SharedBuffer::Create(data_->Data(), data_->size()); |
| 386 EXPECT_EQ(original_data->size(), data_->size()); | 402 EXPECT_EQ(original_data->size(), data_->size()); |
| 387 lazy_decoder_->SetData(original_data, false); | 403 lazy_decoder_->SetData(original_data, false); |
| 388 RefPtr<SharedBuffer> new_data = lazy_decoder_->Data(); | 404 RefPtr<SharedBuffer> new_data = lazy_decoder_->Data(); |
| 389 EXPECT_EQ(original_data->size(), new_data->size()); | 405 EXPECT_EQ(original_data->size(), new_data->size()); |
| 390 EXPECT_EQ(0, std::memcmp(original_data->Data(), new_data->Data(), | 406 EXPECT_EQ(0, std::memcmp(original_data->Data(), new_data->Data(), |
| 391 new_data->size())); | 407 new_data->size())); |
| 392 } | 408 } |
| 393 | 409 |
| 394 } // namespace blink | 410 } // namespace blink |
| OLD | NEW |