OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkData.h" | 9 #include "SkData.h" |
10 #include "SkImageEncoder.h" | 10 #include "SkImageEncoder.h" |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 { kRasterDirect_SurfaceType, true }, | 163 { kRasterDirect_SurfaceType, true }, |
164 #if SK_SUPPORT_GPU | 164 #if SK_SUPPORT_GPU |
165 { kGpu_SurfaceType, false }, | 165 { kGpu_SurfaceType, false }, |
166 { kGpuScratch_SurfaceType, false }, | 166 { kGpuScratch_SurfaceType, false }, |
167 #endif | 167 #endif |
168 }; | 168 }; |
169 | 169 |
170 const SkColor color = SK_ColorRED; | 170 const SkColor color = SK_ColorRED; |
171 const SkPMColor pmcolor = SkPreMultiplyColor(color); | 171 const SkPMColor pmcolor = SkPreMultiplyColor(color); |
172 | 172 |
173 GrContext* context = NULL; | 173 int cnt; |
174 #if SK_SUPPORT_GPU | 174 #if SK_SUPPORT_GPU |
175 context = factory->get(GrContextFactory::kNative_GLContextType); | 175 cnt = GrContextFactory::kGLContextTypeCnt; |
| 176 #else |
| 177 cnt = 1; |
176 #endif | 178 #endif |
177 | 179 |
178 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { | 180 for (int i= 0; i < cnt; ++i) { |
179 SkImageInfo info, requestInfo; | 181 GrContext* context = NULL; |
180 size_t rowBytes; | 182 #if SK_SUPPORT_GPU |
| 183 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext
Type) i; |
| 184 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { |
| 185 continue; |
| 186 } |
| 187 context = factory->get(glCtxType); |
181 | 188 |
182 SkAutoTUnref<SkSurface> surface(createSurface(gRec[i].fType, context, | 189 if (NULL == context) { |
183 &requestInfo)); | 190 continue; |
184 surface->getCanvas()->clear(color); | 191 } |
| 192 #endif |
| 193 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| 194 SkImageInfo info, requestInfo; |
| 195 size_t rowBytes; |
185 | 196 |
186 const void* addr = surface->getCanvas()->peekPixels(&info, &rowBytes); | 197 SkAutoTUnref<SkSurface> surface(createSurface(gRec[i].fType, context
, |
187 bool success = (NULL != addr); | 198 &requestInfo)); |
188 REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success); | 199 surface->getCanvas()->clear(color); |
189 | 200 |
190 SkImageInfo info2; | 201 const void* addr = surface->getCanvas()->peekPixels(&info, &rowBytes
); |
191 size_t rb2; | 202 bool success = (NULL != addr); |
192 const void* addr2 = surface->peekPixels(&info2, &rb2); | 203 REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success); |
193 | 204 |
194 if (success) { | 205 SkImageInfo info2; |
195 REPORTER_ASSERT(reporter, requestInfo == info); | 206 size_t rb2; |
196 REPORTER_ASSERT(reporter, requestInfo.minRowBytes() <= rowBytes); | 207 const void* addr2 = surface->peekPixels(&info2, &rb2); |
197 REPORTER_ASSERT(reporter, pmcolor == *(const SkPMColor*)addr); | |
198 | 208 |
199 REPORTER_ASSERT(reporter, addr2 == addr); | 209 if (success) { |
200 REPORTER_ASSERT(reporter, info2 == info); | 210 REPORTER_ASSERT(reporter, requestInfo == info); |
201 REPORTER_ASSERT(reporter, rb2 == rowBytes); | 211 REPORTER_ASSERT(reporter, requestInfo.minRowBytes() <= rowBytes)
; |
202 } else { | 212 REPORTER_ASSERT(reporter, pmcolor == *(const SkPMColor*)addr); |
203 REPORTER_ASSERT(reporter, NULL == addr2); | 213 |
| 214 REPORTER_ASSERT(reporter, addr2 == addr); |
| 215 REPORTER_ASSERT(reporter, info2 == info); |
| 216 REPORTER_ASSERT(reporter, rb2 == rowBytes); |
| 217 } else { |
| 218 REPORTER_ASSERT(reporter, NULL == addr2); |
| 219 } |
204 } | 220 } |
205 } | 221 } |
206 } | 222 } |
207 | 223 |
208 static void TestSurfaceCopyOnWrite(skiatest::Reporter* reporter, SurfaceType sur
faceType, | 224 static void TestSurfaceCopyOnWrite(skiatest::Reporter* reporter, SurfaceType sur
faceType, |
209 GrContext* context) { | 225 GrContext* context) { |
210 // Verify that the right canvas commands trigger a copy on write | 226 // Verify that the right canvas commands trigger a copy on write |
211 SkSurface* surface = createSurface(surfaceType, context); | 227 SkSurface* surface = createSurface(surfaceType, context); |
212 SkAutoTUnref<SkSurface> aur_surface(surface); | 228 SkAutoTUnref<SkSurface> aur_surface(surface); |
213 SkCanvas* canvas = surface->getCanvas(); | 229 SkCanvas* canvas = surface->getCanvas(); |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL)
; | 438 TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL)
; |
423 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kDiscard
_ContentChangeMode); | 439 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kDiscard
_ContentChangeMode); |
424 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_
ContentChangeMode); | 440 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_
ContentChangeMode); |
425 | 441 |
426 test_imagepeek(reporter); | 442 test_imagepeek(reporter); |
427 test_canvaspeek(reporter, factory); | 443 test_canvaspeek(reporter, factory); |
428 | 444 |
429 #if SK_SUPPORT_GPU | 445 #if SK_SUPPORT_GPU |
430 TestGetTexture(reporter, kRaster_SurfaceType, NULL); | 446 TestGetTexture(reporter, kRaster_SurfaceType, NULL); |
431 if (NULL != factory) { | 447 if (NULL != factory) { |
432 GrContext* context = factory->get(GrContextFactory::kNative_GLContextTyp
e); | 448 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { |
433 if (NULL != context) { | 449 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLCon
textType) i; |
434 TestSurfaceInCache(reporter, kGpu_SurfaceType, context); | 450 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { |
435 TestSurfaceInCache(reporter, kGpuScratch_SurfaceType, context); | 451 continue; |
436 Test_crbug263329(reporter, kGpu_SurfaceType, context); | 452 } |
437 Test_crbug263329(reporter, kGpuScratch_SurfaceType, context); | 453 GrContext* context = factory->get(glCtxType); |
438 TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context); | 454 if (NULL != context) { |
439 TestSurfaceCopyOnWrite(reporter, kGpuScratch_SurfaceType, context); | 455 TestSurfaceInCache(reporter, kGpu_SurfaceType, context); |
440 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceType,
context); | 456 TestSurfaceInCache(reporter, kGpuScratch_SurfaceType, context); |
441 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpuScratch_Surfac
eType, context); | 457 Test_crbug263329(reporter, kGpu_SurfaceType, context); |
442 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::
kDiscard_ContentChangeMode); | 458 Test_crbug263329(reporter, kGpuScratch_SurfaceType, context); |
443 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSu
rface::kDiscard_ContentChangeMode); | 459 TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context); |
444 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::
kRetain_ContentChangeMode); | 460 TestSurfaceCopyOnWrite(reporter, kGpuScratch_SurfaceType, contex
t); |
445 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSu
rface::kRetain_ContentChangeMode); | 461 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceTy
pe, context); |
446 TestGetTexture(reporter, kGpu_SurfaceType, context); | 462 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpuScratch_Su
rfaceType, context); |
447 TestGetTexture(reporter, kGpuScratch_SurfaceType, context); | 463 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa
ce::kDiscard_ContentChangeMode); |
| 464 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context,
SkSurface::kDiscard_ContentChangeMode); |
| 465 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa
ce::kRetain_ContentChangeMode); |
| 466 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context,
SkSurface::kRetain_ContentChangeMode); |
| 467 TestGetTexture(reporter, kGpu_SurfaceType, context); |
| 468 TestGetTexture(reporter, kGpuScratch_SurfaceType, context); |
| 469 } |
448 } | 470 } |
449 } | 471 } |
450 #endif | 472 #endif |
451 } | 473 } |
OLD | NEW |