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