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

Side by Side Diff: tests/SurfaceTest.cpp

Issue 351373005: add SkSurface::NewRasterDirectReleaseProc (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 5 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 | « src/image/SkSurface_Raster.cpp ('k') | 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 "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 }; 28 };
29 29
30 static const int gSurfaceSize = 10; 30 static void release_storage(void* pixels, void* context) {
31 static SkPMColor gSurfaceStorage[gSurfaceSize * gSurfaceSize]; 31 SkASSERT(pixels == context);
32 sk_free(pixels);
33 }
32 34
33 static SkSurface* createSurface(SurfaceType surfaceType, GrContext* context, 35 static SkSurface* createSurface(SurfaceType surfaceType, GrContext* context,
34 SkImageInfo* requestedInfo = NULL) { 36 SkImageInfo* requestedInfo = NULL) {
35 static const SkImageInfo info = SkImageInfo::MakeN32Premul(gSurfaceSize, 37 static const SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10);
36 gSurfaceSize);
37 38
38 if (requestedInfo) { 39 if (requestedInfo) {
39 *requestedInfo = info; 40 *requestedInfo = info;
40 } 41 }
41 42
42 switch (surfaceType) { 43 switch (surfaceType) {
43 case kRaster_SurfaceType: 44 case kRaster_SurfaceType:
44 return SkSurface::NewRaster(info); 45 return SkSurface::NewRaster(info);
45 case kRasterDirect_SurfaceType: 46 case kRasterDirect_SurfaceType: {
46 return SkSurface::NewRasterDirect(info, gSurfaceStorage, 47 const size_t rowBytes = info.minRowBytes();
47 info.minRowBytes()); 48 void* storage = sk_malloc_throw(info.getSafeSize(rowBytes));
49 return SkSurface::NewRasterDirectReleaseProc(info, storage, rowBytes ,
50 release_storage, storag e);
51 }
48 case kGpu_SurfaceType: 52 case kGpu_SurfaceType:
49 #if SK_SUPPORT_GPU 53 #if SK_SUPPORT_GPU
50 return context ? SkSurface::NewRenderTarget(context, info) : NULL; 54 return context ? SkSurface::NewRenderTarget(context, info) : NULL;
51 #endif 55 #endif
52 break; 56 break;
53 case kGpuScratch_SurfaceType: 57 case kGpuScratch_SurfaceType:
54 #if SK_SUPPORT_GPU 58 #if SK_SUPPORT_GPU
55 return context ? SkSurface::NewScratchRenderTarget(context, info) : NULL; 59 return context ? SkSurface::NewScratchRenderTarget(context, info) : NULL;
56 #endif 60 #endif
57 break; 61 break;
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface:: kDiscard_ContentChangeMode); 442 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface:: kDiscard_ContentChangeMode);
439 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSu rface::kDiscard_ContentChangeMode); 443 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSu rface::kDiscard_ContentChangeMode);
440 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface:: kRetain_ContentChangeMode); 444 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface:: kRetain_ContentChangeMode);
441 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSu rface::kRetain_ContentChangeMode); 445 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSu rface::kRetain_ContentChangeMode);
442 TestGetTexture(reporter, kGpu_SurfaceType, context); 446 TestGetTexture(reporter, kGpu_SurfaceType, context);
443 TestGetTexture(reporter, kGpuScratch_SurfaceType, context); 447 TestGetTexture(reporter, kGpuScratch_SurfaceType, context);
444 } 448 }
445 } 449 }
446 #endif 450 #endif
447 } 451 }
OLDNEW
« no previous file with comments | « src/image/SkSurface_Raster.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698