Skia
2DGraphicsLibrary
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GrScratchKey Class Reference

A key used for scratch resources. More...

#include <GrResourceKey.h>

Inheritance diagram for GrScratchKey:
GrResourceKey

Classes

class  Builder
 

Public Types

typedef uint32_t ResourceType
 Uniquely identifies the type of resource that is cached as scratch. More...
 

Public Member Functions

 GrScratchKey ()
 Creates an invalid scratch key. More...
 
 GrScratchKey (const GrScratchKey &that)
 
ResourceType resourceType () const
 
GrScratchKeyoperator= (const GrScratchKey &that)
 
bool operator== (const GrScratchKey &that) const
 
bool operator!= (const GrScratchKey &that) const
 
- Public Member Functions inherited from GrResourceKey
uint32_t hash () const
 
size_t size () const
 

Static Public Member Functions

static ResourceType GenerateResourceType ()
 Generate a unique ResourceType. More...
 

Private Types

typedef GrResourceKey INHERITED
 

Additional Inherited Members

- Protected Member Functions inherited from GrResourceKey
void reset ()
 Reset to an invalid key. More...
 
bool operator== (const GrResourceKey &that) const
 
GrResourceKeyoperator= (const GrResourceKey &that)
 
bool isValid () const
 
uint32_t domain () const
 
size_t dataSize () const
 size of the key data, excluding meta-data (hash, domain, etc). More...
 
const uint32_t * data () const
 ptr to the key data, excluding meta-data (hash, domain, etc). More...
 
- Static Protected Attributes inherited from GrResourceKey
static const uint32_t kInvalidDomain = 0
 

Detailed Description

A key used for scratch resources.

There are three important rules about scratch keys:

  • Multiple resources can share the same scratch key. Therefore resources assigned the same scratch key should be interchangeable with respect to the code that uses them.
  • A resource can have at most one scratch key and it is set at resource creation by the resource itself.
  • When a scratch resource is ref'ed it will not be returned from the cache for a subsequent cache request until all refs are released. This facilitates using a scratch key for multiple render-to-texture scenarios. An example is a separable blur:

GrTexture* texture[2]; texture[0] = get_scratch_texture(scratchKey); texture[1] = get_scratch_texture(scratchKey); // texture[0] is already owned so we will get a // different one for texture[1] draw_mask(texture[0], path); // draws path mask to texture[0] blur_x(texture[0], texture[1]); // blurs texture[0] in y and stores result in texture[1] blur_y(texture[1], texture[0]); // blurs texture[1] in y and stores result in texture[0] texture[1]->unref(); // texture 1 can now be recycled for the next request with scratchKey consume_blur(texture[0]); texture[0]->unref(); // texture 0 can now be recycled for the next request with scratchKey

Member Typedef Documentation

typedef uint32_t GrScratchKey::ResourceType

Uniquely identifies the type of resource that is cached as scratch.

Constructor & Destructor Documentation

GrScratchKey::GrScratchKey ( )
inline

Creates an invalid scratch key.

It must be initialized using a Builder object before use.

Member Function Documentation

static ResourceType GrScratchKey::GenerateResourceType ( )
static

Generate a unique ResourceType.


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