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

Side by Side Diff: sky/engine/platform/graphics/DeferredImageDecoderTest.cpp

Issue 796663002: Update from https://crrev.com/307758 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Updates for SkCanvas::NewRaster deprecation Created 6 years 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
« no previous file with comments | « net/base/mime_util.cc ('k') | testing/android/junit/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 21 matching lines...) Expand all
32 #include "sky/engine/platform/SharedBuffer.h" 32 #include "sky/engine/platform/SharedBuffer.h"
33 #include "sky/engine/platform/graphics/ImageDecodingStore.h" 33 #include "sky/engine/platform/graphics/ImageDecodingStore.h"
34 #include "sky/engine/platform/graphics/skia/NativeImageSkia.h" 34 #include "sky/engine/platform/graphics/skia/NativeImageSkia.h"
35 #include "sky/engine/platform/graphics/test/MockImageDecoder.h" 35 #include "sky/engine/platform/graphics/test/MockImageDecoder.h"
36 #include "sky/engine/wtf/PassRefPtr.h" 36 #include "sky/engine/wtf/PassRefPtr.h"
37 #include "sky/engine/wtf/RefPtr.h" 37 #include "sky/engine/wtf/RefPtr.h"
38 #include "third_party/skia/include/core/SkBitmapDevice.h" 38 #include "third_party/skia/include/core/SkBitmapDevice.h"
39 #include "third_party/skia/include/core/SkCanvas.h" 39 #include "third_party/skia/include/core/SkCanvas.h"
40 #include "third_party/skia/include/core/SkPicture.h" 40 #include "third_party/skia/include/core/SkPicture.h"
41 #include "third_party/skia/include/core/SkPictureRecorder.h" 41 #include "third_party/skia/include/core/SkPictureRecorder.h"
42 #include "third_party/skia/include/core/SkSurface.h"
42 43
43 namespace blink { 44 namespace blink {
44 45
45 namespace { 46 namespace {
46 47
47 // Raw data for a PNG file with 1x1 white pixels. 48 // Raw data for a PNG file with 1x1 white pixels.
48 const unsigned char whitePNG[] = { 49 const unsigned char whitePNG[] = {
49 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 50 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00,
50 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 51 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01,
51 0x00, 0x00, 0x00, 0x01, 0x08, 0x02, 0x00, 0x00, 0x00, 0x90, 52 0x00, 0x00, 0x00, 0x01, 0x08, 0x02, 0x00, 0x00, 0x00, 0x90,
(...skipping 18 matching lines...) Expand all
70 public: 71 public:
71 virtual void SetUp() override 72 virtual void SetUp() override
72 { 73 {
73 ImageDecodingStore::instance()->setCacheLimitInBytes(1024 * 1024); 74 ImageDecodingStore::instance()->setCacheLimitInBytes(1024 * 1024);
74 DeferredImageDecoder::setEnabled(true); 75 DeferredImageDecoder::setEnabled(true);
75 m_data = SharedBuffer::create(whitePNG, sizeof(whitePNG)); 76 m_data = SharedBuffer::create(whitePNG, sizeof(whitePNG));
76 OwnPtr<MockImageDecoder> decoder = MockImageDecoder::create(this); 77 OwnPtr<MockImageDecoder> decoder = MockImageDecoder::create(this);
77 m_actualDecoder = decoder.get(); 78 m_actualDecoder = decoder.get();
78 m_actualDecoder->setSize(1, 1); 79 m_actualDecoder->setSize(1, 1);
79 m_lazyDecoder = DeferredImageDecoder::createForTesting(decoder.release() ); 80 m_lazyDecoder = DeferredImageDecoder::createForTesting(decoder.release() );
80 m_canvas.reset(SkCanvas::NewRasterN32(100, 100)); 81 m_surface.reset(SkSurface::NewRasterPMColor(100, 100));
81 ASSERT_TRUE(m_canvas.get()); 82 ASSERT_TRUE(m_surface.get());
82 m_frameBufferRequestCount = 0; 83 m_frameBufferRequestCount = 0;
83 m_frameCount = 1; 84 m_frameCount = 1;
84 m_repetitionCount = cAnimationNone; 85 m_repetitionCount = cAnimationNone;
85 m_status = ImageFrame::FrameComplete; 86 m_status = ImageFrame::FrameComplete;
86 m_frameDuration = 0; 87 m_frameDuration = 0;
87 m_decodedSize = m_actualDecoder->size(); 88 m_decodedSize = m_actualDecoder->size();
88 } 89 }
89 90
90 virtual void TearDown() override 91 virtual void TearDown() override
91 { 92 {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 130
130 protected: 131 protected:
131 void useMockImageDecoderFactory() 132 void useMockImageDecoderFactory()
132 { 133 {
133 m_lazyDecoder->frameGenerator()->setImageDecoderFactory(MockImageDecoder Factory::create(this, m_decodedSize)); 134 m_lazyDecoder->frameGenerator()->setImageDecoderFactory(MockImageDecoder Factory::create(this, m_decodedSize));
134 } 135 }
135 136
136 // Don't own this but saves the pointer to query states. 137 // Don't own this but saves the pointer to query states.
137 MockImageDecoder* m_actualDecoder; 138 MockImageDecoder* m_actualDecoder;
138 OwnPtr<DeferredImageDecoder> m_lazyDecoder; 139 OwnPtr<DeferredImageDecoder> m_lazyDecoder;
139 SkAutoTUnref<SkCanvas> m_canvas; 140 SkAutoTUnref<SkSurface> m_surface;
140 int m_frameBufferRequestCount; 141 int m_frameBufferRequestCount;
141 RefPtr<SharedBuffer> m_data; 142 RefPtr<SharedBuffer> m_data;
142 size_t m_frameCount; 143 size_t m_frameCount;
143 int m_repetitionCount; 144 int m_repetitionCount;
144 ImageFrame::Status m_status; 145 ImageFrame::Status m_status;
145 float m_frameDuration; 146 float m_frameDuration;
146 IntSize m_decodedSize; 147 IntSize m_decodedSize;
147 }; 148 };
148 149
149 TEST_F(DeferredImageDecoderTest, drawIntoSkPicture) 150 TEST_F(DeferredImageDecoderTest, drawIntoSkPicture)
150 { 151 {
151 m_lazyDecoder->setData(*m_data, true); 152 m_lazyDecoder->setData(*m_data, true);
152 RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewN ativeImage(); 153 RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewN ativeImage();
153 EXPECT_EQ(1, image->bitmap().width()); 154 EXPECT_EQ(1, image->bitmap().width());
154 EXPECT_EQ(1, image->bitmap().height()); 155 EXPECT_EQ(1, image->bitmap().height());
155 EXPECT_FALSE(image->bitmap().isNull()); 156 EXPECT_FALSE(image->bitmap().isNull());
156 EXPECT_TRUE(image->bitmap().isImmutable()); 157 EXPECT_TRUE(image->bitmap().isImmutable());
157 158
158 SkPictureRecorder recorder; 159 SkPictureRecorder recorder;
159 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); 160 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0);
160 tempCanvas->drawBitmap(image->bitmap(), 0, 0); 161 tempCanvas->drawBitmap(image->bitmap(), 0, 0);
161 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording()); 162 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording());
162 EXPECT_EQ(0, m_frameBufferRequestCount); 163 EXPECT_EQ(0, m_frameBufferRequestCount);
163 164
164 m_canvas->drawPicture(picture.get()); 165 m_surface->getCanvas()->drawPicture(picture.get());
165 EXPECT_EQ(0, m_frameBufferRequestCount); 166 EXPECT_EQ(0, m_frameBufferRequestCount);
166 167
167 SkBitmap canvasBitmap; 168 SkBitmap canvasBitmap;
168 canvasBitmap.allocN32Pixels(100, 100); 169 canvasBitmap.allocN32Pixels(100, 100);
169 ASSERT_TRUE(m_canvas->readPixels(&canvasBitmap, 0, 0)); 170 ASSERT_TRUE(m_surface->getCanvas()->readPixels(&canvasBitmap, 0, 0));
170 SkAutoLockPixels autoLock(canvasBitmap); 171 SkAutoLockPixels autoLock(canvasBitmap);
171 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); 172 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0));
172 } 173 }
173 174
174 TEST_F(DeferredImageDecoderTest, drawIntoSkPictureProgressive) 175 TEST_F(DeferredImageDecoderTest, drawIntoSkPictureProgressive)
175 { 176 {
176 RefPtr<SharedBuffer> partialData = SharedBuffer::create(m_data->data(), m_da ta->size() - 10); 177 RefPtr<SharedBuffer> partialData = SharedBuffer::create(m_data->data(), m_da ta->size() - 10);
177 178
178 // Received only half the file. 179 // Received only half the file.
179 m_lazyDecoder->setData(*partialData, false); 180 m_lazyDecoder->setData(*partialData, false);
180 RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewN ativeImage(); 181 RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewN ativeImage();
181 SkPictureRecorder recorder; 182 SkPictureRecorder recorder;
182 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); 183 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0);
183 tempCanvas->drawBitmap(image->bitmap(), 0, 0); 184 tempCanvas->drawBitmap(image->bitmap(), 0, 0);
184 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording()); 185 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording());
185 m_canvas->drawPicture(picture.get()); 186 m_surface->getCanvas()->drawPicture(picture.get());
186 187
187 // Fully received the file and draw the SkPicture again. 188 // Fully received the file and draw the SkPicture again.
188 m_lazyDecoder->setData(*m_data, true); 189 m_lazyDecoder->setData(*m_data, true);
189 image = m_lazyDecoder->frameBufferAtIndex(0)->asNewNativeImage(); 190 image = m_lazyDecoder->frameBufferAtIndex(0)->asNewNativeImage();
190 tempCanvas = recorder.beginRecording(100, 100, 0, 0); 191 tempCanvas = recorder.beginRecording(100, 100, 0, 0);
191 tempCanvas->drawBitmap(image->bitmap(), 0, 0); 192 tempCanvas->drawBitmap(image->bitmap(), 0, 0);
192 picture = adoptRef(recorder.endRecording()); 193 picture = adoptRef(recorder.endRecording());
193 m_canvas->drawPicture(picture.get()); 194 m_surface->getCanvas()->drawPicture(picture.get());
194 195
195 SkBitmap canvasBitmap; 196 SkBitmap canvasBitmap;
196 canvasBitmap.allocN32Pixels(100, 100); 197 canvasBitmap.allocN32Pixels(100, 100);
197 ASSERT_TRUE(m_canvas->readPixels(&canvasBitmap, 0, 0)); 198 ASSERT_TRUE(m_surface->getCanvas()->readPixels(&canvasBitmap, 0, 0));
198 SkAutoLockPixels autoLock(canvasBitmap); 199 SkAutoLockPixels autoLock(canvasBitmap);
199 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); 200 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0));
200 } 201 }
201 202
202 static void rasterizeMain(SkCanvas* canvas, SkPicture* picture) 203 static void rasterizeMain(SkCanvas* canvas, SkPicture* picture)
203 { 204 {
204 canvas->drawPicture(picture); 205 canvas->drawPicture(picture);
205 } 206 }
206 207
207 TEST_F(DeferredImageDecoderTest, decodeOnOtherThread) 208 TEST_F(DeferredImageDecoderTest, decodeOnOtherThread)
208 { 209 {
209 m_lazyDecoder->setData(*m_data, true); 210 m_lazyDecoder->setData(*m_data, true);
210 RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewN ativeImage(); 211 RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewN ativeImage();
211 EXPECT_EQ(1, image->bitmap().width()); 212 EXPECT_EQ(1, image->bitmap().width());
212 EXPECT_EQ(1, image->bitmap().height()); 213 EXPECT_EQ(1, image->bitmap().height());
213 EXPECT_FALSE(image->bitmap().isNull()); 214 EXPECT_FALSE(image->bitmap().isNull());
214 EXPECT_TRUE(image->bitmap().isImmutable()); 215 EXPECT_TRUE(image->bitmap().isImmutable());
215 216
216 SkPictureRecorder recorder; 217 SkPictureRecorder recorder;
217 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); 218 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0);
218 tempCanvas->drawBitmap(image->bitmap(), 0, 0); 219 tempCanvas->drawBitmap(image->bitmap(), 0, 0);
219 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording()); 220 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording());
220 EXPECT_EQ(0, m_frameBufferRequestCount); 221 EXPECT_EQ(0, m_frameBufferRequestCount);
221 222
222 // Create a thread to rasterize SkPicture. 223 // Create a thread to rasterize SkPicture.
223 OwnPtr<base::Thread> thread = adoptPtr(new base::Thread("RasterThread")); 224 OwnPtr<base::Thread> thread = adoptPtr(new base::Thread("RasterThread"));
224 thread->Start(); 225 thread->Start();
225 thread->message_loop()->PostTask(FROM_HERE, base::Bind(&rasterizeMain, m_can vas.get(), picture.get())); 226 thread->message_loop()->PostTask(FROM_HERE, base::Bind(&rasterizeMain, m_sur face->getCanvas(), picture.get()));
226 thread.clear(); 227 thread.clear();
227 EXPECT_EQ(0, m_frameBufferRequestCount); 228 EXPECT_EQ(0, m_frameBufferRequestCount);
228 229
229 SkBitmap canvasBitmap; 230 SkBitmap canvasBitmap;
230 canvasBitmap.allocN32Pixels(100, 100); 231 canvasBitmap.allocN32Pixels(100, 100);
231 ASSERT_TRUE(m_canvas->readPixels(&canvasBitmap, 0, 0)); 232 ASSERT_TRUE(m_surface->getCanvas()->readPixels(&canvasBitmap, 0, 0));
232 SkAutoLockPixels autoLock(canvasBitmap); 233 SkAutoLockPixels autoLock(canvasBitmap);
233 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); 234 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0));
234 } 235 }
235 236
236 TEST_F(DeferredImageDecoderTest, singleFrameImageLoading) 237 TEST_F(DeferredImageDecoderTest, singleFrameImageLoading)
237 { 238 {
238 m_status = ImageFrame::FramePartial; 239 m_status = ImageFrame::FramePartial;
239 m_lazyDecoder->setData(*m_data, false); 240 m_lazyDecoder->setData(*m_data, false);
240 EXPECT_FALSE(m_lazyDecoder->frameIsCompleteAtIndex(0)); 241 EXPECT_FALSE(m_lazyDecoder->frameIsCompleteAtIndex(0));
241 ImageFrame* frame = m_lazyDecoder->frameBufferAtIndex(0); 242 ImageFrame* frame = m_lazyDecoder->frameBufferAtIndex(0);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 EXPECT_TRUE(image->bitmap().isImmutable()); 319 EXPECT_TRUE(image->bitmap().isImmutable());
319 320
320 useMockImageDecoderFactory(); 321 useMockImageDecoderFactory();
321 322
322 // The following code should not fail any assert. 323 // The following code should not fail any assert.
323 SkPictureRecorder recorder; 324 SkPictureRecorder recorder;
324 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); 325 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0);
325 tempCanvas->drawBitmap(image->bitmap(), 0, 0); 326 tempCanvas->drawBitmap(image->bitmap(), 0, 0);
326 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording()); 327 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording());
327 EXPECT_EQ(0, m_frameBufferRequestCount); 328 EXPECT_EQ(0, m_frameBufferRequestCount);
328 m_canvas->drawPicture(picture.get()); 329 m_surface->getCanvas()->drawPicture(picture.get());
329 EXPECT_EQ(1, m_frameBufferRequestCount); 330 EXPECT_EQ(1, m_frameBufferRequestCount);
330 } 331 }
331 332
332 TEST_F(DeferredImageDecoderTest, smallerFrameCount) 333 TEST_F(DeferredImageDecoderTest, smallerFrameCount)
333 { 334 {
334 m_frameCount = 1; 335 m_frameCount = 1;
335 m_lazyDecoder->setData(*m_data, false); 336 m_lazyDecoder->setData(*m_data, false);
336 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount()); 337 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount());
337 m_frameCount = 2; 338 m_frameCount = 2;
338 m_lazyDecoder->setData(*m_data, false); 339 m_lazyDecoder->setData(*m_data, false);
339 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount()); 340 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount());
340 m_frameCount = 0; 341 m_frameCount = 0;
341 m_lazyDecoder->setData(*m_data, true); 342 m_lazyDecoder->setData(*m_data, true);
342 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount()); 343 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount());
343 } 344 }
344 345
345 } // namespace blink 346 } // namespace blink
OLDNEW
« no previous file with comments | « net/base/mime_util.cc ('k') | testing/android/junit/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698