Flutter Engine
The Flutter Engine
Classes | Typedefs | Functions | Variables
CanvasTest.cpp File Reference
#include "include/core/SkBitmap.h"
#include "include/core/SkBlendMode.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkClipOp.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkColorType.h"
#include "include/core/SkDocument.h"
#include "include/core/SkImageFilter.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
#include "include/core/SkPictureRecorder.h"
#include "include/core/SkPixmap.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkRegion.h"
#include "include/core/SkSamplingOptions.h"
#include "include/core/SkScalar.h"
#include "include/core/SkShader.h"
#include "include/core/SkSize.h"
#include "include/core/SkStream.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTypes.h"
#include "include/core/SkVertices.h"
#include "include/effects/SkImageFilters.h"
#include "include/private/base/SkMalloc.h"
#include "include/private/base/SkTemplates.h"
#include "include/utils/SkNWayCanvas.h"
#include "include/utils/SkPaintFilterCanvas.h"
#include "src/core/SkBigPicture.h"
#include "src/core/SkRecord.h"
#include "src/core/SkRecords.h"
#include "src/utils/SkCanvasStack.h"
#include "tests/Test.h"
#include <cstddef>
#include <initializer_list>
#include <memory>
#include <utility>

Go to the source code of this file.

Classes

struct  ClipRectVisitor
 

Typedefs

using CanvasTest = void(*)(SkCanvas *, skiatest::Reporter *)
 

Functions

 DEF_TEST (canvas_unsorted_clip, r)
 
 DEF_TEST (canvas_clipbounds, reporter)
 
 DEF_TEST (CanvasNewRasterTest, reporter)
 
static SkPath make_path_from_rect (SkRect r)
 
static SkRegion make_region_from_irect (SkIRect r)
 
static SkBitmap make_n32_bitmap (int w, int h, SkColor c=SK_ColorWHITE)
 
 DEF_TEST (Canvas_bitmap, reporter)
 
 DEF_TEST (Canvas_SaveState, reporter)
 
 DEF_TEST (Canvas_ClipEmptyPath, reporter)
 
 DEF_TEST (PaintFilterCanvas_ConsistentState, reporter)
 
 DEF_TEST (NWayCanvas, r)
 
 DEF_TEST (CanvasStack, r)
 
static void test_cliptype (SkCanvas *canvas, skiatest::Reporter *r)
 
 DEF_TEST (CanvasClipType, r)
 
 DEF_TEST (Canvas_SaveLayerWithNullBoundsAndZeroBoundsImageFilter, r)
 
 DEF_TEST (Canvas_degenerate_dimension, reporter)
 
 DEF_TEST (Canvas_ClippedOutImageFilter, reporter)
 
 DEF_TEST (canvas_savelayer_destructor, reporter)
 
 DEF_TEST (Canvas_saveLayer_colorSpace, reporter)
 
void test_many_draws (skiatest::Reporter *reporter, SkSurface *surface)
 

Variables

static constexpr SkRect kRect = {0, 0, 2, 1}
 
static constexpr SkColor kColor = 0x01020304
 
static constexpr int kWidth = 2
 
static constexpr int kHeight = 2
 
static CanvasTest kCanvasTests []
 

Typedef Documentation

◆ CanvasTest

using CanvasTest = void (*)(SkCanvas*, skiatest::Reporter*)

Definition at line 269 of file CanvasTest.cpp.

Function Documentation

◆ DEF_TEST() [1/15]

DEF_TEST ( Canvas_bitmap  ,
reporter   
)

Definition at line 409 of file CanvasTest.cpp.

