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

Side by Side Diff: tests/SurfaceTest.cpp

Issue 1071603002: Add helper for creating a SkSurface from a client created texture. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix comment style Created 5 years, 8 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_Gpu.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"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S kAlphaType); 83 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S kAlphaType);
84 84
85 REPORTER_ASSERT(reporter, NULL == SkSurface::NewRaster(info)); 85 REPORTER_ASSERT(reporter, NULL == SkSurface::NewRaster(info));
86 REPORTER_ASSERT(reporter, NULL == SkSurface::NewRasterDirect(info, NULL, 0)) ; 86 REPORTER_ASSERT(reporter, NULL == SkSurface::NewRasterDirect(info, NULL, 0)) ;
87 if (ctx) { 87 if (ctx) {
88 REPORTER_ASSERT(reporter, NULL == 88 REPORTER_ASSERT(reporter, NULL ==
89 SkSurface::NewRenderTarget(ctx, SkSurface::kNo_Budgeted, info, 0, NULL)); 89 SkSurface::NewRenderTarget(ctx, SkSurface::kNo_Budgeted, info, 0, NULL));
90 } 90 }
91 } 91 }
92 92
93 #if SK_SUPPORT_GPU
94 static void test_wrapped_texture_surface(skiatest::Reporter* reporter, GrContext * ctx) {
95 if (NULL == ctx) {
96 return;
97 }
98 // Test the wrapped factory for SkSurface by creating a texture using ctx an d then treat it as
99 // an external texture and wrap it in a SkSurface.
100
101 GrSurfaceDesc texDesc;
102 texDesc.fConfig = kRGBA_8888_GrPixelConfig;
103 texDesc.fFlags = kRenderTarget_GrSurfaceFlag;
104 texDesc.fWidth = texDesc.fHeight = 100;
105 texDesc.fSampleCnt = 0;
106 texDesc.fOrigin = kTopLeft_GrSurfaceOrigin;
107 SkAutoTUnref<GrSurface> dummySurface(ctx->createTexture(texDesc, false));
108
109 REPORTER_ASSERT(reporter, dummySurface && dummySurface->asTexture() &&
110 dummySurface->asRenderTarget());
111 if (!dummySurface || !dummySurface->asTexture() || !dummySurface->asRenderTa rget()) {
112 return;
113 }
114
115 GrBackendObject textureHandle = dummySurface->asTexture()->getTextureHandle( );
116
117 GrBackendTextureDesc wrappedDesc;
118 wrappedDesc.fConfig = dummySurface->config();
119 wrappedDesc.fWidth = dummySurface->width();
120 wrappedDesc.fHeight = dummySurface->height();
121 wrappedDesc.fOrigin = dummySurface->origin();
122 wrappedDesc.fSampleCnt = dummySurface->asRenderTarget()->numSamples();
123 wrappedDesc.fFlags = kRenderTarget_GrBackendTextureFlag;
124 wrappedDesc.fTextureHandle = textureHandle;
125
126 SkAutoTUnref<SkSurface> surface(SkSurface::NewWrappedRenderTarget(ctx, wrapp edDesc, NULL));
127 REPORTER_ASSERT(reporter, surface);
128 }
129 #endif
130
131
93 static void test_image(skiatest::Reporter* reporter) { 132 static void test_image(skiatest::Reporter* reporter) {
94 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); 133 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1);
95 size_t rowBytes = info.minRowBytes(); 134 size_t rowBytes = info.minRowBytes();
96 size_t size = info.getSafeSize(rowBytes); 135 size_t size = info.getSafeSize(rowBytes);
97 SkData* data = SkData::NewUninitialized(size); 136 SkData* data = SkData::NewUninitialized(size);
98 137
99 REPORTER_ASSERT(reporter, data->unique()); 138 REPORTER_ASSERT(reporter, data->unique());
100 SkImage* image = SkImage::NewRasterData(info, data, rowBytes); 139 SkImage* image = SkImage::NewRasterData(info, data, rowBytes);
101 REPORTER_ASSERT(reporter, !data->unique()); 140 REPORTER_ASSERT(reporter, !data->unique());
102 image->unref(); 141 image->unref();
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceTy pe, context); 601 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceTy pe, context);
563 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpuScratch_Su rfaceType, context); 602 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpuScratch_Su rfaceType, context);
564 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa ce::kDiscard_ContentChangeMode); 603 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa ce::kDiscard_ContentChangeMode);
565 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSurface::kDiscard_ContentChangeMode); 604 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSurface::kDiscard_ContentChangeMode);
566 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa ce::kRetain_ContentChangeMode); 605 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa ce::kRetain_ContentChangeMode);
567 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSurface::kRetain_ContentChangeMode); 606 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSurface::kRetain_ContentChangeMode);
568 TestGetTexture(reporter, kGpu_SurfaceType, context); 607 TestGetTexture(reporter, kGpu_SurfaceType, context);
569 TestGetTexture(reporter, kGpuScratch_SurfaceType, context); 608 TestGetTexture(reporter, kGpuScratch_SurfaceType, context);
570 test_empty_surface(reporter, context); 609 test_empty_surface(reporter, context);
571 test_surface_budget(reporter, context); 610 test_surface_budget(reporter, context);
611 test_wrapped_texture_surface(reporter, context);
572 } 612 }
573 } 613 }
574 } 614 }
575 #endif 615 #endif
576 } 616 }
OLDNEW
« no previous file with comments | « src/image/SkSurface_Gpu.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698