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 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 | 76 |
77 GrTestTarget tt; | 77 GrTestTarget tt; |
78 context->getTestTarget(&tt); | 78 context->getTestTarget(&tt); |
79 if (NULL == tt.target()) { | 79 if (NULL == tt.target()) { |
80 SkDEBUGFAIL("Couldn't get Gr test target."); | 80 SkDEBUGFAIL("Couldn't get Gr test target."); |
81 return; | 81 return; |
82 } | 82 } |
83 | 83 |
84 GrDrawState* drawState = tt.target()->drawState(); | 84 GrDrawState* drawState = tt.target()->drawState(); |
85 | 85 |
86 GrTexture* texture[3]; | 86 SkAutoTUnref<GrTexture> texture[3]; |
87 texture[0] = GrLockAndRefCachedBitmapTexture(context, fBmp[0], NULL); | 87 texture[0].reset(GrRefCachedBitmapTexture(context, fBmp[0], NULL)); |
88 texture[1] = GrLockAndRefCachedBitmapTexture(context, fBmp[1], NULL); | 88 texture[1].reset(GrRefCachedBitmapTexture(context, fBmp[1], NULL)); |
89 texture[2] = GrLockAndRefCachedBitmapTexture(context, fBmp[2], NULL); | 89 texture[2].reset(GrRefCachedBitmapTexture(context, fBmp[2], NULL)); |
90 if ((NULL == texture[0]) || (NULL == texture[1]) || (NULL == texture[2])
) { | 90 |
| 91 if (!texture[0] || !texture[1] || !texture[2]) { |
91 return; | 92 return; |
92 } | 93 } |
93 | 94 |
94 static const SkScalar kDrawPad = 10.f; | 95 static const SkScalar kDrawPad = 10.f; |
95 static const SkScalar kTestPad = 10.f; | 96 static const SkScalar kTestPad = 10.f; |
96 static const SkScalar kColorSpaceOffset = 64.f; | 97 static const SkScalar kColorSpaceOffset = 64.f; |
97 | 98 |
98 for (int space = kJPEG_SkYUVColorSpace; space <= kLastEnum_SkYUVColorSpa
ce; | 99 for (int space = kJPEG_SkYUVColorSpace; space <= kLastEnum_SkYUVColorSpa
ce; |
99 ++space) { | 100 ++space) { |
100 SkRect renderRect = SkRect::MakeWH(SkIntToScalar(fBmp[0].width()), | 101 SkRect renderRect = SkRect::MakeWH(SkIntToScalar(fBmp[0].width()), |
101 SkIntToScalar(fBmp[0].height())); | 102 SkIntToScalar(fBmp[0].height())); |
102 renderRect.outset(kDrawPad, kDrawPad); | 103 renderRect.outset(kDrawPad, kDrawPad); |
103 | 104 |
104 SkScalar y = kDrawPad + kTestPad + space * kColorSpaceOffset; | 105 SkScalar y = kDrawPad + kTestPad + space * kColorSpaceOffset; |
105 SkScalar x = kDrawPad + kTestPad; | 106 SkScalar x = kDrawPad + kTestPad; |
106 | 107 |
107 const int indices[6][3] = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2}, {1, 2, 0},
{2, 0, 1}, {2, 1, 0}}; | 108 const int indices[6][3] = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2}, |
| 109 {1, 2, 0}, {2, 0, 1}, {2, 1, 0}}; |
108 | 110 |
109 for (int i = 0; i < 6; ++i) { | 111 for (int i = 0; i < 6; ++i) { |
110 SkAutoTUnref<GrFragmentProcessor> fp( | 112 SkAutoTUnref<GrFragmentProcessor> fp( |
111 GrYUVtoRGBEffect::Create(texture[indices[i][0]], | 113 GrYUVtoRGBEffect::Create(texture[indices[i][0]], |
112 texture[indices[i][1]], | 114 texture[indices[i][1]], |
113 texture[indices[i][2]], | 115 texture[indices[i][2]], |
114 static_cast<SkYUVColorSpace>(
space))); | 116 static_cast<SkYUVColorSpace>
(space))); |
115 if (fp) { | 117 if (fp) { |
116 SkMatrix viewMatrix; | 118 SkMatrix viewMatrix; |
117 viewMatrix.setTranslate(x, y); | 119 viewMatrix.setTranslate(x, y); |
118 drawState->reset(viewMatrix); | 120 drawState->reset(viewMatrix); |
119 drawState->setRenderTarget(rt); | 121 drawState->setRenderTarget(rt); |
120 drawState->setColor(0xffffffff); | 122 drawState->setColor(0xffffffff); |
121 drawState->addColorProcessor(fp); | 123 drawState->addColorProcessor(fp); |
122 tt.target()->drawSimpleRect(renderRect); | 124 tt.target()->drawSimpleRect(renderRect); |
123 } | 125 } |
124 x += renderRect.width() + kTestPad; | 126 x += renderRect.width() + kTestPad; |
125 } | 127 } |
126 } | 128 } |
127 | 129 } |
128 GrUnlockAndUnrefCachedBitmapTexture(texture[0]); | |
129 GrUnlockAndUnrefCachedBitmapTexture(texture[1]); | |
130 GrUnlockAndUnrefCachedBitmapTexture(texture[2]); | |
131 } | |
132 | 130 |
133 private: | 131 private: |
134 SkBitmap fBmp[3]; | 132 SkBitmap fBmp[3]; |
135 | 133 |
136 typedef GM INHERITED; | 134 typedef GM INHERITED; |
137 }; | 135 }; |
138 | 136 |
139 DEF_GM( return SkNEW(YUVtoRGBEffect); ) | 137 DEF_GM( return SkNEW(YUVtoRGBEffect); ) |
140 } | 138 } |
141 | 139 |
142 #endif | 140 #endif |
OLD | NEW |