409 {
410 for (const CanvasTest& test : kCanvasTests) {
411 SkBitmap referenceStore = make_n32_bitmap(kWidth, kHeight);
412 SkCanvas referenceCanvas(referenceStore);
413 test(&referenceCanvas, reporter);
414 }
415}
static CanvasTest kCanvasTests[]
Definition: CanvasTest.cpp:271
static SkBitmap make_n32_bitmap(int w, int h, SkColor c=SK_ColorWHITE)
Definition: CanvasTest.cpp:256
void(*)(SkCanvas *, skiatest::Reporter *) CanvasTest
Definition: CanvasTest.cpp:269
static constexpr int kWidth
Definition: CanvasTest.cpp:266
static constexpr int kHeight
Definition: CanvasTest.cpp:267
#define test(name)
reporter
Definition: FontMgrTest.cpp:39

◆ DEF_TEST() [2/15]

DEF_TEST ( canvas_clipbounds  ,
reporter   
)

Definition at line 109 of file CanvasTest.cpp.

109 {
110 SkCanvas canvas(10, 10);
111 SkIRect irect, irect2;
112 SkRect rect, rect2;
113
114 irect = canvas.getDeviceClipBounds();
115 REPORTER_ASSERT(reporter, irect == SkIRect::MakeWH(10, 10));
116 REPORTER_ASSERT(reporter, canvas.getDeviceClipBounds(&irect2));
117 REPORTER_ASSERT(reporter, irect == irect2);
118
119 // local bounds are always too big today -- can we trim them?
120 rect = canvas.getLocalClipBounds();
121 REPORTER_ASSERT(reporter, rect.contains(SkRect::MakeWH(10, 10)));
122 REPORTER_ASSERT(reporter, canvas.getLocalClipBounds(&rect2));
123 REPORTER_ASSERT(reporter, rect == rect2);
124
125 canvas.clipRect(SkRect::MakeEmpty());
126
127 irect = canvas.getDeviceClipBounds();
129 REPORTER_ASSERT(reporter, !canvas.getDeviceClipBounds(&irect2));
130 REPORTER_ASSERT(reporter, irect == irect2);
131
132 rect = canvas.getLocalClipBounds();
134 REPORTER_ASSERT(reporter, !canvas.getLocalClipBounds(&rect2));
135 REPORTER_ASSERT(reporter, rect == rect2);
136
137 // Test for wacky sizes that we (historically) have guarded against
138 {
139 SkCanvas c(-10, -20);
140 REPORTER_ASSERT(reporter, c.getBaseLayerSize() == SkISize::MakeEmpty());
141
142 SkPictureRecorder().beginRecording({ 5, 5, 4, 4 });
143 }
144}
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
Definition: SkRect.h:32
static constexpr SkIRect MakeEmpty()
Definition: SkRect.h:45
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition: SkRect.h:56
static constexpr SkISize MakeEmpty()
Definition: SkSize.h:22
static constexpr SkRect MakeEmpty()
Definition: SkRect.h:595
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

◆ DEF_TEST() [3/15]

DEF_TEST ( Canvas_ClipEmptyPath  ,
reporter   
)

Definition at line 449 of file CanvasTest.cpp.

449 {
450 SkCanvas canvas(10, 10);
451 canvas.save();
452 SkPath path;
453 canvas.clipPath(path);
454 canvas.restore();
455 canvas.save();
456 path.moveTo(5, 5);
457 canvas.clipPath(path);
458 canvas.restore();
459 canvas.save();
460 path.moveTo(7, 7);
461 canvas.clipPath(path); // should not assert here
462 canvas.restore();
463}
Definition: SkPath.h:59
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57

◆ DEF_TEST() [4/15]

DEF_TEST ( Canvas_ClippedOutImageFilter  ,
reporter   
)

Definition at line 654 of file CanvasTest.cpp.

