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" |
11 #include "SkRRect.h" | 11 #include "SkRRect.h" |
12 #include "SkSurface.h" | 12 #include "SkSurface.h" |
13 #include "SkUtils.h" | 13 #include "SkUtils.h" |
14 #include "Test.h" | 14 #include "Test.h" |
15 | 15 |
16 #if SK_SUPPORT_GPU | 16 #if SK_SUPPORT_GPU |
17 #include "GrContextFactory.h" | 17 #include "GrContextFactory.h" |
18 #else | 18 #else |
19 class GrContextFactory; | 19 class GrContextFactory; |
20 class GrContext; | 20 class GrContext; |
21 #endif | 21 #endif |
22 | 22 |
23 enum SurfaceType { | 23 enum SurfaceType { |
24 kRaster_SurfaceType, | 24 kRaster_SurfaceType, |
25 kRasterDirect_SurfaceType, | 25 kRasterDirect_SurfaceType, |
26 kGpu_SurfaceType, | 26 kGpu_SurfaceType, |
27 kGpuScratch_SurfaceType, | 27 kGpuScratch_SurfaceType, |
28 kPicture_SurfaceType | |
29 }; | 28 }; |
30 | 29 |
31 static const int gSurfaceSize = 10; | 30 static const int gSurfaceSize = 10; |
32 static SkPMColor gSurfaceStorage[gSurfaceSize * gSurfaceSize]; | 31 static SkPMColor gSurfaceStorage[gSurfaceSize * gSurfaceSize]; |
33 | 32 |
34 static SkSurface* createSurface(SurfaceType surfaceType, GrContext* context, | 33 static SkSurface* createSurface(SurfaceType surfaceType, GrContext* context, |
35 SkImageInfo* requestedInfo = NULL) { | 34 SkImageInfo* requestedInfo = NULL) { |
36 static const SkImageInfo info = SkImageInfo::MakeN32Premul(gSurfaceSize, | 35 static const SkImageInfo info = SkImageInfo::MakeN32Premul(gSurfaceSize, |
37 gSurfaceSize); | 36 gSurfaceSize); |
38 | 37 |
(...skipping 10 matching lines...) Expand all Loading... |
49 case kGpu_SurfaceType: | 48 case kGpu_SurfaceType: |
50 #if SK_SUPPORT_GPU | 49 #if SK_SUPPORT_GPU |
51 return context ? SkSurface::NewRenderTarget(context, info) : NULL; | 50 return context ? SkSurface::NewRenderTarget(context, info) : NULL; |
52 #endif | 51 #endif |
53 break; | 52 break; |
54 case kGpuScratch_SurfaceType: | 53 case kGpuScratch_SurfaceType: |
55 #if SK_SUPPORT_GPU | 54 #if SK_SUPPORT_GPU |
56 return context ? SkSurface::NewScratchRenderTarget(context, info) :
NULL; | 55 return context ? SkSurface::NewScratchRenderTarget(context, info) :
NULL; |
57 #endif | 56 #endif |
58 break; | 57 break; |
59 case kPicture_SurfaceType: | |
60 return SkSurface::NewPicture(info.fWidth, info.fHeight); | |
61 } | 58 } |
62 return NULL; | 59 return NULL; |
63 } | 60 } |
64 | 61 |
65 enum ImageType { | 62 enum ImageType { |
66 kRasterCopy_ImageType, | 63 kRasterCopy_ImageType, |
67 kRasterData_ImageType, | 64 kRasterData_ImageType, |
68 kGpu_ImageType, | 65 kGpu_ImageType, |
69 kPicture_ImageType, | |
70 kCodec_ImageType, | 66 kCodec_ImageType, |
71 }; | 67 }; |
72 | 68 |
73 static void test_image(skiatest::Reporter* reporter) { | 69 static void test_image(skiatest::Reporter* reporter) { |
74 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); | 70 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); |
75 size_t rowBytes = info.minRowBytes(); | 71 size_t rowBytes = info.minRowBytes(); |
76 size_t size = info.getSafeSize(rowBytes); | 72 size_t size = info.getSafeSize(rowBytes); |
77 void* addr = sk_malloc_throw(size); | 73 void* addr = sk_malloc_throw(size); |
78 SkData* data = SkData::NewFromMalloc(addr, size); | 74 SkData* data = SkData::NewFromMalloc(addr, size); |
79 | 75 |
(...skipping 16 matching lines...) Expand all Loading... |
96 sk_memset32((SkPMColor*)addr, pmcolor, SkToInt(size >> 2)); | 92 sk_memset32((SkPMColor*)addr, pmcolor, SkToInt(size >> 2)); |
97 SkAutoTUnref<SkData> data(SkData::NewFromMalloc(addr, size)); | 93 SkAutoTUnref<SkData> data(SkData::NewFromMalloc(addr, size)); |
98 | 94 |
99 switch (imageType) { | 95 switch (imageType) { |
100 case kRasterCopy_ImageType: | 96 case kRasterCopy_ImageType: |
101 return SkImage::NewRasterCopy(info, addr, rowBytes); | 97 return SkImage::NewRasterCopy(info, addr, rowBytes); |
102 case kRasterData_ImageType: | 98 case kRasterData_ImageType: |
103 return SkImage::NewRasterData(info, data, rowBytes); | 99 return SkImage::NewRasterData(info, data, rowBytes); |
104 case kGpu_ImageType: | 100 case kGpu_ImageType: |
105 return NULL; // TODO | 101 return NULL; // TODO |
106 case kPicture_ImageType: { | |
107 SkAutoTUnref<SkSurface> surf(SkSurface::NewPicture(info.fWidth, | |
108 info.fHeight)); | |
109 surf->getCanvas()->drawColor(SK_ColorRED); | |
110 return surf->newImageSnapshot(); | |
111 } | |
112 case kCodec_ImageType: { | 102 case kCodec_ImageType: { |
113 SkBitmap bitmap; | 103 SkBitmap bitmap; |
114 bitmap.installPixels(info, addr, rowBytes, NULL, NULL); | 104 bitmap.installPixels(info, addr, rowBytes, NULL, NULL); |
115 SkAutoTUnref<SkData> src( | 105 SkAutoTUnref<SkData> src( |
116 SkImageEncoder::EncodeData(bitmap, SkImageEncoder::kPNG_Type, | 106 SkImageEncoder::EncodeData(bitmap, SkImageEncoder::kPNG_Type, |
117 100)); | 107 100)); |
118 return SkImage::NewEncodedData(src); | 108 return SkImage::NewEncodedData(src); |
119 } | 109 } |
120 } | 110 } |
121 SkASSERT(false); | 111 SkASSERT(false); |
122 return NULL; | 112 return NULL; |
123 } | 113 } |
124 | 114 |
125 static void test_imagepeek(skiatest::Reporter* reporter) { | 115 static void test_imagepeek(skiatest::Reporter* reporter) { |
126 static const struct { | 116 static const struct { |
127 ImageType fType; | 117 ImageType fType; |
128 bool fPeekShouldSucceed; | 118 bool fPeekShouldSucceed; |
129 } gRec[] = { | 119 } gRec[] = { |
130 { kRasterCopy_ImageType, true }, | 120 { kRasterCopy_ImageType, true }, |
131 { kRasterData_ImageType, true }, | 121 { kRasterData_ImageType, true }, |
132 { kGpu_ImageType, false }, | 122 { kGpu_ImageType, false }, |
133 { kPicture_ImageType, false }, | |
134 { kCodec_ImageType, false }, | 123 { kCodec_ImageType, false }, |
135 }; | 124 }; |
136 | 125 |
137 const SkColor color = SK_ColorRED; | 126 const SkColor color = SK_ColorRED; |
138 const SkPMColor pmcolor = SkPreMultiplyColor(color); | 127 const SkPMColor pmcolor = SkPreMultiplyColor(color); |
139 | 128 |
140 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { | 129 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
141 SkImageInfo info; | 130 SkImageInfo info; |
142 size_t rowBytes; | 131 size_t rowBytes; |
143 | 132 |
(...skipping 21 matching lines...) Expand all Loading... |
165 static const struct { | 154 static const struct { |
166 SurfaceType fType; | 155 SurfaceType fType; |
167 bool fPeekShouldSucceed; | 156 bool fPeekShouldSucceed; |
168 } gRec[] = { | 157 } gRec[] = { |
169 { kRaster_SurfaceType, true }, | 158 { kRaster_SurfaceType, true }, |
170 { kRasterDirect_SurfaceType, true }, | 159 { kRasterDirect_SurfaceType, true }, |
171 #if SK_SUPPORT_GPU | 160 #if SK_SUPPORT_GPU |
172 { kGpu_SurfaceType, false }, | 161 { kGpu_SurfaceType, false }, |
173 { kGpuScratch_SurfaceType, false }, | 162 { kGpuScratch_SurfaceType, false }, |
174 #endif | 163 #endif |
175 { kPicture_SurfaceType, false }, | |
176 }; | 164 }; |
177 | 165 |
178 const SkColor color = SK_ColorRED; | 166 const SkColor color = SK_ColorRED; |
179 const SkPMColor pmcolor = SkPreMultiplyColor(color); | 167 const SkPMColor pmcolor = SkPreMultiplyColor(color); |
180 | 168 |
181 GrContext* context = NULL; | 169 GrContext* context = NULL; |
182 #if SK_SUPPORT_GPU | 170 #if SK_SUPPORT_GPU |
183 context = factory->get(GrContextFactory::kNative_GLContextType); | 171 context = factory->get(GrContextFactory::kNative_GLContextType); |
184 #endif | 172 #endif |
185 | 173 |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 SkDEBUGCODE(surface->validate();) | 402 SkDEBUGCODE(surface->validate();) |
415 REPORTER_ASSERT(reporter, image1 != image2); | 403 REPORTER_ASSERT(reporter, image1 != image2); |
416 } | 404 } |
417 | 405 |
418 } | 406 } |
419 | 407 |
420 DEF_GPUTEST(Surface, reporter, factory) { | 408 DEF_GPUTEST(Surface, reporter, factory) { |
421 test_image(reporter); | 409 test_image(reporter); |
422 | 410 |
423 TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL); | 411 TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL); |
424 TestSurfaceCopyOnWrite(reporter, kPicture_SurfaceType, NULL); | |
425 TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL)
; | 412 TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL)
; |
426 TestSurfaceWritableAfterSnapshotRelease(reporter, kPicture_SurfaceType, NULL
); | |
427 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kDiscard
_ContentChangeMode); | 413 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kDiscard
_ContentChangeMode); |
428 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_
ContentChangeMode); | 414 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_
ContentChangeMode); |
429 | 415 |
430 test_imagepeek(reporter); | 416 test_imagepeek(reporter); |
431 test_canvaspeek(reporter, factory); | 417 test_canvaspeek(reporter, factory); |
432 | 418 |
433 #if SK_SUPPORT_GPU | 419 #if SK_SUPPORT_GPU |
434 TestGetTexture(reporter, kRaster_SurfaceType, NULL); | 420 TestGetTexture(reporter, kRaster_SurfaceType, NULL); |
435 TestGetTexture(reporter, kPicture_SurfaceType, NULL); | |
436 if (NULL != factory) { | 421 if (NULL != factory) { |
437 GrContext* context = factory->get(GrContextFactory::kNative_GLContextTyp
e); | 422 GrContext* context = factory->get(GrContextFactory::kNative_GLContextTyp
e); |
438 if (NULL != context) { | 423 if (NULL != context) { |
439 TestSurfaceInCache(reporter, kGpu_SurfaceType, context); | 424 TestSurfaceInCache(reporter, kGpu_SurfaceType, context); |
440 TestSurfaceInCache(reporter, kGpuScratch_SurfaceType, context); | 425 TestSurfaceInCache(reporter, kGpuScratch_SurfaceType, context); |
441 Test_crbug263329(reporter, kGpu_SurfaceType, context); | 426 Test_crbug263329(reporter, kGpu_SurfaceType, context); |
442 Test_crbug263329(reporter, kGpuScratch_SurfaceType, context); | 427 Test_crbug263329(reporter, kGpuScratch_SurfaceType, context); |
443 TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context); | 428 TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context); |
444 TestSurfaceCopyOnWrite(reporter, kGpuScratch_SurfaceType, context); | 429 TestSurfaceCopyOnWrite(reporter, kGpuScratch_SurfaceType, context); |
445 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceType,
context); | 430 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceType,
context); |
446 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpuScratch_Surfac
eType, context); | 431 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpuScratch_Surfac
eType, context); |
447 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::
kDiscard_ContentChangeMode); | 432 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::
kDiscard_ContentChangeMode); |
448 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSu
rface::kDiscard_ContentChangeMode); | 433 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSu
rface::kDiscard_ContentChangeMode); |
449 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::
kRetain_ContentChangeMode); | 434 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::
kRetain_ContentChangeMode); |
450 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSu
rface::kRetain_ContentChangeMode); | 435 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSu
rface::kRetain_ContentChangeMode); |
451 TestGetTexture(reporter, kGpu_SurfaceType, context); | 436 TestGetTexture(reporter, kGpu_SurfaceType, context); |
452 TestGetTexture(reporter, kGpuScratch_SurfaceType, context); | 437 TestGetTexture(reporter, kGpuScratch_SurfaceType, context); |
453 } | 438 } |
454 } | 439 } |
455 #endif | 440 #endif |
456 } | 441 } |
OLD | NEW |