Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
bitmaprecttest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm/gm.h"
13#include "include/core/SkPath.h"
14#include "include/core/SkRect.h"
16
18 SkBitmap bm;
19 bm.allocN32Pixels(60, 60);
20 bm.eraseColor(0);
21
22 SkCanvas canvas(bm);
24 canvas.drawPath(SkPath::Polygon({{6,6}, {6,54}, {30,54}}, false), paint);
25
27 canvas.drawRect(SkRect::MakeLTRB(0.5f, 0.5f, 59.5f, 59.5f), paint);
28 return bm.asImage();
29}
30
31// This creates a close, but imperfect concatenation of
32// scaling the image up by its dst-rect
33// scaling the image down by the matrix' scale
34// The bug was that for cases like this, we were incorrectly trying to take a
35// fast-path in the bitmapshader, but ended up drawing the last col of pixels
36// twice. The fix resulted in (a) not taking the fast-path, but (b) drawing
37// the image correctly.
38//
39DEF_SIMPLE_GM(bitmaprecttest, canvas, 320, 240) {
40 auto image = make_bm();
41
42 canvas->drawImage(image, 150, 45);
43
44 SkScalar scale = 0.472560018f;
45 canvas->save();
46 canvas->scale(scale, scale);
47 canvas->drawImageRect(image, SkRect::MakeXYWH(100, 100, 128, 128), SkSamplingOptions());
48 canvas->restore();
49
50 canvas->scale(-1, 1);
51 canvas->drawImage(image, -310, 45);
52}
static sk_sp< SkImage > make_bm()
sk_sp< SkImage > asImage() const
Definition SkBitmap.cpp:645
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition SkBitmap.cpp:232
void eraseColor(SkColor4f) const
Definition SkBitmap.cpp:442
void drawRect(const SkRect &rect, const SkPaint &paint)
void drawPath(const SkPath &path, const SkPaint &paint)
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
static SkPath Polygon(const SkPoint pts[], int count, bool isClosed, SkPathFillType=SkPathFillType::kWinding, bool isVolatile=false)
Definition SkPath.cpp:3546
const Paint & paint
sk_sp< SkImage > image
Definition examples.cpp:29
float SkScalar
Definition extension.cpp:12
#define DEF_SIMPLE_GM(NAME, CANVAS, W, H)
Definition gm.h:50
const Scalar scale
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition SkRect.h:646