Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(336)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/DeferredImageDecoderTest.cpp

Issue 2640983002: Rename paint data structures (Closed)
Patch Set: Rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 12 matching lines...) Expand all
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/DeferredImageDecoder.h" 26 #include "platform/graphics/DeferredImageDecoder.h"
27 27
28 #include "platform/CrossThreadFunctional.h" 28 #include "platform/CrossThreadFunctional.h"
29 #include "platform/SharedBuffer.h" 29 #include "platform/SharedBuffer.h"
30 #include "platform/WebTaskRunner.h" 30 #include "platform/WebTaskRunner.h"
31 #include "platform/graphics/ImageDecodingStore.h" 31 #include "platform/graphics/ImageDecodingStore.h"
32 #include "platform/graphics/ImageFrameGenerator.h" 32 #include "platform/graphics/ImageFrameGenerator.h"
33 #include "platform/graphics/paint/PaintCanvas.h"
34 #include "platform/graphics/paint/PaintRecord.h"
35 #include "platform/graphics/paint/PaintRecorder.h"
33 #include "platform/graphics/test/MockImageDecoder.h" 36 #include "platform/graphics/test/MockImageDecoder.h"
34 #include "public/platform/Platform.h" 37 #include "public/platform/Platform.h"
35 #include "public/platform/WebThread.h" 38 #include "public/platform/WebThread.h"
36 #include "public/platform/WebTraceLocation.h" 39 #include "public/platform/WebTraceLocation.h"
37 #include "testing/gtest/include/gtest/gtest.h" 40 #include "testing/gtest/include/gtest/gtest.h"
38 #include "third_party/skia/include/core/SkCanvas.h"
39 #include "third_party/skia/include/core/SkImage.h" 41 #include "third_party/skia/include/core/SkImage.h"
40 #include "third_party/skia/include/core/SkPicture.h"
41 #include "third_party/skia/include/core/SkPictureRecorder.h"
42 #include "third_party/skia/include/core/SkPixmap.h" 42 #include "third_party/skia/include/core/SkPixmap.h"
43 #include "third_party/skia/include/core/SkSurface.h" 43 #include "third_party/skia/include/core/SkSurface.h"
44 #include "wtf/PassRefPtr.h" 44 #include "wtf/PassRefPtr.h"
45 #include "wtf/PtrUtil.h" 45 #include "wtf/PtrUtil.h"
46 #include "wtf/RefPtr.h" 46 #include "wtf/RefPtr.h"
47 #include <memory> 47 #include <memory>
48 48
49 namespace blink { 49 namespace blink {
50 50
51 namespace { 51 namespace {
(...skipping 25 matching lines...) Expand all
77 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 77 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20,
78 0x65, 0x7a, 0x67, 0x69, 0x66, 0x2e, 0x63, 0x6f, 0x6d, 0x20, 0x67, 0x69, 78 0x65, 0x7a, 0x67, 0x69, 0x66, 0x2e, 0x63, 0x6f, 0x6d, 0x20, 0x67, 0x69,
79 0x66, 0x20, 0x6d, 0x61, 0x6b, 0x65, 0x72, 0x00, 0x2c, 0x00, 0x00, 0x00, 79 0x66, 0x20, 0x6d, 0x61, 0x6b, 0x65, 0x72, 0x00, 0x2c, 0x00, 0x00, 0x00,
80 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x44, 0x01, 0x00, 0x21, 80 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x44, 0x01, 0x00, 0x21,
81 0xf9, 0x04, 0x00, 0x14, 0x00, 0xff, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 81 0xf9, 0x04, 0x00, 0x14, 0x00, 0xff, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00,
82 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x4c, 0x01, 0x00, 0x3b, 82 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x4c, 0x01, 0x00, 0x3b,
83 }; 83 };
84 84
85 struct Rasterizer { 85 struct Rasterizer {
86 SkCanvas* canvas; 86 SkCanvas* canvas;
87 SkPicture* picture; 87 PaintRecord* picture;
88 }; 88 };
89 89
90 } // namespace 90 } // namespace
91 91
92 class DeferredImageDecoderTest : public ::testing::Test, 92 class DeferredImageDecoderTest : public ::testing::Test,
93 public MockImageDecoderClient { 93 public MockImageDecoderClient {
94 public: 94 public:
95 void SetUp() override { 95 void SetUp() override {
96 ImageDecodingStore::instance().setCacheLimitInBytes(1024 * 1024); 96 ImageDecodingStore::instance().setCacheLimitInBytes(1024 * 1024);
97 m_data = SharedBuffer::create(whitePNG, sizeof(whitePNG)); 97 m_data = SharedBuffer::create(whitePNG, sizeof(whitePNG));
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 IntSize m_decodedSize; 144 IntSize m_decodedSize;
145 }; 145 };
146 146
147 TEST_F(DeferredImageDecoderTest, drawIntoSkPicture) { 147 TEST_F(DeferredImageDecoderTest, drawIntoSkPicture) {
148 m_lazyDecoder->setData(m_data, true); 148 m_lazyDecoder->setData(m_data, true);
149 sk_sp<SkImage> image = m_lazyDecoder->createFrameAtIndex(0); 149 sk_sp<SkImage> image = m_lazyDecoder->createFrameAtIndex(0);
150 ASSERT_TRUE(image); 150 ASSERT_TRUE(image);
151 EXPECT_EQ(1, image->width()); 151 EXPECT_EQ(1, image->width());
152 EXPECT_EQ(1, image->height()); 152 EXPECT_EQ(1, image->height());
153 153
154 SkPictureRecorder recorder; 154 PaintRecorder recorder;
155 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); 155 PaintCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0);
156 tempCanvas->drawImage(image.get(), 0, 0); 156 tempCanvas->drawImage(image.get(), 0, 0);
157 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); 157 sk_sp<PaintRecord> picture = recorder.finishRecordingAsPicture();
158 EXPECT_EQ(0, m_decodeRequestCount); 158 EXPECT_EQ(0, m_decodeRequestCount);
159 159
160 m_surface->getCanvas()->drawPicture(picture); 160 m_surface->getCanvas()->drawPicture(picture);
161 EXPECT_EQ(0, m_decodeRequestCount); 161 EXPECT_EQ(0, m_decodeRequestCount);
162 162
163 SkBitmap canvasBitmap; 163 SkBitmap canvasBitmap;
164 canvasBitmap.allocN32Pixels(100, 100); 164 canvasBitmap.allocN32Pixels(100, 100);
165 ASSERT_TRUE(m_surface->getCanvas()->readPixels(&canvasBitmap, 0, 0)); 165 ASSERT_TRUE(m_surface->getCanvas()->readPixels(&canvasBitmap, 0, 0));
166 SkAutoLockPixels autoLock(canvasBitmap); 166 SkAutoLockPixels autoLock(canvasBitmap);
167 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); 167 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0));
168 } 168 }
169 169
170 TEST_F(DeferredImageDecoderTest, drawIntoSkPictureProgressive) { 170 TEST_F(DeferredImageDecoderTest, drawIntoSkPictureProgressive) {
171 RefPtr<SharedBuffer> partialData = 171 RefPtr<SharedBuffer> partialData =
172 SharedBuffer::create(m_data->data(), m_data->size() - 10); 172 SharedBuffer::create(m_data->data(), m_data->size() - 10);
173 173
174 // Received only half the file. 174 // Received only half the file.
175 m_lazyDecoder->setData(partialData, false); 175 m_lazyDecoder->setData(partialData, false);
176 sk_sp<SkImage> image = m_lazyDecoder->createFrameAtIndex(0); 176 sk_sp<SkImage> image = m_lazyDecoder->createFrameAtIndex(0);
177 ASSERT_TRUE(image); 177 ASSERT_TRUE(image);
178 SkPictureRecorder recorder; 178 PaintRecorder recorder;
179 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); 179 PaintCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0);
180 tempCanvas->drawImage(image.get(), 0, 0); 180 tempCanvas->drawImage(image.get(), 0, 0);
181 m_surface->getCanvas()->drawPicture(recorder.finishRecordingAsPicture()); 181 m_surface->getCanvas()->drawPicture(recorder.finishRecordingAsPicture());
182 182
183 // Fully received the file and draw the SkPicture again. 183 // Fully received the file and draw the PaintRecord again.
184 m_lazyDecoder->setData(m_data, true); 184 m_lazyDecoder->setData(m_data, true);
185 image = m_lazyDecoder->createFrameAtIndex(0); 185 image = m_lazyDecoder->createFrameAtIndex(0);
186 ASSERT_TRUE(image); 186 ASSERT_TRUE(image);
187 tempCanvas = recorder.beginRecording(100, 100, 0, 0); 187 tempCanvas = recorder.beginRecording(100, 100, 0, 0);
188 tempCanvas->drawImage(image.get(), 0, 0); 188 tempCanvas->drawImage(image.get(), 0, 0);
189 m_surface->getCanvas()->drawPicture(recorder.finishRecordingAsPicture()); 189 m_surface->getCanvas()->drawPicture(recorder.finishRecordingAsPicture());
190 190
191 SkBitmap canvasBitmap; 191 SkBitmap canvasBitmap;
192 canvasBitmap.allocN32Pixels(100, 100); 192 canvasBitmap.allocN32Pixels(100, 100);
193 ASSERT_TRUE(m_surface->getCanvas()->readPixels(&canvasBitmap, 0, 0)); 193 ASSERT_TRUE(m_surface->getCanvas()->readPixels(&canvasBitmap, 0, 0));
194 SkAutoLockPixels autoLock(canvasBitmap); 194 SkAutoLockPixels autoLock(canvasBitmap);
195 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); 195 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0));
196 } 196 }
197 197
198 static void rasterizeMain(SkCanvas* canvas, SkPicture* picture) { 198 static void rasterizeMain(PaintCanvas* canvas, PaintRecord* picture) {
199 canvas->drawPicture(picture); 199 canvas->drawPicture(picture);
200 } 200 }
201 201
202 TEST_F(DeferredImageDecoderTest, decodeOnOtherThread) { 202 TEST_F(DeferredImageDecoderTest, decodeOnOtherThread) {
203 m_lazyDecoder->setData(m_data, true); 203 m_lazyDecoder->setData(m_data, true);
204 sk_sp<SkImage> image = m_lazyDecoder->createFrameAtIndex(0); 204 sk_sp<SkImage> image = m_lazyDecoder->createFrameAtIndex(0);
205 ASSERT_TRUE(image); 205 ASSERT_TRUE(image);
206 EXPECT_EQ(1, image->width()); 206 EXPECT_EQ(1, image->width());
207 EXPECT_EQ(1, image->height()); 207 EXPECT_EQ(1, image->height());
208 208
209 SkPictureRecorder recorder; 209 PaintRecorder recorder;
210 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); 210 PaintCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0);
211 tempCanvas->drawImage(image.get(), 0, 0); 211 tempCanvas->drawImage(image.get(), 0, 0);
212 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); 212 sk_sp<PaintRecord> picture = recorder.finishRecordingAsPicture();
213 EXPECT_EQ(0, m_decodeRequestCount); 213 EXPECT_EQ(0, m_decodeRequestCount);
214 214
215 // Create a thread to rasterize SkPicture. 215 // Create a thread to rasterize PaintRecord.
216 std::unique_ptr<WebThread> thread = 216 std::unique_ptr<WebThread> thread =
217 WTF::wrapUnique(Platform::current()->createThread("RasterThread")); 217 WTF::wrapUnique(Platform::current()->createThread("RasterThread"));
218 thread->getWebTaskRunner()->postTask( 218 thread->getWebTaskRunner()->postTask(
219 BLINK_FROM_HERE, 219 BLINK_FROM_HERE,
220 crossThreadBind(&rasterizeMain, 220 crossThreadBind(&rasterizeMain,
221 crossThreadUnretained(m_surface->getCanvas()), 221 crossThreadUnretained(m_surface->getCanvas()),
222 crossThreadUnretained(picture.get()))); 222 crossThreadUnretained(picture.get())));
223 thread.reset(); 223 thread.reset();
224 EXPECT_EQ(0, m_decodeRequestCount); 224 EXPECT_EQ(0, m_decodeRequestCount);
225 225
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 m_decodedSize = IntSize(22, 33); 299 m_decodedSize = IntSize(22, 33);
300 m_lazyDecoder->setData(m_data, true); 300 m_lazyDecoder->setData(m_data, true);
301 sk_sp<SkImage> image = m_lazyDecoder->createFrameAtIndex(0); 301 sk_sp<SkImage> image = m_lazyDecoder->createFrameAtIndex(0);
302 ASSERT_TRUE(image); 302 ASSERT_TRUE(image);
303 EXPECT_EQ(m_decodedSize.width(), image->width()); 303 EXPECT_EQ(m_decodedSize.width(), image->width());
304 EXPECT_EQ(m_decodedSize.height(), image->height()); 304 EXPECT_EQ(m_decodedSize.height(), image->height());
305 305
306 useMockImageDecoderFactory(); 306 useMockImageDecoderFactory();
307 307
308 // The following code should not fail any assert. 308 // The following code should not fail any assert.
309 SkPictureRecorder recorder; 309 PaintRecorder recorder;
310 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); 310 PaintCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0);
311 tempCanvas->drawImage(image.get(), 0, 0); 311 tempCanvas->drawImage(image.get(), 0, 0);
312 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); 312 sk_sp<PaintRecord> picture = recorder.finishRecordingAsPicture();
313 EXPECT_EQ(0, m_decodeRequestCount); 313 EXPECT_EQ(0, m_decodeRequestCount);
314 m_surface->getCanvas()->drawPicture(picture); 314 m_surface->getCanvas()->drawPicture(picture);
315 EXPECT_EQ(1, m_decodeRequestCount); 315 EXPECT_EQ(1, m_decodeRequestCount);
316 } 316 }
317 317
318 TEST_F(DeferredImageDecoderTest, smallerFrameCount) { 318 TEST_F(DeferredImageDecoderTest, smallerFrameCount) {
319 m_frameCount = 1; 319 m_frameCount = 1;
320 m_lazyDecoder->setData(m_data, false); 320 m_lazyDecoder->setData(m_data, false);
321 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount()); 321 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount());
322 m_frameCount = 2; 322 m_frameCount = 2;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 SharedBuffer::create(m_data->data(), m_data->size()); 380 SharedBuffer::create(m_data->data(), m_data->size());
381 EXPECT_EQ(originalData->size(), m_data->size()); 381 EXPECT_EQ(originalData->size(), m_data->size());
382 m_lazyDecoder->setData(originalData, false); 382 m_lazyDecoder->setData(originalData, false);
383 RefPtr<SharedBuffer> newData = m_lazyDecoder->data(); 383 RefPtr<SharedBuffer> newData = m_lazyDecoder->data();
384 EXPECT_EQ(originalData->size(), newData->size()); 384 EXPECT_EQ(originalData->size(), newData->size());
385 EXPECT_EQ( 385 EXPECT_EQ(
386 0, std::memcmp(originalData->data(), newData->data(), newData->size())); 386 0, std::memcmp(originalData->data(), newData->data(), newData->size()));
387 } 387 }
388 388
389 } // namespace blink 389 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698