Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(351)

Side by Side Diff: tests/SurfaceTest.cpp

Issue 789173004: fix surface test for gpu and codecs (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 SkData* data = SkData::NewUninitialized(size); 78 SkData* data = SkData::NewUninitialized(size);
79 79
80 REPORTER_ASSERT(reporter, data->unique()); 80 REPORTER_ASSERT(reporter, data->unique());
81 SkImage* image = SkImage::NewRasterData(info, data, rowBytes); 81 SkImage* image = SkImage::NewRasterData(info, data, rowBytes);
82 REPORTER_ASSERT(reporter, !data->unique()); 82 REPORTER_ASSERT(reporter, !data->unique());
83 image->unref(); 83 image->unref();
84 REPORTER_ASSERT(reporter, data->unique()); 84 REPORTER_ASSERT(reporter, data->unique());
85 data->unref(); 85 data->unref();
86 } 86 }
87 87
88 static SkImage* createImage(ImageType imageType, GrContext* context, 88 static SkImage* createImage(ImageType imageType, GrContext* context, SkColor col or) {
89 SkColor color) {
90 const SkPMColor pmcolor = SkPreMultiplyColor(color); 89 const SkPMColor pmcolor = SkPreMultiplyColor(color);
91 const SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10); 90 const SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10);
92 const size_t rowBytes = info.minRowBytes(); 91 const size_t rowBytes = info.minRowBytes();
93 const size_t size = rowBytes * info.height(); 92 const size_t size = rowBytes * info.height();
94 93
95 SkAutoTUnref<SkData> data(SkData::NewUninitialized(size)); 94 SkAutoTUnref<SkData> data(SkData::NewUninitialized(size));
96 void* addr = data->writable_data(); 95 void* addr = data->writable_data();
97 sk_memset32((SkPMColor*)addr, pmcolor, SkToInt(size >> 2)); 96 sk_memset32((SkPMColor*)addr, pmcolor, SkToInt(size >> 2));
98 97
99 switch (imageType) { 98 switch (imageType) {
100 case kRasterCopy_ImageType: 99 case kRasterCopy_ImageType:
101 return SkImage::NewRasterCopy(info, addr, rowBytes); 100 return SkImage::NewRasterCopy(info, addr, rowBytes);
102 case kRasterData_ImageType: 101 case kRasterData_ImageType:
103 return SkImage::NewRasterData(info, data, rowBytes); 102 return SkImage::NewRasterData(info, data, rowBytes);
104 case kGpu_ImageType: 103 case kGpu_ImageType: {
105 return NULL; // TODO 104 SkAutoTUnref<SkSurface> surf(SkSurface::NewRenderTarget(context, inf o, 0));
105 surf->getCanvas()->clear(color);
106 return surf->newImageSnapshot();
107 }
106 case kCodec_ImageType: { 108 case kCodec_ImageType: {
107 SkBitmap bitmap; 109 SkBitmap bitmap;
108 bitmap.installPixels(info, addr, rowBytes); 110 bitmap.installPixels(info, addr, rowBytes);
109 SkAutoTUnref<SkData> src( 111 SkAutoTUnref<SkData> src(
110 SkImageEncoder::EncodeData(bitmap, SkImageEncoder::kPNG_Type, 112 SkImageEncoder::EncodeData(bitmap, SkImageEncoder::kPNG_Type, 1 00));
111 100));
112 return SkImage::NewFromGenerator( 113 return SkImage::NewFromGenerator(
113 SkDecodingImageGenerator::Create(data, SkDecodingImageGenerator: :Options())); 114 SkDecodingImageGenerator::Create(src, SkDecodingImageGenerator:: Options()));
114 } 115 }
115 } 116 }
116 SkASSERT(false); 117 SkASSERT(false);
117 return NULL; 118 return NULL;
118 } 119 }
119 120
120 static void test_imagepeek(skiatest::Reporter* reporter) { 121 static void test_imagepeek(skiatest::Reporter* reporter, GrContextFactory* facto ry) {
121 static const struct { 122 static const struct {
122 ImageType fType; 123 ImageType fType;
123 bool fPeekShouldSucceed; 124 bool fPeekShouldSucceed;
125 const char* fName;
124 } gRec[] = { 126 } gRec[] = {
125 { kRasterCopy_ImageType, true }, 127 { kRasterCopy_ImageType, true, "RasterCopy" },
126 { kRasterData_ImageType, true }, 128 { kRasterData_ImageType, true, "RasterData" },
127 { kGpu_ImageType, false }, 129 { kGpu_ImageType, false, "Gpu" },
128 { kCodec_ImageType, false }, 130 { kCodec_ImageType, false, "Codec" },
129 }; 131 };
130 132
131 const SkColor color = SK_ColorRED; 133 const SkColor color = SK_ColorRED;
132 const SkPMColor pmcolor = SkPreMultiplyColor(color); 134 const SkPMColor pmcolor = SkPreMultiplyColor(color);
133 135
136 GrContext* ctx = NULL;
137 #if SK_SUPPORT_GPU
138 ctx = factory->get(GrContextFactory::kNative_GLContextType);
139 #endif
140
134 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { 141 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
135 SkImageInfo info; 142 SkImageInfo info;
136 size_t rowBytes; 143 size_t rowBytes;
137 144
138 SkAutoTUnref<SkImage> image(createImage(gRec[i].fType, NULL, color)); 145 SkAutoTUnref<SkImage> image(createImage(gRec[i].fType, ctx, color));
139 if (!image.get()) { 146 if (!image.get()) {
147 SkDebugf("failed to createImage[%d] %s\n", i, gRec[i].fName);
140 continue; // gpu may not be enabled 148 continue; // gpu may not be enabled
141 } 149 }
142 const void* addr = image->peekPixels(&info, &rowBytes); 150 const void* addr = image->peekPixels(&info, &rowBytes);
143 bool success = SkToBool(addr); 151 bool success = SkToBool(addr);
144 REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success); 152 REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success);
145 if (success) { 153 if (success) {
146 REPORTER_ASSERT(reporter, 10 == info.width()); 154 REPORTER_ASSERT(reporter, 10 == info.width());
147 REPORTER_ASSERT(reporter, 10 == info.height()); 155 REPORTER_ASSERT(reporter, 10 == info.height());
148 REPORTER_ASSERT(reporter, kN32_SkColorType == info.colorType()); 156 REPORTER_ASSERT(reporter, kN32_SkColorType == info.colorType());
149 REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.alphaType() || 157 REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.alphaType() ||
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 } 414 }
407 415
408 DEF_GPUTEST(Surface, reporter, factory) { 416 DEF_GPUTEST(Surface, reporter, factory) {
409 test_image(reporter); 417 test_image(reporter);
410 418
411 TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL); 419 TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL);
412 TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL) ; 420 TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL) ;
413 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kDiscard _ContentChangeMode); 421 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kDiscard _ContentChangeMode);
414 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_ ContentChangeMode); 422 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_ ContentChangeMode);
415 423
416 test_imagepeek(reporter); 424 test_imagepeek(reporter, factory);
417 test_canvaspeek(reporter, factory); 425 test_canvaspeek(reporter, factory);
418 426
419 #if SK_SUPPORT_GPU 427 #if SK_SUPPORT_GPU
420 TestGetTexture(reporter, kRaster_SurfaceType, NULL); 428 TestGetTexture(reporter, kRaster_SurfaceType, NULL);
421 if (factory) { 429 if (factory) {
422 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { 430 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) {
423 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLCon textType) i; 431 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLCon textType) i;
424 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { 432 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) {
425 continue; 433 continue;
426 } 434 }
427 GrContext* context = factory->get(glCtxType); 435 GrContext* context = factory->get(glCtxType);
428 if (context) { 436 if (context) {
429 Test_crbug263329(reporter, kGpu_SurfaceType, context); 437 Test_crbug263329(reporter, kGpu_SurfaceType, context);
430 Test_crbug263329(reporter, kGpuScratch_SurfaceType, context); 438 Test_crbug263329(reporter, kGpuScratch_SurfaceType, context);
431 TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context); 439 TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context);
432 TestSurfaceCopyOnWrite(reporter, kGpuScratch_SurfaceType, contex t); 440 TestSurfaceCopyOnWrite(reporter, kGpuScratch_SurfaceType, contex t);
433 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceTy pe, context); 441 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceTy pe, context);
434 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpuScratch_Su rfaceType, context); 442 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpuScratch_Su rfaceType, context);
435 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa ce::kDiscard_ContentChangeMode); 443 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa ce::kDiscard_ContentChangeMode);
436 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSurface::kDiscard_ContentChangeMode); 444 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSurface::kDiscard_ContentChangeMode);
437 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa ce::kRetain_ContentChangeMode); 445 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa ce::kRetain_ContentChangeMode);
438 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSurface::kRetain_ContentChangeMode); 446 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSurface::kRetain_ContentChangeMode);
439 TestGetTexture(reporter, kGpu_SurfaceType, context); 447 TestGetTexture(reporter, kGpu_SurfaceType, context);
440 TestGetTexture(reporter, kGpuScratch_SurfaceType, context); 448 TestGetTexture(reporter, kGpuScratch_SurfaceType, context);
441 } 449 }
442 } 450 }
443 } 451 }
444 #endif 452 #endif
445 } 453 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698