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

Side by Side Diff: tests/PictureTest.cpp

Issue 22978012: Split SkDevice into SkBaseDevice and SkBitmapDevice (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Updating to ToT (10994) Created 7 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 | Annotate | Revision Log
« no previous file with comments | « tests/LayerDrawLooperTest.cpp ('k') | tests/PremulAlphaRoundTripTest.cpp » ('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 2012 Google Inc. 2 * Copyright 2012 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 #include "Test.h" 7 #include "Test.h"
8 #include "SkBitmapDevice.h"
8 #include "SkCanvas.h" 9 #include "SkCanvas.h"
9 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
10 #include "SkData.h" 11 #include "SkData.h"
11 #include "SkDevice.h"
12 #include "SkError.h" 12 #include "SkError.h"
13 #include "SkPaint.h" 13 #include "SkPaint.h"
14 #include "SkPicture.h" 14 #include "SkPicture.h"
15 #include "SkPictureUtils.h"
15 #include "SkRandom.h" 16 #include "SkRandom.h"
16 #include "SkRRect.h" 17 #include "SkRRect.h"
17 #include "SkShader.h" 18 #include "SkShader.h"
18 #include "SkStream.h" 19 #include "SkStream.h"
19 20
20 #include "SkPictureUtils.h"
21 21
22 static void make_bm(SkBitmap* bm, int w, int h, SkColor color, bool immutable) { 22 static void make_bm(SkBitmap* bm, int w, int h, SkColor color, bool immutable) {
23 bm->setConfig(SkBitmap::kARGB_8888_Config, w, h); 23 bm->setConfig(SkBitmap::kARGB_8888_Config, w, h);
24 bm->allocPixels(); 24 bm->allocPixels();
25 bm->eraseColor(color); 25 bm->eraseColor(color);
26 if (immutable) { 26 if (immutable) {
27 bm->setImmutable(); 27 bm->setImmutable();
28 } 28 }
29 } 29 }
30 30
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom); 549 REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom);
550 REPORTER_ASSERT(reporter, 8 == clipBounds.fRight); 550 REPORTER_ASSERT(reporter, 8 == clipBounds.fRight);
551 } 551 }
552 } 552 }
553 553
554 /** 554 /**
555 * A canvas that records the number of clip commands. 555 * A canvas that records the number of clip commands.
556 */ 556 */
557 class ClipCountingCanvas : public SkCanvas { 557 class ClipCountingCanvas : public SkCanvas {
558 public: 558 public:
559 explicit ClipCountingCanvas(SkDevice* device) 559 explicit ClipCountingCanvas(SkBaseDevice* device)
560 : SkCanvas(device) 560 : SkCanvas(device)
561 , fClipCount(0){ 561 , fClipCount(0){
562 } 562 }
563 563
564 virtual bool clipRect(const SkRect& r, SkRegion::Op op, bool doAA) 564 virtual bool clipRect(const SkRect& r, SkRegion::Op op, bool doAA)
565 SK_OVERRIDE { 565 SK_OVERRIDE {
566 fClipCount += 1; 566 fClipCount += 1;
567 return this->INHERITED::clipRect(r, op, doAA); 567 return this->INHERITED::clipRect(r, op, doAA);
568 } 568 }
569 569
(...skipping 22 matching lines...) Expand all
592 SkCanvas* canvas = picture.beginRecording(10, 10, 0); 592 SkCanvas* canvas = picture.beginRecording(10, 10, 0);
593 593
594 canvas->clipRect(SkRect::MakeEmpty(), SkRegion::kReplace_Op); 594 canvas->clipRect(SkRect::MakeEmpty(), SkRegion::kReplace_Op);
595 // The following expanding clip should not be skipped. 595 // The following expanding clip should not be skipped.
596 canvas->clipRect(SkRect::MakeXYWH(4, 4, 3, 3), SkRegion::kUnion_Op); 596 canvas->clipRect(SkRect::MakeXYWH(4, 4, 3, 3), SkRegion::kUnion_Op);
597 // Draw something so the optimizer doesn't just fold the world. 597 // Draw something so the optimizer doesn't just fold the world.
598 SkPaint p; 598 SkPaint p;
599 p.setColor(SK_ColorBLUE); 599 p.setColor(SK_ColorBLUE);
600 canvas->drawPaint(p); 600 canvas->drawPaint(p);
601 601
602 SkDevice testDevice(SkBitmap::kNo_Config, 10, 10); 602 SkBitmapDevice testDevice(SkBitmap::kNo_Config, 10, 10);
603 ClipCountingCanvas testCanvas(&testDevice); 603 ClipCountingCanvas testCanvas(&testDevice);
604 picture.draw(&testCanvas); 604 picture.draw(&testCanvas);
605 605
606 // Both clips should be present on playback. 606 // Both clips should be present on playback.
607 REPORTER_ASSERT(reporter, testCanvas.getClipCount() == 2); 607 REPORTER_ASSERT(reporter, testCanvas.getClipCount() == 2);
608 } 608 }
609 609
610 static void TestPicture(skiatest::Reporter* reporter) { 610 static void TestPicture(skiatest::Reporter* reporter) {
611 #ifdef SK_DEBUG 611 #ifdef SK_DEBUG
612 test_deleting_empty_playback(); 612 test_deleting_empty_playback();
613 test_serializing_empty_picture(); 613 test_serializing_empty_picture();
614 #else 614 #else
615 test_bad_bitmap(); 615 test_bad_bitmap();
616 #endif 616 #endif
617 test_peephole(); 617 test_peephole();
618 test_gatherpixelrefs(reporter); 618 test_gatherpixelrefs(reporter);
619 test_bitmap_with_encoded_data(reporter); 619 test_bitmap_with_encoded_data(reporter);
620 test_clone_empty(reporter); 620 test_clone_empty(reporter);
621 test_clip_bound_opt(reporter); 621 test_clip_bound_opt(reporter);
622 test_clip_expansion(reporter); 622 test_clip_expansion(reporter);
623 } 623 }
624 624
625 #include "TestClassDef.h" 625 #include "TestClassDef.h"
626 DEFINE_TESTCLASS("Pictures", PictureTestClass, TestPicture) 626 DEFINE_TESTCLASS("Pictures", PictureTestClass, TestPicture)
OLDNEW
« no previous file with comments | « tests/LayerDrawLooperTest.cpp ('k') | tests/PremulAlphaRoundTripTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698