2011-07-28 14:26:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2012-08-02 14:03:32 +00:00
|
|
|
|
|
|
|
// This test only works with the GPU backend.
|
|
|
|
|
2011-07-18 15:25:04 +00:00
|
|
|
#include "gm.h"
|
2012-08-03 15:00:52 +00:00
|
|
|
|
|
|
|
#if SK_SUPPORT_GPU
|
2011-07-18 15:25:04 +00:00
|
|
|
#include "GrContext.h"
|
2012-07-26 19:39:06 +00:00
|
|
|
#include "effects/GrSingleTextureEffect.h"
|
2011-07-18 15:25:04 +00:00
|
|
|
#include "SkColorPriv.h"
|
|
|
|
#include "SkDevice.h"
|
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
extern GrContext* GetGr();
|
|
|
|
|
|
|
|
static const int S = 200;
|
|
|
|
|
|
|
|
class TexDataGM : public GM {
|
|
|
|
public:
|
2011-10-31 14:18:20 +00:00
|
|
|
TexDataGM() {
|
|
|
|
this->setBGColor(0xff000000);
|
|
|
|
}
|
2011-07-18 15:25:04 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual SkString onShortName() {
|
|
|
|
return SkString("texdata");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual SkISize onISize() {
|
|
|
|
return make_isize(2*S, 2*S);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
|
|
|
SkDevice* device = canvas->getDevice();
|
|
|
|
GrRenderTarget* target = (GrRenderTarget*) device->accessRenderTarget();
|
|
|
|
GrContext* ctx = GetGr();
|
|
|
|
if (ctx && target) {
|
|
|
|
SkPMColor gTextureData[(2 * S) * (2 * S)];
|
|
|
|
static const int stride = 2 * S;
|
|
|
|
static const SkPMColor gray = SkPackARGB32(0x40, 0x40, 0x40, 0x40);
|
|
|
|
static const SkPMColor white = SkPackARGB32(0xff, 0xff, 0xff, 0xff);
|
|
|
|
static const SkPMColor red = SkPackARGB32(0x80, 0x80, 0x00, 0x00);
|
|
|
|
static const SkPMColor blue = SkPackARGB32(0x80, 0x00, 0x00, 0x80);
|
|
|
|
static const SkPMColor green = SkPackARGB32(0x80, 0x00, 0x80, 0x00);
|
|
|
|
static const SkPMColor black = SkPackARGB32(0x00, 0x00, 0x00, 0x00);
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
int offset = 0;
|
|
|
|
// fill upper-left
|
|
|
|
for (int y = 0; y < S; ++y) {
|
|
|
|
for (int x = 0; x < S; ++x) {
|
|
|
|
gTextureData[offset + y * stride + x] = gray;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// fill upper-right
|
|
|
|
offset = S;
|
|
|
|
for (int y = 0; y < S; ++y) {
|
|
|
|
for (int x = 0; x < S; ++x) {
|
|
|
|
gTextureData[offset + y * stride + x] = white;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// fill lower left
|
|
|
|
offset = S * stride;
|
|
|
|
for (int y = 0; y < S; ++y) {
|
|
|
|
for (int x = 0; x < S; ++x) {
|
|
|
|
gTextureData[offset + y * stride + x] = black;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// fill lower right
|
|
|
|
offset = S * stride + S;
|
|
|
|
for (int y = 0; y < S; ++y) {
|
|
|
|
for (int x = 0; x < S; ++x) {
|
|
|
|
gTextureData[offset + y * stride + x] = gray;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GrTextureDesc desc;
|
|
|
|
// use RT flag bit because in GL it makes the texture be bottom-up
|
|
|
|
desc.fFlags = i ? kRenderTarget_GrTextureFlagBit :
|
|
|
|
kNone_GrTextureFlags;
|
2011-12-06 14:46:34 +00:00
|
|
|
desc.fConfig = kSkia8888_PM_GrPixelConfig;
|
2011-07-18 15:25:04 +00:00
|
|
|
desc.fWidth = 2 * S;
|
|
|
|
desc.fHeight = 2 * S;
|
2012-08-23 18:14:13 +00:00
|
|
|
GrTexture* texture =
|
2011-07-18 15:25:04 +00:00
|
|
|
ctx->createUncachedTexture(desc, gTextureData, 0);
|
|
|
|
|
|
|
|
if (!texture) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
GrAutoUnref au(texture);
|
|
|
|
|
2012-07-11 20:57:46 +00:00
|
|
|
GrContext::AutoClip acs(ctx, GrRect::MakeWH(2*S, 2*S));
|
2012-07-11 18:20:35 +00:00
|
|
|
|
2011-07-18 15:25:04 +00:00
|
|
|
ctx->setRenderTarget(target);
|
|
|
|
|
|
|
|
GrPaint paint;
|
|
|
|
paint.reset();
|
|
|
|
paint.fColor = 0xffffffff;
|
2012-06-06 20:51:20 +00:00
|
|
|
paint.fSrcBlendCoeff = kOne_GrBlendCoeff;
|
|
|
|
paint.fDstBlendCoeff = kISA_GrBlendCoeff;
|
2011-07-18 15:25:04 +00:00
|
|
|
GrMatrix vm;
|
|
|
|
if (i) {
|
2011-09-29 18:08:18 +00:00
|
|
|
vm.setRotate(90 * SK_Scalar1,
|
|
|
|
S * SK_Scalar1,
|
|
|
|
S * SK_Scalar1);
|
2011-07-18 15:25:04 +00:00
|
|
|
} else {
|
|
|
|
vm.reset();
|
|
|
|
}
|
|
|
|
ctx->setMatrix(vm);
|
|
|
|
GrMatrix tm;
|
|
|
|
tm = vm;
|
2011-12-12 18:45:07 +00:00
|
|
|
GrMatrix* sampleMat = paint.textureSampler(0)->matrix();
|
|
|
|
*sampleMat = vm;
|
|
|
|
sampleMat->postIDiv(2*S, 2*S);
|
2012-07-26 19:39:06 +00:00
|
|
|
paint.textureSampler(0)->setCustomStage(
|
|
|
|
SkNEW_ARGS(GrSingleTextureEffect, (texture)))->unref();
|
|
|
|
|
2011-07-18 15:25:04 +00:00
|
|
|
|
|
|
|
ctx->drawRect(paint, GrRect::MakeWH(2*S, 2*S));
|
|
|
|
|
|
|
|
// now update the lower right of the texture in first pass
|
|
|
|
// or upper right in second pass
|
|
|
|
offset = 0;
|
|
|
|
for (int y = 0; y < S; ++y) {
|
|
|
|
for (int x = 0; x < S; ++x) {
|
2012-08-23 18:14:13 +00:00
|
|
|
gTextureData[offset + y * stride + x] =
|
2011-07-18 15:25:04 +00:00
|
|
|
((x + y) % 2) ? (i ? green : red) : blue;
|
|
|
|
}
|
|
|
|
}
|
2011-11-16 20:36:03 +00:00
|
|
|
texture->writePixels(S, (i ? 0 : S), S, S,
|
|
|
|
texture->config(), gTextureData,
|
|
|
|
4 * stride);
|
2011-07-18 15:25:04 +00:00
|
|
|
ctx->drawRect(paint, GrRect::MakeWH(2*S, 2*S));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static GM* MyFactory(void*) { return new TexDataGM; }
|
|
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|