skia2/gm/bitmaprecttest.cpp
Mike Klein c0bd9f9fe5 rewrite includes to not need so much -Ifoo
Current strategy: everything from the top

Things to look at first are the manual changes:

   - added tools/rewrite_includes.py
   - removed -Idirectives from BUILD.gn
   - various compile.sh simplifications
   - tweak tools/embed_resources.py
   - update gn/find_headers.py to write paths from the top
   - update gn/gn_to_bp.py SkUserConfig.h layout
     so that #include "include/config/SkUserConfig.h" always
     gets the header we want.

No-Presubmit: true
Change-Id: I73a4b181654e0e38d229bc456c0d0854bae3363e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/209706
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Hal Canary <halcanary@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
2019-04-24 16:27:11 +00:00

52 lines
1.4 KiB
C++

/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkPath.h"
static void make_bm(SkBitmap* bm) {
bm->allocN32Pixels(60, 60);
bm->eraseColor(0);
SkCanvas canvas(*bm);
SkPaint paint;
SkPath path;
path.moveTo(6, 6);
path.lineTo(6, 54);
path.lineTo(30, 54);
canvas.drawPath(path, paint);
paint.setStyle(SkPaint::kStroke_Style);
canvas.drawRect(SkRect::MakeLTRB(0.5f, 0.5f, 59.5f, 59.5f), paint);
}
// This creates a close, but imperfect concatenation of
// scaling the image up by its dst-rect
// scaling the image down by the matrix' scale
// The bug was that for cases like this, we were incorrectly trying to take a
// fast-path in the bitmapshader, but ended up drawing the last col of pixels
// twice. The fix resulted in (a) not taking the fast-path, but (b) drawing
// the image correctly.
//
DEF_SIMPLE_GM(bitmaprecttest, canvas, 320, 240) {
SkBitmap bm;
make_bm(&bm);
canvas->drawBitmap(bm, 150, 45, nullptr);
SkScalar scale = 0.472560018f;
canvas->save();
canvas->scale(scale, scale);
canvas->drawBitmapRect(bm, SkRect::MakeXYWH(100, 100, 128, 128), nullptr);
canvas->restore();
canvas->scale(-1, 1);
canvas->drawBitmap(bm, -310, 45, nullptr);
}