Flutter Engine
The Flutter Engine
Classes | Typedefs | Functions | Variables
drawbitmaprect.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkBlurTypes.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkFont.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkMaskFilter.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/SkTypeface.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkGradientShader.h"
#include "include/gpu/GrDirectContext.h"
#include "src/base/SkMathPriv.h"
#include "src/core/SkBlurMask.h"
#include "tools/GpuToolUtils.h"
#include "tools/ToolUtils.h"
#include "tools/fonts/FontToolUtils.h"

Go to the source code of this file.

Classes

class  DrawBitmapRectGM
 

Typedefs

typedef void DrawRectRectProc(SkCanvas *, sk_sp< SkImage >, const SkBitmap &, const SkIRect &srcR, const SkRect &dstR, const SkSamplingOptions &, const SkPaint *)
 

Functions

static SkBitmap make_chessbm (int w, int h)
 
static sk_sp< SkImagemakebm (SkCanvas *origCanvas, SkBitmap *resultBM, int w, int h)
 
static void bitmapproc (SkCanvas *canvas, sk_sp< SkImage > image, const SkBitmap &, const SkIRect &srcR, const SkRect &dstR, const SkSamplingOptions &sampling, const SkPaint *paint)
 
static void bitmapsubsetproc (SkCanvas *canvas, sk_sp< SkImage > image, const SkBitmap &bm, const SkIRect &srcR, const SkRect &dstR, const SkSamplingOptions &sampling, const SkPaint *paint)
 
static void imageproc (SkCanvas *canvas, sk_sp< SkImage > image, const SkBitmap &, const SkIRect &srcR, const SkRect &dstR, const SkSamplingOptions &sampling, const SkPaint *paint)
 
static void imagesubsetproc (SkCanvas *canvas, sk_sp< SkImage > image, const SkBitmap &bm, const SkIRect &srcR, const SkRect &dstR, const SkSamplingOptions &sampling, const SkPaint *paint)
 

Variables

constexpr int gSize = 1024
 
constexpr int gBmpSize = 2048
 

Typedef Documentation

◆ DrawRectRectProc

typedef void DrawRectRectProc(SkCanvas *, sk_sp< SkImage >, const SkBitmap &, const SkIRect &srcR, const SkRect &dstR, const SkSamplingOptions &, const SkPaint *)

Definition at line 161 of file drawbitmaprect.cpp.

Function Documentation

◆ bitmapproc()

static void bitmapproc ( SkCanvas canvas,
sk_sp< SkImage image,
const SkBitmap ,
const SkIRect srcR,
const SkRect dstR,
const SkSamplingOptions sampling,
const SkPaint paint 
)
static

Definition at line 109 of file drawbitmaprect.cpp.

