Flutter Engine
The Flutter Engine
Classes | Namespaces | Macros | Functions
lazytiling.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRect.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/gpu/GrDirectContext.h"
#include "src/base/SkRectMemcpy.h"
#include "src/core/SkCanvasPriv.h"
#include "src/core/SkConvertPixels.h"
#include "src/gpu/ganesh/GrCanvas.h"
#include "src/gpu/ganesh/GrCaps.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "src/gpu/ganesh/GrPaint.h"
#include "src/gpu/ganesh/GrProxyProvider.h"
#include "src/gpu/ganesh/GrResourceProvider.h"
#include "src/gpu/ganesh/GrTexture.h"
#include "src/gpu/ganesh/SkGr.h"
#include "src/gpu/ganesh/SurfaceDrawContext.h"
#include "src/gpu/ganesh/effects/GrTextureEffect.h"
#include "tools/gpu/ProxyUtils.h"

Go to the source code of this file.

Classes

class  skiagm::LazyTilingGM
 

Namespaces

namespace  skiagm
 

Macros

#define USE_LAZY_PROXIES   1
 

Functions

static GrSurfaceProxyView create_view (GrDirectContext *dContext, const SkBitmap &src, GrSurfaceOrigin origin)
 
static SkBitmap create_bitmap (SkIRect contentRect, SkISize fullSize, GrSurfaceOrigin origin)
 
static void draw_texture (const GrCaps *caps, skgpu::ganesh::SurfaceDrawContext *sdc, const GrSurfaceProxyView &src, const SkIRect &srcRect, const SkIRect &drawRect, const SkMatrix &mat, GrSamplerState::WrapMode xTileMode, GrSamplerState::WrapMode yTileMode)
 

Macro Definition Documentation

◆ USE_LAZY_PROXIES

#define USE_LAZY_PROXIES   1

Function Documentation

◆ create_bitmap()

static SkBitmap create_bitmap ( SkIRect  contentRect,
SkISize  fullSize,
GrSurfaceOrigin  origin 
)
static

Definition at line 90 of file lazytiling.cpp.

