OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkRRect.h" | 9 #include "SkRRect.h" |
10 #include "SkSurface.h" | 10 #include "SkSurface.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 // This test succeeds by not triggering an assertion. | 139 // This test succeeds by not triggering an assertion. |
140 // The test verifies that the surface remains writable (usable) after | 140 // The test verifies that the surface remains writable (usable) after |
141 // acquiring and releasing a snapshot without triggering a copy on write. | 141 // acquiring and releasing a snapshot without triggering a copy on write. |
142 SkSurface* surface = createSurface(surfaceType, context); | 142 SkSurface* surface = createSurface(surfaceType, context); |
143 SkAutoTUnref<SkSurface> aur_surface(surface); | 143 SkAutoTUnref<SkSurface> aur_surface(surface); |
144 SkCanvas* canvas = surface->getCanvas(); | 144 SkCanvas* canvas = surface->getCanvas(); |
145 canvas->clear(1); | 145 canvas->clear(1); |
146 surface->newImageSnapshot()->unref(); // Create and destroy SkImage | 146 surface->newImageSnapshot()->unref(); // Create and destroy SkImage |
147 canvas->clear(2); | 147 canvas->clear(2); |
148 } | 148 } |
| 149 |
| 150 static void TestGetTexture(skiatest::Reporter* reporter, |
| 151 SurfaceType surfaceType, |
| 152 GrContext* context) { |
| 153 SkAutoTUnref<SkSurface> surface(createSurface(surfaceType, context)); |
| 154 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); |
| 155 GrTexture* texture = image->getTexture(); |
| 156 if (surfaceType == kGpu_SurfaceType) { |
| 157 REPORTER_ASSERT(reporter, NULL != texture); |
| 158 REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle()); |
| 159 } else { |
| 160 REPORTER_ASSERT(reporter, NULL == texture); |
| 161 } |
| 162 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); |
| 163 REPORTER_ASSERT(reporter, image->getTexture() == texture); |
| 164 } |
| 165 |
149 static void TestSurfaceNoCanvas(skiatest::Reporter* reporter, | 166 static void TestSurfaceNoCanvas(skiatest::Reporter* reporter, |
150 SurfaceType surfaceType, | 167 SurfaceType surfaceType, |
151 GrContext* context, | 168 GrContext* context, |
152 SkSurface::ContentChangeMode mode) { | 169 SkSurface::ContentChangeMode mode) { |
153 // Verifies the robustness of SkSurface for handling use cases where calls | 170 // Verifies the robustness of SkSurface for handling use cases where calls |
154 // are made before a canvas is created. | 171 // are made before a canvas is created. |
155 { | 172 { |
156 // Test passes by not asserting | 173 // Test passes by not asserting |
157 SkSurface* surface = createSurface(surfaceType, context); | 174 SkSurface* surface = createSurface(surfaceType, context); |
158 SkAutoTUnref<SkSurface> aur_surface(surface); | 175 SkAutoTUnref<SkSurface> aur_surface(surface); |
(...skipping 19 matching lines...) Expand all Loading... |
178 | 195 |
179 } | 196 } |
180 | 197 |
181 static void TestSurface(skiatest::Reporter* reporter, GrContextFactory* factory)
{ | 198 static void TestSurface(skiatest::Reporter* reporter, GrContextFactory* factory)
{ |
182 TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL); | 199 TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL); |
183 TestSurfaceCopyOnWrite(reporter, kPicture_SurfaceType, NULL); | 200 TestSurfaceCopyOnWrite(reporter, kPicture_SurfaceType, NULL); |
184 TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL)
; | 201 TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL)
; |
185 TestSurfaceWritableAfterSnapshotRelease(reporter, kPicture_SurfaceType, NULL
); | 202 TestSurfaceWritableAfterSnapshotRelease(reporter, kPicture_SurfaceType, NULL
); |
186 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kDiscard
_ContentChangeMode); | 203 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kDiscard
_ContentChangeMode); |
187 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_
ContentChangeMode); | 204 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_
ContentChangeMode); |
| 205 TestGetTexture(reporter, kRaster_SurfaceType, NULL); |
| 206 TestGetTexture(reporter, kPicture_SurfaceType, NULL); |
188 #if SK_SUPPORT_GPU | 207 #if SK_SUPPORT_GPU |
189 if (NULL != factory) { | 208 if (NULL != factory) { |
190 GrContext* context = factory->get(GrContextFactory::kNative_GLContextTyp
e); | 209 GrContext* context = factory->get(GrContextFactory::kNative_GLContextTyp
e); |
191 TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context); | 210 TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context); |
192 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceType, cont
ext); | 211 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceType, cont
ext); |
193 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::kDis
card_ContentChangeMode); | 212 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::kDis
card_ContentChangeMode); |
194 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::kRet
ain_ContentChangeMode); | 213 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::kRet
ain_ContentChangeMode); |
| 214 TestGetTexture(reporter, kGpu_SurfaceType, context); |
195 } | 215 } |
196 #endif | 216 #endif |
197 } | 217 } |
198 | 218 |
199 #include "TestClassDef.h" | 219 #include "TestClassDef.h" |
200 DEFINE_GPUTESTCLASS("Surface", SurfaceTestClass, TestSurface) | 220 DEFINE_GPUTESTCLASS("Surface", SurfaceTestClass, TestSurface) |
OLD | NEW |