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
Definition at line 197 of file ResourceKey.h.