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

Side by Side Diff: tests/GrSurfaceTest.cpp

Issue 1121813002: new image from backend desc (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix no-gpu version Created 5 years, 7 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 "SkTypes.h" 8 #include "SkTypes.h"
9 9
10 #if SK_SUPPORT_GPU 10 #if SK_SUPPORT_GPU
11 11
12 #include "GrContext.h" 12 #include "GrContext.h"
13 #include "GrContextFactory.h" 13 #include "GrContextFactory.h"
14 #include "GrRenderTarget.h" 14 #include "GrRenderTarget.h"
15 #include "GrTexture.h" 15 #include "GrTexture.h"
16 #include "GrSurfacePriv.h" 16 #include "GrSurfacePriv.h"
17 #include "SkCanvas.h"
18 #include "SkImage.h"
19 #include "SkSurface.h"
20 #include "SkUtils.h"
17 #include "Test.h" 21 #include "Test.h"
18 22
19 // Tests that GrSurface::asTexture(), GrSurface::asRenderTarget(), and static up casting of texture 23 // Tests that GrSurface::asTexture(), GrSurface::asRenderTarget(), and static up casting of texture
20 // and render targets to GrSurface all work as expected. 24 // and render targets to GrSurface all work as expected.
21 DEF_GPUTEST(GrSurface, reporter, factory) { 25 DEF_GPUTEST(GrSurface, reporter, factory) {
22 GrContext* context = factory->get(GrContextFactory::kNull_GLContextType); 26 GrContext* context = factory->get(GrContextFactory::kNull_GLContextType);
23 if (context) { 27 if (context) {
24 GrSurfaceDesc desc; 28 GrSurfaceDesc desc;
25 desc.fConfig = kSkia8888_GrPixelConfig; 29 desc.fConfig = kSkia8888_GrPixelConfig;
26 desc.fFlags = kRenderTarget_GrSurfaceFlag; 30 desc.fFlags = kRenderTarget_GrSurfaceFlag;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 static_cast<GrSurface*>(texRT2->asTexture())); 64 static_cast<GrSurface*>(texRT2->asTexture()));
61 REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget ()) == 65 REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget ()) ==
62 static_cast<GrSurface*>(texRT2->asTexture())) ; 66 static_cast<GrSurface*>(texRT2->asTexture())) ;
63 67
64 texRT1->unref(); 68 texRT1->unref();
65 texRT2->unref(); 69 texRT2->unref();
66 tex1->unref(); 70 tex1->unref();
67 } 71 }
68 } 72 }
69 73
74 static SkImage* make_gpu_image(GrContext* ctx, int w, int h, SkColor color) {
bsalomon 2015/05/07 19:52:22 This file is really about testing GrSurface, not S
reed1 2015/05/07 20:28:00 Done.
75 const SkImageInfo info = SkImageInfo::MakeN32Premul(w, h);
76 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, SkSurface::k No_Budgeted, info));
77 if (!surface) {
78 return NULL;
79 }
80 surface->getCanvas()->drawColor(color);
81 surface->getCanvas()->flush();
82 return surface->newImageSnapshot();
83 }
84
85 static void test_tex_image(skiatest::Reporter* reporter, GrContext* ctx, GrBacke ndObject nativeTex,
86 int w, int h, bool testCopy, SkPMColor expected) {
87 GrBackendTextureDesc desc;
88 desc.fConfig = kSkia8888_GrPixelConfig;
89 // need to be a rendertarget for now...
90 desc.fFlags = kRenderTarget_GrBackendTextureFlag; //kNone_GrBackendTexture Flag;
91 desc.fWidth = w;
92 desc.fHeight = h;
93 desc.fSampleCnt = 0;
94 desc.fTextureHandle = nativeTex;
95 SkAutoTUnref<SkImage> image(testCopy ?
96 SkImage::NewFromTextureCopy(ctx, desc) :
97 SkImage::NewFromTexture(ctx, desc));
98 REPORTER_ASSERT(reporter, image.get() != NULL);
99 if (image) {
100 const SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1);
101 SkPMColor pixel;
102 REPORTER_ASSERT(reporter, image->readPixels(info, &pixel, sizeof(pixel), 0, 0));
103 REPORTER_ASSERT(reporter, pixel == expected);
104 }
105 }
106
robertphillips 2015/05/07 20:09:08 // Test wrapping a GrBackendObject in a surface, r
reed1 2015/05/07 20:28:00 Acknowledged.
107 DEF_GPUTEST(SkImage_NewFromTexture, reporter, factory) {
108 GrContext* ctx = factory->get(GrContextFactory::kNative_GLContextType);
109 if (!ctx) {
110 REPORTER_ASSERT(reporter, false);
111 return;
112 }
113
114 const int w = 10;
115 const int h = 10;
116 const SkColor srcColor = SK_ColorRED;
robertphillips 2015/05/07 20:09:07 constify 'expected' too ?
reed1 2015/05/07 20:28:00 Done.
117 SkPMColor expected = SkPreMultiplyColor(srcColor);
118 SkAutoTUnref<SkImage> srcImg(make_gpu_image(ctx, w, h, srcColor));
119 if (!srcImg) {
120 REPORTER_ASSERT(reporter, false);
121 return;
122 }
123
124 GrBackendObject srcTex = srcImg->getTexture()->getTextureHandle();
125 test_tex_image(reporter, ctx, srcTex, w, h, false, expected);
126 test_tex_image(reporter, ctx, srcTex, w, h, true, expected);
127 }
128
robertphillips 2015/05/07 20:09:08 // Test pulling a GrBackendObject from a GrTexture
reed1 2015/05/07 20:28:00 Acknowledged.
129 DEF_GPUTEST(SkImage_NewFromTexture2, reporter, factory) {
130 GrContext* ctx = factory->get(GrContextFactory::kNative_GLContextType);
131 if (!ctx) {
132 REPORTER_ASSERT(reporter, false);
133 return;
134 }
135 GrTextureProvider* provider = ctx->textureProvider();
136
137 const int w = 10;
138 const int h = 10;
139 SkPMColor storage[w * h];
140 SkPMColor expected = SkPreMultiplyColor(SK_ColorRED);
141 sk_memset32(storage, expected, w * h);
142
143 GrSurfaceDesc desc;
144 desc.fFlags = kRenderTarget_GrSurfaceFlag; // needs to be a rendertarget fo r readpixels();
145 desc.fOrigin = kDefault_GrSurfaceOrigin;
146 desc.fWidth = w;
147 desc.fHeight = h;
148 desc.fConfig = kSkia8888_GrPixelConfig;
149 desc.fSampleCnt = 0;
150
151 SkAutoTUnref<GrTexture> tex(provider->createTexture(desc, false, storage, w * 4));
152 if (!tex) {
153 REPORTER_ASSERT(reporter, false);
154 return;
155 }
156
157 GrBackendObject srcTex = tex->getTextureHandle();
158 test_tex_image(reporter, ctx, srcTex, w, h, false, expected);
159 test_tex_image(reporter, ctx, srcTex, w, h, true, expected);
robertphillips 2015/05/07 20:09:08 Re-scribble on 'tex' and readback again ?
reed1 2015/05/07 20:28:00 Done.
160 }
161
70 #endif 162 #endif
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