aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/texdata.cpp
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2017-01-24 16:24:41 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-01-24 22:03:40 +0000
commit901f29ad3e38b7072a2abef5ff1665cd755d21a2 (patch)
tree8b231c4cf579b0c591014c5287790b40d38e8868 /gm/texdata.cpp
parentc8c901fc36816b9a2603a8c129cdca1d2b4d7fe2 (diff)
Allow GrSingleTextureEffect to take GrTextureProxies
Change-Id: I1dd441a5838f665c6815a5c629f5763f43f66e09 Reviewed-on: https://skia-review.googlesource.com/7429 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'gm/texdata.cpp')
-rw-r--r--gm/texdata.cpp115
1 files changed, 68 insertions, 47 deletions
diff --git a/gm/texdata.cpp b/gm/texdata.cpp
index 372ff5dc11..70afd22ec5 100644
--- a/gm/texdata.cpp
+++ b/gm/texdata.cpp
@@ -11,13 +11,56 @@
#if SK_SUPPORT_GPU
#include "GrContext.h"
+#include "GrContextPriv.h"
#include "GrRenderTargetContext.h"
+#include "GrTextureContext.h"
#include "GrFixedClip.h"
#include "SkColorPriv.h"
#include "effects/GrPorterDuffXferProcessor.h"
#include "effects/GrSimpleTextureEffect.h"
constexpr int S = 200;
+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;
+ }
+ }
+}
DEF_SIMPLE_GM_BG(texdata, canvas, 2 * S, 2 * S, SK_ColorBLACK) {
GrRenderTargetContext* renderTargetContext =
@@ -32,56 +75,35 @@ DEF_SIMPLE_GM_BG(texdata, canvas, 2 * S, 2 * S, SK_ColorBLACK) {
return;
}
+ const SkImageInfo ii = SkImageInfo::Make(S, S, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
+
SkAutoTArray<SkPMColor> gTextureData((2 * S) * (2 * S));
- constexpr int stride = 2 * S;
- const SkPMColor gray = SkPackARGB32(0x40, 0x40, 0x40, 0x40);
- const SkPMColor white = SkPackARGB32(0xff, 0xff, 0xff, 0xff);
const SkPMColor red = SkPackARGB32(0x80, 0x80, 0x00, 0x00);
const SkPMColor blue = SkPackARGB32(0x80, 0x00, 0x00, 0x80);
const SkPMColor green = SkPackARGB32(0x80, 0x00, 0x80, 0x00);
- 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;
- }
- }
+ fill_in_pixels(gTextureData.get());
GrSurfaceDesc desc;
desc.fOrigin = i ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin;
- desc.fConfig = kSkia8888_GrPixelConfig;
+ desc.fConfig = kBGRA_8888_GrPixelConfig;
desc.fWidth = 2 * S;
desc.fHeight = 2 * S;
- GrTexture* texture = context->textureProvider()->createTexture(
- desc, SkBudgeted::kNo, gTextureData.get(), 0);
- if (!texture) {
+ 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) {
return;
}
- sk_sp<GrTexture> au(texture);
// setup new clip
GrFixedClip clip(SkIRect::MakeWH(2*S, 2*S));
@@ -91,29 +113,28 @@ DEF_SIMPLE_GM_BG(texdata, canvas, 2 * S, 2 * S, SK_ColorBLACK) {
SkMatrix vm;
if (i) {
- vm.setRotate(90 * SK_Scalar1,
- S * SK_Scalar1,
- S * SK_Scalar1);
+ vm.setRotate(90 * SK_Scalar1, S * SK_Scalar1, S * SK_Scalar1);
} else {
vm.reset();
}
- paint.addColorTextureProcessor(texture, nullptr, vm);
+ paint.addColorTextureProcessor(context, sk_ref_sp(tContext->asDeferredTexture()),
+ nullptr, vm);
renderTargetContext->drawRect(clip, GrPaint(paint), GrAA::kNo, vm,
SkRect::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) {
- gTextureData[offset + y * stride + x] =
- ((x + y) % 2) ? (i ? green : red) : blue;
+ gTextureData[y * kStride + x] = ((x + y) % 2) ? (i ? green : red) : blue;
}
}
- texture->writePixels(S, (i ? 0 : S), S, S,
- texture->config(), gTextureData.get(),
- 4 * stride);
+
+ if (!tContext->writePixels(ii, gTextureData.get(), 4 * kStride, S, i ? 0 : S)) {
+ continue;
+ }
+
renderTargetContext->drawRect(clip, std::move(paint), GrAA::kNo, vm,
SkRect::MakeWH(2 * S, 2 * S));
}