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<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100)); | |
157 surface->getCanvas()->clear(SK_ColorGREEN); | |
158 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); | |
159 int beginImageRefCount = image->getRefCnt(); | |
mtklein
2014/09/27 15:41:22
We generally try to avoid calling getRefCnt(). He
Rémi Piotaix
2014/09/29 17:57:55
Done.
| |
160 { | |
161 SkRecord record; | |
162 SkRecorder recorder(&record, 100, 100); | |
163 | |
164 // DrawImage is supposed to take a reference | |
165 recorder.drawImage(image.get(), 0, 0); | |
166 REPORTER_ASSERT(reporter, image->getRefCnt() == beginImageRefCount + 1); | |
167 | |
168 recorder.drawImageRect(image.get(), 0, SkRect::MakeWH(100, 100)); | |
169 REPORTER_ASSERT(reporter, image->getRefCnt() == beginImageRefCount + 2); | |
170 | |
171 Tally tally; | |
172 tally.apply(record); | |
173 | |
174 REPORTER_ASSERT(reporter, 1 == tally.count<SkRecords::DrawImage>()); | |
175 REPORTER_ASSERT(reporter, 1 == tally.count<SkRecords::DrawImageRect>()); | |
176 } | |
177 // The SkImage should have the same refCnt as before | |
178 REPORTER_ASSERT(reporter, image->getRefCnt() == beginImageRefCount); | |
179 } | |
OLD | NEW |