2 * Copyright 2011 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 // This test only works with the GPU backend.
13 #include "GrContext.h"
14 #include "GrContextPriv.h"
15 #include "GrRenderTargetContext.h"
16 #include "GrTextureContext.h"
17 #include "GrFixedClip.h"
18 #include "SkColorPriv.h"
20 #include "effects/GrPorterDuffXferProcessor.h"
21 #include "effects/GrSimpleTextureEffect.h"
23 constexpr int S = 200;
24 constexpr int kStride = 2 * S;
26 // Fill in the pixels:
30 static void fill_in_pixels(SkPMColor* pixels) {
31 const SkPMColor gray = SkPackARGB32(0x40, 0x40, 0x40, 0x40);
32 const SkPMColor white = SkPackARGB32(0xff, 0xff, 0xff, 0xff);
33 const SkPMColor black = SkPackARGB32(0x00, 0x00, 0x00, 0x00);
38 for (int y = 0; y < S; ++y) {
39 for (int x = 0; x < S; ++x) {
40 pixels[offset + y * kStride + x] = gray;
45 for (int y = 0; y < S; ++y) {
46 for (int x = 0; x < S; ++x) {
47 pixels[offset + y * kStride + x] = white;
52 for (int y = 0; y < S; ++y) {
53 for (int x = 0; x < S; ++x) {
54 pixels[offset + y * kStride + x] = black;
58 offset = S * kStride + S;
59 for (int y = 0; y < S; ++y) {
60 for (int x = 0; x < S; ++x) {
61 pixels[offset + y * kStride + x] = gray;
66 DEF_SIMPLE_GM_BG(texdata, canvas, 2 * S, 2 * S, SK_ColorBLACK) {
67 GrRenderTargetContext* renderTargetContext =
68 canvas->internal_private_accessTopLayerRenderTargetContext();
69 if (!renderTargetContext) {
70 skiagm::GM::DrawGpuOnlyMessage(canvas);
74 GrContext* context = canvas->getGrContext();
79 const SkImageInfo ii = SkImageInfo::Make(S, S, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
81 SkAutoTArray<SkPMColor> gTextureData((2 * S) * (2 * S));
82 const SkPMColor red = SkPackARGB32(0x80, 0x80, 0x00, 0x00);
83 const SkPMColor blue = SkPackARGB32(0x80, 0x00, 0x00, 0x80);
84 const SkPMColor green = SkPackARGB32(0x80, 0x00, 0x80, 0x00);
85 for (int i = 0; i < 2; ++i) {
86 fill_in_pixels(gTextureData.get());
89 desc.fOrigin = i ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin;
92 desc.fConfig = SkImageInfo2GrPixelConfig(ii, *context->caps());
94 sk_sp<GrTextureProxy> proxy = GrSurfaceProxy::MakeDeferred(context->resourceProvider(),
95 desc, SkBudgeted::kNo,
96 gTextureData.get(), 0);
101 sk_sp<GrSurfaceContext> tContext = context->contextPriv().makeWrappedSurfaceContext(
102 std::move(proxy), nullptr);
109 GrFixedClip clip(SkIRect::MakeWH(2*S, 2*S));
112 paint.setPorterDuffXPFactory(SkBlendMode::kSrcOver);
116 vm.setRotate(90 * SK_Scalar1, S * SK_Scalar1, S * SK_Scalar1);
120 paint.addColorTextureProcessor(context->resourceProvider(), tContext->asTextureProxyRef(),
123 renderTargetContext->drawRect(clip, GrPaint(paint), GrAA::kNo, vm,
124 SkRect::MakeWH(2 * S, 2 * S));
126 // now update the lower right of the texture in first pass
127 // or upper right in second pass
128 for (int y = 0; y < S; ++y) {
129 for (int x = 0; x < S; ++x) {
130 gTextureData[y * kStride + x] = ((x + y) % 2) ? (i ? green : red) : blue;
134 if (!tContext->writePixels(ii, gTextureData.get(), 4 * kStride, S, i ? 0 : S)) {
138 renderTargetContext->drawRect(clip, std::move(paint), GrAA::kNo, vm,
139 SkRect::MakeWH(2 * S, 2 * S));