Skia
2D Graphics Library
|
SkData holds an immutable data buffer. More...
#include <SkData.h>
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< SkData > | MakeWithCopy (const void *data, size_t length) |
Create a new dataref by copying the specified data. More... | |
static sk_sp< SkData > | MakeUninitialized (size_t length) |
Create a new data with uninitialized contents. More... | |
static sk_sp< SkData > | MakeZeroInitialized (size_t length) |
Create a new data with zero-initialized contents. More... | |
static sk_sp< SkData > | MakeWithCString (const char cstr[]) |
Create a new dataref by copying the specified c-string (a null-terminated array of bytes). More... | |
static sk_sp< SkData > | MakeWithProc (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< SkData > | MakeWithoutCopy (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< SkData > | MakeFromMalloc (const void *data, size_t length) |
Create a new dataref from a pointer allocated by malloc. More... | |
static sk_sp< SkData > | MakeFromFileName (const char path[]) |
Create a new dataref the file with the specified path. More... | |
static sk_sp< SkData > | MakeFromFILE (FILE *f) |
Create a new dataref from a stdio FILE. More... | |
static sk_sp< SkData > | MakeFromFD (int fd) |
Create a new dataref from a file descriptor. More... | |
static sk_sp< SkData > | MakeFromStream (SkStream *, size_t size) |
Attempt to read size bytes into a SkData. More... | |
static sk_sp< SkData > | MakeSubset (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< SkData > | MakeEmpty () |
Returns a new empty dataref (or a reference to a shared empty dataref). More... | |
Friends | |
class | SkNVRefCnt< SkData > |
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.
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.
|
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.
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.
|
inline |
Returns the ptr to the data.
|
inlineinherited |
bool SkData::equals | ( | const SkData * | other | ) | const |
Returns true if these two objects have the same length and contents, effectively returning 0 == memcmp(...)
|
inline |
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.
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.
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.
Create a new dataref the file with the specified path.
If the file cannot be opened, this returns NULL.
Create a new dataref from a pointer allocated by malloc.
The Data object takes ownership of that allocation, and will handling calling sk_free.
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().
Create a new dataref using a subset of the data in the specified src dataref.
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.
Create a new dataref by copying the specified data.
Call this when the data parameter is already const and will outlive the lifetime of the SkData.
Suitable for with const globals.
|
static |
Create a new dataref, taking the ptr as is, and using the releaseproc to free it.
The proc may be NULL.
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.
|
inlineinherited |
|
inlineinherited |
|
inline |
Returns the number of bytes stored.
|
inlineinherited |
|
inlineinherited |
|
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.
|
friend |