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 #if SK_SUPPORT_GPU | 10 #if SK_SUPPORT_GPU |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 SkRecord rerecord; | 83 SkRecord rerecord; |
84 SkRecorder canvas(&rerecord, kWidth, kHeight); | 84 SkRecorder canvas(&rerecord, kWidth, kHeight); |
85 | 85 |
86 GrRecordReplaceDraw(pic, &canvas, nullptr, SkMatrix::I(), nullptr/*callback*
/); | 86 GrRecordReplaceDraw(pic, &canvas, nullptr, SkMatrix::I(), nullptr/*callback*
/); |
87 | 87 |
88 // ensure rerecord is balanced (in this case by checking that the count is o
dd) | 88 // ensure rerecord is balanced (in this case by checking that the count is o
dd) |
89 REPORTER_ASSERT(r, (rerecord.count() & 1) == 1); | 89 REPORTER_ASSERT(r, (rerecord.count() & 1) == 1); |
90 } | 90 } |
91 | 91 |
92 // Test out the layer replacement functionality with and w/o a BBH | 92 // Test out the layer replacement functionality with and w/o a BBH |
93 void test_replacements(skiatest::Reporter* r, GrContext* context, bool useBBH) { | 93 void test_replacements(skiatest::Reporter* r, GrContext* context, bool doReplace
) { |
94 SkAutoTUnref<const SkPicture> pic; | 94 SkAutoTUnref<const SkPicture> pic; |
95 | 95 |
96 { | 96 { |
97 SkRTreeFactory bbhFactory; | |
98 SkPictureRecorder recorder; | 97 SkPictureRecorder recorder; |
99 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kWidth), SkIntT
oScalar(kHeight), | 98 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kWidth), SkIntT
oScalar(kHeight)); |
100 useBBH ? &bbhFactory : nullpt
r); | |
101 | |
102 SkPaint paint; | 99 SkPaint paint; |
103 canvas->saveLayer(nullptr, &paint); | 100 canvas->saveLayer(nullptr, &paint); |
104 canvas->clear(SK_ColorRED); | 101 canvas->clear(SK_ColorRED); |
105 canvas->restore(); | 102 canvas->restore(); |
106 canvas->drawRect(SkRect::MakeWH(SkIntToScalar(kWidth / 2), SkIntToScalar
(kHeight / 2)), | 103 canvas->drawRect(SkRect::MakeWH(SkIntToScalar(kWidth / 2), SkIntToScalar
(kHeight / 2)), |
107 SkPaint()); | 104 SkPaint()); |
108 pic.reset(recorder.endRecording()); | 105 pic.reset(recorder.endRecording()); |
109 } | 106 } |
110 | 107 |
111 int key[1] = { 0 }; | 108 SkAutoTUnref<GrTexture> texture; |
112 | |
113 SkPaint paint; | 109 SkPaint paint; |
114 GrLayerCache* layerCache = context->getLayerCache(); | 110 GrLayerCache* layerCache = context->getLayerCache(); |
115 GrCachedLayer* layer = layerCache->findLayerOrCreate(pic->uniqueID(), 0, 2, | |
116 SkIRect::MakeWH(kWidth,
kHeight), | |
117 SkIRect::MakeWH(kWidth,
kHeight), | |
118 SkMatrix::I(), key, 1,
&paint); | |
119 | 111 |
120 GrSurfaceDesc desc; | 112 if (doReplace) { |
121 desc.fConfig = kSkia8888_GrPixelConfig; | 113 int key[1] = { 0 }; |
122 desc.fFlags = kRenderTarget_GrSurfaceFlag; | |
123 desc.fWidth = kWidth; | |
124 desc.fHeight = kHeight; | |
125 desc.fSampleCnt = 0; | |
126 | 114 |
127 SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTexture(de
sc, | 115 GrCachedLayer* layer = layerCache->findLayerOrCreate(pic->uniqueID(), 0,
2, |
128 false, nullptr, 0)); | 116 SkIRect::MakeWH(kWi
dth, kHeight), |
129 layer->setTexture(texture, SkIRect::MakeWH(kWidth, kHeight)); | 117 SkIRect::MakeWH(kWi
dth, kHeight), |
| 118 SkMatrix::I(), key,
1, &paint); |
130 | 119 |
131 SkAutoTUnref<SkBBoxHierarchy> bbh; | 120 GrSurfaceDesc desc; |
| 121 desc.fConfig = kSkia8888_GrPixelConfig; |
| 122 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 123 desc.fWidth = kWidth; |
| 124 desc.fHeight = kHeight; |
| 125 desc.fSampleCnt = 0; |
| 126 |
| 127 texture.reset(context->textureProvider()->createTexture(desc, false, nul
lptr, 0)); |
| 128 layer->setTexture(texture, SkIRect::MakeWH(kWidth, kHeight)); |
| 129 } |
132 | 130 |
133 SkRecord rerecord; | 131 SkRecord rerecord; |
134 SkRecorder canvas(&rerecord, kWidth, kHeight); | 132 SkRecorder canvas(&rerecord, kWidth, kHeight); |
135 GrRecordReplaceDraw(pic, &canvas, layerCache, SkMatrix::I(), nullptr/*callba
ck*/); | 133 GrRecordReplaceDraw(pic, &canvas, layerCache, SkMatrix::I(), nullptr/*callba
ck*/); |
136 | 134 |
137 int recount = rerecord.count(); | 135 int numLayers = count_instances_of_type<SkRecords::SaveLayer>(rerecord); |
138 REPORTER_ASSERT(r, 2 == recount || 4 == recount); | 136 if (doReplace) { |
139 | 137 REPORTER_ASSERT(r, 0 == numLayers); |
140 int index = 0; | 138 } else { |
141 if (4 == recount) { | 139 REPORTER_ASSERT(r, 1 == numLayers); |
142 assert_type<SkRecords::Save>(r, rerecord, 0); | |
143 index += 1; | |
144 } | |
145 assert_type<SkRecords::DrawSprite>(r, rerecord, index + 0); | |
146 assert_type<SkRecords::DrawRect>(r, rerecord, index + 1); | |
147 if (4 == recount) { | |
148 assert_type<SkRecords::Restore>(r, rerecord, 3); | |
149 } | 140 } |
150 } | 141 } |
151 | 142 |
152 DEF_GPUTEST(RecordReplaceDraw, r, factory) { | 143 DEF_GPUTEST(RecordReplaceDraw, r, factory) { |
153 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { | 144 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { |
154 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G
LContextType>(type); | 145 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G
LContextType>(type); |
155 if (!GrContextFactory::IsRenderingGLContext(glType)) { | 146 if (!GrContextFactory::IsRenderingGLContext(glType)) { |
156 continue; | 147 continue; |
157 } | 148 } |
158 GrContext* context = factory->get(glType); | 149 GrContext* context = factory->get(glType); |
159 if (nullptr == context) { | 150 if (nullptr == context) { |
160 continue; | 151 continue; |
161 } | 152 } |
162 | 153 |
| 154 test_replacements(r, context, false); |
163 test_replacements(r, context, true); | 155 test_replacements(r, context, true); |
164 test_replacements(r, context, false); | |
165 } | 156 } |
166 } | 157 } |
167 | 158 |
168 #endif | 159 #endif |
OLD | NEW |