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

Side by Side Diff: tests/SurfaceTest.cpp

Issue 544233002: "NULL !=" = NULL (Closed) Base URL: https://skia.googlesource.com/skia.git@are
Patch Set: rebase Created 6 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/SkResourceCacheTest.cpp ('k') | tests/TextBlobTest.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 "SkImageEncoder.h" 10 #include "SkImageEncoder.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 132
133 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { 133 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
134 SkImageInfo info; 134 SkImageInfo info;
135 size_t rowBytes; 135 size_t rowBytes;
136 136
137 SkAutoTUnref<SkImage> image(createImage(gRec[i].fType, NULL, color)); 137 SkAutoTUnref<SkImage> image(createImage(gRec[i].fType, NULL, color));
138 if (!image.get()) { 138 if (!image.get()) {
139 continue; // gpu may not be enabled 139 continue; // gpu may not be enabled
140 } 140 }
141 const void* addr = image->peekPixels(&info, &rowBytes); 141 const void* addr = image->peekPixels(&info, &rowBytes);
142 bool success = (NULL != addr); 142 bool success = SkToBool(addr);
143 REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success); 143 REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success);
144 if (success) { 144 if (success) {
145 REPORTER_ASSERT(reporter, 10 == info.width()); 145 REPORTER_ASSERT(reporter, 10 == info.width());
146 REPORTER_ASSERT(reporter, 10 == info.height()); 146 REPORTER_ASSERT(reporter, 10 == info.height());
147 REPORTER_ASSERT(reporter, kN32_SkColorType == info.colorType()); 147 REPORTER_ASSERT(reporter, kN32_SkColorType == info.colorType());
148 REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.alphaType() || 148 REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.alphaType() ||
149 kOpaque_SkAlphaType == info.alphaType()); 149 kOpaque_SkAlphaType == info.alphaType());
150 REPORTER_ASSERT(reporter, info.minRowBytes() <= rowBytes); 150 REPORTER_ASSERT(reporter, info.minRowBytes() <= rowBytes);
151 REPORTER_ASSERT(reporter, pmcolor == *(const SkPMColor*)addr); 151 REPORTER_ASSERT(reporter, pmcolor == *(const SkPMColor*)addr);
152 } 152 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 #endif 192 #endif
193 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { 193 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
194 SkImageInfo info, requestInfo; 194 SkImageInfo info, requestInfo;
195 size_t rowBytes; 195 size_t rowBytes;
196 196
197 SkAutoTUnref<SkSurface> surface(createSurface(gRec[i].fType, context , 197 SkAutoTUnref<SkSurface> surface(createSurface(gRec[i].fType, context ,
198 &requestInfo)); 198 &requestInfo));
199 surface->getCanvas()->clear(color); 199 surface->getCanvas()->clear(color);
200 200
201 const void* addr = surface->getCanvas()->peekPixels(&info, &rowBytes ); 201 const void* addr = surface->getCanvas()->peekPixels(&info, &rowBytes );
202 bool success = (NULL != addr); 202 bool success = SkToBool(addr);
203 REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success); 203 REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success);
204 204
205 SkImageInfo info2; 205 SkImageInfo info2;
206 size_t rb2; 206 size_t rb2;
207 const void* addr2 = surface->peekPixels(&info2, &rb2); 207 const void* addr2 = surface->peekPixels(&info2, &rb2);
208 208
209 if (success) { 209 if (success) {
210 REPORTER_ASSERT(reporter, requestInfo == info); 210 REPORTER_ASSERT(reporter, requestInfo == info);
211 REPORTER_ASSERT(reporter, requestInfo.minRowBytes() <= rowBytes) ; 211 REPORTER_ASSERT(reporter, requestInfo.minRowBytes() <= rowBytes) ;
212 REPORTER_ASSERT(reporter, pmcolor == *(const SkPMColor*)addr); 212 REPORTER_ASSERT(reporter, pmcolor == *(const SkPMColor*)addr);
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 REPORTER_ASSERT(reporter, image2->getTexture() != image1->getTexture()); 382 REPORTER_ASSERT(reporter, image2->getTexture() != image1->getTexture());
383 } 383 }
384 384
385 static void TestGetTexture(skiatest::Reporter* reporter, 385 static void TestGetTexture(skiatest::Reporter* reporter,
386 SurfaceType surfaceType, 386 SurfaceType surfaceType,
387 GrContext* context) { 387 GrContext* context) {
388 SkAutoTUnref<SkSurface> surface(createSurface(surfaceType, context)); 388 SkAutoTUnref<SkSurface> surface(createSurface(surfaceType, context));
389 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); 389 SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
390 GrTexture* texture = image->getTexture(); 390 GrTexture* texture = image->getTexture();
391 if (surfaceType == kGpu_SurfaceType || surfaceType == kGpuScratch_SurfaceTyp e) { 391 if (surfaceType == kGpu_SurfaceType || surfaceType == kGpuScratch_SurfaceTyp e) {
392 REPORTER_ASSERT(reporter, NULL != texture); 392 REPORTER_ASSERT(reporter, texture);
393 REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle()); 393 REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle());
394 } else { 394 } else {
395 REPORTER_ASSERT(reporter, NULL == texture); 395 REPORTER_ASSERT(reporter, NULL == texture);
396 } 396 }
397 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); 397 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode);
398 REPORTER_ASSERT(reporter, image->getTexture() == texture); 398 REPORTER_ASSERT(reporter, image->getTexture() == texture);
399 } 399 }
400 #endif 400 #endif
401 401
402 static void TestSurfaceNoCanvas(skiatest::Reporter* reporter, 402 static void TestSurfaceNoCanvas(skiatest::Reporter* reporter,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL); 437 TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL);
438 TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL) ; 438 TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL) ;
439 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kDiscard _ContentChangeMode); 439 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kDiscard _ContentChangeMode);
440 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_ ContentChangeMode); 440 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_ ContentChangeMode);
441 441
442 test_imagepeek(reporter); 442 test_imagepeek(reporter);
443 test_canvaspeek(reporter, factory); 443 test_canvaspeek(reporter, factory);
444 444
445 #if SK_SUPPORT_GPU 445 #if SK_SUPPORT_GPU
446 TestGetTexture(reporter, kRaster_SurfaceType, NULL); 446 TestGetTexture(reporter, kRaster_SurfaceType, NULL);
447 if (NULL != factory) { 447 if (factory) {
448 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { 448 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) {
449 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLCon textType) i; 449 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLCon textType) i;
450 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { 450 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) {
451 continue; 451 continue;
452 } 452 }
453 GrContext* context = factory->get(glCtxType); 453 GrContext* context = factory->get(glCtxType);
454 if (NULL != context) { 454 if (context) {
455 TestSurfaceInCache(reporter, kGpu_SurfaceType, context); 455 TestSurfaceInCache(reporter, kGpu_SurfaceType, context);
456 TestSurfaceInCache(reporter, kGpuScratch_SurfaceType, context); 456 TestSurfaceInCache(reporter, kGpuScratch_SurfaceType, context);
457 Test_crbug263329(reporter, kGpu_SurfaceType, context); 457 Test_crbug263329(reporter, kGpu_SurfaceType, context);
458 Test_crbug263329(reporter, kGpuScratch_SurfaceType, context); 458 Test_crbug263329(reporter, kGpuScratch_SurfaceType, context);
459 TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context); 459 TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context);
460 TestSurfaceCopyOnWrite(reporter, kGpuScratch_SurfaceType, contex t); 460 TestSurfaceCopyOnWrite(reporter, kGpuScratch_SurfaceType, contex t);
461 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceTy pe, context); 461 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceTy pe, context);
462 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpuScratch_Su rfaceType, context); 462 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpuScratch_Su rfaceType, context);
463 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa ce::kDiscard_ContentChangeMode); 463 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa ce::kDiscard_ContentChangeMode);
464 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSurface::kDiscard_ContentChangeMode); 464 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSurface::kDiscard_ContentChangeMode);
465 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa ce::kRetain_ContentChangeMode); 465 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa ce::kRetain_ContentChangeMode);
466 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSurface::kRetain_ContentChangeMode); 466 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSurface::kRetain_ContentChangeMode);
467 TestGetTexture(reporter, kGpu_SurfaceType, context); 467 TestGetTexture(reporter, kGpu_SurfaceType, context);
468 TestGetTexture(reporter, kGpuScratch_SurfaceType, context); 468 TestGetTexture(reporter, kGpuScratch_SurfaceType, context);
469 } 469 }
470 } 470 }
471 } 471 }
472 #endif 472 #endif
473 } 473 }
OLDNEW
« no previous file with comments | « tests/SkResourceCacheTest.cpp ('k') | tests/TextBlobTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698