Flutter Engine
The Flutter Engine
Classes | Functions
bleed.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/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/SkTiledImageUtils.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GrContextOptions.h"
#include "include/private/base/SkTDArray.h"
#include "src/core/SkBlurMask.h"
#include "tools/ToolUtils.h"

Go to the source code of this file.

Classes

class  SrcRectConstraintGM
 

Functions

std::tuple< sk_sp< SkImage >, SkRectmake_ringed_image (SkCanvas *canvas, int width, int height)
 
 DEF_GM (return new SrcRectConstraintGM("strict_constraint_no_red_allowed", SkCanvas::kStrict_SrcRectConstraint, false);)
 
 DEF_GM (return new SrcRectConstraintGM("strict_constraint_no_red_allowed_manual", SkCanvas::kStrict_SrcRectConstraint, true);)
 
 DEF_GM (return new SrcRectConstraintGM("strict_constraint_batch_no_red_allowed", SkCanvas::kStrict_SrcRectConstraint, false);)
 
 DEF_GM (return new SrcRectConstraintGM("strict_constraint_batch_no_red_allowed_manual", SkCanvas::kStrict_SrcRectConstraint, true);)
 
 DEF_GM (return new SrcRectConstraintGM("fast_constraint_red_is_allowed", SkCanvas::kFast_SrcRectConstraint, false);)
 
 DEF_GM (return new SrcRectConstraintGM("fast_constraint_red_is_allowed_manual", SkCanvas::kFast_SrcRectConstraint, true);)
 
static sk_sp< SkImagemake_image (SkCanvas *canvas, SkRect *srcR)
 
 DEF_SIMPLE_GM (bleed_downscale, canvas, 360, 240)
 

Function Documentation

◆ DEF_GM() [1/6]

DEF_GM ( return new SrcRectConstraintGM("fast_constraint_red_is_allowed", SkCanvas::kFast_SrcRectConstraint, false);  )

◆ DEF_GM() [2/6]

DEF_GM ( return new SrcRectConstraintGM("fast_constraint_red_is_allowed_manual", SkCanvas::kFast_SrcRectConstraint, true);  )

◆ DEF_GM() [3/6]

DEF_GM ( return new SrcRectConstraintGM("strict_constraint_batch_no_red_allowed", SkCanvas::kStrict_SrcRectConstraint, false);  )

◆ DEF_GM() [4/6]

DEF_GM ( return new SrcRectConstraintGM("strict_constraint_batch_no_red_allowed_manual", SkCanvas::kStrict_SrcRectConstraint, true);  )

◆ DEF_GM() [5/6]

DEF_GM ( return new SrcRectConstraintGM("strict_constraint_no_red_allowed", SkCanvas::kStrict_SrcRectConstraint, false);  )

◆ DEF_GM() [6/6]

DEF_GM ( return new SrcRectConstraintGM("strict_constraint_no_red_allowed_manual", SkCanvas::kStrict_SrcRectConstraint, true);  )

◆ DEF_SIMPLE_GM()

DEF_SIMPLE_GM ( bleed_downscale  ,
canvas  ,
360  ,
240   
)

Definition at line 386 of file bleed.cpp.

386 {
387 SkRect src;
388 sk_sp<SkImage> img = make_image(canvas, &src);
390
391 canvas->translate(10, 10);
392
393 const SkCanvas::SrcRectConstraint constraints[] = {
395 };
396 const SkSamplingOptions samplings[] = {
400 };
401 for (auto constraint : constraints) {
402 canvas->save();
403 for (auto sampling : samplings) {
404 auto surf = ToolUtils::makeSurface(canvas, SkImageInfo::MakeN32Premul(1, 1));
405 surf->getCanvas()->drawImageRect(img, src, SkRect::MakeWH(1, 1), sampling,
406 nullptr, constraint);
407 // now blow up the 1 pixel result
408 canvas->drawImageRect(surf->makeImageSnapshot(), SkRect::MakeWH(100, 100),
410 canvas->translate(120, 0);
411 }
412 canvas->restore();
413 canvas->translate(0, 120);
414 }
415}
static sk_sp< SkImage > make_image(SkCanvas *canvas, SkRect *srcR)
Definition: bleed.cpp:366
SrcRectConstraint
Definition: SkCanvas.h:1541
@ kStrict_SrcRectConstraint
sample only inside bounds; slower
Definition: SkCanvas.h:1542
@ kFast_SrcRectConstraint
sample outside bounds; faster
Definition: SkCanvas.h:1543
const Paint & paint
Definition: color_source.cc:38
SkSamplingOptions sampling
Definition: SkRecords.h:337
sk_sp< SkSurface > makeSurface(SkCanvas *canvas, const SkImageInfo &info, const SkSurfaceProps *props)
Definition: ToolUtils.cpp:512
SkSamplingOptions(SkFilterMode::kLinear))
static SkImageInfo MakeN32Premul(int width, int height)
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