654 {
655 SkCanvas canvas(100, 100);
656
657 SkPaint p;
658 p.setColor(SK_ColorGREEN);
659 p.setImageFilter(SkImageFilters::Blur(3.0f, 3.0f, nullptr, nullptr));
660
661 SkRect blurredRect = SkRect::MakeXYWH(60, 10, 30, 30);
662
663 SkMatrix invM;
664 invM.setRotate(-45);
665 invM.mapRect(&blurredRect);
666
667 const SkRect clipRect = SkRect::MakeXYWH(0, 50, 50, 50);
668
669 canvas.clipRect(clipRect);
670
671 canvas.rotate(45);
672 const SkMatrix preCTM = canvas.getTotalMatrix();
673 canvas.drawRect(blurredRect, p);
674 const SkMatrix postCTM = canvas.getTotalMatrix();
675 REPORTER_ASSERT(reporter, preCTM == postCTM);
676}
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
static sk_sp< SkImageFilter > Blur(SkScalar sigmaX, SkScalar sigmaY, SkTileMode tileMode, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
SkMatrix & setRotate(SkScalar degrees, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:452
bool mapRect(SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Definition: SkMatrix.cpp:1141
clipRect(r.rect, r.opAA.op(), r.opAA.aa())) template<> void Draw
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659

◆ DEF_TEST() [5/15]

DEF_TEST ( Canvas_degenerate_dimension  ,
reporter   
)

Definition at line 637 of file CanvasTest.cpp.

637 {
638 // Need a paint that will sneak us past the quickReject in SkCanvas, so we can test the
639 // raster code further downstream.
642 REPORTER_ASSERT(reporter, !paint.canComputeFastBounds());
643
644 const int big = 100 * 1024; // big enough to definitely trigger tiling
645 const SkISize sizes[] {SkISize{0, big}, {big, 0}, {0, 0}};
646 for (SkISize size : sizes) {
647 SkBitmap bm;
648 bm.setInfo(SkImageInfo::MakeN32Premul(size.width(), size.height()));
649 SkCanvas canvas(bm);
650 canvas.drawRect({0, 0, 100, 90*1024}, paint);
651 }
652}
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
bool setInfo(const SkImageInfo &imageInfo, size_t rowBytes=0)
Definition: SkBitmap.cpp:114
static sk_sp< SkImageFilter > Shader(sk_sp< SkShader > shader, const CropRect &cropRect={})
const Paint & paint
Definition: color_source.cc:38
SK_API sk_sp< SkShader > Color(SkColor)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
Definition: SkSize.h:16
static SkImageInfo MakeN32Premul(int width, int height)

◆ DEF_TEST() [6/15]

DEF_TEST ( Canvas_saveLayer_colorSpace  ,
reporter   
)

Definition at line 736 of file CanvasTest.cpp.

736 {
737 SkColor pixels[1];
739 SkPixmap pm(info, pixels, sizeof(SkColor));
740
741 auto surf = SkSurfaces::WrapPixels(pm);
742 auto canvas = surf->getCanvas();
743
745 canvas->saveLayer(SkCanvas::SaveLayerRec(nullptr, nullptr, nullptr, cs.get(), 0));
747 paint.setColor(SK_ColorRED);
748 canvas->drawPaint(paint);
749 canvas->restore();
750
751 REPORTER_ASSERT(reporter, pm.getColor(0, 0) == SK_ColorBLUE);
752}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
static sk_sp< SkColorSpace > MakeSRGB()
sk_sp< SkColorSpace > makeColorSpin() const
T * get() const
Definition: SkRefCnt.h:303
SK_API sk_sp< SkSurface > WrapPixels(const SkImageInfo &imageInfo, void *pixels, size_t rowBytes, const SkSurfaceProps *surfaceProps=nullptr)
static SkImageInfo MakeN32(int width, int height, SkAlphaType at)

◆ DEF_TEST() [7/15]

DEF_TEST ( canvas_savelayer_destructor  ,
reporter   
)

Definition at line 678 of file CanvasTest.cpp.

678 {
679 // What should happen in our destructor if we have unbalanced saveLayers?
680
681 SkPMColor pixels[16];
683 SkPixmap pm(info, pixels, 4 * sizeof(SkPMColor));
684
685 // check all of the pixel values in pm
686 auto check_pixels = [&](SkColor expected) {
687 const SkPMColor pmc = SkPreMultiplyColor(expected);
688 for (int y = 0; y < pm.info().height(); ++y) {
689 for (int x = 0; x < pm.info().width(); ++x) {
690 if (*pm.addr32(x, y) != pmc) {
691 ERRORF(reporter, "check_pixels_failed");
692 return;
693 }
694 }
695 }
696 };
697
698 auto do_test = [&](int saveCount, int restoreCount) {
699 SkASSERT(restoreCount <= saveCount);
700
701 auto surf = SkSurfaces::WrapPixels(pm);
702 auto canvas = surf->getCanvas();
703
704 canvas->clear(SK_ColorRED);
706
707 for (int i = 0; i < saveCount; ++i) {
708 canvas->saveLayer(nullptr, nullptr);
709 }
710
711 canvas->clear(SK_ColorBLUE);
712 // so far, we still expect to see the red, since the blue was drawn in a layer
714
715 for (int i = 0; i < restoreCount; ++i) {
716 canvas->restore();
717 }
718 // by returning, we are implicitly deleting the surface, and its associated canvas
719 };
720
721 do_test(1, 1);
722 // since we called restore, we expect to see now see blue
724
725 // Now repeat that, but delete the canvas before we restore it
726 do_test(1, 0);
727 // We don't blit the unbalanced saveLayers, so we expect to see red (not the layer's blue)
729
730 // Finally, test with multiple unbalanced saveLayers. This led to a crash in an earlier
731 // implementation (crbug.com/1238731)
732 do_test(2, 0);
734}
bool check_pixels(skiatest::Reporter *reporter, GrDirectContext *dContext, const GrBackendTexture &tex, const SkImageInfo &info, SkColor expectedColor)
#define SkASSERT(cond)
Definition: SkAssert.h:116
SK_API SkPMColor SkPreMultiplyColor(SkColor c)
Definition: SkColor.cpp:21
uint32_t SkPMColor
Definition: SkColor.h:205
#define ERRORF(r,...)
Definition: Test.h:293
double y
double x
int32_t height
int32_t width

◆ DEF_TEST() [8/15]

DEF_TEST ( Canvas_SaveLayerWithNullBoundsAndZeroBoundsImageFilter  ,
 
)

Definition at line 625 of file CanvasTest.cpp.

625 {
626 SkCanvas canvas(10, 10);
627 SkPaint p;
628 p.setImageFilter(SkImageFilters::Empty());
629 // This should not fail any assert.
630 canvas.saveLayer(nullptr, &p);
631 REPORTER_ASSERT(r, canvas.getDeviceClipBounds().isEmpty());
632 canvas.restore();
633}
static sk_sp< SkImageFilter > Empty()

◆ DEF_TEST() [9/15]

DEF_TEST ( Canvas_SaveState  ,
reporter   
)

Definition at line 431 of file CanvasTest.cpp.

431 {
432 SkCanvas canvas(10, 10);
433 REPORTER_ASSERT(reporter, 1 == canvas.getSaveCount());
434
435 int n = canvas.save();
436 REPORTER_ASSERT(reporter, 1 == n);
437 REPORTER_ASSERT(reporter, 2 == canvas.getSaveCount());
438
439 n = canvas.saveLayer(nullptr, nullptr);
440 REPORTER_ASSERT(reporter, 2 == n);
441 REPORTER_ASSERT(reporter, 3 == canvas.getSaveCount());
442
443 canvas.restore();
444 REPORTER_ASSERT(reporter, 2 == canvas.getSaveCount());
445 canvas.restore();
446 REPORTER_ASSERT(reporter, 1 == canvas.getSaveCount());
447}

◆ DEF_TEST() [10/15]

DEF_TEST ( canvas_unsorted_clip  ,
 
)

Definition at line 87 of file CanvasTest.cpp.

87 {
88 // Test that sorted and unsorted clip rects are forwarded
89 // to picture subclasses and/or devices sorted.
90 //
91 // We can't just test this with an SkCanvas on stack and
92 // SkCanvas::getLocalClipBounds(), as that only tests the raster device,
93 // which sorts these rects itself.
94 for (SkRect clip : {SkRect{0,0,5,5}, SkRect{5,5,0,0}}) {
96 rec.beginRecording({0,0,10,10})
97 ->clipRect(clip);
99
100 auto bp = (const SkBigPicture*)pic.get();
101 const SkRecord* record = bp->record();
102
103 REPORTER_ASSERT(r, record->count() == 1);
104 REPORTER_ASSERT(r, record->visit(0, ClipRectVisitor{r})
105 .isSorted());
106 }
107}
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
sk_sp< SkPicture > finishRecordingAsPicture()
auto visit(int i, F &&f) const -> decltype(f(SkRecords::NoOp()))
Definition: SkRecord.h:45
int count() const
Definition: SkRecord.h:38

◆ DEF_TEST() [11/15]

DEF_TEST ( CanvasClipType  ,
 
)

Definition at line 592 of file CanvasTest.cpp.

592 {
593 // test rasterclip backend
595
596#ifdef SK_SUPPORT_PDF
597 // test clipstack backend
599 if (auto doc = SkPDF::MakeDocument(&stream)) {
600 test_cliptype(doc->beginPage(100, 100), r);
601 }
602#endif
603}
static void test_cliptype(SkCanvas *canvas, skiatest::Reporter *r)
Definition: CanvasTest.cpp:566
SK_API sk_sp< SkDocument > MakeDocument(SkWStream *stream, const Metadata &metadata)
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)

◆ DEF_TEST() [12/15]

DEF_TEST ( CanvasNewRasterTest  ,
reporter   
)

Definition at line 199 of file CanvasTest.cpp.

199 {
201 const size_t minRowBytes = info.minRowBytes();
202 const size_t size = info.computeByteSize(minRowBytes);
204 SkPMColor* baseAddr = storage.get();
205 sk_bzero(baseAddr, size);
206
207 std::unique_ptr<SkCanvas> canvas = SkCanvas::MakeRasterDirect(info, baseAddr, minRowBytes);
208 REPORTER_ASSERT(reporter, canvas);
209
210 SkPixmap pmap;
211 const SkPMColor* addr = canvas->peekPixels(&pmap) ? pmap.addr32() : nullptr;
213 REPORTER_ASSERT(reporter, info == pmap.info());
214 REPORTER_ASSERT(reporter, minRowBytes == pmap.rowBytes());
215 for (int y = 0; y < info.height(); ++y) {
216 for (int x = 0; x < info.width(); ++x) {
218 }
219 addr = (const SkPMColor*)((const char*)addr + pmap.rowBytes());
220 }
221
222 // unaligned rowBytes
224 minRowBytes + 1));
225
226 // now try a deliberately bad info
227 info = info.makeWH(-1, info.height());
228 REPORTER_ASSERT(reporter, nullptr == SkCanvas::MakeRasterDirect(info, baseAddr, minRowBytes));
229
230 // too big
231 info = info.makeWH(1 << 30, 1 << 30);
232 REPORTER_ASSERT(reporter, nullptr == SkCanvas::MakeRasterDirect(info, baseAddr, minRowBytes));
233
234 // not a valid pixel type
235 info = SkImageInfo::Make(10, 10, kUnknown_SkColorType, info.alphaType());
236 REPORTER_ASSERT(reporter, nullptr == SkCanvas::MakeRasterDirect(info, baseAddr, minRowBytes));
237
238 // We should not succeed with a zero-sized valid info
240 canvas = SkCanvas::MakeRasterDirect(info, baseAddr, minRowBytes);
241 REPORTER_ASSERT(reporter, nullptr == canvas);
242}
sk_bzero(glyphs, sizeof(glyphs))
@ kUnknown_SkColorType
uninitialized
Definition: SkColorType.h:20
static std::unique_ptr< SkCanvas > MakeRasterDirect(const SkImageInfo &info, void *pixels, size_t rowBytes, const SkSurfaceProps *props=nullptr)
Definition: SkCanvas.cpp:2801
const uint32_t * addr32() const
Definition: SkPixmap.h:352
size_t rowBytes() const
Definition: SkPixmap.h:145
const SkImageInfo & info() const
Definition: SkPixmap.h:135
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ DEF_TEST() [13/15]

