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"
|
2017-01-24 21:24:41 +00:00
|
|
|
#include "GrContextPriv.h"
|
2016-10-27 18:47:55 +00:00
|
|
|
#include "GrRenderTargetContext.h"
|
2017-01-24 21:24:41 +00:00
|
|
|
#include "GrTextureContext.h"
|
2016-08-19 20:29:27 +00:00
|
|
|
#include "GrFixedClip.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
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr int S = 200;
|
2017-01-24 21:24:41 +00:00
|
|
|
constexpr int kStride = 2 * S;
|
|
|
|
|
|
|
|
// Fill in the pixels:
|
|
|
|
// gray | white
|
|
|
|
// -------------
|
|
|
|
// black | gray
|
|
|
|
static void fill_in_pixels(SkPMColor* pixels) {
|
|
|
|
const SkPMColor gray = SkPackARGB32(0x40, 0x40, 0x40, 0x40);
|
|
|
|
const SkPMColor white = SkPackARGB32(0xff, 0xff, 0xff, 0xff);
|
|
|
|
const SkPMColor black = SkPackARGB32(0x00, 0x00, 0x00, 0x00);
|
|
|
|
|
|
|
|
int offset = 0;
|
|
|
|
|
|
|
|
// fill upper-left
|
|
|
|
for (int y = 0; y < S; ++y) {
|
|
|
|
for (int x = 0; x < S; ++x) {
|
|
|
|
pixels[offset + y * kStride + x] = gray;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// fill upper-right
|
|
|
|
offset = S;
|
|
|
|
for (int y = 0; y < S; ++y) {
|
|
|
|
for (int x = 0; x < S; ++x) {
|
|
|
|
pixels[offset + y * kStride + x] = white;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// fill lower left
|
|
|
|
offset = S * kStride;
|
|
|
|
for (int y = 0; y < S; ++y) {
|
|
|
|
for (int x = 0; x < S; ++x) {
|
|
|
|
pixels[offset + y * kStride + x] = black;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// fill lower right
|
|
|
|
offset = S * kStride + S;
|
|
|
|
for (int y = 0; y < S; ++y) {
|
|
|
|
for (int x = 0; x < S; ++x) {
|
|
|
|
pixels[offset + y * kStride + x] = gray;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-07-18 15:25:04 +00:00
|
|
|
|
2015-09-09 15:16:41 +00:00
|
|
|
DEF_SIMPLE_GM_BG(texdata, canvas, 2 * S, 2 * S, SK_ColorBLACK) {
|
2016-10-27 18:47:55 +00:00
|
|
|
GrRenderTargetContext* renderTargetContext =
|
|
|
|
canvas->internal_private_accessTopLayerRenderTargetContext();
|
|
|
|
if (!renderTargetContext) {
|
2016-04-28 21:32:04 +00:00
|
|
|
skiagm::GM::DrawGpuOnlyMessage(canvas);
|
|
|
|
return;
|
|
|
|
}
|
2011-07-18 15:25:04 +00:00
|
|
|
|
2016-04-28 21:32:04 +00:00
|
|
|
GrContext* context = canvas->getGrContext();
|
|
|
|
if (!context) {
|
|
|
|
return;
|
|
|
|
}
|
2011-07-18 15:25:04 +00:00
|
|
|
|
2017-01-24 21:24:41 +00:00
|
|
|
const SkImageInfo ii = SkImageInfo::Make(S, S, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
|
|
|
|
|
2016-04-28 21:32:04 +00:00
|
|
|
SkAutoTArray<SkPMColor> gTextureData((2 * S) * (2 * S));
|
2016-09-01 18:24:54 +00:00
|
|
|
const SkPMColor red = SkPackARGB32(0x80, 0x80, 0x00, 0x00);
|
|
|
|
const SkPMColor blue = SkPackARGB32(0x80, 0x00, 0x00, 0x80);
|
|
|
|
const SkPMColor green = SkPackARGB32(0x80, 0x00, 0x80, 0x00);
|
2016-04-28 21:32:04 +00:00
|
|
|
for (int i = 0; i < 2; ++i) {
|
2017-01-24 21:24:41 +00:00
|
|
|
fill_in_pixels(gTextureData.get());
|
2011-07-18 15:25:04 +00:00
|
|
|
|
2016-04-28 21:32:04 +00:00
|
|
|
GrSurfaceDesc desc;
|
2016-05-11 12:15:55 +00:00
|
|
|
desc.fOrigin = i ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin;
|
2017-01-24 21:24:41 +00:00
|
|
|
desc.fConfig = kBGRA_8888_GrPixelConfig;
|
2016-04-28 21:32:04 +00:00
|
|
|
desc.fWidth = 2 * S;
|
|
|
|
desc.fHeight = 2 * S;
|
2012-07-11 18:20:35 +00:00
|
|
|
|
2017-01-24 21:24:41 +00:00
|
|
|
sk_sp<GrSurfaceProxy> proxy = GrSurfaceProxy::MakeDeferred(*context->caps(),
|
|
|
|
context->textureProvider(),
|
|
|
|
desc, SkBudgeted::kNo,
|
|
|
|
gTextureData.get(), 0);
|
|
|
|
if (!proxy) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sk_sp<GrSurfaceContext> tContext = context->contextPriv().makeWrappedSurfaceContext(
|
|
|
|
std::move(proxy), nullptr);
|
|
|
|
|
|
|
|
if (!tContext) {
|
2016-04-28 21:32:04 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-12-09 19:15:43 +00:00
|
|
|
|
2016-04-28 21:32:04 +00:00
|
|
|
// setup new clip
|
2016-05-13 17:25:00 +00:00
|
|
|
GrFixedClip clip(SkIRect::MakeWH(2*S, 2*S));
|
2011-07-18 15:25:04 +00:00
|
|
|
|
2016-04-28 21:32:04 +00:00
|
|
|
GrPaint paint;
|
2016-10-28 19:42:34 +00:00
|
|
|
paint.setPorterDuffXPFactory(SkBlendMode::kSrcOver);
|
2011-07-18 15:25:04 +00:00
|
|
|
|
2016-04-28 21:32:04 +00:00
|
|
|
SkMatrix vm;
|
|
|
|
if (i) {
|
2017-01-24 21:24:41 +00:00
|
|
|
vm.setRotate(90 * SK_Scalar1, S * SK_Scalar1, S * SK_Scalar1);
|
2015-01-31 15:51:14 +00:00
|
|
|
} else {
|
2016-04-28 21:32:04 +00:00
|
|
|
vm.reset();
|
2011-07-18 15:25:04 +00:00
|
|
|
}
|
2017-01-24 21:24:41 +00:00
|
|
|
paint.addColorTextureProcessor(context, sk_ref_sp(tContext->asDeferredTexture()),
|
|
|
|
nullptr, vm);
|
2016-04-28 21:32:04 +00:00
|
|
|
|
2017-01-11 18:42:54 +00:00
|
|
|
renderTargetContext->drawRect(clip, GrPaint(paint), GrAA::kNo, vm,
|
|
|
|
SkRect::MakeWH(2 * S, 2 * S));
|
2016-04-28 21:32:04 +00:00
|
|
|
|
|
|
|
// now update the lower right of the texture in first pass
|
|
|
|
// or upper right in second pass
|
|
|
|
for (int y = 0; y < S; ++y) {
|
|
|
|
for (int x = 0; x < S; ++x) {
|
2017-01-24 21:24:41 +00:00
|
|
|
gTextureData[y * kStride + x] = ((x + y) % 2) ? (i ? green : red) : blue;
|
2016-04-28 21:32:04 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-24 21:24:41 +00:00
|
|
|
|
|
|
|
if (!tContext->writePixels(ii, gTextureData.get(), 4 * kStride, S, i ? 0 : S)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-01-11 18:42:54 +00:00
|
|
|
renderTargetContext->drawRect(clip, std::move(paint), GrAA::kNo, vm,
|
|
|
|
SkRect::MakeWH(2 * S, 2 * S));
|
2016-04-28 21:32:04 +00:00
|
|
|
}
|
2011-07-18 15:25:04 +00:00
|
|
|
}
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
2016-04-28 21:32:04 +00:00
|
|
|
|