◆ make_image()

static sk_sp< SkImage > make_image ( SkCanvas canvas,
SkRect srcR 
)
static

Definition at line 366 of file bleed.cpp.

366 {
367 // Intentially making the size a power of 2 to avoid the noise from how different GPUs will
368 // produce different mipmap filtering when we have an odd sized texture.
369 const int N = 10 + 2 + 8 + 2 + 10;
371 auto surface = ToolUtils::makeSurface(canvas, info);
372 SkCanvas* c = surface->getCanvas();
373 SkRect r = SkRect::MakeIWH(info.width(), info.height());
375
376 paint.setColor(SK_ColorRED);
377 c->drawRect(r, paint);
378 r.inset(10, 10);
379 paint.setColor(SK_ColorBLUE);
380 c->drawRect(r, paint);
381
382 *srcR = r.makeInset(2, 2);
383 return surface->makeImageSnapshot();
384}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
#define N
Definition: beziers.cpp:19
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
VkSurfaceKHR surface
Definition: main.cc:49
void inset(float dx, float dy)
Definition: SkRect.h:1060
static SkRect MakeIWH(int w, int h)
Definition: SkRect.h:623
SkRect makeInset(float dx, float dy) const
Definition: SkRect.h:987

◆ make_ringed_image()

std::tuple< sk_sp< SkImage >, SkRect > make_ringed_image ( SkCanvas canvas,
int  width,
int  height 
)

Creates an image with two one-pixel wide borders around a checkerboard. The checkerboard is 2x2 checks where each check has as many pixels as is necessary to fill the interior. It returns the image and a src rect that bounds the checkerboard portion.

Definition at line 42 of file bleed.cpp.

42 {
43
44 // These are kRGBA_8888_SkColorType values.
45 static constexpr uint32_t kOuterRingColor = 0xFFFF0000,
46 kInnerRingColor = 0xFF0000FF,
47 kCheckColor1 = 0xFF000000,
48 kCheckColor2 = 0xFFFFFFFF;
49
50 SkASSERT(0 == width % 2 && 0 == height % 2);
51 SkASSERT(width >= 6 && height >= 6);
52
55 size_t rowBytes = SkAlign4(info.minRowBytes());
57 bitmap.allocPixels(info, rowBytes);
58
59 uint32_t* scanline = bitmap.getAddr32(0, 0);
60 for (int x = 0; x < width; ++x) {
61 scanline[x] = kOuterRingColor;
62 }
63 scanline = bitmap.getAddr32(0, 1);
64 scanline[0] = kOuterRingColor;
65 for (int x = 1; x < width - 1; ++x) {
66 scanline[x] = kInnerRingColor;
67 }
68 scanline[width - 1] = kOuterRingColor;
69
70 for (int y = 2; y < height / 2; ++y) {
71 scanline = bitmap.getAddr32(0, y);
72 scanline[0] = kOuterRingColor;
73 scanline[1] = kInnerRingColor;
74 for (int x = 2; x < width / 2; ++x) {
75 scanline[x] = kCheckColor1;
76 }
77 for (int x = width / 2; x < width - 2; ++x) {
78 scanline[x] = kCheckColor2;
79 }
80 scanline[width - 2] = kInnerRingColor;
81 scanline[width - 1] = kOuterRingColor;
82 }
83
84 for (int y = height / 2; y < height - 2; ++y) {
85 scanline = bitmap.getAddr32(0, y);
86 scanline[0] = kOuterRingColor;
87 scanline[1] = kInnerRingColor;
88 for (int x = 2; x < width / 2; ++x) {
89 scanline[x] = kCheckColor2;
90 }
91 for (int x = width / 2; x < width - 2; ++x) {
92 scanline[x] = kCheckColor1;
93 }
94 scanline[width - 2] = kInnerRingColor;
95 scanline[width - 1] = kOuterRingColor;
96 }
97
98 scanline = bitmap.getAddr32(0, height - 2);
99 scanline[0] = kOuterRingColor;
100 for (int x = 1; x < width - 1; ++x) {
101 scanline[x] = kInnerRingColor;
102 }
103 scanline[width - 1] = kOuterRingColor;
104
105 scanline = bitmap.getAddr32(0, height - 1);
106 for (int x = 0; x < width; ++x) {
107 scanline[x] = kOuterRingColor;
108 }
109 bitmap.setImmutable();
110 return { bitmap.asImage(), SkRect::Make({2, 2, width - 2, height - 2})};
111}
static constexpr T SkAlign4(T x)
Definition: SkAlign.h:16
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
#define SkASSERT(cond)
Definition: SkAssert.h:116
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
double y
double x
Definition: bitmap.py:1
int32_t height
int32_t width
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669