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 "SkDecodingImageGenerator.h" | 10 #include "SkDecodingImageGenerator.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 return NULL; | 64 return NULL; |
65 } | 65 } |
66 | 66 |
67 enum ImageType { | 67 enum ImageType { |
68 kRasterCopy_ImageType, | 68 kRasterCopy_ImageType, |
69 kRasterData_ImageType, | 69 kRasterData_ImageType, |
70 kGpu_ImageType, | 70 kGpu_ImageType, |
71 kCodec_ImageType, | 71 kCodec_ImageType, |
72 }; | 72 }; |
73 | 73 |
| 74 #include "SkImageGenerator.h" |
| 75 |
| 76 class EmptyGenerator : public SkImageGenerator { |
| 77 protected: |
| 78 bool onGetInfo(SkImageInfo* info) SK_OVERRIDE { |
| 79 *info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_SkAlphaType); |
| 80 return true; |
| 81 } |
| 82 }; |
| 83 |
| 84 static void test_empty_image(skiatest::Reporter* reporter) { |
| 85 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S
kAlphaType); |
| 86 |
| 87 REPORTER_ASSERT(reporter, NULL == SkImage::NewRasterCopy(info, NULL, 0)); |
| 88 REPORTER_ASSERT(reporter, NULL == SkImage::NewRasterData(info, NULL, 0)); |
| 89 REPORTER_ASSERT(reporter, NULL == SkImage::NewFromGenerator(SkNEW(EmptyGener
ator))); |
| 90 } |
| 91 |
| 92 static void test_empty_surface(skiatest::Reporter* reporter, GrContext* ctx) { |
| 93 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S
kAlphaType); |
| 94 |
| 95 REPORTER_ASSERT(reporter, NULL == SkSurface::NewRaster(info)); |
| 96 REPORTER_ASSERT(reporter, NULL == SkSurface::NewRasterDirect(info, NULL, 0))
; |
| 97 if (ctx) { |
| 98 REPORTER_ASSERT(reporter, NULL == SkSurface::NewRenderTarget(ctx, info,
0, NULL)); |
| 99 REPORTER_ASSERT(reporter, NULL == SkSurface::NewScratchRenderTarget(ctx,
info, 0, NULL)); |
| 100 } |
| 101 } |
| 102 |
74 static void test_image(skiatest::Reporter* reporter) { | 103 static void test_image(skiatest::Reporter* reporter) { |
75 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); | 104 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); |
76 size_t rowBytes = info.minRowBytes(); | 105 size_t rowBytes = info.minRowBytes(); |
77 size_t size = info.getSafeSize(rowBytes); | 106 size_t size = info.getSafeSize(rowBytes); |
78 SkData* data = SkData::NewUninitialized(size); | 107 SkData* data = SkData::NewUninitialized(size); |
79 | 108 |
80 REPORTER_ASSERT(reporter, data->unique()); | 109 REPORTER_ASSERT(reporter, data->unique()); |
81 SkImage* image = SkImage::NewRasterData(info, data, rowBytes); | 110 SkImage* image = SkImage::NewRasterData(info, data, rowBytes); |
82 REPORTER_ASSERT(reporter, !data->unique()); | 111 REPORTER_ASSERT(reporter, !data->unique()); |
83 image->unref(); | 112 image->unref(); |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 } | 497 } |
469 | 498 |
470 DEF_GPUTEST(Surface, reporter, factory) { | 499 DEF_GPUTEST(Surface, reporter, factory) { |
471 test_image(reporter); | 500 test_image(reporter); |
472 | 501 |
473 TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL); | 502 TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL); |
474 TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL)
; | 503 TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL)
; |
475 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kDiscard
_ContentChangeMode); | 504 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kDiscard
_ContentChangeMode); |
476 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_
ContentChangeMode); | 505 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_
ContentChangeMode); |
477 | 506 |
| 507 test_empty_image(reporter); |
| 508 test_empty_surface(reporter, NULL); |
| 509 |
478 test_imagepeek(reporter, factory); | 510 test_imagepeek(reporter, factory); |
479 test_canvaspeek(reporter, factory); | 511 test_canvaspeek(reporter, factory); |
480 | 512 |
481 #if SK_SUPPORT_GPU | 513 #if SK_SUPPORT_GPU |
482 TestGetTexture(reporter, kRaster_SurfaceType, NULL); | 514 TestGetTexture(reporter, kRaster_SurfaceType, NULL); |
483 if (factory) { | 515 if (factory) { |
484 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { | 516 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { |
485 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLCon
textType) i; | 517 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLCon
textType) i; |
486 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { | 518 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { |
487 continue; | 519 continue; |
488 } | 520 } |
489 GrContext* context = factory->get(glCtxType); | 521 GrContext* context = factory->get(glCtxType); |
490 if (context) { | 522 if (context) { |
491 Test_crbug263329(reporter, kGpu_SurfaceType, context); | 523 Test_crbug263329(reporter, kGpu_SurfaceType, context); |
492 Test_crbug263329(reporter, kGpuScratch_SurfaceType, context); | 524 Test_crbug263329(reporter, kGpuScratch_SurfaceType, context); |
493 TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context); | 525 TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context); |
494 TestSurfaceCopyOnWrite(reporter, kGpuScratch_SurfaceType, contex
t); | 526 TestSurfaceCopyOnWrite(reporter, kGpuScratch_SurfaceType, contex
t); |
495 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceTy
pe, context); | 527 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceTy
pe, context); |
496 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpuScratch_Su
rfaceType, context); | 528 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpuScratch_Su
rfaceType, context); |
497 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa
ce::kDiscard_ContentChangeMode); | 529 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa
ce::kDiscard_ContentChangeMode); |
498 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context,
SkSurface::kDiscard_ContentChangeMode); | 530 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context,
SkSurface::kDiscard_ContentChangeMode); |
499 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa
ce::kRetain_ContentChangeMode); | 531 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa
ce::kRetain_ContentChangeMode); |
500 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context,
SkSurface::kRetain_ContentChangeMode); | 532 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context,
SkSurface::kRetain_ContentChangeMode); |
501 TestGetTexture(reporter, kGpu_SurfaceType, context); | 533 TestGetTexture(reporter, kGpu_SurfaceType, context); |
502 TestGetTexture(reporter, kGpuScratch_SurfaceType, context); | 534 TestGetTexture(reporter, kGpuScratch_SurfaceType, context); |
| 535 test_empty_surface(reporter, context); |
503 } | 536 } |
504 } | 537 } |
505 } | 538 } |
506 #endif | 539 #endif |
507 } | 540 } |
OLD | NEW |