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 namespace skiagm { | 22 namespace skiagm { |
23 /** | 23 /** |
24 * This GM directly exercises GrYUVtoRGBEffect. | 24 * This GM directly exercises GrYUVtoRGBEffect. |
25 */ | 25 */ |
26 class YUVtoRGBEffect : public GM { | 26 class YUVtoRGBEffect : public GM { |
27 public: | 27 public: |
28 YUVtoRGBEffect() { | 28 YUVtoRGBEffect(SkPixelRef::YUVColorSpace colorSpace) |
| 29 : fColorSpace(colorSpace) { |
29 this->setBGColor(0xFFFFFFFF); | 30 this->setBGColor(0xFFFFFFFF); |
30 } | 31 } |
31 | 32 |
32 protected: | 33 protected: |
33 virtual SkString onShortName() SK_OVERRIDE { | 34 virtual SkString onShortName() SK_OVERRIDE { |
34 return SkString("yuv_to_rgb_effect"); | 35 SkString out("yuv_to_rgb_effect_"); |
| 36 switch(fColorSpace) { |
| 37 case SkPixelRef::kJPEG_YUVColorSpace: |
| 38 out.append("jpeg"); |
| 39 break; |
| 40 case SkPixelRef::kRec601_YUVColorSpace: |
| 41 out.append("rec601"); |
| 42 break; |
| 43 } |
| 44 return out; |
35 } | 45 } |
36 | 46 |
37 virtual SkISize onISize() SK_OVERRIDE { | 47 virtual SkISize onISize() SK_OVERRIDE { |
38 return SkISize::Make(334, 64); | 48 return SkISize::Make(334, 64); |
39 } | 49 } |
40 | 50 |
41 virtual uint32_t onGetFlags() const SK_OVERRIDE { | 51 virtual uint32_t onGetFlags() const SK_OVERRIDE { |
42 // This is a GPU-specific GM. | 52 // This is a GPU-specific GM. |
43 return kGPUOnly_Flag; | 53 return kGPUOnly_Flag; |
44 } | 54 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 110 |
101 SkScalar y = kDrawPad + kTestPad; | 111 SkScalar y = kDrawPad + kTestPad; |
102 SkScalar x = kDrawPad + kTestPad; | 112 SkScalar x = kDrawPad + kTestPad; |
103 | 113 |
104 const int indices[6][3] = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2}, {1, 2, 0}, {
2, 0, 1}, {2, 1, 0}}; | 114 const int indices[6][3] = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2}, {1, 2, 0}, {
2, 0, 1}, {2, 1, 0}}; |
105 | 115 |
106 for (int i = 0; i < 6; ++i) { | 116 for (int i = 0; i < 6; ++i) { |
107 SkAutoTUnref<GrEffect> effect( | 117 SkAutoTUnref<GrEffect> effect( |
108 GrYUVtoRGBEffect::Create(texture[indices[i][0]], | 118 GrYUVtoRGBEffect::Create(texture[indices[i][0]], |
109 texture[indices[i][1]], | 119 texture[indices[i][1]], |
110 texture[indices[i][2]])); | 120 texture[indices[i][2]], |
| 121 SkPixelRef::kJPEG_YUVColorSpace
)); |
111 if (effect) { | 122 if (effect) { |
112 SkMatrix viewMatrix; | 123 SkMatrix viewMatrix; |
113 viewMatrix.setTranslate(x, y); | 124 viewMatrix.setTranslate(x, y); |
114 drawState->reset(viewMatrix); | 125 drawState->reset(viewMatrix); |
115 drawState->setRenderTarget(rt); | 126 drawState->setRenderTarget(rt); |
116 drawState->setColor(0xffffffff); | 127 drawState->setColor(0xffffffff); |
117 drawState->addColorEffect(effect, 1); | 128 drawState->addColorEffect(effect, 1); |
118 tt.target()->drawSimpleRect(renderRect); | 129 tt.target()->drawSimpleRect(renderRect); |
119 } | 130 } |
120 x += renderRect.width() + kTestPad; | 131 x += renderRect.width() + kTestPad; |
121 } | 132 } |
122 | 133 |
123 GrUnlockAndUnrefCachedBitmapTexture(texture[0]); | 134 GrUnlockAndUnrefCachedBitmapTexture(texture[0]); |
124 GrUnlockAndUnrefCachedBitmapTexture(texture[1]); | 135 GrUnlockAndUnrefCachedBitmapTexture(texture[1]); |
125 GrUnlockAndUnrefCachedBitmapTexture(texture[2]); | 136 GrUnlockAndUnrefCachedBitmapTexture(texture[2]); |
126 } | 137 } |
127 | 138 |
128 private: | 139 private: |
129 SkBitmap fBmp[3]; | 140 SkBitmap fBmp[3]; |
| 141 SkPixelRef::YUVColorSpace fColorSpace; |
130 | 142 |
131 typedef GM INHERITED; | 143 typedef GM INHERITED; |
132 }; | 144 }; |
133 | 145 |
134 DEF_GM( return SkNEW(YUVtoRGBEffect); ) | 146 DEF_GM( return SkNEW_ARGS(YUVtoRGBEffect, (SkPixelRef::kJPEG_YUVColorSpace)); ) |
| 147 DEF_GM( return SkNEW_ARGS(YUVtoRGBEffect, (SkPixelRef::kRec601_YUVColorSpace));
) |
135 } | 148 } |
136 | 149 |
137 #endif | 150 #endif |
OLD | NEW |