DEF_TEST ( CanvasStack  ,
 
)

Definition at line 545 of file CanvasTest.cpp.

545 {
546 const int w = 10;
547 const int h = 10;
548 bool life[2];
549 std::unique_ptr<SkCanvas> c0 = std::unique_ptr<SkCanvas>(new LifeLineCanvas(w, h, &life[0]));
550 std::unique_ptr<SkCanvas> c1 = std::unique_ptr<SkCanvas>(new LifeLineCanvas(w, h, &life[1]));
551 REPORTER_ASSERT(r, life[0]);
552 REPORTER_ASSERT(r, life[1]);
553
554 {
555 SkCanvasStack stack(w, h);
556 stack.pushCanvas(std::move(c0), {0,0});
557 stack.pushCanvas(std::move(c1), {0,0});
558 REPORTER_ASSERT(r, life[0]);
559 REPORTER_ASSERT(r, life[1]);
560 }
561 // Now assert that the death of the canvasstack has also killed the sub-canvases
562 REPORTER_ASSERT(r, !life[0]);
563 REPORTER_ASSERT(r, !life[1]);
564}
SkScalar w
SkScalar h

◆ DEF_TEST() [14/15]

DEF_TEST ( NWayCanvas  ,
 
)

Definition at line 516 of file CanvasTest.cpp.

