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

Side by Side Diff: tests/SurfaceTest.cpp

Issue 568683002: use SkData::NewUninitialized (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add SkStream::readIntoData 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
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 kRasterCopy_ImageType, 67 kRasterCopy_ImageType,
68 kRasterData_ImageType, 68 kRasterData_ImageType,
69 kGpu_ImageType, 69 kGpu_ImageType,
70 kCodec_ImageType, 70 kCodec_ImageType,
71 }; 71 };
72 72
73 static void test_image(skiatest::Reporter* reporter) { 73 static void test_image(skiatest::Reporter* reporter) {
74 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); 74 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1);
75 size_t rowBytes = info.minRowBytes(); 75 size_t rowBytes = info.minRowBytes();
76 size_t size = info.getSafeSize(rowBytes); 76 size_t size = info.getSafeSize(rowBytes);
77 void* addr = sk_malloc_throw(size); 77 SkData* data = SkData::NewUninitialized(size);
78 SkData* data = SkData::NewFromMalloc(addr, size);
79 78
80 REPORTER_ASSERT(reporter, 1 == data->getRefCnt()); 79 REPORTER_ASSERT(reporter, 1 == data->getRefCnt());
81 SkImage* image = SkImage::NewRasterData(info, data, rowBytes); 80 SkImage* image = SkImage::NewRasterData(info, data, rowBytes);
82 REPORTER_ASSERT(reporter, 2 == data->getRefCnt()); 81 REPORTER_ASSERT(reporter, 2 == data->getRefCnt());
83 image->unref(); 82 image->unref();
84 REPORTER_ASSERT(reporter, 1 == data->getRefCnt()); 83 REPORTER_ASSERT(reporter, 1 == data->getRefCnt());
85 data->unref(); 84 data->unref();
86 } 85 }
87 86
88 static SkImage* createImage(ImageType imageType, GrContext* context, 87 static SkImage* createImage(ImageType imageType, GrContext* context,
89 SkColor color) { 88 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 void* addr = sk_malloc_throw(size); 94 SkAutoTUnref<SkData> data(SkData::NewUninitialized(size));
95 void* addr = data->writable_data();
96 sk_memset32((SkPMColor*)addr, pmcolor, SkToInt(size >> 2)); 96 sk_memset32((SkPMColor*)addr, pmcolor, SkToInt(size >> 2));
97 SkAutoTUnref<SkData> data(SkData::NewFromMalloc(addr, size));
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 return NULL; // TODO
106 case kCodec_ImageType: { 105 case kCodec_ImageType: {
107 SkBitmap bitmap; 106 SkBitmap bitmap;
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSurface::kDiscard_ContentChangeMode); 463 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSurface::kDiscard_ContentChangeMode);
465 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa ce::kRetain_ContentChangeMode); 464 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa ce::kRetain_ContentChangeMode);
466 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSurface::kRetain_ContentChangeMode); 465 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSurface::kRetain_ContentChangeMode);
467 TestGetTexture(reporter, kGpu_SurfaceType, context); 466 TestGetTexture(reporter, kGpu_SurfaceType, context);
468 TestGetTexture(reporter, kGpuScratch_SurfaceType, context); 467 TestGetTexture(reporter, kGpuScratch_SurfaceType, context);
469 } 468 }
470 } 469 }
471 } 470 }
472 #endif 471 #endif
473 } 472 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698