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

Side by Side Diff: gm/imagefromyuvtextures.cpp

Issue 1429863009: Use a struct for client GL texture handles (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 5 years, 1 month 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 | « no previous file | gyp/skia_for_android_framework_defines.gypi » ('j') | include/gpu/gl/GrGLTypes.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 int uvIndex = j * kBmpSize / 2 + i; 86 int uvIndex = j * kBmpSize / 2 + i;
87 uvPixels[0][uvIndex] = static_cast<signed char>( 87 uvPixels[0][uvIndex] = static_cast<signed char>(
88 ((-38 * rgb[0] - 74 * rgb[1] + 112 * rgb[2] + 128) >> 8) + 128); 88 ((-38 * rgb[0] - 74 * rgb[1] + 112 * rgb[2] + 128) >> 8) + 128);
89 uvPixels[1][uvIndex] = static_cast<signed char>( 89 uvPixels[1][uvIndex] = static_cast<signed char>(
90 ((112 * rgb[0] - 94 * rgb[1] - 18 * rgb[2] + 128) >> 8) + 128); 90 ((112 * rgb[0] - 94 * rgb[1] - 18 * rgb[2] + 128) >> 8) + 128);
91 } 91 }
92 } 92 }
93 fRGBImage.reset(SkImage::NewRasterCopy(rgbBmp.info(), rgbColors, rgbBmp. rowBytes())); 93 fRGBImage.reset(SkImage::NewRasterCopy(rgbBmp.info(), rgbColors, rgbBmp. rowBytes()));
94 } 94 }
95 95
96 void createYUVTextures(GrContext* context, GrBackendObject yuvIDs[3]) { 96 void createYUVTextures(GrContext* context, GrBackendObject yuvHandles[3]) {
97 const GrGpu* gpu = context->getGpu(); 97 const GrGpu* gpu = context->getGpu();
98 if (!gpu) { 98 if (!gpu) {
99 return; 99 return;
100 } 100 }
101 101
102 for (int i = 0; i < 3; ++i) { 102 for (int i = 0; i < 3; ++i) {
103 SkASSERT(fYUVBmps[i].width() == SkToInt(fYUVBmps[i].rowBytes())); 103 SkASSERT(fYUVBmps[i].width() == SkToInt(fYUVBmps[i].rowBytes()));
104 yuvIDs[i] = gpu->createTestingOnlyBackendTexture(fYUVBmps[i].getPixe ls(), 104 yuvHandles[i] = gpu->createTestingOnlyBackendTexture(fYUVBmps[i].get Pixels(),
105 fYUVBmps[i].width() , 105 fYUVBmps[i].wid th(),
106 fYUVBmps[i].height( ), 106 fYUVBmps[i].hei ght(),
107 kAlpha_8_GrPixelCon fig); 107 kAlpha_8_GrPixe lConfig);
108 } 108 }
109 context->resetContext(); 109 context->resetContext();
110 } 110 }
111 111
112 void deleteYUVTextures(GrContext* context, const GrBackendObject yuvIDs[3]) { 112 void deleteYUVTextures(GrContext* context, const GrBackendObject yuvHandles[ 3]) {
113 113
114 const GrGpu* gpu = context->getGpu(); 114 const GrGpu* gpu = context->getGpu();
115 if (!gpu) { 115 if (!gpu) {
116 return; 116 return;
117 } 117 }
118 118
119 for (int i = 0; i < 3; ++i) { 119 for (int i = 0; i < 3; ++i) {
120 gpu->deleteTestingOnlyBackendTexture(yuvIDs[i]); 120 gpu->deleteTestingOnlyBackendTexture(yuvHandles[i]);
121 } 121 }
122 122
123 context->resetContext(); 123 context->resetContext();
124 } 124 }
125 125
126 void onDraw(SkCanvas* canvas) override { 126 void onDraw(SkCanvas* canvas) override {
127 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget (); 127 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget ();
128 GrContext* context; 128 GrContext* context;
129 if (!rt || !(context = rt->getContext())) { 129 if (!rt || !(context = rt->getContext())) {
130 skiagm::GM::DrawGpuOnlyMessage(canvas); 130 skiagm::GM::DrawGpuOnlyMessage(canvas);
131 return; 131 return;
132 } 132 }
133 133
134 GrBackendObject yuvIDs[3]; 134 GrBackendObject yuvHandles[3];
135 this->createYUVTextures(context, yuvIDs); 135 this->createYUVTextures(context, yuvHandles);
136 136
137 static const SkScalar kPad = 10.f; 137 static const SkScalar kPad = 10.f;
138 138
139 SkISize sizes[] = { 139 SkISize sizes[] = {
140 { fYUVBmps[0].width(), fYUVBmps[0].height()}, 140 { fYUVBmps[0].width(), fYUVBmps[0].height()},
141 { fYUVBmps[1].width(), fYUVBmps[1].height()}, 141 { fYUVBmps[1].width(), fYUVBmps[1].height()},
142 { fYUVBmps[2].width(), fYUVBmps[2].height()}, 142 { fYUVBmps[2].width(), fYUVBmps[2].height()},
143 }; 143 };
144 SkTArray<SkImage*> images; 144 SkTArray<SkImage*> images;
145 images.push_back(SkRef(fRGBImage.get())); 145 images.push_back(SkRef(fRGBImage.get()));
146 for (int space = kJPEG_SkYUVColorSpace; space <= kLastEnum_SkYUVColorSpa ce; ++space) { 146 for (int space = kJPEG_SkYUVColorSpace; space <= kLastEnum_SkYUVColorSpa ce; ++space) {
147 images.push_back(SkImage::NewFromYUVTexturesCopy(context, 147 images.push_back(SkImage::NewFromYUVTexturesCopy(context,
148 static_cast<SkYUVCo lorSpace>(space), 148 static_cast<SkYUVCo lorSpace>(space),
149 yuvIDs, sizes, 149 yuvHandles, sizes,
150 kTopLeft_GrSurfaceO rigin)); 150 kTopLeft_GrSurfaceO rigin));
151 } 151 }
152 this->deleteYUVTextures(context, yuvIDs); 152 this->deleteYUVTextures(context, yuvHandles);
153 for (int i = 0; i < images.count(); ++ i) { 153 for (int i = 0; i < images.count(); ++ i) {
154 SkScalar y = (i + 1) * kPad + i * fYUVBmps[0].height(); 154 SkScalar y = (i + 1) * kPad + i * fYUVBmps[0].height();
155 SkScalar x = kPad; 155 SkScalar x = kPad;
156 156
157 canvas->drawImage(images[i], x, y); 157 canvas->drawImage(images[i], x, y);
158 images[i]->unref(); 158 images[i]->unref();
159 images[i] = nullptr; 159 images[i] = nullptr;
160 } 160 }
161 } 161 }
162 162
163 private: 163 private:
164 SkAutoTUnref<SkImage> fRGBImage; 164 SkAutoTUnref<SkImage> fRGBImage;
165 SkBitmap fYUVBmps[3]; 165 SkBitmap fYUVBmps[3];
166 166
167 static const int kBmpSize = 32; 167 static const int kBmpSize = 32;
168 168
169 typedef GM INHERITED; 169 typedef GM INHERITED;
170 }; 170 };
171 171
172 DEF_GM(return new ImageFromYUVTextures;) 172 DEF_GM(return new ImageFromYUVTextures;)
173 } 173 }
174 174
175 #endif 175 #endif
OLDNEW
« no previous file with comments | « no previous file | gyp/skia_for_android_framework_defines.gypi » ('j') | include/gpu/gl/GrGLTypes.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698