516 {
517 const int w = 10;
518 const int h = 10;
519 bool life[2];
520 {
521 LifeLineCanvas c0(w, h, &life[0]);
522 REPORTER_ASSERT(r, life[0]);
523 }
524 REPORTER_ASSERT(r, !life[0]);
525
526
527 std::unique_ptr<SkCanvas> c0 = std::unique_ptr<SkCanvas>(new LifeLineCanvas(w, h, &life[0]));
528 std::unique_ptr<SkCanvas> c1 = std::unique_ptr<SkCanvas>(new LifeLineCanvas(w, h, &life[1]));
529 REPORTER_ASSERT(r, life[0]);
530 REPORTER_ASSERT(r, life[1]);
531
532 {
533 SkNWayCanvas nway(w, h);
534 nway.addCanvas(c0.get());
535 nway.addCanvas(c1.get());
536 REPORTER_ASSERT(r, life[0]);
537 REPORTER_ASSERT(r, life[1]);
538 }
539 // Now assert that the death of the nway has NOT also killed the sub-canvases
540 REPORTER_ASSERT(r, life[0]);
541 REPORTER_ASSERT(r, life[1]);
542}

◆ DEF_TEST() [15/15]

DEF_TEST ( PaintFilterCanvas_ConsistentState  ,
reporter   
)