90 {
91
92 const int kContentSize = contentRect.width();
93 SkBitmap contentBM;
94
95 {
96 SkImageInfo contentInfo = SkImageInfo::Make(kContentSize, kContentSize,
98 contentBM.allocPixels(contentInfo);
99
100 contentBM.eraseColor(SK_ColorWHITE);
101
102 const int halfM1 = kContentSize/2 - 1;
103
104 // The coordinate frame
105 contentBM.eraseArea(SkIRect::MakeXYWH(halfM1, 2,2, halfM1), SK_ColorGRAY);
106 contentBM.eraseArea(SkIRect::MakeXYWH(2, halfM1, kContentSize-4, 2), SK_ColorGRAY);
107
108 contentBM.eraseArea(SkIRect::MakeXYWH(2, halfM1, 2, 2), SK_ColorRED);
109 contentBM.eraseArea(SkIRect::MakeXYWH(kContentSize-4, halfM1, 2, 2), SK_ColorGREEN);
110
111 // The 1-pixel wide rim around the content rect
112 contentBM.eraseArea(SkIRect::MakeXYWH(0, 0, kContentSize, 1), SK_ColorBLUE);
113 contentBM.eraseArea(SkIRect::MakeXYWH(0, 0, 1, kContentSize), SK_ColorBLUE);
114 contentBM.eraseArea(SkIRect::MakeXYWH(kContentSize-1, 0, 1, kContentSize), SK_ColorBLUE);
115 contentBM.eraseArea(SkIRect::MakeXYWH(0, kContentSize-1, kContentSize, 1), SK_ColorBLUE);
116 }
117
118 SkBitmap bigBM;
119
120 {
121 const int kLeft = contentRect.fLeft;
122 const int kTop = contentRect.fTop;
123
124 SkImageInfo bigInfo = SkImageInfo::Make(fullSize.fWidth, fullSize.fHeight,
126
127 bigBM.allocPixels(bigInfo);
128
130
131 const char* src = static_cast<const char*>(contentBM.getPixels());
132 size_t srcRB = contentBM.rowBytes();
133 size_t dstRB = bigBM.rowBytes();
134
136 char* dst = static_cast<char*>(bigBM.getAddr(kLeft, fullSize.height() - kTop - 1));
137 for (int y = 0; y < contentBM.height(); ++y) {
138 memcpy(dst, src, srcRB);
139 src = src + srcRB;
140 dst = dst - dstRB;
141 }
142 } else {
143 char* dst = static_cast<char*>(bigBM.getAddr(kLeft, kTop));
144 SkRectMemcpy(dst, dstRB, src, srcRB,
145 contentBM.rowBytes(), contentBM.height());
146 }
147
149 bigBM.setImmutable();
150 }
151
152 return bigBM;
153}
@ kBottomLeft_GrSurfaceOrigin
Definition: GrTypes.h:149
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
constexpr SkColor SK_ColorGRAY
Definition: SkColor.h:113
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
static void SkRectMemcpy(void *dst, size_t dstRB, const void *src, size_t srcRB, size_t trimRowBytes, int rowCount)
Definition: SkRectMemcpy.h:16
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition: SkBitmap.cpp:258
void setImmutable()
Definition: SkBitmap.cpp:400
void eraseArea(const SkIRect &area, SkColor c) const
Definition: SkBitmap.h:854
void * getAddr(int x, int y) const
Definition: SkBitmap.cpp:406
size_t rowBytes() const
Definition: SkBitmap.h:238
void * getPixels() const
Definition: SkBitmap.h:283
bool setAlphaType(SkAlphaType alphaType)
Definition: SkBitmap.cpp:148
int height() const
Definition: SkBitmap.h:158
void eraseColor(SkColor4f) const
Definition: SkBitmap.cpp:442
#define USE_LAZY_PROXIES
double y
dst
Definition: cp.py:12
int32_t fTop
smaller y-axis bounds
Definition: SkRect.h:34
constexpr int32_t width() const
Definition: SkRect.h:158
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 fHeight
Definition: SkSize.h:18
int32_t fWidth
Definition: SkSize.h:17
constexpr int32_t height() const
Definition: SkSize.h:37
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ create_view()

static GrSurfaceProxyView create_view ( GrDirectContext dContext,
const SkBitmap src,
GrSurfaceOrigin  origin 
)
static

Definition at line 31 of file lazytiling.cpp.

33 {
34 SkASSERT(src.colorType() == kRGBA_8888_SkColorType);
35
36#define USE_LAZY_PROXIES 1 // Toggle this to generate the reference images
37
38 if (USE_LAZY_PROXIES) {
41 if (!format.isValid()) {
42 return {};
43 }
44
48 SkASSERT(desc.fMipmapped == skgpu::Mipmapped::kNo);
49 GrMipLevel mipLevel = {src.getPixels(), src.rowBytes(), nullptr};
50 auto colorType = SkColorTypeToGrColorType(src.colorType());
51
52 return rp->createTexture(src.dimensions(),
53 desc.fFormat,
54 desc.fTextureType,
56 desc.fRenderable,
57 desc.fSampleCnt,
58 desc.fBudgeted,
59 desc.fFit,
60 desc.fProtected,
61 mipLevel,
62 desc.fLabel);
63 },
64 format,
66 1,
68 *dContext->priv().caps(),
70
71 if (!proxy) {
72 return {};
73 }
74
75 auto swizzle = dContext->priv().caps()->getReadSwizzle(proxy->backendFormat(),
77 return GrSurfaceProxyView(std::move(proxy), origin, swizzle);
78 }
79
82 origin,
83 src.pixmap());
84}
static constexpr GrColorType SkColorTypeToGrColorType(SkColorType ct)
Definition: GrTypesPriv.h:629
#define SkASSERT(cond)
Definition: SkAssert.h:116
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
const GrCaps * caps() const
GrBackendFormat getDefaultBackendFormat(GrColorType, GrRenderable) const
Definition: GrCaps.cpp:400
skgpu::Swizzle getReadSwizzle(const GrBackendFormat &format, GrColorType colorType) const
Definition: GrCaps.cpp:443
GrDirectContextPriv priv()
static sk_sp< GrTextureProxy > MakeFullyLazyProxy(LazyInstantiateCallback &&, const GrBackendFormat &, GrRenderable, int renderTargetSampleCnt, GrProtected, const GrCaps &, UseAllocator)
sk_sp< GrTexture > createTexture(SkISize dimensions, const GrBackendFormat &format, GrTextureType textureType, skgpu::Renderable renderable, int renderTargetSampleCnt, skgpu::Mipmapped mipmapped, skgpu::Budgeted budgeted, skgpu::Protected isProtected, std::string_view label)
const GrBackendFormat & backendFormat() const
uint32_t uint32_t * format
GrSurfaceProxyView MakeTextureProxyViewFromData(GrDirectContext *dContext, GrRenderable renderable, GrSurfaceOrigin origin, GrCPixmap pixmap)
Definition: ProxyUtils.cpp:56

◆ draw_texture()

static void draw_texture ( const GrCaps caps,
skgpu::ganesh::SurfaceDrawContext sdc,
const GrSurfaceProxyView src,
const SkIRect srcRect,
const SkIRect drawRect,
const SkMatrix mat,
GrSamplerState::WrapMode  xTileMode,
GrSamplerState::WrapMode  yTileMode 
)
static

Definition at line 155 of file lazytiling.cpp.

162 {
163 GrSamplerState sampler(xTileMode, yTileMode, SkFilterMode::kNearest);
164
166 sampler, SkRect::Make(srcRect), *caps);
168 paint.setColorFragmentProcessor(std::move(fp));
169
170 sdc->drawRect(nullptr, std::move(paint), GrAA::kNo, SkMatrix::I(), SkRect::Make(drawRect));
171}
static std::unique_ptr< GrFragmentProcessor > MakeSubset(GrSurfaceProxyView, SkAlphaType, const SkMatrix &, GrSamplerState, const SkRect &subset, const GrCaps &caps, const float border[4]=kDefaultBorder, bool alwaysUseShaderTileMode=false)
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
void drawRect(const GrClip *, GrPaint &&paint, GrAA, const SkMatrix &viewMatrix, const SkRect &, const GrStyle *style=nullptr)
const Paint & paint
Definition: color_source.cc:38
const uint32_t fp
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669