112 {
113 canvas->drawImageRect(image, SkRect::Make(srcR), dstR, sampling, paint,
115}
@ kStrict_SrcRectConstraint
sample only inside bounds; slower
Definition: SkCanvas.h:1542
void drawImageRect(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
Definition: SkCanvas.cpp:2333
const Paint & paint
Definition: color_source.cc:38
sk_sp< const SkImage > image
Definition: SkRecords.h:269
SkSamplingOptions sampling
Definition: SkRecords.h:337
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669

◆ bitmapsubsetproc()

static void bitmapsubsetproc ( SkCanvas canvas,
sk_sp< SkImage image,
const SkBitmap bm,
const SkIRect srcR,
const SkRect dstR,
const SkSamplingOptions sampling,
const SkPaint paint 
)
static

Definition at line 117 of file drawbitmaprect.cpp.

120 {
121 if (!bm.bounds().contains(srcR)) {
122 bitmapproc(canvas, std::move(image), bm, srcR, dstR, sampling, paint);
123 return;
124 }
125
126 SkBitmap subset;
127 if (bm.extractSubset(&subset, srcR)) {
128 sk_sp<SkImage> subsetImg = ToolUtils::MakeTextureImage(canvas, subset.asImage());
129 canvas->drawImageRect(subsetImg, dstR, sampling, paint);
130 }
131}
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:645
bool extractSubset(SkBitmap *dst, const SkIRect &subset) const
Definition: SkBitmap.cpp:453
SkIRect bounds() const
Definition: SkBitmap.h:382
static void bitmapproc(SkCanvas *canvas, sk_sp< SkImage > image, const SkBitmap &, const SkIRect &srcR, const SkRect &dstR, const SkSamplingOptions &sampling, const SkPaint *paint)
sk_sp< SkImage > MakeTextureImage(SkCanvas *canvas, sk_sp< SkImage > orig)
bool contains(int32_t x, int32_t y) const
Definition: SkRect.h:463

◆ imageproc()

static void imageproc ( SkCanvas canvas,
sk_sp< SkImage image,
const SkBitmap ,
const SkIRect srcR,
const SkRect dstR,
const SkSamplingOptions sampling,
const SkPaint paint 
)
static

Definition at line 133 of file drawbitmaprect.cpp.

134 {
135 sk_sp<SkImage> tmp = ToolUtils::MakeTextureImage(canvas, std::move(image));
136 canvas->drawImageRect(tmp, SkRect::Make(srcR), dstR, sampling, paint,
138}

◆ imagesubsetproc()

static void imagesubsetproc ( SkCanvas canvas,
sk_sp< SkImage image,
const SkBitmap bm,
const SkIRect srcR,
const SkRect dstR,
const SkSamplingOptions sampling,
const SkPaint paint 
)
static

Definition at line 140 of file drawbitmaprect.cpp.

142 {
144 if (!image->bounds().contains(srcR)) {
145 imageproc(canvas, std::move(image), bm, srcR, dstR, sampling, paint);
146 return;
147 }
148
149 auto direct = GrAsDirectContext(canvas->recordingContext());
150 if (sk_sp<SkImage> subset = image->makeSubset(direct, srcR)) {
151 canvas->drawImageRect(subset, dstR, sampling, paint);
152 return;
153 }
154#if defined(SK_GRAPHITE)
155 if (sk_sp<SkImage> subset = image->makeSubset(canvas->recorder(), srcR, {})) {
156 canvas->drawImageRect(subset, dstR, sampling, paint);
157 }
158#endif
159}
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
#define SkASSERT_RELEASE(cond)
Definition: SkAssert.h:100
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
virtual skgpu::graphite::Recorder * recorder() const
Definition: SkCanvas.cpp:1641
SkIRect bounds() const
Definition: SkImage.h:303
virtual sk_sp< SkImage > makeSubset(GrDirectContext *direct, const SkIRect &subset) const =0
static void imageproc(SkCanvas *canvas, sk_sp< SkImage > image, const SkBitmap &, const SkIRect &srcR, const SkRect &dstR, const SkSamplingOptions &sampling, const SkPaint *paint)

◆ make_chessbm()

static SkBitmap make_chessbm ( int  w,
int  h 
)
static

Definition at line 38 of file drawbitmaprect.cpp.

38 {
39 SkBitmap bm;
40 bm.allocN32Pixels(w, h);
41
42 for (int y = 0; y < bm.height(); y++) {
43 uint32_t* p = bm.getAddr32(0, y);
44 for (int x = 0; x < bm.width(); x++) {
45 p[x] = ((x + y) & 1) ? SK_ColorWHITE : SK_ColorBLACK;
46 }
47 }
48 bm.setImmutable();
49 return bm;
50}
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
void setImmutable()
Definition: SkBitmap.cpp:400
int width() const
Definition: SkBitmap.h:149
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition: SkBitmap.cpp:232
int height() const
Definition: SkBitmap.h:158
uint32_t * getAddr32(int x, int y) const
Definition: SkBitmap.h:1260
double y
double x
SkScalar w
SkScalar h

◆ makebm()

static sk_sp< SkImage > makebm ( SkCanvas origCanvas,
SkBitmap resultBM,
int  w,
int  h 
)
static

Definition at line 53 of file drawbitmaprect.cpp.

53 {
55
56 auto surface(ToolUtils::makeSurface(origCanvas, info));
57 SkCanvas* canvas = surface->getCanvas();
58
60
61 SkScalar wScalar = SkIntToScalar(w);
62 SkScalar hScalar = SkIntToScalar(h);
63
64 SkPoint pt = { wScalar / 2, hScalar / 2 };
65
66 SkScalar radius = 4 * std::max(wScalar, hScalar);
67
72
73 SkScalar pos[] = {0,
74 SK_Scalar1 / 6,
75 2 * SK_Scalar1 / 6,
76 3 * SK_Scalar1 / 6,
77 4 * SK_Scalar1 / 6,
78 5 * SK_Scalar1 / 6,
80
82 SkRect rect = SkRect::MakeWH(wScalar, hScalar);
83 SkMatrix mat = SkMatrix::I();
84 for (int i = 0; i < 4; ++i) {
86 pt, radius,
87 colors, pos,
90 0, &mat));
91 canvas->drawRect(rect, paint);
92 rect.inset(wScalar / 8, hScalar / 8);
93 mat.postScale(SK_Scalar1 / 4, SK_Scalar1 / 4);
94 }
95
96 auto image = surface->makeImageSnapshot();
97
98 SkBitmap tempBM;
99
100 image->asLegacyBitmap(&tempBM);
101
102 // Let backends know we won't change this, so they don't have to deep copy it defensively.
103 tempBM.setImmutable();
104 *resultBM = tempBM;
105
106 return image;
107}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
SkPoint pos
constexpr SkColor SK_ColorYELLOW
Definition: SkColor.h:139
constexpr SkColor SK_ColorMAGENTA
Definition: SkColor.h:147
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorCYAN
Definition: SkColor.h:143
constexpr SkColor SK_ColorTRANSPARENT
Definition: SkColor.h:99
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
#define SK_Scalar1
Definition: SkScalar.h:18
#define SkIntToScalar(x)
Definition: SkScalar.h:57
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void clear(SkColor color)
Definition: SkCanvas.h:1199
static sk_sp< SkShader > MakeRadial(const SkPoint &center, SkScalar radius, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
bool asLegacyBitmap(SkBitmap *bitmap, LegacyBitmapMode legacyBitmapMode=kRO_LegacyBitmapMode) const
Definition: SkImage.cpp:233
SkMatrix & postScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:360
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
VkSurfaceKHR surface
Definition: main.cc:49
float SkScalar
Definition: extension.cpp:12
static float max(float r, float g, float b)
Definition: hsl.cpp:49
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
PODArray< SkColor > colors
Definition: SkRecords.h:276
sk_sp< SkSurface > makeSurface(SkCanvas *canvas, const SkImageInfo &info, const SkSurfaceProps *props)
Definition: ToolUtils.cpp:512
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
static SkImageInfo MakeN32Premul(int width, int height)
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

Variable Documentation

◆ gBmpSize

constexpr int gBmpSize = 2048
constexpr

Definition at line 166 of file drawbitmaprect.cpp.

◆ gSize

constexpr int gSize = 1024
constexpr

Definition at line 165 of file drawbitmaprect.cpp.