Definition at line 481 of file CanvasTest.cpp.

481 {
482 SkCanvas canvas(100, 100);
483 canvas.clipRect(SkRect::MakeXYWH(12.7f, 12.7f, 75, 75));
484 canvas.scale(0.5f, 0.75f);
485
486 MockFilterCanvas filterCanvas(&canvas);
487 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMatrix());
488 REPORTER_ASSERT(reporter, canvas.getLocalClipBounds() == filterCanvas.getLocalClipBounds());
489
490 filterCanvas.clipRect(SkRect::MakeXYWH(30.5f, 30.7f, 100, 100));
491 filterCanvas.scale(0.75f, 0.5f);
492 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMatrix());
493 REPORTER_ASSERT(reporter, filterCanvas.getLocalClipBounds().contains(canvas.getLocalClipBounds()));
494}

◆ make_n32_bitmap()

static SkBitmap make_n32_bitmap ( int  w,
int  h,
SkColor  c = SK_ColorWHITE 
)
static

Definition at line 256 of file CanvasTest.cpp.

256 {
257 SkBitmap bm;
258 bm.allocN32Pixels(w, h);
259 bm.eraseColor(c);
260 return bm;
261}
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition: SkBitmap.cpp:232
void eraseColor(SkColor4f) const
Definition: SkBitmap.cpp:442

