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