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"
|
2015-05-26 18:38:03 +00:00
|
|
|
#include "GrDrawContext.h"
|
2014-12-08 21:26:43 +00:00
|
|
|
#include "SkColorPriv.h"
|
2014-12-09 19:15:43 +00:00
|
|
|
#include "effects/GrPorterDuffXferProcessor.h"
|
|
|
|
#include "effects/GrSimpleTextureEffect.h"
|
2011-07-18 15:25:04 +00:00
|
|
|
|
|
|
|
static const int S = 200;
|
|
|
|
|
2015-09-09 15:16:41 +00:00
|
|
|
DEF_SIMPLE_GM_BG(texdata, canvas, 2 * S, 2 * S, SK_ColorBLACK) {
|
2014-03-12 18:28:35 +00:00
|
|
|
GrRenderTarget* target = canvas->internal_private_accessTopLayerRenderTarget();
|
2013-11-21 06:21:58 +00:00
|
|
|
GrContext* ctx = canvas->getGrContext();
|
2015-10-15 15:01:48 +00:00
|
|
|
SkAutoTUnref<GrDrawContext> drawContext(ctx ? ctx->drawContext(target) : nullptr);
|
2015-05-26 18:38:03 +00:00
|
|
|
if (drawContext && target) {
|
2013-10-16 11:50:50 +00:00
|
|
|
SkAutoTArray<SkPMColor> gTextureData((2 * S) * (2 * S));
|
2011-07-18 15:25:04 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-28 21:33:06 +00:00
|
|
|
GrSurfaceDesc desc;
|
2011-07-18 15:25:04 +00:00
|
|
|
// use RT flag bit because in GL it makes the texture be bottom-up
|
2014-10-28 21:33:06 +00:00
|
|
|
desc.fFlags = i ? kRenderTarget_GrSurfaceFlag :
|
|
|
|
kNone_GrSurfaceFlags;
|
2013-02-07 14:43:04 +00:00
|
|
|
desc.fConfig = kSkia8888_GrPixelConfig;
|
2011-07-18 15:25:04 +00:00
|
|
|
desc.fWidth = 2 * S;
|
|
|
|
desc.fHeight = 2 * S;
|
2015-04-30 21:18:54 +00:00
|
|
|
GrTexture* texture = ctx->textureProvider()->createTexture(
|
|
|
|
desc, false, gTextureData.get(), 0);
|
2011-07-18 15:25:04 +00:00
|
|
|
|
|
|
|
if (!texture) {
|
|
|
|
return;
|
|
|
|
}
|
2014-07-21 21:24:01 +00:00
|
|
|
SkAutoTUnref<GrTexture> au(texture);
|
2011-07-18 15:25:04 +00:00
|
|
|
|
2015-02-25 21:19:48 +00:00
|
|
|
// setup new clip
|
|
|
|
GrClip clip(SkRect::MakeWH(2*S, 2*S));
|
2012-07-11 18:20:35 +00:00
|
|
|
|
2011-07-18 15:25:04 +00:00
|
|
|
GrPaint paint;
|
2014-12-09 19:15:43 +00:00
|
|
|
paint.setPorterDuffXPFactory(SkXfermode::kSrcOver_Mode);
|
|
|
|
|
2012-11-01 18:02:54 +00:00
|
|
|
SkMatrix vm;
|
2011-07-18 15:25:04 +00:00
|
|
|
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();
|
|
|
|
}
|
2012-11-01 18:02:54 +00:00
|
|
|
SkMatrix tm;
|
2011-07-18 15:25:04 +00:00
|
|
|
tm = vm;
|
2012-10-16 15:19:45 +00:00
|
|
|
tm.postIDiv(2*S, 2*S);
|
2014-09-23 16:50:21 +00:00
|
|
|
paint.addColorTextureProcessor(texture, tm);
|
2011-07-18 15:25:04 +00:00
|
|
|
|
2015-10-15 15:01:48 +00:00
|
|
|
drawContext->drawRect(clip, paint, vm, SkRect::MakeWH(2*S, 2*S));
|
2011-07-18 15:25:04 +00:00
|
|
|
|
|
|
|
// 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,
|
2013-10-16 11:50:50 +00:00
|
|
|
texture->config(), gTextureData.get(),
|
2011-11-16 20:36:03 +00:00
|
|
|
4 * stride);
|
2015-10-15 15:01:48 +00:00
|
|
|
drawContext->drawRect(clip, paint, vm, SkRect::MakeWH(2*S, 2*S));
|
2011-07-18 15:25:04 +00:00
|
|
|
}
|
2015-01-31 15:51:14 +00:00
|
|
|
} else {
|
2015-09-09 15:16:41 +00:00
|
|
|
skiagm::GM::DrawGpuOnlyMessage(canvas);
|
2011-07-18 15:25:04 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|