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

Side by Side Diff: tests/LayerRasterizerTest.cpp

Issue 1821533002: guard rasterizer and drawlooper setters (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update android sdk Created 4 years, 9 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 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 "SkDeque.h" 8 #include "SkDeque.h"
9 #include "SkLayerRasterizer.h" 9 #include "SkLayerRasterizer.h"
10 #include "SkPaint.h" 10 #include "SkPaint.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 }; 42 };
43 43
44 int DummyRasterizer::gCount; 44 int DummyRasterizer::gCount;
45 45
46 SkFlattenable* DummyRasterizer::CreateProc(SkReadBuffer&) { return new DummyRast erizer; } 46 SkFlattenable* DummyRasterizer::CreateProc(SkReadBuffer&) { return new DummyRast erizer; }
47 47
48 // Check to make sure that the SkPaint in the layer has its destructor called. 48 // Check to make sure that the SkPaint in the layer has its destructor called.
49 DEF_TEST(LayerRasterizer_destructor, reporter) { 49 DEF_TEST(LayerRasterizer_destructor, reporter) {
50 { 50 {
51 SkPaint paint; 51 SkPaint paint;
52 paint.setRasterizer(new DummyRasterizer)->unref(); 52 paint.setRasterizer(sk_make_sp<DummyRasterizer>());
53 REPORTER_ASSERT(reporter, DummyRasterizer::GetCount() == 1); 53 REPORTER_ASSERT(reporter, DummyRasterizer::GetCount() == 1);
54 54
55 SkLayerRasterizer::Builder builder; 55 SkLayerRasterizer::Builder builder;
56 builder.addLayer(paint); 56 builder.addLayer(paint);
57 } 57 }
58 REPORTER_ASSERT(reporter, DummyRasterizer::GetCount() == 0); 58 REPORTER_ASSERT(reporter, DummyRasterizer::GetCount() == 0);
59 } 59 }
60 60
61 class LayerRasterizerTester { 61 class LayerRasterizerTester {
62 public: 62 public:
(...skipping 11 matching lines...) Expand all
74 SkPaint fPaint; 74 SkPaint fPaint;
75 SkVector fOffset; 75 SkVector fOffset;
76 }; 76 };
77 77
78 static bool equals(const SkLayerRasterizer_Rec& rec1, const SkLayerRasterizer_Re c& rec2) { 78 static bool equals(const SkLayerRasterizer_Rec& rec1, const SkLayerRasterizer_Re c& rec2) {
79 return rec1.fPaint == rec2.fPaint && rec1.fOffset == rec2.fOffset; 79 return rec1.fPaint == rec2.fPaint && rec1.fOffset == rec2.fOffset;
80 } 80 }
81 81
82 DEF_TEST(LayerRasterizer_copy, reporter) { 82 DEF_TEST(LayerRasterizer_copy, reporter) {
83 SkLayerRasterizer::Builder builder; 83 SkLayerRasterizer::Builder builder;
84 REPORTER_ASSERT(reporter, nullptr == builder.snapshotRasterizer()); 84 REPORTER_ASSERT(reporter, nullptr == builder.snapshot());
85 SkPaint paint; 85 SkPaint paint;
86 // Create a bunch of paints with different flags. 86 // Create a bunch of paints with different flags.
87 for (uint32_t flags = 0x01; flags < SkPaint::kAllFlags; flags <<= 1) { 87 for (uint32_t flags = 0x01; flags < SkPaint::kAllFlags; flags <<= 1) {
88 paint.setFlags(flags); 88 paint.setFlags(flags);
89 builder.addLayer(paint, static_cast<SkScalar>(flags), static_cast<SkScal ar>(flags)); 89 builder.addLayer(paint, static_cast<SkScalar>(flags), static_cast<SkScal ar>(flags));
90 } 90 }
91 91
92 // Create a layer rasterizer with all the existing layers. 92 // Create a layer rasterizer with all the existing layers.
93 SkAutoTUnref<SkLayerRasterizer> firstCopy(builder.snapshotRasterizer()); 93 sk_sp<SkLayerRasterizer> firstCopy(builder.snapshot());
94 94
95 // Add one more layer. 95 // Add one more layer.
96 paint.setFlags(SkPaint::kAllFlags); 96 paint.setFlags(SkPaint::kAllFlags);
97 builder.addLayer(paint); 97 builder.addLayer(paint);
98 98
99 SkAutoTUnref<SkLayerRasterizer> oneLarger(builder.snapshotRasterizer()); 99 sk_sp<SkLayerRasterizer> oneLarger(builder.snapshot());
100 SkAutoTUnref<SkLayerRasterizer> detached(builder.detachRasterizer()); 100 sk_sp<SkLayerRasterizer> detached(builder.detach());
101 101
102 // Check the counts for consistency. 102 // Check the counts for consistency.
103 const int largerCount = LayerRasterizerTester::CountLayers(*oneLarger.get()) ; 103 const int largerCount = LayerRasterizerTester::CountLayers(*oneLarger.get()) ;
104 const int smallerCount = LayerRasterizerTester::CountLayers(*firstCopy.get() ); 104 const int smallerCount = LayerRasterizerTester::CountLayers(*firstCopy.get() );
105 REPORTER_ASSERT(reporter, largerCount == LayerRasterizerTester::CountLayers( *detached.get())); 105 REPORTER_ASSERT(reporter, largerCount == LayerRasterizerTester::CountLayers( *detached.get()));
106 REPORTER_ASSERT(reporter, smallerCount == largerCount - 1); 106 REPORTER_ASSERT(reporter, smallerCount == largerCount - 1);
107 107
108 const SkLayerRasterizer_Rec* recFirstCopy = nullptr; 108 const SkLayerRasterizer_Rec* recFirstCopy = nullptr;
109 const SkLayerRasterizer_Rec* recOneLarger = nullptr; 109 const SkLayerRasterizer_Rec* recOneLarger = nullptr;
110 const SkLayerRasterizer_Rec* recDetached = nullptr; 110 const SkLayerRasterizer_Rec* recDetached = nullptr;
(...skipping 22 matching lines...) Expand all
133 if (smallerCount == i) { 133 if (smallerCount == i) {
134 REPORTER_ASSERT(reporter, recFirstCopy == nullptr); 134 REPORTER_ASSERT(reporter, recFirstCopy == nullptr);
135 } else { 135 } else {
136 REPORTER_ASSERT(reporter, equals(*recFirstCopy, *recOneLarger)); 136 REPORTER_ASSERT(reporter, equals(*recFirstCopy, *recOneLarger));
137 } 137 }
138 } 138 }
139 } 139 }
140 140
141 DEF_TEST(LayerRasterizer_detachEmpty, reporter) { 141 DEF_TEST(LayerRasterizer_detachEmpty, reporter) {
142 SkLayerRasterizer::Builder builder; 142 SkLayerRasterizer::Builder builder;
143 REPORTER_ASSERT(reporter, nullptr == builder.detachRasterizer()); 143 REPORTER_ASSERT(reporter, nullptr == builder.detach());
144 } 144 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698