3 * Copyright 2011 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
9 // This test only works with the GPU backend.
14 #include "GrContext.h"
15 #include "effects/GrSimpleTextureEffect.h"
16 #include "SkColorPriv.h"
20 static const int S = 200;
22 class TexDataGM : public GM {
25 this->setBGColor(0xff000000);
29 virtual SkString onShortName() {
30 return SkString("texdata");
33 virtual SkISize onISize() {
34 return SkISize::Make(2*S, 2*S);
37 virtual uint32_t onGetFlags() const SK_OVERRIDE { return kGPUOnly_Flag; }
39 virtual void onDraw(SkCanvas* canvas) {
40 GrRenderTarget* target = canvas->internal_private_accessTopLayerRenderTarget();
41 GrContext* ctx = canvas->getGrContext();
43 SkAutoTArray<SkPMColor> gTextureData((2 * S) * (2 * S));
44 static const int stride = 2 * S;
45 static const SkPMColor gray = SkPackARGB32(0x40, 0x40, 0x40, 0x40);
46 static const SkPMColor white = SkPackARGB32(0xff, 0xff, 0xff, 0xff);
47 static const SkPMColor red = SkPackARGB32(0x80, 0x80, 0x00, 0x00);
48 static const SkPMColor blue = SkPackARGB32(0x80, 0x00, 0x00, 0x80);
49 static const SkPMColor green = SkPackARGB32(0x80, 0x00, 0x80, 0x00);
50 static const SkPMColor black = SkPackARGB32(0x00, 0x00, 0x00, 0x00);
51 for (int i = 0; i < 2; ++i) {
54 for (int y = 0; y < S; ++y) {
55 for (int x = 0; x < S; ++x) {
56 gTextureData[offset + y * stride + x] = gray;
61 for (int y = 0; y < S; ++y) {
62 for (int x = 0; x < S; ++x) {
63 gTextureData[offset + y * stride + x] = white;
68 for (int y = 0; y < S; ++y) {
69 for (int x = 0; x < S; ++x) {
70 gTextureData[offset + y * stride + x] = black;
74 offset = S * stride + S;
75 for (int y = 0; y < S; ++y) {
76 for (int x = 0; x < S; ++x) {
77 gTextureData[offset + y * stride + x] = gray;
82 // use RT flag bit because in GL it makes the texture be bottom-up
83 desc.fFlags = i ? kRenderTarget_GrSurfaceFlag :
85 desc.fConfig = kSkia8888_GrPixelConfig;
89 ctx->createUncachedTexture(desc, gTextureData.get(), 0);
94 SkAutoTUnref<GrTexture> au(texture);
96 GrContext::AutoClip acs(ctx, SkRect::MakeWH(2*S, 2*S));
98 ctx->setRenderTarget(target);
101 paint.setBlendFunc(kOne_GrBlendCoeff, kISA_GrBlendCoeff);
104 vm.setRotate(90 * SK_Scalar1,
113 tm.postIDiv(2*S, 2*S);
114 paint.addColorTextureProcessor(texture, tm);
116 ctx->drawRect(paint, SkRect::MakeWH(2*S, 2*S));
118 // now update the lower right of the texture in first pass
119 // or upper right in second pass
121 for (int y = 0; y < S; ++y) {
122 for (int x = 0; x < S; ++x) {
123 gTextureData[offset + y * stride + x] =
124 ((x + y) % 2) ? (i ? green : red) : blue;
127 texture->writePixels(S, (i ? 0 : S), S, S,
128 texture->config(), gTextureData.get(),
130 ctx->drawRect(paint, SkRect::MakeWH(2*S, 2*S));
136 typedef GM INHERITED;
139 //////////////////////////////////////////////////////////////////////////////
141 static GM* MyFactory(void*) { return new TexDataGM; }
142 static GMRegistry reg(MyFactory);