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

Side by Side Diff: gm/imagefromyuvtextures.cpp

Issue 1232173002: Remove GL-specific code from GMs and tests (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fixes (for GLBench in particular) Created 5 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
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2015 Google Inc. 3 * Copyright 2015 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 // This test only works with the GPU backend. 9 // This test only works with the GPU backend.
10 10
11 #include "gm.h" 11 #include "gm.h"
12 12
13 #if SK_SUPPORT_GPU 13 #if SK_SUPPORT_GPU
14 14
15 #include "GrContext.h" 15 #include "GrContext.h"
16 #include "gl/GrGLInterface.h"
17 #include "gl/GrGLUtil.h"
18 #include "GrTest.h" 16 #include "GrTest.h"
19 #include "SkBitmap.h" 17 #include "SkBitmap.h"
20 #include "SkGradientShader.h" 18 #include "SkGradientShader.h"
21 #include "SkImage.h" 19 #include "SkImage.h"
22 20
23 namespace skiagm { 21 namespace skiagm {
24 class ImageFromYUVTextures : public GM { 22 class ImageFromYUVTextures : public GM {
25 public: 23 public:
26 ImageFromYUVTextures() { 24 ImageFromYUVTextures() {
27 this->setBGColor(0xFFFFFFFF); 25 this->setBGColor(0xFFFFFFFF);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 int uvIndex = j * kBmpSize / 2 + i; 87 int uvIndex = j * kBmpSize / 2 + i;
90 uvPixels[0][uvIndex] = static_cast<signed char>( 88 uvPixels[0][uvIndex] = static_cast<signed char>(
91 ((-38 * rgb[0] - 74 * rgb[1] + 112 * rgb[2] + 128) >> 8) + 128); 89 ((-38 * rgb[0] - 74 * rgb[1] + 112 * rgb[2] + 128) >> 8) + 128);
92 uvPixels[1][uvIndex] = static_cast<signed char>( 90 uvPixels[1][uvIndex] = static_cast<signed char>(
93 ((112 * rgb[0] - 94 * rgb[1] - 18 * rgb[2] + 128) >> 8) + 128); 91 ((112 * rgb[0] - 94 * rgb[1] - 18 * rgb[2] + 128) >> 8) + 128);
94 } 92 }
95 } 93 }
96 fRGBImage.reset(SkImage::NewRasterCopy(rgbBmp.info(), rgbColors, rgbBmp. rowBytes())); 94 fRGBImage.reset(SkImage::NewRasterCopy(rgbBmp.info(), rgbColors, rgbBmp. rowBytes()));
97 } 95 }
98 96
99 void createYUVTextures(GrContext* context, GrGLuint yuvIDs[3]) { 97 void createYUVTextures(GrContext* context, GrBackendObject yuvIDs[3]) {
robertphillips 2015/07/10 20:23:41 hav -> have ?
100 GrTestTarget tt; 98 // Note: We currently hav only implemented the texture uploads for GL.
101 context->getTestTarget(&tt); 99 const GrGpu* gpu = context->getGpu();
102 if (!tt.target()) { 100 if (!gpu) {
103 SkDEBUGFAIL("Couldn't get Gr test target.");
104 return; 101 return;
105 } 102 }
106 103
107 // We currently hav only implemented the texture uploads for GL.
108 const GrGLInterface* gl = tt.glContext()->interface();
109 if (!gl) {
110 return;
111 }
112
113 GR_GL_CALL(gl, GenTextures(3, yuvIDs));
114 GR_GL_CALL(gl, ActiveTexture(GR_GL_TEXTURE0));
115 GR_GL_CALL(gl, PixelStorei(GR_GL_UNPACK_ALIGNMENT, 1));
116 for (int i = 0; i < 3; ++i) { 104 for (int i = 0; i < 3; ++i) {
117 GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, yuvIDs[i]));
118 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MAG_FIL TER,
119 GR_GL_NEAREST));
120 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MIN_FIL TER,
121 GR_GL_NEAREST));
122 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_WRAP_S,
123 GR_GL_CLAMP_TO_EDGE));
124 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_WRAP_T,
125 GR_GL_CLAMP_TO_EDGE));
126 SkASSERT(fYUVBmps[i].width() == SkToInt(fYUVBmps[i].rowBytes())); 105 SkASSERT(fYUVBmps[i].width() == SkToInt(fYUVBmps[i].rowBytes()));
127 GR_GL_CALL(gl, TexImage2D(GR_GL_TEXTURE_2D, 0, GR_GL_RED, fYUVBmps[i ].width(), 106 yuvIDs[i] = gpu->createBackendTexture(fYUVBmps[i].getPixels(),
128 fYUVBmps[i].height(), 0, GR_GL_RED, GR_GL_ UNSIGNED_BYTE, 107 fYUVBmps[i].width(), fYUVBmps[ i].height(),
129 fYUVBmps[i].getPixels())); 108 kAlpha_8_GrPixelConfig);
130 } 109 }
131 context->resetContext(); 110 context->resetContext();
132 } 111 }
133 112
134 void deleteYUVTextures(GrContext* context, const GrGLuint yuvIDs[3]) { 113 void deleteYUVTextures(GrContext* context, const GrBackendObject yuvIDs[3]) {
135 GrTestTarget tt; 114
136 context->getTestTarget(&tt); 115 const GrGpu* gpu = context->getGpu();
137 if (!tt.target()) { 116 if (!gpu) {
138 SkDEBUGFAIL("Couldn't get Gr test target.");
139 return; 117 return;
140 } 118 }
141 119
142 const GrGLInterface* gl = tt.glContext()->interface(); 120 for (int i = 0; i < 3; ++i) {
143 if (!gl) { 121 gpu->deleteBackendTexture(yuvIDs[i]);
144 return;
145 } 122 }
146 GR_GL_CALL(gl, DeleteTextures(3, yuvIDs)); 123
147 context->resetContext(); 124 context->resetContext();
148 } 125 }
149 126
150 void onDraw(SkCanvas* canvas) override { 127 void onDraw(SkCanvas* canvas) override {
151 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget (); 128 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget ();
152 GrContext* context; 129 GrContext* context;
153 if (!rt || !(context = rt->getContext())) { 130 if (!rt || !(context = rt->getContext())) {
154 this->drawGpuOnlyMessage(canvas); 131 this->drawGpuOnlyMessage(canvas);
155 return; 132 return;
156 } 133 }
157 134
158 GrGLuint yuvIDs[3]; 135 GrBackendObject yuvIDs[3];
159 this->createYUVTextures(context, yuvIDs); 136 this->createYUVTextures(context, yuvIDs);
160 137
161 static const SkScalar kPad = 10.f; 138 static const SkScalar kPad = 10.f;
162 139
163 GrBackendObject backendTextureObjects[] = {
164 static_cast<GrBackendObject>(yuvIDs[0]),
165 static_cast<GrBackendObject>(yuvIDs[1]),
166 static_cast<GrBackendObject>(yuvIDs[2])
167 };
168 SkISize sizes[] = { 140 SkISize sizes[] = {
169 { fYUVBmps[0].width(), fYUVBmps[0].height()}, 141 { fYUVBmps[0].width(), fYUVBmps[0].height()},
170 { fYUVBmps[1].width(), fYUVBmps[1].height()}, 142 { fYUVBmps[1].width(), fYUVBmps[1].height()},
171 { fYUVBmps[2].width(), fYUVBmps[2].height()}, 143 { fYUVBmps[2].width(), fYUVBmps[2].height()},
172 }; 144 };
173 SkTArray<SkImage*> images; 145 SkTArray<SkImage*> images;
174 images.push_back(SkRef(fRGBImage.get())); 146 images.push_back(SkRef(fRGBImage.get()));
175 for (int space = kJPEG_SkYUVColorSpace; space <= kLastEnum_SkYUVColorSpa ce; ++space) { 147 for (int space = kJPEG_SkYUVColorSpace; space <= kLastEnum_SkYUVColorSpa ce; ++space) {
176 images.push_back(SkImage::NewFromYUVTexturesCopy(context, 148 images.push_back(SkImage::NewFromYUVTexturesCopy(context,
177 static_cast<SkYUVCo lorSpace>(space), 149 static_cast<SkYUVCo lorSpace>(space),
178 backendTextureObjec ts, sizes, 150 yuvIDs, sizes,
179 kTopLeft_GrSurfaceO rigin)); 151 kTopLeft_GrSurfaceO rigin));
180 } 152 }
181 this->deleteYUVTextures(context, yuvIDs); 153 this->deleteYUVTextures(context, yuvIDs);
182 for (int i = 0; i < images.count(); ++ i) { 154 for (int i = 0; i < images.count(); ++ i) {
183 SkScalar y = (i + 1) * kPad + i * fYUVBmps[0].height(); 155 SkScalar y = (i + 1) * kPad + i * fYUVBmps[0].height();
184 SkScalar x = kPad; 156 SkScalar x = kPad;
185 157
186 canvas->drawImage(images[i], x, y); 158 canvas->drawImage(images[i], x, y);
187 images[i]->unref(); 159 images[i]->unref();
188 images[i] = NULL; 160 images[i] = NULL;
189 } 161 }
190 } 162 }
191 163
192 private: 164 private:
193 SkAutoTUnref<SkImage> fRGBImage; 165 SkAutoTUnref<SkImage> fRGBImage;
194 SkBitmap fYUVBmps[3]; 166 SkBitmap fYUVBmps[3];
195 167
196 static const int kBmpSize = 32; 168 static const int kBmpSize = 32;
197 169
198 typedef GM INHERITED; 170 typedef GM INHERITED;
199 }; 171 };
200 172
201 DEF_GM( return SkNEW(ImageFromYUVTextures); ) 173 DEF_GM( return SkNEW(ImageFromYUVTextures); )
202 } 174 }
203 175
204 #endif 176 #endif
OLDNEW
« bench/GLBench.cpp ('K') | « bench/GLBench.cpp ('k') | src/gpu/GrGpu.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698