OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 // This test only works with the GPU backend. | 8 // This test only works with the GPU backend. |
9 | 9 |
10 #include "gm.h" | 10 #include "gm.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 | 108 |
109 SkScalar y = kDrawPad + kTestPad + space * kColorSpaceOffset; | 109 SkScalar y = kDrawPad + kTestPad + space * kColorSpaceOffset; |
110 SkScalar x = kDrawPad + kTestPad; | 110 SkScalar x = kDrawPad + kTestPad; |
111 | 111 |
112 const int indices[6][3] = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2}, | 112 const int indices[6][3] = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2}, |
113 {1, 2, 0}, {2, 0, 1}, {2, 1, 0}}; | 113 {1, 2, 0}, {2, 0, 1}, {2, 1, 0}}; |
114 | 114 |
115 for (int i = 0; i < 6; ++i) { | 115 for (int i = 0; i < 6; ++i) { |
116 GrPipelineBuilder pipelineBuilder; | 116 GrPipelineBuilder pipelineBuilder; |
117 pipelineBuilder.setXPFactory(GrPorterDuffXPFactory::Make(SkXferm
ode::kSrc_Mode)); | 117 pipelineBuilder.setXPFactory(GrPorterDuffXPFactory::Make(SkXferm
ode::kSrc_Mode)); |
118 sk_sp<GrFragmentProcessor> fp( | 118 sk_sp<GrFragmentProcessor> fp(GrYUVEffect::MakeYUVToRGB( |
119 GrYUVEffect::MakeYUVToRGB(texture[indices[i][0]], | 119 texture[indices[i][0]], texture[indices[i][1]], texture[indi
ces[i][2]], sizes, |
120 texture[indices[i][1]], | 120 static_cast<SkYUVColorSpace>(space), false)); |
121 texture[indices[i][2]], | |
122 sizes, | |
123 static_cast<SkYUVColorSpac
e>(space))); | |
124 if (fp) { | 121 if (fp) { |
125 SkMatrix viewMatrix; | 122 SkMatrix viewMatrix; |
126 viewMatrix.setTranslate(x, y); | 123 viewMatrix.setTranslate(x, y); |
127 pipelineBuilder.addColorFragmentProcessor(std::move(fp)); | 124 pipelineBuilder.addColorFragmentProcessor(std::move(fp)); |
128 SkAutoTUnref<GrDrawBatch> batch( | 125 SkAutoTUnref<GrDrawBatch> batch( |
129 GrRectBatchFactory::CreateNonAAFill(GrColor_WHITE, v
iewMatrix, | 126 GrRectBatchFactory::CreateNonAAFill(GrColor_WHITE, v
iewMatrix, |
130 renderRect, null
ptr, nullptr)); | 127 renderRect, null
ptr, nullptr)); |
131 drawContext->drawContextPriv().testingOnly_drawBatch(pipelin
eBuilder, batch); | 128 drawContext->drawContextPriv().testingOnly_drawBatch(pipelin
eBuilder, batch); |
132 } | 129 } |
133 x += renderRect.width() + kTestPad; | 130 x += renderRect.width() + kTestPad; |
134 } | 131 } |
135 } | 132 } |
136 } | 133 } |
137 | 134 |
138 private: | 135 private: |
139 SkBitmap fBmp[3]; | 136 SkBitmap fBmp[3]; |
140 | 137 |
141 typedef GM INHERITED; | 138 typedef GM INHERITED; |
142 }; | 139 }; |
143 | 140 |
144 DEF_GM(return new YUVtoRGBEffect;) | 141 DEF_GM(return new YUVtoRGBEffect;) |
| 142 |
| 143 ////////////////////////////////////////////////////////////////////////////// |
| 144 |
| 145 class YUVNV12toRGBEffect : public GM { |
| 146 public: |
| 147 YUVNV12toRGBEffect() { |
| 148 this->setBGColor(0xFFFFFFFF); |
| 149 } |
| 150 |
| 151 protected: |
| 152 SkString onShortName() override { |
| 153 return SkString("yuv_nv12_to_rgb_effect"); |
| 154 } |
| 155 |
| 156 SkISize onISize() override { |
| 157 return SkISize::Make(48, 120); |
| 158 } |
| 159 |
| 160 void onOnceBeforeDraw() override { |
| 161 SkImageInfo yinfo = SkImageInfo::MakeA8(YSIZE, YSIZE); |
| 162 fBmp[0].allocPixels(yinfo); |
| 163 SkImageInfo uvinfo = SkImageInfo::MakeN32Premul(USIZE, USIZE); |
| 164 fBmp[1].allocPixels(uvinfo); |
| 165 int color[] = {0, 85, 170}; |
| 166 const int limit[] = {255, 0, 255}; |
| 167 const int invl[] = {0, 255, 0}; |
| 168 const int inc[] = {1, -1, 1}; |
| 169 |
| 170 { |
| 171 unsigned char* pixels = (unsigned char*)fBmp[0].getPixels(); |
| 172 const size_t nbBytes = fBmp[0].rowBytes() * fBmp[0].height(); |
| 173 for (size_t j = 0; j < nbBytes; ++j) { |
| 174 pixels[j] = (unsigned char)color[0]; |
| 175 color[0] = (color[0] == limit[0]) ? invl[0] : color[0] + inc[0]; |
| 176 } |
| 177 } |
| 178 |
| 179 { |
| 180 for (int y = 0; y < fBmp[1].height(); ++y) { |
| 181 uint32_t* pixels = fBmp[1].getAddr32(0, y); |
| 182 for (int j = 0; j < fBmp[1].width(); ++j) { |
| 183 pixels[j] = SkColorSetARGB(0, color[1], color[2], 0); |
| 184 color[1] = (color[1] == limit[1]) ? invl[1] : color[1] + inc
[1]; |
| 185 color[2] = (color[2] == limit[2]) ? invl[2] : color[2] + inc
[2]; |
| 186 } |
| 187 } |
| 188 } |
| 189 } |
| 190 |
| 191 void onDraw(SkCanvas* canvas) override { |
| 192 GrDrawContext* drawContext = canvas->internal_private_accessTopLayerDraw
Context(); |
| 193 if (!drawContext) { |
| 194 skiagm::GM::DrawGpuOnlyMessage(canvas); |
| 195 return; |
| 196 } |
| 197 |
| 198 GrContext* context = canvas->getGrContext(); |
| 199 if (!context) { |
| 200 return; |
| 201 } |
| 202 |
| 203 SkAutoTUnref<GrTexture> texture[3]; |
| 204 texture[0].reset(GrRefCachedBitmapTexture(context, fBmp[0], GrTexturePar
ams::ClampBilerp(), |
| 205 SkSourceGammaTreatment::kRespe
ct)); |
| 206 texture[1].reset(GrRefCachedBitmapTexture(context, fBmp[1], GrTexturePar
ams::ClampBilerp(), |
| 207 SkSourceGammaTreatment::kRespe
ct)); |
| 208 texture[2].reset(GrRefCachedBitmapTexture(context, fBmp[1], GrTexturePar
ams::ClampBilerp(), |
| 209 SkSourceGammaTreatment::kRespe
ct)); |
| 210 |
| 211 if (!texture[0] || !texture[1] || !texture[2]) { |
| 212 return; |
| 213 } |
| 214 |
| 215 static const SkScalar kDrawPad = 10.f; |
| 216 static const SkScalar kTestPad = 10.f; |
| 217 static const SkScalar kColorSpaceOffset = 36.f; |
| 218 SkISize sizes[3] = {{YSIZE, YSIZE}, {USIZE, USIZE}, {VSIZE, VSIZE}}; |
| 219 |
| 220 for (int space = kJPEG_SkYUVColorSpace; space <= kLastEnum_SkYUVColorSpa
ce; ++space) { |
| 221 SkRect renderRect = |
| 222 SkRect::MakeWH(SkIntToScalar(fBmp[0].width()), SkIntToScalar(fBm
p[0].height())); |
| 223 renderRect.outset(kDrawPad, kDrawPad); |
| 224 |
| 225 SkScalar y = kDrawPad + kTestPad + space * kColorSpaceOffset; |
| 226 SkScalar x = kDrawPad + kTestPad; |
| 227 |
| 228 GrPipelineBuilder pipelineBuilder; |
| 229 pipelineBuilder.setXPFactory(GrPorterDuffXPFactory::Make(SkXfermode:
:kSrc_Mode)); |
| 230 sk_sp<GrFragmentProcessor> fp( |
| 231 GrYUVEffect::MakeYUVToRGB(texture[0], texture[1], texture[2], si
zes, |
| 232 static_cast<SkYUVColorSpace>(space), t
rue)); |
| 233 if (fp) { |
| 234 SkMatrix viewMatrix; |
| 235 viewMatrix.setTranslate(x, y); |
| 236 pipelineBuilder.addColorFragmentProcessor(fp); |
| 237 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateNonAAF
ill( |
| 238 GrColor_WHITE, viewMatrix, renderRect, nullptr, nullptr)); |
| 239 drawContext->drawContextPriv().testingOnly_drawBatch(pipelineBui
lder, batch); |
| 240 } |
| 241 } |
| 242 } |
| 243 |
| 244 private: |
| 245 SkBitmap fBmp[2]; |
| 246 |
| 247 typedef GM INHERITED; |
| 248 }; |
| 249 |
| 250 DEF_GM(return new YUVNV12toRGBEffect;) |
145 } | 251 } |
146 | 252 |
147 #endif | 253 #endif |
OLD | NEW |