Skia
2D Graphics Library
SkData Class Referencefinal

SkData holds an immutable data buffer. More...

#include <SkData.h>

Inheritance diagram for SkData:

Public Types

typedef void(* ReleaseProc) (const void *ptr, void *context)
 Function that, if provided, will be called when the SkData goes out of scope, allowing for custom allocation/freeing of the data's contents. More...
 

Public Member Functions

size_t size () const
 Returns the number of bytes stored. More...
 
bool isEmpty () const
 
const void * data () const
 Returns the ptr to the data. More...
 
const uint8_t * bytes () const
 Like data(), returns a read-only ptr into the data, but in this case it is cast to uint8_t*, to make it easy to add an offset to it. More...
 
void * writable_data ()
 USE WITH CAUTION. More...
 
size_t copyRange (size_t offset, size_t length, void *buffer) const
 Helper to copy a range of the data into a caller-provided buffer. More...
 
bool equals (const SkData *other) const
 Returns true if these two objects have the same length and contents, effectively returning 0 == memcmp(...) More...
 
bool unique () const
 
void ref () const
 
void unref () const
 
void deref () const
 
bool refCntGreaterThan (int32_t threadIsolatedTestCnt) const
 

Static Public Member Functions

static sk_sp< SkDataMakeWithCopy (const void *data, size_t length)
 Create a new dataref by copying the specified data. More...
 
static sk_sp< SkDataMakeUninitialized (size_t length)
 Create a new data with uninitialized contents. More...
 
static sk_sp< SkDataMakeZeroInitialized (size_t length)
 Create a new data with zero-initialized contents. More...
 
static sk_sp< SkDataMakeWithCString (const char cstr[])
 Create a new dataref by copying the specified c-string (a null-terminated array of bytes). More...
 
static sk_sp< SkDataMakeWithProc (const void *ptr, size_t length, ReleaseProc proc, void *ctx)
 Create a new dataref, taking the ptr as is, and using the releaseproc to free it. More...
 
static sk_sp< SkDataMakeWithoutCopy (const void *data, size_t length)
 Call this when the data parameter is already const and will outlive the lifetime of the SkData. More...
 
static sk_sp< SkDataMakeFromMalloc (const void *data, size_t length)
 Create a new dataref from a pointer allocated by malloc. More...
 
static sk_sp< SkDataMakeFromFileName (const char path[])
 Create a new dataref the file with the specified path. More...
 
static sk_sp< SkDataMakeFromFILE (FILE *f)
 Create a new dataref from a stdio FILE. More...
 
static sk_sp< SkDataMakeFromFD (int fd)
 Create a new dataref from a file descriptor. More...
 
static sk_sp< SkDataMakeFromStream (SkStream *, size_t size)
 Attempt to read size bytes into a SkData. More...
 
static sk_sp< SkDataMakeSubset (const SkData *src, size_t offset, size_t length)
 Create a new dataref using a subset of the data in the specified src dataref. More...
 
static sk_sp< SkDataMakeEmpty ()
 Returns a new empty dataref (or a reference to a shared empty dataref). More...
 

Friends

class SkNVRefCnt< SkData >
 

Detailed Description

SkData holds an immutable data buffer.

Not only is the data immutable, but the actual ptr that is returned (by data() or bytes()) is guaranteed to always be the same for the life of this instance.

Member Typedef Documentation

◆ ReleaseProc

typedef void(* SkData::ReleaseProc) (const void *ptr, void *context)

Function that, if provided, will be called when the SkData goes out of scope, allowing for custom allocation/freeing of the data's contents.

Member Function Documentation

◆ bytes()

const uint8_t* SkData::bytes ( ) const
inline

Like data(), returns a read-only ptr into the data, but in this case it is cast to uint8_t*, to make it easy to add an offset to it.

◆ copyRange()

size_t SkData::copyRange ( size_t  offset,
size_t  length,
void *  buffer 
) const

Helper to copy a range of the data into a caller-provided buffer.

Returns the actual number of bytes copied, after clamping offset and length to the size of the data. If buffer is NULL, it is ignored, and only the computed number of bytes is returned.

◆ data()

const void* SkData::data ( ) const
inline

Returns the ptr to the data.

◆ deref()

void SkNVRefCnt< SkData >::deref ( ) const
inlineinherited

◆ equals()

bool SkData::equals ( const SkData other) const

