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