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

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

Issue 2823003002: SkBitmap and SkPixelRef no longer need lock/unlock (Closed)
Patch Set: win fix after rebase Created 3 years, 8 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 PaintCanvas* temp_canvas = recorder.beginRecording(100, 100); 165 PaintCanvas* temp_canvas = recorder.beginRecording(100, 100);
166 temp_canvas->drawImage( 166 temp_canvas->drawImage(
167 PaintImage(std::move(image), PaintImage::AnimationType::STATIC, 167 PaintImage(std::move(image), PaintImage::AnimationType::STATIC,
168 PaintImage::CompletionState::DONE), 168 PaintImage::CompletionState::DONE),
169 0, 0); 169 0, 0);
170 sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture(); 170 sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture();
171 EXPECT_EQ(0, decode_request_count_); 171 EXPECT_EQ(0, decode_request_count_);
172 172
173 canvas_->drawPicture(record); 173 canvas_->drawPicture(record);
174 EXPECT_EQ(0, decode_request_count_); 174 EXPECT_EQ(0, decode_request_count_);
175
176 SkAutoLockPixels auto_lock(bitmap_);
177 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), bitmap_.getColor(0, 0)); 175 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), bitmap_.getColor(0, 0));
178 } 176 }
179 177
180 TEST_F(DeferredImageDecoderTest, drawIntoPaintRecordProgressive) { 178 TEST_F(DeferredImageDecoderTest, drawIntoPaintRecordProgressive) {
181 RefPtr<SharedBuffer> partial_data = 179 RefPtr<SharedBuffer> partial_data =
182 SharedBuffer::Create(data_->Data(), data_->size() - 10); 180 SharedBuffer::Create(data_->Data(), data_->size() - 10);
183 181
184 // Received only half the file. 182 // Received only half the file.
185 lazy_decoder_->SetData(partial_data, false); 183 lazy_decoder_->SetData(partial_data, false);
186 sk_sp<SkImage> image = lazy_decoder_->CreateFrameAtIndex(0); 184 sk_sp<SkImage> image = lazy_decoder_->CreateFrameAtIndex(0);
187 ASSERT_TRUE(image); 185 ASSERT_TRUE(image);
188 PaintRecorder recorder; 186 PaintRecorder recorder;
189 PaintCanvas* temp_canvas = recorder.beginRecording(100, 100); 187 PaintCanvas* temp_canvas = recorder.beginRecording(100, 100);
190 temp_canvas->drawImage( 188 temp_canvas->drawImage(
191 PaintImage(std::move(image), PaintImage::AnimationType::STATIC, 189 PaintImage(std::move(image), PaintImage::AnimationType::STATIC,
192 PaintImage::CompletionState::PARTIALLY_DONE), 190 PaintImage::CompletionState::PARTIALLY_DONE),
193 0, 0); 191 0, 0);
194 canvas_->drawPicture(recorder.finishRecordingAsPicture()); 192 canvas_->drawPicture(recorder.finishRecordingAsPicture());
195 193
196 // Fully received the file and draw the PaintRecord again. 194 // Fully received the file and draw the PaintRecord again.
197 lazy_decoder_->SetData(data_, true); 195 lazy_decoder_->SetData(data_, true);
198 image = lazy_decoder_->CreateFrameAtIndex(0); 196 image = lazy_decoder_->CreateFrameAtIndex(0);
199 ASSERT_TRUE(image); 197 ASSERT_TRUE(image);
200 temp_canvas = recorder.beginRecording(100, 100); 198 temp_canvas = recorder.beginRecording(100, 100);
201 temp_canvas->drawImage( 199 temp_canvas->drawImage(
202 PaintImage(std::move(image), PaintImage::AnimationType::STATIC, 200 PaintImage(std::move(image), PaintImage::AnimationType::STATIC,
203 PaintImage::CompletionState::DONE), 201 PaintImage::CompletionState::DONE),
204 0, 0); 202 0, 0);
205 canvas_->drawPicture(recorder.finishRecordingAsPicture()); 203 canvas_->drawPicture(recorder.finishRecordingAsPicture());
206
207 SkAutoLockPixels auto_lock(bitmap_);
208 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), bitmap_.getColor(0, 0)); 204 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), bitmap_.getColor(0, 0));
209 } 205 }
210 206
211 static void RasterizeMain(PaintCanvas* canvas, sk_sp<PaintRecord> record) { 207 static void RasterizeMain(PaintCanvas* canvas, sk_sp<PaintRecord> record) {
212 canvas->drawPicture(record); 208 canvas->drawPicture(record);
213 } 209 }
214 210
215 TEST_F(DeferredImageDecoderTest, decodeOnOtherThread) { 211 TEST_F(DeferredImageDecoderTest, decodeOnOtherThread) {
216 lazy_decoder_->SetData(data_, true); 212 lazy_decoder_->SetData(data_, true);
217 sk_sp<SkImage> image = lazy_decoder_->CreateFrameAtIndex(0); 213 sk_sp<SkImage> image = lazy_decoder_->CreateFrameAtIndex(0);
(...skipping 12 matching lines...) Expand all
230 226
231 // Create a thread to rasterize PaintRecord. 227 // Create a thread to rasterize PaintRecord.
232 std::unique_ptr<WebThread> thread = 228 std::unique_ptr<WebThread> thread =
233 WTF::WrapUnique(Platform::Current()->CreateThread("RasterThread")); 229 WTF::WrapUnique(Platform::Current()->CreateThread("RasterThread"));
234 thread->GetWebTaskRunner()->PostTask( 230 thread->GetWebTaskRunner()->PostTask(
235 BLINK_FROM_HERE, 231 BLINK_FROM_HERE,
236 CrossThreadBind(&RasterizeMain, CrossThreadUnretained(canvas_.get()), 232 CrossThreadBind(&RasterizeMain, CrossThreadUnretained(canvas_.get()),
237 record)); 233 record));
238 thread.reset(); 234 thread.reset();
239 EXPECT_EQ(0, decode_request_count_); 235 EXPECT_EQ(0, decode_request_count_);
240
241 SkAutoLockPixels auto_lock(bitmap_);
242 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), bitmap_.getColor(0, 0)); 236 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), bitmap_.getColor(0, 0));
243 } 237 }
244 238
245 TEST_F(DeferredImageDecoderTest, singleFrameImageLoading) { 239 TEST_F(DeferredImageDecoderTest, singleFrameImageLoading) {
246 status_ = ImageFrame::kFramePartial; 240 status_ = ImageFrame::kFramePartial;
247 lazy_decoder_->SetData(data_, false); 241 lazy_decoder_->SetData(data_, false);
248 EXPECT_FALSE(lazy_decoder_->FrameIsCompleteAtIndex(0)); 242 EXPECT_FALSE(lazy_decoder_->FrameIsCompleteAtIndex(0));
249 sk_sp<SkImage> image = lazy_decoder_->CreateFrameAtIndex(0); 243 sk_sp<SkImage> image = lazy_decoder_->CreateFrameAtIndex(0);
250 ASSERT_TRUE(image); 244 ASSERT_TRUE(image);
251 unsigned first_id = image->uniqueID(); 245 unsigned first_id = image->uniqueID();
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 SharedBuffer::Create(data_->Data(), data_->size()); 395 SharedBuffer::Create(data_->Data(), data_->size());
402 EXPECT_EQ(original_data->size(), data_->size()); 396 EXPECT_EQ(original_data->size(), data_->size());
403 lazy_decoder_->SetData(original_data, false); 397 lazy_decoder_->SetData(original_data, false);
404 RefPtr<SharedBuffer> new_data = lazy_decoder_->Data(); 398 RefPtr<SharedBuffer> new_data = lazy_decoder_->Data();
405 EXPECT_EQ(original_data->size(), new_data->size()); 399 EXPECT_EQ(original_data->size(), new_data->size());
406 EXPECT_EQ(0, std::memcmp(original_data->Data(), new_data->Data(), 400 EXPECT_EQ(0, std::memcmp(original_data->Data(), new_data->Data(),
407 new_data->size())); 401 new_data->size()));
408 } 402 }
409 403
410 } // namespace blink 404 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698