Returns true if these two objects have the same length and contents, effectively returning 0 == memcmp(...)

◆ isEmpty()

bool SkData::isEmpty ( ) const
inline

◆ MakeEmpty()

static sk_sp<SkData> SkData::MakeEmpty ( )
static

Returns a new empty dataref (or a reference to a shared empty dataref).

New or shared, the caller must see that unref() is eventually called.

◆ MakeFromFD()

static sk_sp<SkData> SkData::MakeFromFD ( int  fd)
static

Create a new dataref from a file descriptor.

This does not take ownership of the file descriptor, nor close it. The caller is free to close the file descriptor at its convenience. The file descriptor must be open for reading only. Returns NULL on failure.

◆ MakeFromFILE()

static sk_sp<SkData> SkData::MakeFromFILE ( FILE *  f)
static

Create a new dataref from a stdio FILE.

This does not take ownership of the FILE, nor close it. The caller is free to close the FILE at its convenience. The FILE must be open for reading only. Returns NULL on failure.

◆ MakeFromFileName()

static sk_sp<SkData> SkData::MakeFromFileName ( const char  path[])
static

Create a new dataref the file with the specified path.

If the file cannot be opened, this returns NULL.

◆ MakeFromMalloc()

static sk_sp<SkData> SkData::MakeFromMalloc ( const void *  data,
size_t  length 
)
static

Create a new dataref from a pointer allocated by malloc.

The Data object takes ownership of that allocation, and will handling calling sk_free.

◆ MakeFromStream()

static sk_sp<SkData> SkData::MakeFromStream ( SkStream ,
size_t  size 
)
static

Attempt to read size bytes into a SkData.

If the read succeeds, return the data, else return NULL. Either way the stream's cursor may have been changed as a result of calling read().

◆ MakeSubset()

static sk_sp<SkData> SkData::MakeSubset ( const SkData src,
size_t  offset,
size_t  length 
)
static

Create a new dataref using a subset of the data in the specified src dataref.

◆ MakeUninitialized()

static sk_sp<SkData> SkData::MakeUninitialized ( size_t  length)
static

Create a new data with uninitialized contents.

The caller should call writable_data() to write into the buffer, but this must be done before another ref() is made.

◆ MakeWithCopy()

static sk_sp<SkData> SkData::MakeWithCopy ( const void *  data,
size_t  length 
)
static

Create a new dataref by copying the specified data.

◆ MakeWithCString()

static sk_sp<SkData> SkData::MakeWithCString ( const char  cstr[])
static

Create a new dataref by copying the specified c-string (a null-terminated array of bytes).

The returned SkData will have size() equal to strlen(cstr) + 1. If cstr is NULL, it will be treated the same as "".

◆ MakeWithoutCopy()

static sk_sp<SkData> SkData::MakeWithoutCopy ( const void *  data,
size_t  length 
)
inlinestatic

Call this when the data parameter is already const and will outlive the lifetime of the SkData.

Suitable for with const globals.

◆ MakeWithProc()

static sk_sp<SkData> SkData::MakeWithProc ( const void *  ptr,
size_t  length,
ReleaseProc  proc,
void *  ctx 
)
static

Create a new dataref, taking the ptr as is, and using the releaseproc to free it.

The proc may be NULL.

◆ MakeZeroInitialized()

static sk_sp<SkData> SkData::MakeZeroInitialized ( size_t  length)
static

Create a new data with zero-initialized contents.

The caller should call writable_data() to write into the buffer, but this must be done before another ref() is made.

◆ ref()

void SkNVRefCnt< SkData >::ref ( ) const
inlineinherited

◆ refCntGreaterThan()

bool SkNVRefCnt< SkData >::refCntGreaterThan ( int32_t  threadIsolatedTestCnt) const
inlineinherited

◆ size()

size_t SkData::size ( ) const
inline

Returns the number of bytes stored.

◆ unique()

bool SkNVRefCnt< SkData >::unique ( ) const
inlineinherited

◆ unref()

void SkNVRefCnt< SkData >::unref ( ) const
inlineinherited

◆ writable_data()

void* SkData::writable_data ( )
inline

USE WITH CAUTION.

This call will assert that the refcnt is 1, as a precaution against modifying the contents when another client/thread has access to the data.

Friends And Related Function Documentation

◆ SkNVRefCnt< SkData >

friend class SkNVRefCnt< SkData >
friend

The documentation for this class was generated from the following file: