OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 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 "GrTest.h" | 16 #include "GrTest.h" |
17 #include "effects/GrYUVtoRGBEffect.h" | 17 #include "effects/GrYUVtoRGBEffect.h" |
18 #include "SkBitmap.h" | 18 #include "SkBitmap.h" |
19 #include "SkGr.h" | 19 #include "SkGr.h" |
20 #include "SkGradientShader.h" | 20 #include "SkGradientShader.h" |
21 | 21 |
| 22 #define YSIZE 8 |
| 23 #define USIZE 4 |
| 24 #define VSIZE 4 |
| 25 |
22 namespace skiagm { | 26 namespace skiagm { |
23 /** | 27 /** |
24 * This GM directly exercises GrYUVtoRGBEffect. | 28 * This GM directly exercises GrYUVtoRGBEffect. |
25 */ | 29 */ |
26 class YUVtoRGBEffect : public GM { | 30 class YUVtoRGBEffect : public GM { |
27 public: | 31 public: |
28 YUVtoRGBEffect() { | 32 YUVtoRGBEffect() { |
29 this->setBGColor(0xFFFFFFFF); | 33 this->setBGColor(0xFFFFFFFF); |
30 } | 34 } |
31 | 35 |
32 protected: | 36 protected: |
33 SkString onShortName() SK_OVERRIDE { | 37 SkString onShortName() SK_OVERRIDE { |
34 return SkString("yuv_to_rgb_effect"); | 38 return SkString("yuv_to_rgb_effect"); |
35 } | 39 } |
36 | 40 |
37 SkISize onISize() SK_OVERRIDE { | 41 SkISize onISize() SK_OVERRIDE { |
38 return SkISize::Make(334, 128); | 42 return SkISize::Make(238, 84); |
39 } | 43 } |
40 | 44 |
41 void onOnceBeforeDraw() SK_OVERRIDE { | 45 void onOnceBeforeDraw() SK_OVERRIDE { |
42 SkImageInfo info = SkImageInfo::MakeA8(24, 24); | 46 SkImageInfo yinfo = SkImageInfo::MakeA8(YSIZE, YSIZE); |
43 fBmp[0].allocPixels(info); | 47 fBmp[0].allocPixels(yinfo); |
44 fBmp[1].allocPixels(info); | 48 SkImageInfo uinfo = SkImageInfo::MakeA8(USIZE, USIZE); |
45 fBmp[2].allocPixels(info); | 49 fBmp[1].allocPixels(uinfo); |
| 50 SkImageInfo vinfo = SkImageInfo::MakeA8(VSIZE, VSIZE); |
| 51 fBmp[2].allocPixels(vinfo); |
46 unsigned char* pixels[3]; | 52 unsigned char* pixels[3]; |
47 for (int i = 0; i < 3; ++i) { | 53 for (int i = 0; i < 3; ++i) { |
48 pixels[i] = (unsigned char*)fBmp[i].getPixels(); | 54 pixels[i] = (unsigned char*)fBmp[i].getPixels(); |
49 } | 55 } |
50 int color[] = {0, 85, 170}; | 56 int color[] = {0, 85, 170}; |
51 const int limit[] = {255, 0, 255}; | 57 const int limit[] = {255, 0, 255}; |
52 const int invl[] = {0, 255, 0}; | 58 const int invl[] = {0, 255, 0}; |
53 const int inc[] = {1, -1, 1}; | 59 const int inc[] = {1, -1, 1}; |
54 for (int j = 0; j < 576; ++j) { | 60 for (int i = 0; i < 3; ++i) { |
55 for (int i = 0; i < 3; ++i) { | 61 const size_t nbBytes = fBmp[i].rowBytes() * fBmp[i].height(); |
| 62 for (size_t j = 0; j < nbBytes; ++j) { |
56 pixels[i][j] = (unsigned char)color[i]; | 63 pixels[i][j] = (unsigned char)color[i]; |
57 color[i] = (color[i] == limit[i]) ? invl[i] : color[i] + inc[i]; | 64 color[i] = (color[i] == limit[i]) ? invl[i] : color[i] + inc[i]; |
58 } | 65 } |
59 } | 66 } |
60 } | 67 } |
61 | 68 |
62 void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 69 void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
63 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget
(); | 70 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget
(); |
64 if (NULL == rt) { | 71 if (NULL == rt) { |
65 return; | 72 return; |
(...skipping 15 matching lines...) Expand all Loading... |
81 texture[0].reset(GrRefCachedBitmapTexture(context, fBmp[0], NULL)); | 88 texture[0].reset(GrRefCachedBitmapTexture(context, fBmp[0], NULL)); |
82 texture[1].reset(GrRefCachedBitmapTexture(context, fBmp[1], NULL)); | 89 texture[1].reset(GrRefCachedBitmapTexture(context, fBmp[1], NULL)); |
83 texture[2].reset(GrRefCachedBitmapTexture(context, fBmp[2], NULL)); | 90 texture[2].reset(GrRefCachedBitmapTexture(context, fBmp[2], NULL)); |
84 | 91 |
85 if (!texture[0] || !texture[1] || !texture[2]) { | 92 if (!texture[0] || !texture[1] || !texture[2]) { |
86 return; | 93 return; |
87 } | 94 } |
88 | 95 |
89 static const SkScalar kDrawPad = 10.f; | 96 static const SkScalar kDrawPad = 10.f; |
90 static const SkScalar kTestPad = 10.f; | 97 static const SkScalar kTestPad = 10.f; |
91 static const SkScalar kColorSpaceOffset = 64.f; | 98 static const SkScalar kColorSpaceOffset = 36.f; |
| 99 SkISize sizes[3] = {{YSIZE, YSIZE}, {USIZE, USIZE}, {VSIZE, VSIZE}}; |
92 | 100 |
93 for (int space = kJPEG_SkYUVColorSpace; space <= kLastEnum_SkYUVColorSpa
ce; | 101 for (int space = kJPEG_SkYUVColorSpace; space <= kLastEnum_SkYUVColorSpa
ce; |
94 ++space) { | 102 ++space) { |
95 SkRect renderRect = SkRect::MakeWH(SkIntToScalar(fBmp[0].width()), | 103 SkRect renderRect = SkRect::MakeWH(SkIntToScalar(fBmp[0].width()), |
96 SkIntToScalar(fBmp[0].height())); | 104 SkIntToScalar(fBmp[0].height())); |
97 renderRect.outset(kDrawPad, kDrawPad); | 105 renderRect.outset(kDrawPad, kDrawPad); |
98 | 106 |
99 SkScalar y = kDrawPad + kTestPad + space * kColorSpaceOffset; | 107 SkScalar y = kDrawPad + kTestPad + space * kColorSpaceOffset; |
100 SkScalar x = kDrawPad + kTestPad; | 108 SkScalar x = kDrawPad + kTestPad; |
101 | 109 |
102 const int indices[6][3] = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2}, | 110 const int indices[6][3] = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2}, |
103 {1, 2, 0}, {2, 0, 1}, {2, 1, 0}}; | 111 {1, 2, 0}, {2, 0, 1}, {2, 1, 0}}; |
104 | 112 |
105 for (int i = 0; i < 6; ++i) { | 113 for (int i = 0; i < 6; ++i) { |
106 SkAutoTUnref<GrFragmentProcessor> fp( | 114 SkAutoTUnref<GrFragmentProcessor> fp( |
107 GrYUVtoRGBEffect::Create(texture[indices[i][0]], | 115 GrYUVtoRGBEffect::Create(texture[indices[i][0]], |
108 texture[indices[i][1]], | 116 texture[indices[i][1]], |
109 texture[indices[i][2]], | 117 texture[indices[i][2]], |
110 static_cast<SkYUVColorSpace>
(space))); | 118 sizes, |
| 119 static_cast<SkYUVColorSpace
>(space))); |
111 if (fp) { | 120 if (fp) { |
112 SkMatrix viewMatrix; | 121 SkMatrix viewMatrix; |
113 viewMatrix.setTranslate(x, y); | 122 viewMatrix.setTranslate(x, y); |
114 GrPipelineBuilder pipelineBuilder; | 123 GrPipelineBuilder pipelineBuilder; |
115 pipelineBuilder.setRenderTarget(rt); | 124 pipelineBuilder.setRenderTarget(rt); |
116 pipelineBuilder.addColorProcessor(fp); | 125 pipelineBuilder.addColorProcessor(fp); |
117 tt.target()->drawSimpleRect(&pipelineBuilder, GrColor_WHITE,
viewMatrix, | 126 tt.target()->drawSimpleRect(&pipelineBuilder, GrColor_WHITE,
viewMatrix, |
118 renderRect); | 127 renderRect); |
119 } | 128 } |
120 x += renderRect.width() + kTestPad; | 129 x += renderRect.width() + kTestPad; |
121 } | 130 } |
122 } | 131 } |
123 } | 132 } |
124 | 133 |
125 private: | 134 private: |
126 SkBitmap fBmp[3]; | 135 SkBitmap fBmp[3]; |
127 | 136 |
128 typedef GM INHERITED; | 137 typedef GM INHERITED; |
129 }; | 138 }; |
130 | 139 |
131 DEF_GM( return SkNEW(YUVtoRGBEffect); ) | 140 DEF_GM( return SkNEW(YUVtoRGBEffect); ) |
132 } | 141 } |
133 | 142 |
134 #endif | 143 #endif |
OLD | NEW |