Flutter Engine
The Flutter Engine
Classes | Namespaces | Functions
drawimageset.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBlendMode.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorFilter.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkShader.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTileMode.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkGradientShader.h"
#include "include/gpu/GrDirectContext.h"
#include "tools/GpuToolUtils.h"
#include "tools/ToolUtils.h"
#include <algorithm>
#include <initializer_list>
#include <utility>

Go to the source code of this file.

Classes

class  skiagm::DrawImageSetGM
 
class  skiagm::DrawImageSetRectToRectGM
 
class  skiagm::DrawImageSetAlphaOnlyGM
 

Namespaces

namespace  skiagm
 

Functions

static void make_image_tiles (int tileW, int tileH, int m, int n, const SkColor colors[4], SkCanvas::ImageSetEntry set[], const SkColor bgColor=SK_ColorLTGRAY)
 

Function Documentation

◆ make_image_tiles()

static void make_image_tiles ( int  tileW,
int  tileH,
int  m,
int  n,
const SkColor  colors[4],
SkCanvas::ImageSetEntry  set[],
const SkColor  bgColor = SK_ColorLTGRAY 
)
static

Definition at line 38 of file drawimageset.cpp.

39 {
40 const int w = tileW * m;
41 const int h = tileH * n;
42 auto surf = SkSurfaces::Raster(
44 surf->getCanvas()->clear(bgColor);
45
46 static constexpr SkScalar kStripeW = 10;
47 static constexpr SkScalar kStripeSpacing = 30;
49
50 SkPoint pts1[] = {{0.f, 0.f}, {(SkScalar)w, (SkScalar)h}};
51 auto grad = SkGradientShader::MakeLinear(pts1, colors, nullptr, 2, SkTileMode::kClamp);
52 paint.setShader(std::move(grad));
53 paint.setAntiAlias(true);
55 paint.setStrokeWidth(kStripeW);
56 SkPoint stripePts[] = {{-w - kStripeW, -kStripeW}, {kStripeW, h + kStripeW}};
57 while (stripePts[0].fX <= w) {
58 surf->getCanvas()->drawPoints(SkCanvas::kLines_PointMode, 2, stripePts, paint);
59 stripePts[0].fX += kStripeSpacing;
60 stripePts[1].fX += kStripeSpacing;
61 }
62
63 SkPoint pts2[] = {{0.f, (SkScalar)h}, {(SkScalar)w, 0.f}};
64 grad = SkGradientShader::MakeLinear(pts2, colors + 2, nullptr, 2, SkTileMode::kClamp);
65 paint.setShader(std::move(grad));
66 paint.setBlendMode(SkBlendMode::kMultiply);
67 stripePts[0] = {-w - kStripeW, h + kStripeW};
68 stripePts[1] = {kStripeW, -kStripeW};
69 while (stripePts[0].fX <= w) {
70 surf->getCanvas()->drawPoints(SkCanvas::kLines_PointMode, 2, stripePts, paint);
71 stripePts[0].fX += kStripeSpacing;
72 stripePts[1].fX += kStripeSpacing;
73 }
74 auto fullImage = surf->makeImageSnapshot();
75 for (int y = 0; y < n; ++y) {
76 for (int x = 0; x < m; ++x) {
77 // Images will have 1 pixel of overlap at interior seams for filtering continuity.
78 SkIRect subset = SkIRect::MakeXYWH(x * tileW - 1, y * tileH - 1, tileW + 2, tileH + 2);
79 set[y * m + x].fAAFlags = SkCanvas::kNone_QuadAAFlags;
80 if (x == 0) {
81 subset.fLeft = 0;
82 set[y * m + x].fAAFlags |= SkCanvas::kLeft_QuadAAFlag;
83 }
84 if (x == m - 1) {
85 subset.fRight = w;
86 set[y * m + x].fAAFlags |= SkCanvas::kRight_QuadAAFlag;
87 }
88 if (y == 0) {
89 subset.fTop = 0;
90 set[y * m + x].fAAFlags |= SkCanvas::kTop_QuadAAFlag;
91 }
92 if (y == n - 1) {
93 subset.fBottom = h;
94 set[y * m + x].fAAFlags |= SkCanvas::kBottom_QuadAAFlag;
95 }
96 set[y * m + x].fImage = fullImage->makeSubset(nullptr, subset);
97 set[y * m + x].fSrcRect =
98 SkRect::MakeXYWH(x == 0 ? 0 : 1, y == 0 ? 0 : 1, tileW, tileH);
99 set[y * m + x].fDstRect = SkRect::MakeXYWH(x * tileW, y * tileH, tileW, tileH);
100 set[y * m + x].fAlpha = 1.f;
101 SkASSERT(set[y * m + x].fImage);
102 }
103 }
104}
static const SkColor bgColor
Definition: BlurTest.cpp:59
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
#define SkASSERT(cond)
Definition: SkAssert.h:116
@ kMultiply
r = s*(1-da) + d*(1-sa) + s*d
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
@ kLines_PointMode
draw each pair of points as a line segment
Definition: SkCanvas.h:1242
@ kTop_QuadAAFlag
Definition: SkCanvas.h:1660
@ kRight_QuadAAFlag
Definition: SkCanvas.h:1661
@ kLeft_QuadAAFlag
Definition: SkCanvas.h:1659
@ kBottom_QuadAAFlag
Definition: SkCanvas.h:1662
@ kNone_QuadAAFlags
Definition: SkCanvas.h:1664
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
double y
double x
PODArray< SkColor > colors
Definition: SkRecords.h:276
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not set
Definition: switches.h:76
SkScalar w
SkScalar h
Definition: SkRect.h:32
int32_t fBottom
larger y-axis bounds
Definition: SkRect.h:36
int32_t fTop
smaller y-axis bounds
Definition: SkRect.h:34
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: SkRect.h:104
int32_t fLeft
smaller x-axis bounds
Definition: SkRect.h:33
int32_t fRight
larger x-axis bounds
Definition: SkRect.h:35
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
float fX
x-axis value
Definition: SkPoint_impl.h:164
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659