| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 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 24 matching lines...) Expand all Loading... |
| 35 return make_isize(2*S, 2*S); | 35 return make_isize(2*S, 2*S); |
| 36 } | 36 } |
| 37 | 37 |
| 38 virtual uint32_t onGetFlags() const SK_OVERRIDE { return kGPUOnly_Flag; } | 38 virtual uint32_t onGetFlags() const SK_OVERRIDE { return kGPUOnly_Flag; } |
| 39 | 39 |
| 40 virtual void onDraw(SkCanvas* canvas) { | 40 virtual void onDraw(SkCanvas* canvas) { |
| 41 SkBaseDevice* device = canvas->getTopDevice(); | 41 SkBaseDevice* device = canvas->getTopDevice(); |
| 42 GrRenderTarget* target = device->accessRenderTarget(); | 42 GrRenderTarget* target = device->accessRenderTarget(); |
| 43 GrContext* ctx = GM::GetGr(canvas); | 43 GrContext* ctx = GM::GetGr(canvas); |
| 44 if (ctx && target) { | 44 if (ctx && target) { |
| 45 SkPMColor gTextureData[(2 * S) * (2 * S)]; | 45 SkAutoTArray<SkPMColor> gTextureData((2 * S) * (2 * S)); |
| 46 static const int stride = 2 * S; | 46 static const int stride = 2 * S; |
| 47 static const SkPMColor gray = SkPackARGB32(0x40, 0x40, 0x40, 0x40); | 47 static const SkPMColor gray = SkPackARGB32(0x40, 0x40, 0x40, 0x40); |
| 48 static const SkPMColor white = SkPackARGB32(0xff, 0xff, 0xff, 0xff); | 48 static const SkPMColor white = SkPackARGB32(0xff, 0xff, 0xff, 0xff); |
| 49 static const SkPMColor red = SkPackARGB32(0x80, 0x80, 0x00, 0x00); | 49 static const SkPMColor red = SkPackARGB32(0x80, 0x80, 0x00, 0x00); |
| 50 static const SkPMColor blue = SkPackARGB32(0x80, 0x00, 0x00, 0x80); | 50 static const SkPMColor blue = SkPackARGB32(0x80, 0x00, 0x00, 0x80); |
| 51 static const SkPMColor green = SkPackARGB32(0x80, 0x00, 0x80, 0x00); | 51 static const SkPMColor green = SkPackARGB32(0x80, 0x00, 0x80, 0x00); |
| 52 static const SkPMColor black = SkPackARGB32(0x00, 0x00, 0x00, 0x00); | 52 static const SkPMColor black = SkPackARGB32(0x00, 0x00, 0x00, 0x00); |
| 53 for (int i = 0; i < 2; ++i) { | 53 for (int i = 0; i < 2; ++i) { |
| 54 int offset = 0; | 54 int offset = 0; |
| 55 // fill upper-left | 55 // fill upper-left |
| (...skipping 25 matching lines...) Expand all Loading... |
| 81 } | 81 } |
| 82 | 82 |
| 83 GrTextureDesc desc; | 83 GrTextureDesc desc; |
| 84 // use RT flag bit because in GL it makes the texture be bottom-
up | 84 // use RT flag bit because in GL it makes the texture be bottom-
up |
| 85 desc.fFlags = i ? kRenderTarget_GrTextureFlagBit : | 85 desc.fFlags = i ? kRenderTarget_GrTextureFlagBit : |
| 86 kNone_GrTextureFlags; | 86 kNone_GrTextureFlags; |
| 87 desc.fConfig = kSkia8888_GrPixelConfig; | 87 desc.fConfig = kSkia8888_GrPixelConfig; |
| 88 desc.fWidth = 2 * S; | 88 desc.fWidth = 2 * S; |
| 89 desc.fHeight = 2 * S; | 89 desc.fHeight = 2 * S; |
| 90 GrTexture* texture = | 90 GrTexture* texture = |
| 91 ctx->createUncachedTexture(desc, gTextureData, 0); | 91 ctx->createUncachedTexture(desc, gTextureData.get(), 0); |
| 92 | 92 |
| 93 if (!texture) { | 93 if (!texture) { |
| 94 return; | 94 return; |
| 95 } | 95 } |
| 96 SkAutoUnref au(texture); | 96 SkAutoUnref au(texture); |
| 97 | 97 |
| 98 GrContext::AutoClip acs(ctx, SkRect::MakeWH(2*S, 2*S)); | 98 GrContext::AutoClip acs(ctx, SkRect::MakeWH(2*S, 2*S)); |
| 99 | 99 |
| 100 ctx->setRenderTarget(target); | 100 ctx->setRenderTarget(target); |
| 101 | 101 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 120 // now update the lower right of the texture in first pass | 120 // now update the lower right of the texture in first pass |
| 121 // or upper right in second pass | 121 // or upper right in second pass |
| 122 offset = 0; | 122 offset = 0; |
| 123 for (int y = 0; y < S; ++y) { | 123 for (int y = 0; y < S; ++y) { |
| 124 for (int x = 0; x < S; ++x) { | 124 for (int x = 0; x < S; ++x) { |
| 125 gTextureData[offset + y * stride + x] = | 125 gTextureData[offset + y * stride + x] = |
| 126 ((x + y) % 2) ? (i ? green : red) : blue; | 126 ((x + y) % 2) ? (i ? green : red) : blue; |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 texture->writePixels(S, (i ? 0 : S), S, S, | 129 texture->writePixels(S, (i ? 0 : S), S, S, |
| 130 texture->config(), gTextureData, | 130 texture->config(), gTextureData.get(), |
| 131 4 * stride); | 131 4 * stride); |
| 132 ctx->drawRect(paint, SkRect::MakeWH(2*S, 2*S)); | 132 ctx->drawRect(paint, SkRect::MakeWH(2*S, 2*S)); |
| 133 } | 133 } |
| 134 } | 134 } |
| 135 } | 135 } |
| 136 | 136 |
| 137 private: | 137 private: |
| 138 typedef GM INHERITED; | 138 typedef GM INHERITED; |
| 139 }; | 139 }; |
| 140 | 140 |
| 141 ////////////////////////////////////////////////////////////////////////////// | 141 ////////////////////////////////////////////////////////////////////////////// |
| 142 | 142 |
| 143 static GM* MyFactory(void*) { return new TexDataGM; } | 143 static GM* MyFactory(void*) { return new TexDataGM; } |
| 144 static GMRegistry reg(MyFactory); | 144 static GMRegistry reg(MyFactory); |
| 145 | 145 |
| 146 } | 146 } |
| 147 | 147 |
| 148 #endif | 148 #endif |
| OLD | NEW |