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

Side by Side Diff: tests/SurfaceTest.cpp

Issue 1316233002: Style Change: NULL->nullptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-27 (Thursday) 10:25:06 EDT Created 5 years, 3 months 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 | « tests/StringTest.cpp ('k') | tests/SwizzlerTest.cpp » ('j') | 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 "SkDevice.h" 10 #include "SkDevice.h"
(...skipping 23 matching lines...) Expand all
34 }; 34 };
35 static const int kSurfaceTypeCnt = kLastSurfaceType + 1; 35 static const int kSurfaceTypeCnt = kLastSurfaceType + 1;
36 36
37 static void release_storage(void* pixels, void* context) { 37 static void release_storage(void* pixels, void* context) {
38 SkASSERT(pixels == context); 38 SkASSERT(pixels == context);
39 sk_free(pixels); 39 sk_free(pixels);
40 } 40 }
41 41
42 static SkSurface* create_surface(SurfaceType surfaceType, GrContext* context, 42 static SkSurface* create_surface(SurfaceType surfaceType, GrContext* context,
43 SkAlphaType at = kPremul_SkAlphaType, 43 SkAlphaType at = kPremul_SkAlphaType,
44 SkImageInfo* requestedInfo = NULL) { 44 SkImageInfo* requestedInfo = nullptr) {
45 const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at); 45 const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at);
46 46
47 if (requestedInfo) { 47 if (requestedInfo) {
48 *requestedInfo = info; 48 *requestedInfo = info;
49 } 49 }
50 50
51 switch (surfaceType) { 51 switch (surfaceType) {
52 case kRaster_SurfaceType: 52 case kRaster_SurfaceType:
53 return SkSurface::NewRaster(info); 53 return SkSurface::NewRaster(info);
54 case kRasterDirect_SurfaceType: { 54 case kRasterDirect_SurfaceType: {
55 const size_t rowBytes = info.minRowBytes(); 55 const size_t rowBytes = info.minRowBytes();
56 void* storage = sk_malloc_throw(info.getSafeSize(rowBytes)); 56 void* storage = sk_malloc_throw(info.getSafeSize(rowBytes));
57 return SkSurface::NewRasterDirectReleaseProc(info, storage, rowBytes , 57 return SkSurface::NewRasterDirectReleaseProc(info, storage, rowBytes ,
58 release_storage, storag e); 58 release_storage, storag e);
59 } 59 }
60 case kGpu_SurfaceType: 60 case kGpu_SurfaceType:
61 return SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info, 0, NULL); 61 return SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info, 0, nullptr);
62 case kGpuScratch_SurfaceType: 62 case kGpuScratch_SurfaceType:
63 return SkSurface::NewRenderTarget(context, SkSurface::kYes_Budgeted, info, 0, NULL); 63 return SkSurface::NewRenderTarget(context, SkSurface::kYes_Budgeted, info, 0, nullptr);
64 } 64 }
65 return NULL; 65 return nullptr;
66 } 66 }
67 67
68 enum ImageType { 68 enum ImageType {
69 kRasterCopy_ImageType, 69 kRasterCopy_ImageType,
70 kRasterData_ImageType, 70 kRasterData_ImageType,
71 kRasterProc_ImageType, 71 kRasterProc_ImageType,
72 kGpu_ImageType, 72 kGpu_ImageType,
73 kCodec_ImageType, 73 kCodec_ImageType,
74 }; 74 };
75 75
76 #include "SkImageGenerator.h" 76 #include "SkImageGenerator.h"
77 77
78 class EmptyGenerator : public SkImageGenerator { 78 class EmptyGenerator : public SkImageGenerator {
79 public: 79 public:
80 EmptyGenerator() : SkImageGenerator(SkImageInfo::MakeN32Premul(0, 0)) {} 80 EmptyGenerator() : SkImageGenerator(SkImageInfo::MakeN32Premul(0, 0)) {}
81 }; 81 };
82 82
83 static void test_empty_image(skiatest::Reporter* reporter) { 83 static void test_empty_image(skiatest::Reporter* reporter) {
84 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S kAlphaType); 84 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S kAlphaType);
85 85
86 REPORTER_ASSERT(reporter, NULL == SkImage::NewRasterCopy(info, NULL, 0)); 86 REPORTER_ASSERT(reporter, nullptr == SkImage::NewRasterCopy(info, nullptr, 0 ));
87 REPORTER_ASSERT(reporter, NULL == SkImage::NewRasterData(info, NULL, 0)); 87 REPORTER_ASSERT(reporter, nullptr == SkImage::NewRasterData(info, nullptr, 0 ));
88 REPORTER_ASSERT(reporter, NULL == SkImage::NewFromRaster(info, NULL, 0, NULL , NULL)); 88 REPORTER_ASSERT(reporter, nullptr == SkImage::NewFromRaster(info, nullptr, 0 , nullptr, nullptr));
89 REPORTER_ASSERT(reporter, NULL == SkImage::NewFromGenerator(new EmptyGenerat or)); 89 REPORTER_ASSERT(reporter, nullptr == SkImage::NewFromGenerator(new EmptyGene rator));
90 } 90 }
91 91
92 static void test_empty_surface(skiatest::Reporter* reporter, GrContext* ctx) { 92 static void test_empty_surface(skiatest::Reporter* reporter, GrContext* ctx) {
93 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S kAlphaType); 93 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S kAlphaType);
94 94
95 REPORTER_ASSERT(reporter, NULL == SkSurface::NewRaster(info)); 95 REPORTER_ASSERT(reporter, nullptr == SkSurface::NewRaster(info));
96 REPORTER_ASSERT(reporter, NULL == SkSurface::NewRasterDirect(info, NULL, 0)) ; 96 REPORTER_ASSERT(reporter, nullptr == SkSurface::NewRasterDirect(info, nullpt r, 0));
97 if (ctx) { 97 if (ctx) {
98 REPORTER_ASSERT(reporter, NULL == 98 REPORTER_ASSERT(reporter, nullptr ==
99 SkSurface::NewRenderTarget(ctx, SkSurface::kNo_Budgeted, info, 0, NULL)); 99 SkSurface::NewRenderTarget(ctx, SkSurface::kNo_Budgeted, info, 0, nullptr));
100 } 100 }
101 } 101 }
102 102
103 #if SK_SUPPORT_GPU 103 #if SK_SUPPORT_GPU
104 static void test_wrapped_texture_surface(skiatest::Reporter* reporter, GrContext * ctx) { 104 static void test_wrapped_texture_surface(skiatest::Reporter* reporter, GrContext * ctx) {
105 if (NULL == ctx) { 105 if (nullptr == ctx) {
106 return; 106 return;
107 } 107 }
108 108
109 const GrGpu* gpu = ctx->getGpu(); 109 const GrGpu* gpu = ctx->getGpu();
110 if (!gpu) { 110 if (!gpu) {
111 return; 111 return;
112 } 112 }
113 113
114 // Test the wrapped factory for SkSurface by creating a backend texture and then wrap it in 114 // Test the wrapped factory for SkSurface by creating a backend texture and then wrap it in
115 // a SkSurface. 115 // a SkSurface.
116 static const int kW = 100; 116 static const int kW = 100;
117 static const int kH = 100; 117 static const int kH = 100;
118 static const uint32_t kOrigColor = 0xFFAABBCC; 118 static const uint32_t kOrigColor = 0xFFAABBCC;
119 SkAutoTArray<uint32_t> pixels(kW * kH); 119 SkAutoTArray<uint32_t> pixels(kW * kH);
120 sk_memset32(pixels.get(), kOrigColor, kW * kH); 120 sk_memset32(pixels.get(), kOrigColor, kW * kH);
121 GrBackendObject texID = gpu->createTestingOnlyBackendTexture(pixels.get(), k W, kH, 121 GrBackendObject texID = gpu->createTestingOnlyBackendTexture(pixels.get(), k W, kH,
122 kRGBA_8888_GrPi xelConfig); 122 kRGBA_8888_GrPi xelConfig);
123 123
124 GrBackendTextureDesc wrappedDesc; 124 GrBackendTextureDesc wrappedDesc;
125 wrappedDesc.fConfig = kRGBA_8888_GrPixelConfig; 125 wrappedDesc.fConfig = kRGBA_8888_GrPixelConfig;
126 wrappedDesc.fWidth = kW; 126 wrappedDesc.fWidth = kW;
127 wrappedDesc.fHeight = kH; 127 wrappedDesc.fHeight = kH;
128 wrappedDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; 128 wrappedDesc.fOrigin = kBottomLeft_GrSurfaceOrigin;
129 wrappedDesc.fSampleCnt = 0; 129 wrappedDesc.fSampleCnt = 0;
130 wrappedDesc.fFlags = kRenderTarget_GrBackendTextureFlag; 130 wrappedDesc.fFlags = kRenderTarget_GrBackendTextureFlag;
131 wrappedDesc.fTextureHandle = texID; 131 wrappedDesc.fTextureHandle = texID;
132 132
133 SkAutoTUnref<SkSurface> surface(SkSurface::NewWrappedRenderTarget(ctx, wrapp edDesc, NULL)); 133 SkAutoTUnref<SkSurface> surface(SkSurface::NewWrappedRenderTarget(ctx, wrapp edDesc, nullptr));
134 REPORTER_ASSERT(reporter, surface); 134 REPORTER_ASSERT(reporter, surface);
135 if (surface) { 135 if (surface) {
136 // Validate that we can draw to the canvas and that the original texture color is preserved 136 // Validate that we can draw to the canvas and that the original texture color is preserved
137 // in pixels that aren't rendered to via the surface. 137 // in pixels that aren't rendered to via the surface.
138 SkPaint paint; 138 SkPaint paint;
139 static const SkColor kRectColor = ~kOrigColor | 0xFF000000; 139 static const SkColor kRectColor = ~kOrigColor | 0xFF000000;
140 paint.setColor(kRectColor); 140 paint.setColor(kRectColor);
141 surface->getCanvas()->drawRect(SkRect::MakeWH(SkIntToScalar(kW), SkIntTo Scalar(kH)/2), 141 surface->getCanvas()->drawRect(SkRect::MakeWH(SkIntToScalar(kW), SkIntTo Scalar(kH)/2),
142 paint); 142 paint);
143 SkImageInfo readInfo = SkImageInfo::MakeN32Premul(kW, kH); 143 SkImageInfo readInfo = SkImageInfo::MakeN32Premul(kW, kH);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 189
190 // Want to ensure that our Release is called when the owning image is destroyed 190 // Want to ensure that our Release is called when the owning image is destroyed
191 struct ReleaseDataContext { 191 struct ReleaseDataContext {
192 skiatest::Reporter* fReporter; 192 skiatest::Reporter* fReporter;
193 SkData* fData; 193 SkData* fData;
194 194
195 static void Release(const void* pixels, void* context) { 195 static void Release(const void* pixels, void* context) {
196 ReleaseDataContext* state = (ReleaseDataContext*)context; 196 ReleaseDataContext* state = (ReleaseDataContext*)context;
197 REPORTER_ASSERT(state->fReporter, state->fData); 197 REPORTER_ASSERT(state->fReporter, state->fData);
198 state->fData->unref(); 198 state->fData->unref();
199 state->fData = NULL; 199 state->fData = nullptr;
200 } 200 }
201 }; 201 };
202 202
203 // May we (soon) eliminate the need to keep testing this, by hiding the bloody d evice! 203 // May we (soon) eliminate the need to keep testing this, by hiding the bloody d evice!
204 #include "SkDevice.h" 204 #include "SkDevice.h"
205 static uint32_t get_legacy_gen_id(SkSurface* surf) { 205 static uint32_t get_legacy_gen_id(SkSurface* surf) {
206 SkBaseDevice* device = surf->getCanvas()->getDevice_just_for_deprecated_comp atibility_testing(); 206 SkBaseDevice* device = surf->getCanvas()->getDevice_just_for_deprecated_comp atibility_testing();
207 return device->accessBitmap(false).getGenerationID(); 207 return device->accessBitmap(false).getGenerationID();
208 } 208 }
209 209
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 } 300 }
301 case kCodec_ImageType: { 301 case kCodec_ImageType: {
302 SkBitmap bitmap; 302 SkBitmap bitmap;
303 bitmap.installPixels(info, addr, rowBytes); 303 bitmap.installPixels(info, addr, rowBytes);
304 SkAutoTUnref<SkData> src( 304 SkAutoTUnref<SkData> src(
305 SkImageEncoder::EncodeData(bitmap, SkImageEncoder::kPNG_Type, 1 00)); 305 SkImageEncoder::EncodeData(bitmap, SkImageEncoder::kPNG_Type, 1 00));
306 return SkImage::NewFromEncoded(src); 306 return SkImage::NewFromEncoded(src);
307 } 307 }
308 } 308 }
309 SkASSERT(false); 309 SkASSERT(false);
310 return NULL; 310 return nullptr;
311 } 311 }
312 312
313 static void set_pixels(SkPMColor pixels[], int count, SkPMColor color) { 313 static void set_pixels(SkPMColor pixels[], int count, SkPMColor color) {
314 sk_memset32(pixels, color, count); 314 sk_memset32(pixels, color, count);
315 } 315 }
316 static bool has_pixels(const SkPMColor pixels[], int count, SkPMColor expected) { 316 static bool has_pixels(const SkPMColor pixels[], int count, SkPMColor expected) {
317 for (int i = 0; i < count; ++i) { 317 for (int i = 0; i < count; ++i) {
318 if (pixels[i] != expected) { 318 if (pixels[i] != expected) {
319 return false; 319 return false;
320 } 320 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 { kRasterCopy_ImageType, true, "RasterCopy" }, 418 { kRasterCopy_ImageType, true, "RasterCopy" },
419 { kRasterData_ImageType, true, "RasterData" }, 419 { kRasterData_ImageType, true, "RasterData" },
420 { kRasterProc_ImageType, true, "RasterProc" }, 420 { kRasterProc_ImageType, true, "RasterProc" },
421 { kGpu_ImageType, false, "Gpu" }, 421 { kGpu_ImageType, false, "Gpu" },
422 { kCodec_ImageType, false, "Codec" }, 422 { kCodec_ImageType, false, "Codec" },
423 }; 423 };
424 424
425 const SkColor color = SK_ColorRED; 425 const SkColor color = SK_ColorRED;
426 const SkPMColor pmcolor = SkPreMultiplyColor(color); 426 const SkPMColor pmcolor = SkPreMultiplyColor(color);
427 427
428 GrContext* ctx = NULL; 428 GrContext* ctx = nullptr;
429 #if SK_SUPPORT_GPU 429 #if SK_SUPPORT_GPU
430 ctx = factory->get(GrContextFactory::kNative_GLContextType); 430 ctx = factory->get(GrContextFactory::kNative_GLContextType);
431 if (NULL == ctx) { 431 if (nullptr == ctx) {
432 return; 432 return;
433 } 433 }
434 #endif 434 #endif
435 435
436 ReleaseDataContext releaseCtx; 436 ReleaseDataContext releaseCtx;
437 releaseCtx.fReporter = reporter; 437 releaseCtx.fReporter = reporter;
438 438
439 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { 439 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
440 SkImageInfo info; 440 SkImageInfo info;
441 size_t rowBytes; 441 size_t rowBytes;
442 442
443 releaseCtx.fData = NULL; 443 releaseCtx.fData = nullptr;
444 SkAutoTUnref<SkImage> image(create_image(reporter, gRec[i].fType, ctx, c olor, &releaseCtx)); 444 SkAutoTUnref<SkImage> image(create_image(reporter, gRec[i].fType, ctx, c olor, &releaseCtx));
445 if (!image.get()) { 445 if (!image.get()) {
446 SkDebugf("failed to createImage[%d] %s\n", i, gRec[i].fName); 446 SkDebugf("failed to createImage[%d] %s\n", i, gRec[i].fName);
447 continue; // gpu may not be enabled 447 continue; // gpu may not be enabled
448 } 448 }
449 if (kRasterProc_ImageType == gRec[i].fType) { 449 if (kRasterProc_ImageType == gRec[i].fType) {
450 REPORTER_ASSERT(reporter, NULL != releaseCtx.fData); // we are trac king the data 450 REPORTER_ASSERT(reporter, nullptr != releaseCtx.fData); // we are t racking the data
451 } else { 451 } else {
452 REPORTER_ASSERT(reporter, NULL == releaseCtx.fData); // we ignored the context 452 REPORTER_ASSERT(reporter, nullptr == releaseCtx.fData); // we ignor ed the context
453 } 453 }
454 454
455 test_legacy_bitmap(reporter, image); 455 test_legacy_bitmap(reporter, image);
456 456
457 const void* addr = image->peekPixels(&info, &rowBytes); 457 const void* addr = image->peekPixels(&info, &rowBytes);
458 bool success = SkToBool(addr); 458 bool success = SkToBool(addr);
459 REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success); 459 REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success);
460 if (success) { 460 if (success) {
461 REPORTER_ASSERT(reporter, 10 == info.width()); 461 REPORTER_ASSERT(reporter, 10 == info.width());
462 REPORTER_ASSERT(reporter, 10 == info.height()); 462 REPORTER_ASSERT(reporter, 10 == info.height());
463 REPORTER_ASSERT(reporter, kN32_SkColorType == info.colorType()); 463 REPORTER_ASSERT(reporter, kN32_SkColorType == info.colorType());
464 REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.alphaType() || 464 REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.alphaType() ||
465 kOpaque_SkAlphaType == info.alphaType()); 465 kOpaque_SkAlphaType == info.alphaType());
466 REPORTER_ASSERT(reporter, info.minRowBytes() <= rowBytes); 466 REPORTER_ASSERT(reporter, info.minRowBytes() <= rowBytes);
467 REPORTER_ASSERT(reporter, pmcolor == *(const SkPMColor*)addr); 467 REPORTER_ASSERT(reporter, pmcolor == *(const SkPMColor*)addr);
468 } 468 }
469 469
470 test_image_readpixels(reporter, image, pmcolor); 470 test_image_readpixels(reporter, image, pmcolor);
471 } 471 }
472 REPORTER_ASSERT(reporter, NULL == releaseCtx.fData); // we released the dat a 472 REPORTER_ASSERT(reporter, nullptr == releaseCtx.fData); // we released the data
473 } 473 }
474 474
475 static void test_canvaspeek(skiatest::Reporter* reporter, 475 static void test_canvaspeek(skiatest::Reporter* reporter,
476 GrContextFactory* factory) { 476 GrContextFactory* factory) {
477 static const struct { 477 static const struct {
478 SurfaceType fType; 478 SurfaceType fType;
479 bool fPeekShouldSucceed; 479 bool fPeekShouldSucceed;
480 } gRec[] = { 480 } gRec[] = {
481 { kRaster_SurfaceType, true }, 481 { kRaster_SurfaceType, true },
482 { kRasterDirect_SurfaceType, true }, 482 { kRasterDirect_SurfaceType, true },
483 #if SK_SUPPORT_GPU 483 #if SK_SUPPORT_GPU
484 { kGpu_SurfaceType, false }, 484 { kGpu_SurfaceType, false },
485 { kGpuScratch_SurfaceType, false }, 485 { kGpuScratch_SurfaceType, false },
486 #endif 486 #endif
487 }; 487 };
488 488
489 const SkColor color = SK_ColorRED; 489 const SkColor color = SK_ColorRED;
490 const SkPMColor pmcolor = SkPreMultiplyColor(color); 490 const SkPMColor pmcolor = SkPreMultiplyColor(color);
491 491
492 int cnt; 492 int cnt;
493 #if SK_SUPPORT_GPU 493 #if SK_SUPPORT_GPU
494 cnt = GrContextFactory::kGLContextTypeCnt; 494 cnt = GrContextFactory::kGLContextTypeCnt;
495 #else 495 #else
496 cnt = 1; 496 cnt = 1;
497 #endif 497 #endif
498 498
499 for (int i= 0; i < cnt; ++i) { 499 for (int i= 0; i < cnt; ++i) {
500 GrContext* context = NULL; 500 GrContext* context = nullptr;
501 #if SK_SUPPORT_GPU 501 #if SK_SUPPORT_GPU
502 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext Type) i; 502 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext Type) i;
503 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { 503 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) {
504 continue; 504 continue;
505 } 505 }
506 context = factory->get(glCtxType); 506 context = factory->get(glCtxType);
507 507
508 if (NULL == context) { 508 if (nullptr == context) {
509 continue; 509 continue;
510 } 510 }
511 #endif 511 #endif
512 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { 512 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
513 SkImageInfo info, requestInfo; 513 SkImageInfo info, requestInfo;
514 size_t rowBytes; 514 size_t rowBytes;
515 515
516 SkAutoTUnref<SkSurface> surface(create_surface(gRec[i].fType, contex t, 516 SkAutoTUnref<SkSurface> surface(create_surface(gRec[i].fType, contex t,
517 kPremul_SkAlphaType, &requestInfo)); 517 kPremul_SkAlphaType, &requestInfo));
518 surface->getCanvas()->clear(color); 518 surface->getCanvas()->clear(color);
519 519
520 const void* addr = surface->getCanvas()->peekPixels(&info, &rowBytes ); 520 const void* addr = surface->getCanvas()->peekPixels(&info, &rowBytes );
521 bool success = SkToBool(addr); 521 bool success = SkToBool(addr);
522 REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success); 522 REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success);
523 523
524 SkImageInfo info2; 524 SkImageInfo info2;
525 size_t rb2; 525 size_t rb2;
526 const void* addr2 = surface->peekPixels(&info2, &rb2); 526 const void* addr2 = surface->peekPixels(&info2, &rb2);
527 527
528 if (success) { 528 if (success) {
529 REPORTER_ASSERT(reporter, requestInfo == info); 529 REPORTER_ASSERT(reporter, requestInfo == info);
530 REPORTER_ASSERT(reporter, requestInfo.minRowBytes() <= rowBytes) ; 530 REPORTER_ASSERT(reporter, requestInfo.minRowBytes() <= rowBytes) ;
531 REPORTER_ASSERT(reporter, pmcolor == *(const SkPMColor*)addr); 531 REPORTER_ASSERT(reporter, pmcolor == *(const SkPMColor*)addr);
532 532
533 REPORTER_ASSERT(reporter, addr2 == addr); 533 REPORTER_ASSERT(reporter, addr2 == addr);
534 REPORTER_ASSERT(reporter, info2 == info); 534 REPORTER_ASSERT(reporter, info2 == info);
535 REPORTER_ASSERT(reporter, rb2 == rowBytes); 535 REPORTER_ASSERT(reporter, rb2 == rowBytes);
536 } else { 536 } else {
537 REPORTER_ASSERT(reporter, NULL == addr2); 537 REPORTER_ASSERT(reporter, nullptr == addr2);
538 } 538 }
539 } 539 }
540 } 540 }
541 } 541 }
542 542
543 // For compatibility with clients that still call accessBitmap(), we need to ens ure that we bump 543 // For compatibility with clients that still call accessBitmap(), we need to ens ure that we bump
544 // the bitmap's genID when we draw to it, else they won't know it has new values . When they are 544 // the bitmap's genID when we draw to it, else they won't know it has new values . When they are
545 // exclusively using surface/image, and we can hide accessBitmap from device, we can remove this 545 // exclusively using surface/image, and we can hide accessBitmap from device, we can remove this
546 // test. 546 // test.
547 static void test_accessPixels(skiatest::Reporter* reporter, GrContextFactory* fa ctory) { 547 static void test_accessPixels(skiatest::Reporter* reporter, GrContextFactory* fa ctory) {
(...skipping 10 matching lines...) Expand all
558 }; 558 };
559 559
560 int cnt; 560 int cnt;
561 #if SK_SUPPORT_GPU 561 #if SK_SUPPORT_GPU
562 cnt = GrContextFactory::kGLContextTypeCnt; 562 cnt = GrContextFactory::kGLContextTypeCnt;
563 #else 563 #else
564 cnt = 1; 564 cnt = 1;
565 #endif 565 #endif
566 566
567 for (int i= 0; i < cnt; ++i) { 567 for (int i= 0; i < cnt; ++i) {
568 GrContext* context = NULL; 568 GrContext* context = nullptr;
569 #if SK_SUPPORT_GPU 569 #if SK_SUPPORT_GPU
570 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext Type) i; 570 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext Type) i;
571 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { 571 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) {
572 continue; 572 continue;
573 } 573 }
574 context = factory->get(glCtxType); 574 context = factory->get(glCtxType);
575 575
576 if (NULL == context) { 576 if (nullptr == context) {
577 continue; 577 continue;
578 } 578 }
579 #endif 579 #endif
580 for (size_t j = 0; j < SK_ARRAY_COUNT(gRec); ++j) { 580 for (size_t j = 0; j < SK_ARRAY_COUNT(gRec); ++j) {
581 SkImageInfo info, requestInfo; 581 SkImageInfo info, requestInfo;
582 582
583 SkAutoTUnref<SkSurface> surface(create_surface(gRec[j].fType, contex t, 583 SkAutoTUnref<SkSurface> surface(create_surface(gRec[j].fType, contex t,
584 kPremul_SkAlphaType, &requestInfo)); 584 kPremul_SkAlphaType, &requestInfo));
585 SkCanvas* canvas = surface->getCanvas(); 585 SkCanvas* canvas = surface->getCanvas();
586 canvas->clear(0); 586 canvas->clear(0);
587 587
588 SkBaseDevice* device = canvas->getDevice_just_for_deprecated_compati bility_testing(); 588 SkBaseDevice* device = canvas->getDevice_just_for_deprecated_compati bility_testing();
589 SkBitmap bm = device->accessBitmap(false); 589 SkBitmap bm = device->accessBitmap(false);
590 uint32_t genID0 = bm.getGenerationID(); 590 uint32_t genID0 = bm.getGenerationID();
591 // Now we draw something, which needs to "dirty" the genID (sorta li ke copy-on-write) 591 // Now we draw something, which needs to "dirty" the genID (sorta li ke copy-on-write)
592 canvas->drawColor(SK_ColorBLUE); 592 canvas->drawColor(SK_ColorBLUE);
593 // Now check that we get a different genID 593 // Now check that we get a different genID
594 uint32_t genID1 = bm.getGenerationID(); 594 uint32_t genID1 = bm.getGenerationID();
595 REPORTER_ASSERT(reporter, genID0 != genID1); 595 REPORTER_ASSERT(reporter, genID0 != genID1);
596 } 596 }
597 } 597 }
598 } 598 }
599 599
600 static void test_snap_alphatype(skiatest::Reporter* reporter, GrContextFactory* factory) { 600 static void test_snap_alphatype(skiatest::Reporter* reporter, GrContextFactory* factory) {
601 GrContext* context = NULL; 601 GrContext* context = nullptr;
602 #if SK_SUPPORT_GPU 602 #if SK_SUPPORT_GPU
603 context = factory->get(GrContextFactory::kNative_GLContextType); 603 context = factory->get(GrContextFactory::kNative_GLContextType);
604 if (NULL == context) { 604 if (nullptr == context) {
605 return; 605 return;
606 } 606 }
607 #endif 607 #endif
608 for (int opaque = 0; opaque < 2; ++opaque) { 608 for (int opaque = 0; opaque < 2; ++opaque) {
609 SkAlphaType atype = SkToBool(opaque) ? kOpaque_SkAlphaType : kPremul_SkA lphaType; 609 SkAlphaType atype = SkToBool(opaque) ? kOpaque_SkAlphaType : kPremul_SkA lphaType;
610 for (int st = 0; st < kSurfaceTypeCnt; ++st) { 610 for (int st = 0; st < kSurfaceTypeCnt; ++st) {
611 SurfaceType stype = (SurfaceType)st; 611 SurfaceType stype = (SurfaceType)st;
612 SkAutoTUnref<SkSurface> surface(create_surface(stype, context, atype )); 612 SkAutoTUnref<SkSurface> surface(create_surface(stype, context, atype ));
613 REPORTER_ASSERT(reporter, surface); 613 REPORTER_ASSERT(reporter, surface);
614 if (surface) { 614 if (surface) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 EXPECT_COPY_ON_WRITE(clear(testColor)) 699 EXPECT_COPY_ON_WRITE(clear(testColor))
700 EXPECT_COPY_ON_WRITE(drawPaint(testPaint)) 700 EXPECT_COPY_ON_WRITE(drawPaint(testPaint))
701 EXPECT_COPY_ON_WRITE(drawPoints(SkCanvas::kPoints_PointMode, testPointCount, testPoints, \ 701 EXPECT_COPY_ON_WRITE(drawPoints(SkCanvas::kPoints_PointMode, testPointCount, testPoints, \
702 testPaint)) 702 testPaint))
703 EXPECT_COPY_ON_WRITE(drawOval(testRect, testPaint)) 703 EXPECT_COPY_ON_WRITE(drawOval(testRect, testPaint))
704 EXPECT_COPY_ON_WRITE(drawRect(testRect, testPaint)) 704 EXPECT_COPY_ON_WRITE(drawRect(testRect, testPaint))
705 EXPECT_COPY_ON_WRITE(drawRRect(testRRect, testPaint)) 705 EXPECT_COPY_ON_WRITE(drawRRect(testRRect, testPaint))
706 EXPECT_COPY_ON_WRITE(drawPath(testPath, testPaint)) 706 EXPECT_COPY_ON_WRITE(drawPath(testPath, testPaint))
707 EXPECT_COPY_ON_WRITE(drawBitmap(testBitmap, 0, 0)) 707 EXPECT_COPY_ON_WRITE(drawBitmap(testBitmap, 0, 0))
708 EXPECT_COPY_ON_WRITE(drawBitmapRect(testBitmap, testRect, nullptr)) 708 EXPECT_COPY_ON_WRITE(drawBitmapRect(testBitmap, testRect, nullptr))
709 EXPECT_COPY_ON_WRITE(drawBitmapNine(testBitmap, testIRect, testRect, NULL)) 709 EXPECT_COPY_ON_WRITE(drawBitmapNine(testBitmap, testIRect, testRect, nullptr ))
710 EXPECT_COPY_ON_WRITE(drawSprite(testBitmap, 0, 0, NULL)) 710 EXPECT_COPY_ON_WRITE(drawSprite(testBitmap, 0, 0, nullptr))
711 EXPECT_COPY_ON_WRITE(drawText(testText.c_str(), testText.size(), 0, 1, testP aint)) 711 EXPECT_COPY_ON_WRITE(drawText(testText.c_str(), testText.size(), 0, 1, testP aint))
712 EXPECT_COPY_ON_WRITE(drawPosText(testText.c_str(), testText.size(), testPoin ts2, \ 712 EXPECT_COPY_ON_WRITE(drawPosText(testText.c_str(), testText.size(), testPoin ts2, \
713 testPaint)) 713 testPaint))
714 EXPECT_COPY_ON_WRITE(drawTextOnPath(testText.c_str(), testText.size(), testP ath, NULL, \ 714 EXPECT_COPY_ON_WRITE(drawTextOnPath(testText.c_str(), testText.size(), testP ath, nullptr, \
715 testPaint)) 715 testPaint))
716 716
717 const SkSurface::BackendHandleAccess accessModes[] = { 717 const SkSurface::BackendHandleAccess accessModes[] = {
718 SkSurface::kFlushRead_BackendHandleAccess, 718 SkSurface::kFlushRead_BackendHandleAccess,
719 SkSurface::kFlushWrite_BackendHandleAccess, 719 SkSurface::kFlushWrite_BackendHandleAccess,
720 SkSurface::kDiscardWrite_BackendHandleAccess, 720 SkSurface::kDiscardWrite_BackendHandleAccess,
721 }; 721 };
722 722
723 for (auto access : accessModes) { 723 for (auto access : accessModes) {
724 test_backend_cow(reporter, surface, access, 724 test_backend_cow(reporter, surface, access,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 static void TestGetTexture(skiatest::Reporter* reporter, 789 static void TestGetTexture(skiatest::Reporter* reporter,
790 SurfaceType surfaceType, 790 SurfaceType surfaceType,
791 GrContext* context) { 791 GrContext* context) {
792 SkAutoTUnref<SkSurface> surface(create_surface(surfaceType, context)); 792 SkAutoTUnref<SkSurface> surface(create_surface(surfaceType, context));
793 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); 793 SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
794 GrTexture* texture = as_IB(image)->getTexture(); 794 GrTexture* texture = as_IB(image)->getTexture();
795 if (surfaceType == kGpu_SurfaceType || surfaceType == kGpuScratch_SurfaceTyp e) { 795 if (surfaceType == kGpu_SurfaceType || surfaceType == kGpuScratch_SurfaceTyp e) {
796 REPORTER_ASSERT(reporter, texture); 796 REPORTER_ASSERT(reporter, texture);
797 REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle()); 797 REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle());
798 } else { 798 } else {
799 REPORTER_ASSERT(reporter, NULL == texture); 799 REPORTER_ASSERT(reporter, nullptr == texture);
800 } 800 }
801 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); 801 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode);
802 REPORTER_ASSERT(reporter, as_IB(image)->getTexture() == texture); 802 REPORTER_ASSERT(reporter, as_IB(image)->getTexture() == texture);
803 } 803 }
804 804
805 #include "GrGpuResourcePriv.h" 805 #include "GrGpuResourcePriv.h"
806 #include "SkGpuDevice.h" 806 #include "SkGpuDevice.h"
807 #include "SkImage_Gpu.h" 807 #include "SkImage_Gpu.h"
808 #include "SkSurface_Gpu.h" 808 #include "SkSurface_Gpu.h"
809 809
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 SkDEBUGCODE(image2->validate();) 876 SkDEBUGCODE(image2->validate();)
877 SkDEBUGCODE(surface->validate();) 877 SkDEBUGCODE(surface->validate();)
878 REPORTER_ASSERT(reporter, image1 != image2); 878 REPORTER_ASSERT(reporter, image1 != image2);
879 } 879 }
880 880
881 } 881 }
882 882
883 DEF_GPUTEST(Surface, reporter, factory) { 883 DEF_GPUTEST(Surface, reporter, factory) {
884 test_image(reporter); 884 test_image(reporter);
885 885
886 TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL); 886 TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, nullptr);
887 TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL) ; 887 TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, nullp tr);
888 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kDiscard _ContentChangeMode); 888 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, nullptr, SkSurface::kDisc ard_ContentChangeMode);
889 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_ ContentChangeMode); 889 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, nullptr, SkSurface::kReta in_ContentChangeMode);
890 890
891 test_empty_image(reporter); 891 test_empty_image(reporter);
892 test_empty_surface(reporter, NULL); 892 test_empty_surface(reporter, nullptr);
893 893
894 test_imagepeek(reporter, factory); 894 test_imagepeek(reporter, factory);
895 test_canvaspeek(reporter, factory); 895 test_canvaspeek(reporter, factory);
896 896
897 test_accessPixels(reporter, factory); 897 test_accessPixels(reporter, factory);
898 898
899 test_snap_alphatype(reporter, factory); 899 test_snap_alphatype(reporter, factory);
900 900
901 #if SK_SUPPORT_GPU 901 #if SK_SUPPORT_GPU
902 TestGetTexture(reporter, kRaster_SurfaceType, NULL); 902 TestGetTexture(reporter, kRaster_SurfaceType, nullptr);
903 if (factory) { 903 if (factory) {
904 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { 904 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) {
905 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLCon textType) i; 905 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLCon textType) i;
906 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { 906 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) {
907 continue; 907 continue;
908 } 908 }
909 GrContext* context = factory->get(glCtxType); 909 GrContext* context = factory->get(glCtxType);
910 if (context) { 910 if (context) {
911 Test_crbug263329(reporter, kGpu_SurfaceType, context); 911 Test_crbug263329(reporter, kGpu_SurfaceType, context);
912 Test_crbug263329(reporter, kGpuScratch_SurfaceType, context); 912 Test_crbug263329(reporter, kGpuScratch_SurfaceType, context);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 SkAutoTUnref<GrTexture> tex(provider->createTexture(desc, false, storage, w * 4)); 998 SkAutoTUnref<GrTexture> tex(provider->createTexture(desc, false, storage, w * 4));
999 if (!tex) { 999 if (!tex) {
1000 REPORTER_ASSERT(reporter, false); 1000 REPORTER_ASSERT(reporter, false);
1001 return; 1001 return;
1002 } 1002 }
1003 1003
1004 GrBackendObject srcTex = tex->getTextureHandle(); 1004 GrBackendObject srcTex = tex->getTextureHandle();
1005 ReleaseTextureContext releaseCtx(reporter); 1005 ReleaseTextureContext releaseCtx(reporter);
1006 1006
1007 SkAutoTUnref<SkImage> refImg(make_desc_image(ctx, w, h, srcTex, &releaseCtx) ); 1007 SkAutoTUnref<SkImage> refImg(make_desc_image(ctx, w, h, srcTex, &releaseCtx) );
1008 SkAutoTUnref<SkImage> cpyImg(make_desc_image(ctx, w, h, srcTex, NULL)); 1008 SkAutoTUnref<SkImage> cpyImg(make_desc_image(ctx, w, h, srcTex, nullptr));
1009 1009
1010 test_image_color(reporter, refImg, expected0); 1010 test_image_color(reporter, refImg, expected0);
1011 test_image_color(reporter, cpyImg, expected0); 1011 test_image_color(reporter, cpyImg, expected0);
1012 1012
1013 // Now lets jam new colors into our "external" texture, and see if the image s notice 1013 // Now lets jam new colors into our "external" texture, and see if the image s notice
1014 const SkPMColor expected1 = SkPreMultiplyColor(SK_ColorBLUE); 1014 const SkPMColor expected1 = SkPreMultiplyColor(SK_ColorBLUE);
1015 sk_memset32(storage, expected1, w * h); 1015 sk_memset32(storage, expected1, w * h);
1016 tex->writePixels(0, 0, w, h, kSkia8888_GrPixelConfig, storage, GrContext::kF lushWrites_PixelOp); 1016 tex->writePixels(0, 0, w, h, kSkia8888_GrPixelConfig, storage, GrContext::kF lushWrites_PixelOp);
1017 1017
1018 // The cpy'd one should still see the old color 1018 // The cpy'd one should still see the old color
1019 #if 0 1019 #if 0
1020 // There is no guarantee that refImg sees the new color. We are free to have made a copy. Our 1020 // There is no guarantee that refImg sees the new color. We are free to have made a copy. Our
1021 // write pixels call violated the contract with refImg and refImg is now und efined. 1021 // write pixels call violated the contract with refImg and refImg is now und efined.
1022 test_image_color(reporter, refImg, expected1); 1022 test_image_color(reporter, refImg, expected1);
1023 #endif 1023 #endif
1024 test_image_color(reporter, cpyImg, expected0); 1024 test_image_color(reporter, cpyImg, expected0);
1025 1025
1026 // Now exercise the release proc 1026 // Now exercise the release proc
1027 REPORTER_ASSERT(reporter, !releaseCtx.fIsReleased); 1027 REPORTER_ASSERT(reporter, !releaseCtx.fIsReleased);
1028 refImg.reset(NULL); // force a release of the image 1028 refImg.reset(nullptr); // force a release of the image
1029 REPORTER_ASSERT(reporter, releaseCtx.fIsReleased); 1029 REPORTER_ASSERT(reporter, releaseCtx.fIsReleased);
1030 } 1030 }
1031 #endif 1031 #endif
OLDNEW
« no previous file with comments | « tests/StringTest.cpp ('k') | tests/SwizzlerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698