◆ make_path_from_rect()

static SkPath make_path_from_rect ( SkRect  r)
static

Definition at line 244 of file CanvasTest.cpp.

244 {
245 SkPath path;
246 path.addRect(r);
247 return path;
248}

◆ make_region_from_irect()

static SkRegion make_region_from_irect ( SkIRect  r)
static

Definition at line 250 of file CanvasTest.cpp.

250 {
252 region.setRect(r);
253 return region;
254}
bool setRect(const SkIRect &rect)
Definition: SkRegion.cpp:192
ClipOpAndAA opAA SkRegion region
Definition: SkRecords.h:238

◆ test_cliptype()

static void test_cliptype ( SkCanvas canvas,
skiatest::Reporter r 
)
static

Definition at line 566 of file CanvasTest.cpp.

566 {
567 REPORTER_ASSERT(r, !canvas->isClipEmpty());
568 REPORTER_ASSERT(r, canvas->isClipRect());
569
570 canvas->save();
571 canvas->clipRect({0, 0, 0, 0});
572 REPORTER_ASSERT(r, canvas->isClipEmpty());
573 REPORTER_ASSERT(r, !canvas->isClipRect());
574 canvas->restore();
575
576 canvas->save();
577 canvas->clipRect({2, 2, 6, 6});
578 REPORTER_ASSERT(r, !canvas->isClipEmpty());
579 REPORTER_ASSERT(r, canvas->isClipRect());
580 canvas->restore();
581
582 canvas->save();
583 canvas->clipRect({2, 2, 6, 6}, SkClipOp::kDifference); // punch a hole in the clip
584 REPORTER_ASSERT(r, !canvas->isClipEmpty());
585 REPORTER_ASSERT(r, !canvas->isClipRect());
586 canvas->restore();
587
588 REPORTER_ASSERT(r, !canvas->isClipEmpty());
589 REPORTER_ASSERT(r, canvas->isClipRect());
590}
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
virtual bool isClipEmpty() const
Definition: SkCanvas.cpp:1549
void restore()
Definition: SkCanvas.cpp:461
virtual bool isClipRect() const
Definition: SkCanvas.cpp:1553
int save()
Definition: SkCanvas.cpp:447

◆ test_many_draws()

void test_many_draws ( skiatest::Reporter reporter,
SkSurface surface 
)

Definition at line 756 of file CanvasTest.cpp.

756 {
757 SkCanvas* canvas = surface->getCanvas();
759 for (int i = 0; i < 10000; ++i) {
760 paint.setColor((0xFF << 24) | i);
761 canvas->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint);
762 }
763}
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
VkSurfaceKHR surface
Definition: main.cc:49

Variable Documentation

◆ kCanvasTests

CanvasTest kCanvasTests[]
static

Definition at line 271 of file CanvasTest.cpp.

◆ kColor

constexpr SkColor kColor = 0x01020304
staticconstexpr

Definition at line 265 of file CanvasTest.cpp.

◆ kHeight

constexpr int kHeight = 2
staticconstexpr

Definition at line 267 of file CanvasTest.cpp.

◆ kRect

constexpr SkRect kRect = {0, 0, 2, 1}
staticconstexpr

Definition at line 264 of file CanvasTest.cpp.

◆ kWidth

constexpr int kWidth = 2
staticconstexpr

Definition at line 266 of file CanvasTest.cpp.