OLD | NEW |
---|---|
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 | 9 |
10 #include "SkPictureRecorder.h" | 10 #include "SkPictureRecorder.h" |
11 #include "SkRecord.h" | 11 #include "SkRecord.h" |
12 #include "SkRecorder.h" | 12 #include "SkRecorder.h" |
13 #include "SkRecords.h" | 13 #include "SkRecords.h" |
14 #include "SkShader.h" | 14 #include "SkShader.h" |
15 #include "SkSurface.h" | |
15 | 16 |
16 #define COUNT(T) + 1 | 17 #define COUNT(T) + 1 |
17 static const int kRecordTypes = SK_RECORD_TYPES(COUNT); | 18 static const int kRecordTypes = SK_RECORD_TYPES(COUNT); |
18 #undef COUNT | 19 #undef COUNT |
19 | 20 |
20 // Tallies the types of commands it sees into a histogram. | 21 // Tallies the types of commands it sees into a histogram. |
21 class Tally { | 22 class Tally { |
22 public: | 23 public: |
23 Tally() { sk_bzero(&fHistogram, sizeof(fHistogram)); } | 24 Tally() { sk_bzero(&fHistogram, sizeof(fHistogram)); } |
24 | 25 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 recorder.restore(); | 144 recorder.restore(); |
144 REPORTER_ASSERT(r, recorder.isDrawingToLayer()); | 145 REPORTER_ASSERT(r, recorder.isDrawingToLayer()); |
145 recorder.restore(); | 146 recorder.restore(); |
146 REPORTER_ASSERT(r, recorder.isDrawingToLayer()); | 147 REPORTER_ASSERT(r, recorder.isDrawingToLayer()); |
147 recorder.restore(); | 148 recorder.restore(); |
148 REPORTER_ASSERT(r, !recorder.isDrawingToLayer()); | 149 REPORTER_ASSERT(r, !recorder.isDrawingToLayer()); |
149 recorder.restore(); | 150 recorder.restore(); |
150 REPORTER_ASSERT(r, !recorder.isDrawingToLayer()); | 151 REPORTER_ASSERT(r, !recorder.isDrawingToLayer()); |
151 } | 152 } |
152 | 153 |
154 DEF_TEST(Recorder_drawImage_takeReference, reporter) { | |
155 | |
156 SkAutoTUnref<SkImage> image; | |
157 { | |
158 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100)); | |
159 surface->getCanvas()->clear(SK_ColorGREEN); | |
160 image.reset(surface->newImageSnapshot()); | |
161 } | |
162 { | |
163 SkRecord record; | |
164 SkRecorder recorder(&record, 100, 100); | |
165 | |
166 // DrawImage is supposed to take a reference | |
167 recorder.drawImage(image.get(), 0, 0); | |
168 REPORTER_ASSERT(reporter, !image->unique()); | |
169 | |
170 Tally tally; | |
171 tally.apply(record); | |
172 | |
173 REPORTER_ASSERT(reporter, 1 == tally.count<SkRecords::DrawImage>()); | |
174 } | |
175 | |
176 // The SkImage should be unique | |
mtklein
2014/09/30 14:42:21
This comment and its friend below say exactly what
Rémi Piotaix
2014/09/30 15:48:09
Done.
| |
177 REPORTER_ASSERT(reporter, image->unique()); | |
178 { | |
179 SkRecord record; | |
180 SkRecorder recorder(&record, 100, 100); | |
181 | |
182 // DrawImageRect is supposed to take a reference | |
183 recorder.drawImageRect(image.get(), 0, SkRect::MakeWH(100, 100)); | |
184 REPORTER_ASSERT(reporter, !image->unique()); | |
185 | |
186 Tally tally; | |
187 tally.apply(record); | |
188 | |
189 REPORTER_ASSERT(reporter, 1 == tally.count<SkRecords::DrawImageRect>()); | |
190 } | |
191 // The SkImage should be unique | |
192 REPORTER_ASSERT(reporter, image->unique()); | |
193 } | |
OLD | NEW |