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 "SkColorPriv.h"
16 #include "effects/GrPorterDuffXferProcessor.h"
17 #include "effects/GrSimpleTextureEffect.h"
21 static const int S = 200;
23 class TexDataGM : public GM {
26 this->setBGColor(0xff000000);
30 SkString onShortName() SK_OVERRIDE {
31 return SkString("texdata");
34 SkISize onISize() SK_OVERRIDE {
35 return SkISize::Make(2*S, 2*S);
38 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
39 GrRenderTarget* target = canvas->internal_private_accessTopLayerRenderTarget();
40 GrContext* ctx = canvas->getGrContext();
42 SkAutoTArray<SkPMColor> gTextureData((2 * S) * (2 * S));
43 static const int stride = 2 * S;
44 static const SkPMColor gray = SkPackARGB32(0x40, 0x40, 0x40, 0x40);
45 static const SkPMColor white = SkPackARGB32(0xff, 0xff, 0xff, 0xff);
46 static const SkPMColor red = SkPackARGB32(0x80, 0x80, 0x00, 0x00);
47 static const SkPMColor blue = SkPackARGB32(0x80, 0x00, 0x00, 0x80);
48 static const SkPMColor green = SkPackARGB32(0x80, 0x00, 0x80, 0x00);
49 static const SkPMColor black = SkPackARGB32(0x00, 0x00, 0x00, 0x00);
50 for (int i = 0; i < 2; ++i) {
53 for (int y = 0; y < S; ++y) {
54 for (int x = 0; x < S; ++x) {
55 gTextureData[offset + y * stride + x] = gray;
60 for (int y = 0; y < S; ++y) {
61 for (int x = 0; x < S; ++x) {
62 gTextureData[offset + y * stride + x] = white;
67 for (int y = 0; y < S; ++y) {
68 for (int x = 0; x < S; ++x) {
69 gTextureData[offset + y * stride + x] = black;
73 offset = S * stride + S;
74 for (int y = 0; y < S; ++y) {
75 for (int x = 0; x < S; ++x) {
76 gTextureData[offset + y * stride + x] = gray;
81 // use RT flag bit because in GL it makes the texture be bottom-up
82 desc.fFlags = i ? kRenderTarget_GrSurfaceFlag :
84 desc.fConfig = kSkia8888_GrPixelConfig;
87 GrTexture* texture = ctx->createTexture(desc, false, gTextureData.get(), 0);
92 SkAutoTUnref<GrTexture> au(texture);
95 GrClip clip(SkRect::MakeWH(2*S, 2*S));
98 paint.setPorterDuffXPFactory(SkXfermode::kSrcOver_Mode);
102 vm.setRotate(90 * SK_Scalar1,
110 tm.postIDiv(2*S, 2*S);
111 paint.addColorTextureProcessor(texture, tm);
113 ctx->drawRect(target, clip, paint, vm, SkRect::MakeWH(2*S, 2*S));
115 // now update the lower right of the texture in first pass
116 // or upper right in second pass
118 for (int y = 0; y < S; ++y) {
119 for (int x = 0; x < S; ++x) {
120 gTextureData[offset + y * stride + x] =
121 ((x + y) % 2) ? (i ? green : red) : blue;
124 texture->writePixels(S, (i ? 0 : S), S, S,
125 texture->config(), gTextureData.get(),
127 ctx->drawRect(target, clip, paint, vm, SkRect::MakeWH(2*S, 2*S));
130 this->drawGpuOnlyMessage(canvas);
135 typedef GM INHERITED;
138 //////////////////////////////////////////////////////////////////////////////
140 static GM* MyFactory(void*) { return new TexDataGM; }
141 static GMRegistry reg(MyFactory);