Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(296)

Unified Diff: gm/texdata.cpp

Issue 1930623003: Clean up test drawContext usage (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix typo Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gm/rrects.cpp ('k') | gm/texturedomaineffect.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/texdata.cpp
diff --git a/gm/texdata.cpp b/gm/texdata.cpp
index 20cad0c739e9bf9520bc72d446bbf49d6dfde30a..977947b0c67e979fd70f9265876c6feaaef669ff 100644
--- a/gm/texdata.cpp
+++ b/gm/texdata.cpp
@@ -19,100 +19,105 @@
static const int S = 200;
DEF_SIMPLE_GM_BG(texdata, canvas, 2 * S, 2 * S, SK_ColorBLACK) {
- GrRenderTarget* target = canvas->internal_private_accessTopLayerRenderTarget();
- GrContext* ctx = canvas->getGrContext();
- sk_sp<GrDrawContext> drawContext(ctx ? ctx->drawContext(sk_ref_sp(target)) : nullptr);
- if (drawContext && target) {
- SkAutoTArray<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;
- }
- }
+ GrDrawContext* drawContext = canvas->internal_private_accessTopLayerDrawContext();
+ if (!drawContext) {
+ skiagm::GM::DrawGpuOnlyMessage(canvas);
+ return;
+ }
- GrSurfaceDesc desc;
- // use RT flag bit because in GL it makes the texture be bottom-up
- desc.fFlags = i ? kRenderTarget_GrSurfaceFlag :
- kNone_GrSurfaceFlags;
- desc.fConfig = kSkia8888_GrPixelConfig;
- desc.fWidth = 2 * S;
- desc.fHeight = 2 * S;
- GrTexture* texture = ctx->textureProvider()->createTexture(
- desc, SkBudgeted::kNo, gTextureData.get(), 0);
+ GrContext* context = canvas->getGrContext();
+ if (!context) {
+ return;
+ }
- if (!texture) {
- return;
- }
- SkAutoTUnref<GrTexture> au(texture);
+ SkAutoTArray<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;
+ }
+ }
- // setup new clip
- GrClip clip(SkRect::MakeWH(2*S, 2*S));
+ GrSurfaceDesc desc;
+ // use RT flag bit because in GL it makes the texture be bottom-up
+ desc.fFlags = i ? kRenderTarget_GrSurfaceFlag :
+ kNone_GrSurfaceFlags;
+ desc.fConfig = kSkia8888_GrPixelConfig;
+ desc.fWidth = 2 * S;
+ desc.fHeight = 2 * S;
+ GrTexture* texture = context->textureProvider()->createTexture(
+ desc, SkBudgeted::kNo, gTextureData.get(), 0);
- GrPaint paint;
- paint.setPorterDuffXPFactory(SkXfermode::kSrcOver_Mode);
+ if (!texture) {
+ return;
+ }
+ SkAutoTUnref<GrTexture> au(texture);
- SkMatrix vm;
- if (i) {
- vm.setRotate(90 * SK_Scalar1,
- S * SK_Scalar1,
- S * SK_Scalar1);
- } else {
- vm.reset();
- }
- SkMatrix tm;
- tm = vm;
- tm.postIDiv(2*S, 2*S);
- paint.addColorTextureProcessor(texture, tm);
+ // setup new clip
+ GrClip clip(SkRect::MakeWH(2*S, 2*S));
- drawContext->drawRect(clip, paint, vm, SkRect::MakeWH(2*S, 2*S));
+ GrPaint paint;
+ paint.setPorterDuffXPFactory(SkXfermode::kSrcOver_Mode);
- // 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;
- }
- }
- texture->writePixels(S, (i ? 0 : S), S, S,
- texture->config(), gTextureData.get(),
- 4 * stride);
- drawContext->drawRect(clip, paint, vm, SkRect::MakeWH(2*S, 2*S));
- }
+ SkMatrix vm;
+ if (i) {
+ vm.setRotate(90 * SK_Scalar1,
+ S * SK_Scalar1,
+ S * SK_Scalar1);
} else {
- skiagm::GM::DrawGpuOnlyMessage(canvas);
+ vm.reset();
}
+ SkMatrix tm;
+ tm = vm;
+ tm.postIDiv(2*S, 2*S);
+ paint.addColorTextureProcessor(texture, tm);
+
+ drawContext->drawRect(clip, paint, 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;
+ }
+ }
+ texture->writePixels(S, (i ? 0 : S), S, S,
+ texture->config(), gTextureData.get(),
+ 4 * stride);
+ drawContext->drawRect(clip, paint, vm, SkRect::MakeWH(2*S, 2*S));
+ }
}
#endif
+
« no previous file with comments | « gm/rrects.cpp ('k') | gm/texturedomaineffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698