Flutter Engine
The Flutter Engine
Public Member Functions | Public Attributes | List of all members
SkWritePixelsRec Struct Reference

#include <SkWritePixelsRec.h>

Public Member Functions

 SkWritePixelsRec (const SkImageInfo &info, const void *pixels, size_t rowBytes, int x, int y)
 
 SkWritePixelsRec (const SkPixmap &pm, int x, int y)
 
bool trim (int dstWidth, int dstHeight)
 

Public Attributes

const void * fPixels
 
size_t fRowBytes
 
SkImageInfo fInfo
 
int fX
 
int fY
 

Detailed Description

Helper class to package and trim the parameters passed to writePixels()

Definition at line 19 of file SkWritePixelsRec.h.

Constructor & Destructor Documentation

◆ SkWritePixelsRec() [1/2]

SkWritePixelsRec::SkWritePixelsRec ( const SkImageInfo info,
const void *  pixels,
size_t  rowBytes,
int  x,
int  y 
)
inline

Definition at line 20 of file SkWritePixelsRec.h.

21 : fPixels(pixels)
22 , fRowBytes(rowBytes)
23 , fInfo(info)
24 , fX(x)
25 , fY(y)
26 {}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
double y
double x
const void * fPixels

◆ SkWritePixelsRec() [2/2]

SkWritePixelsRec::SkWritePixelsRec ( const SkPixmap pm,
int  x,
int  y 
)
inline

Definition at line 28 of file SkWritePixelsRec.h.

29 : fPixels(pm.addr())
30 , fRowBytes(pm.rowBytes())
31 , fInfo(pm.info())
32 , fX(x)
33 , fY(y)
34 {}
size_t rowBytes() const
Definition: SkPixmap.h:145
const SkImageInfo & info() const
Definition: SkPixmap.h:135
const void * addr() const
Definition: SkPixmap.h:153

Member Function Documentation

◆ trim()

bool SkWritePixelsRec::trim ( int  dstWidth,
int  dstHeight 
)

Definition at line 12 of file SkWritePixelsRec.cpp.

12 {
13 if (nullptr == fPixels || fRowBytes < fInfo.minRowBytes()) {
14 return false;
15 }
16 if (0 >= fInfo.width() || 0 >= fInfo.height()) {
17 return false;
18 }
19
20 int x = fX;
21 int y = fY;
23 if (!dstR.intersect({0, 0, dstWidth, dstHeight})) {
24 return false;
25 }
26
27 // if x or y are negative, then we have to adjust pixels
28 if (x > 0) {
29 x = 0;
30 }
31 if (y > 0) {
32 y = 0;
33 }
34 // here x,y are either 0 or negative
35 // we negate and add them so UBSAN (pointer-overflow) doesn't get confused.
36 fPixels = ((const char*)fPixels + -y*fRowBytes + -x*fInfo.bytesPerPixel());
37 // the intersect may have shrunk info's logical size
39 fX = dstR.x();
40 fY = dstR.y();
41
42 return true;
43}
Definition: SkRect.h:32
constexpr int32_t x() const
Definition: SkRect.h:141
constexpr int32_t y() const
Definition: SkRect.h:148
bool intersect(const SkIRect &r)
Definition: SkRect.h:513
constexpr SkISize size() const
Definition: SkRect.h:172
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: SkRect.h:104
size_t minRowBytes() const
Definition: SkImageInfo.h:517
SkImageInfo makeDimensions(SkISize newSize) const
Definition: SkImageInfo.h:454
int bytesPerPixel() const
Definition: SkImageInfo.h:492
int width() const
Definition: SkImageInfo.h:365
int height() const
Definition: SkImageInfo.h:371

Member Data Documentation

◆ fInfo

SkImageInfo SkWritePixelsRec::fInfo

Definition at line 38 of file SkWritePixelsRec.h.

◆ fPixels

const void* SkWritePixelsRec::fPixels

Definition at line 36 of file SkWritePixelsRec.h.

◆ fRowBytes

size_t SkWritePixelsRec::fRowBytes

Definition at line 37 of file SkWritePixelsRec.h.

◆ fX

int SkWritePixelsRec::fX

Definition at line 39 of file SkWritePixelsRec.h.

◆ fY

int SkWritePixelsRec::fY

Definition at line 40 of file SkWritePixelsRec.h.


The documentation for this struct was generated from the following files: