Flutter Engine
The Flutter Engine
Classes | Typedefs | Enumerations | Functions
SkCanvasStateUtils.cpp File Reference
#include "include/utils/SkCanvasStateUtils.h"
#include "include/core/SkAlphaType.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColorType.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPixmap.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkSize.h"
#include "include/private/base/SkMalloc.h"
#include "src/core/SkDevice.h"
#include "src/core/SkWriter32.h"
#include "src/utils/SkCanvasStack.h"
#include <cstddef>
#include <cstdint>
#include <utility>

Go to the source code of this file.

Classes

struct  ClipRect
 
struct  SkMCState
 
struct  SkCanvasLayerState
 
class  SkCanvasState
 
class  SkCanvasState_v1
 

Typedefs

typedef int32_t RasterConfig
 
typedef int32_t CanvasBackend
 

Enumerations

enum  RasterConfigs { kUnknown_RasterConfig = 0 , kRGB_565_RasterConfig = 1 , kARGB_8888_RasterConfig = 2 }
 
enum  CanvasBackends { kUnknown_CanvasBackend = 0 , kRaster_CanvasBackend = 1 , kGPU_CanvasBackend = 2 , kPDF_CanvasBackend = 3 }
 

Functions

static void setup_MC_state (SkMCState *state, const SkMatrix &matrix, const SkIRect &clip)
 
static void setup_canvas_from_MC_state (const SkMCState &state, SkCanvas *canvas)
 
static std::unique_ptr< SkCanvasmake_canvas_from_canvas_layer (const SkCanvasLayerState &layerState)
 

Typedef Documentation

◆ CanvasBackend

typedef int32_t CanvasBackend

Definition at line 55 of file SkCanvasStateUtils.cpp.

◆ RasterConfig

typedef int32_t RasterConfig

Definition at line 47 of file SkCanvasStateUtils.cpp.

Enumeration Type Documentation

◆ CanvasBackends

Enumerator
kUnknown_CanvasBackend 
kRaster_CanvasBackend 
kGPU_CanvasBackend 
kPDF_CanvasBackend 

Definition at line 49 of file SkCanvasStateUtils.cpp.

49 {
54};
@ kGPU_CanvasBackend
@ kRaster_CanvasBackend
@ kPDF_CanvasBackend
@ kUnknown_CanvasBackend

◆ RasterConfigs

Enumerator
kUnknown_RasterConfig 
kRGB_565_RasterConfig 
kARGB_8888_RasterConfig 

Definition at line 42 of file SkCanvasStateUtils.cpp.

42 {
46};
@ kARGB_8888_RasterConfig
@ kUnknown_RasterConfig
@ kRGB_565_RasterConfig

Function Documentation

◆ make_canvas_from_canvas_layer()

static std::unique_ptr< SkCanvas > make_canvas_from_canvas_layer ( const SkCanvasLayerState layerState)
static

Definition at line 271 of file SkCanvasStateUtils.cpp.

271 {
272 SkASSERT(kRaster_CanvasBackend == layerState.type);
273
276 layerState.raster.config == kARGB_8888_RasterConfig ? kN32_SkColorType :
279
281 return nullptr;
282 }
283
284 bitmap.installPixels(SkImageInfo::Make(layerState.width, layerState.height,
286 layerState.raster.pixels, (size_t) layerState.raster.rowBytes);
287
288 SkASSERT(!bitmap.empty());
289 SkASSERT(!bitmap.isNull());
290
291 std::unique_ptr<SkCanvas> canvas(new SkCanvas(bitmap));
292
293 // setup the matrix and clip
294 setup_canvas_from_MC_state(layerState.mcState, canvas.get());
295
296 return canvas;
297}
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
#define SkASSERT(cond)
Definition: SkAssert.h:116
static void setup_canvas_from_MC_state(const SkMCState &state, SkCanvas *canvas)
SkColorType
Definition: SkColorType.h:19
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
Definition: SkColorType.h:22
@ kUnknown_SkColorType
uninitialized
Definition: SkColorType.h:20
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
Definition: bitmap.py:1
struct SkCanvasLayerState::@423::@425 raster
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ setup_canvas_from_MC_state()

static void setup_canvas_from_MC_state ( const SkMCState state,
SkCanvas canvas 
)
static

Definition at line 243 of file SkCanvasStateUtils.cpp.

243 {
244 // reconstruct the matrix
246 for (int i = 0; i < 9; i++) {
247 matrix.set(i, state.matrix[i]);
248 }
249
250 // only realy support 1 rect, so if the caller (legacy?) sent us more, we just take the bounds
251 // of what they sent.
253 if (state.clipRectCount > 0) {
254 bounds.setLTRB(state.clipRects[0].left,
255 state.clipRects[0].top,
256 state.clipRects[0].right,
257 state.clipRects[0].bottom);
258 for (int i = 1; i < state.clipRectCount; ++i) {
259 bounds.join({state.clipRects[i].left,
260 state.clipRects[i].top,
261 state.clipRects[i].right,
262 state.clipRects[i].bottom});
263 }
264 }
265
266 canvas->clipRect(SkRect::Make(bounds));
267 canvas->concat(matrix);
268}
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void concat(const SkMatrix &matrix)
Definition: SkCanvas.cpp:1318
AtkStateType state
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
Optional< SkRect > bounds
Definition: SkRecords.h:189
Definition: SkRect.h:32
static constexpr SkIRect MakeEmpty()
Definition: SkRect.h:45
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669

◆ setup_MC_state()

static void setup_MC_state ( SkMCState state,
const SkMatrix matrix,
const SkIRect clip 
)
static

Definition at line 153 of file SkCanvasStateUtils.cpp.

153 {
154 // initialize the struct
155 state->clipRectCount = 0;
156
157 // capture the matrix
158 for (int i = 0; i < 9; i++) {
159 state->matrix[i] = matrix.get(i);
160 }
161
162 /*
163 * We only support a single clipRect, so we take the clip's bounds. Clients have long made
164 * this assumption anyway, so this restriction is fine.
165 */
166 SkSWriter32<sizeof(ClipRect)> clipWriter;
167
168 if (!clip.isEmpty()) {
169 state->clipRectCount = 1;
170 state->clipRects = (ClipRect*)sk_malloc_throw(sizeof(ClipRect));
171 state->clipRects->left = clip.fLeft;
172 state->clipRects->top = clip.fTop;
173 state->clipRects->right = clip.fRight;
174 state->clipRects->bottom = clip.fBottom;
175 }
176}
static void * sk_malloc_throw(size_t size)
Definition: SkMalloc.h:67
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
bool isEmpty() const
Definition: SkPath.cpp:416