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

Side by Side Diff: tests/RecordOptsTest.cpp

Issue 2309623002: test picture-ops for savelayer (Closed)
Patch Set: proposed fix Created 4 years, 3 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
« no previous file with comments | « src/core/SkRecordOpts.cpp ('k') | no next file » | 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 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Test.h" 8 #include "Test.h"
9 #include "RecordTestUtils.h" 9 #include "RecordTestUtils.h"
10 10
11 #include "SkColorFilter.h" 11 #include "SkColorFilter.h"
12 #include "SkRecord.h" 12 #include "SkRecord.h"
13 #include "SkRecordOpts.h" 13 #include "SkRecordOpts.h"
14 #include "SkRecorder.h" 14 #include "SkRecorder.h"
15 #include "SkRecords.h" 15 #include "SkRecords.h"
16 #include "SkXfermode.h" 16 #include "SkXfermode.h"
17 #include "SkPictureRecorder.h" 17 #include "SkPictureRecorder.h"
18 #include "SkPictureImageFilter.h" 18 #include "SkPictureImageFilter.h"
19 #include "SkSurface.h"
19 20
20 static const int W = 1920, H = 1080; 21 static const int W = 1920, H = 1080;
21 22
22 DEF_TEST(RecordOpts_NoopDraw, r) { 23 DEF_TEST(RecordOpts_NoopDraw, r) {
23 SkRecord record; 24 SkRecord record;
24 SkRecorder recorder(&record, W, H); 25 SkRecorder recorder(&record, W, H);
25 26
26 recorder.drawRect(SkRect::MakeWH(200, 200), SkPaint()); 27 recorder.drawRect(SkRect::MakeWH(200, 200), SkPaint());
27 recorder.drawRect(SkRect::MakeWH(300, 300), SkPaint()); 28 recorder.drawRect(SkRect::MakeWH(300, 300), SkPaint());
28 recorder.drawRect(SkRect::MakeWH(100, 100), SkPaint()); 29 recorder.drawRect(SkRect::MakeWH(100, 100), SkPaint());
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 recorder.saveLayer(nullptr, &opaqueFilterLayerPaint); 337 recorder.saveLayer(nullptr, &opaqueFilterLayerPaint);
337 recorder.restore(); 338 recorder.restore();
338 recorder.restore(); 339 recorder.restore();
339 SkRecordMergeSvgOpacityAndFilterLayers(&record); 340 SkRecordMergeSvgOpacityAndFilterLayers(&record);
340 assert_type<SkRecords::SaveLayer>(r, record, index); 341 assert_type<SkRecords::SaveLayer>(r, record, index);
341 assert_type<SkRecords::SaveLayer>(r, record, index + 1); 342 assert_type<SkRecords::SaveLayer>(r, record, index + 1);
342 assert_type<SkRecords::Restore>(r, record, index + 2); 343 assert_type<SkRecords::Restore>(r, record, index + 2);
343 assert_type<SkRecords::Restore>(r, record, index + 3); 344 assert_type<SkRecords::Restore>(r, record, index + 3);
344 index += 4; 345 index += 4;
345 } 346 }
347
348 static void do_draw(SkCanvas* canvas, SkColor color, bool doLayer) {
349 canvas->drawColor(SK_ColorWHITE);
350
351 SkPaint p;
352 p.setColor(color);
353
354 if (doLayer) {
355 canvas->saveLayer(nullptr, nullptr);
356 p.setXfermodeMode(SkXfermode::kSrc_Mode);
357 canvas->drawPaint(p);
358 canvas->restore();
359 } else {
360 canvas->drawPaint(p);
361 }
362 }
363
364 static bool is_equal(SkSurface* a, SkSurface* b) {
365 const SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1);
366 SkPMColor ca, cb;
367 a->readPixels(info, &ca, sizeof(SkPMColor), 0, 0);
368 b->readPixels(info, &cb, sizeof(SkPMColor), 0, 0);
369 return ca == cb;
370 }
371
372 // Test drawing w/ and w/o a simple layer (no bounds or paint), so see that draw ing ops
373 // that *should* draw the same in fact do.
374 //
375 // Perform this test twice : once directly, and once via a picture
376 //
377 static void do_savelayer_srcmode(skiatest::Reporter* r, SkColor color) {
378 for (int doPicture = 0; doPicture <= 1; ++doPicture) {
379 sk_sp<SkSurface> surf0 = SkSurface::MakeRasterN32Premul(10, 10);
380 sk_sp<SkSurface> surf1 = SkSurface::MakeRasterN32Premul(10, 10);
381 SkCanvas* c0 = surf0->getCanvas();
382 SkCanvas* c1 = surf1->getCanvas();
383
384 SkPictureRecorder rec0, rec1;
385 if (doPicture) {
386 c0 = rec0.beginRecording(10, 10);
387 c1 = rec1.beginRecording(10, 10);
388 }
389
390 do_draw(c0, color, false);
391 do_draw(c1, color, true);
392
393 if (doPicture) {
394 surf0->getCanvas()->drawPicture(rec0.finishRecordingAsPicture());
395 surf1->getCanvas()->drawPicture(rec1.finishRecordingAsPicture());
396 }
397
398 // we replicate the assert so we can see which line is reported if there is a failure
399 if (doPicture) {
400 REPORTER_ASSERT(r, is_equal(surf0.get(), surf1.get()));
401 } else {
402 REPORTER_ASSERT(r, is_equal(surf0.get(), surf1.get()));
403 }
404 }
405 }
406
407 DEF_TEST(savelayer_srcmode_opaque, r) {
408 do_savelayer_srcmode(r, SK_ColorRED);
409 }
410
411 DEF_TEST(savelayer_srcmode_alpha, r) {
412 do_savelayer_srcmode(r, 0x80FF0000);
413 }
414
OLDNEW
« no previous file with comments | « src/core/SkRecordOpts.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698