GrGpuResource.h revision 6d4488c5e03010c94200b3706631d34ec3201411
1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/* 2c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon * Copyright 2014 Google Inc. 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 68fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com */ 78fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com 86d3fe022d68fd6dd32c0fab30e24fa5a4f048946bsalomon#ifndef GrGpuResource_DEFINED 96d3fe022d68fd6dd32c0fab30e24fa5a4f048946bsalomon#define GrGpuResource_DEFINED 108fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com 11bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon#include "GrResourceKey.h" 12bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon#include "GrTypesPriv.h" 13c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon#include "SkInstCnt.h" 1442619d8df206b0bcd36d952909d972b8961e75debsalomon@google.com#include "SkTInternalLList.h" 159474ed06176fe24c77091b0d75f35442e851073frobertphillips@google.com 16f7b5c1ebfdad1a77d301d1676235e79f8006883ebsalomon@google.comclass GrContext; 1737dd331b20a92ce79cc26556e065dec98a66cb0bbsalomonclass GrGpu; 1837dd331b20a92ce79cc26556e065dec98a66cb0bbsalomonclass GrResourceCache2; 1937dd331b20a92ce79cc26556e065dec98a66cb0bbsalomonclass GrResourceCacheEntry; 208fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com 2176b7fcc79ee47db6ebea4f27e0070c467684418absalomon@google.com/** 2200b76bd750e668a6989dd497313e715d1b476fdcbsalomon * Base class for GrGpuResource. Handles the various types of refs we need. Separated out as a base 2300b76bd750e668a6989dd497313e715d1b476fdcbsalomon * class to isolate the ref-cnting behavior and provide friendship without exposing all of 2400b76bd750e668a6989dd497313e715d1b476fdcbsalomon * GrGpuResource. 2500b76bd750e668a6989dd497313e715d1b476fdcbsalomon * 2600b76bd750e668a6989dd497313e715d1b476fdcbsalomon * Gpu resources can have three types of refs: 2700b76bd750e668a6989dd497313e715d1b476fdcbsalomon * 1) Normal ref (+ by ref(), - by unref()): These are used by code that is issuing draw calls 2800b76bd750e668a6989dd497313e715d1b476fdcbsalomon * that read and write the resource via GrDrawTarget and by any object that must own a 2900b76bd750e668a6989dd497313e715d1b476fdcbsalomon * GrGpuResource and is itself owned (directly or indirectly) by Skia-client code. 30bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon * 2) Pending read (+ by addPendingRead(), - by completedRead()): GrContext has scheduled a read 3100b76bd750e668a6989dd497313e715d1b476fdcbsalomon * of the resource by the GPU as a result of a skia API call but hasn't executed it yet. 32bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon * 3) Pending write (+ by addPendingWrite(), - by completedWrite()): GrContext has scheduled a 3300b76bd750e668a6989dd497313e715d1b476fdcbsalomon * write to the resource by the GPU as a result of a skia API call but hasn't executed it yet. 3400b76bd750e668a6989dd497313e715d1b476fdcbsalomon * 3500b76bd750e668a6989dd497313e715d1b476fdcbsalomon * The latter two ref types are private and intended only for Gr core code. 36bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon * 37bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon * When an item is purgable DERIVED:notifyIsPurgable() will be called (static poly morphism using 38bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon * CRTP). GrIORef and GrGpuResource are separate classes for organizational reasons and to be 39bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon * able to give access via friendship to only the functions related to pending IO operations. 4076b7fcc79ee47db6ebea4f27e0070c467684418absalomon@google.com */ 41bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomontemplate <typename DERIVED> class GrIORef : public SkNoncopyable { 428fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.compublic: 4345725db1d82615d43408ec488549aec6218f80e4bsalomon SK_DECLARE_INST_COUNT_ROOT(GrIORef) 44c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon 4500b76bd750e668a6989dd497313e715d1b476fdcbsalomon // Some of the signatures are written to mirror SkRefCnt so that GrGpuResource can work with 4600b76bd750e668a6989dd497313e715d1b476fdcbsalomon // templated helper classes (e.g. SkAutoTUnref). However, we have different categories of 4700b76bd750e668a6989dd497313e715d1b476fdcbsalomon // refs (e.g. pending reads). We also don't require thread safety as GrCacheable objects are 4800b76bd750e668a6989dd497313e715d1b476fdcbsalomon // not intended to cross thread boundaries. 4900b76bd750e668a6989dd497313e715d1b476fdcbsalomon void ref() const { 509323b8b8e16df4adcd63ee8496a6382e8df535c9Brian Salomon this->validate(); 51bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon ++fRefCnt; 5200b76bd750e668a6989dd497313e715d1b476fdcbsalomon } 5300b76bd750e668a6989dd497313e715d1b476fdcbsalomon 5400b76bd750e668a6989dd497313e715d1b476fdcbsalomon void unref() const { 5500b76bd750e668a6989dd497313e715d1b476fdcbsalomon this->validate(); 5600b76bd750e668a6989dd497313e715d1b476fdcbsalomon --fRefCnt; 57bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon this->didUnref(); 5800b76bd750e668a6989dd497313e715d1b476fdcbsalomon } 5900b76bd750e668a6989dd497313e715d1b476fdcbsalomon 60bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon bool isPurgable() const { return this->reffedOnlyByCache() && !this->internalHasPendingIO(); } 61bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon bool reffedOnlyByCache() const { return 1 == fRefCnt; } 6200b76bd750e668a6989dd497313e715d1b476fdcbsalomon 63c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon void validate() const { 6400b76bd750e668a6989dd497313e715d1b476fdcbsalomon#ifdef SK_DEBUG 6500b76bd750e668a6989dd497313e715d1b476fdcbsalomon SkASSERT(fRefCnt >= 0); 6600b76bd750e668a6989dd497313e715d1b476fdcbsalomon SkASSERT(fPendingReads >= 0); 6700b76bd750e668a6989dd497313e715d1b476fdcbsalomon SkASSERT(fPendingWrites >= 0); 6800b76bd750e668a6989dd497313e715d1b476fdcbsalomon SkASSERT(fRefCnt + fPendingReads + fPendingWrites > 0); 69c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon#endif 7000b76bd750e668a6989dd497313e715d1b476fdcbsalomon } 7100b76bd750e668a6989dd497313e715d1b476fdcbsalomon 7200b76bd750e668a6989dd497313e715d1b476fdcbsalomonprotected: 731e2530babb65a883a01df5ee87147432f6707ce3bsalomon GrIORef() : fRefCnt(1), fPendingReads(0), fPendingWrites(0) { } 7400b76bd750e668a6989dd497313e715d1b476fdcbsalomon 758d034a154fec81167ecb696c07da389b98cc02a7bsalomon bool internalHasPendingRead() const { return SkToBool(fPendingReads); } 768d034a154fec81167ecb696c07da389b98cc02a7bsalomon bool internalHasPendingWrite() const { return SkToBool(fPendingWrites); } 778d034a154fec81167ecb696c07da389b98cc02a7bsalomon bool internalHasPendingIO() const { return SkToBool(fPendingWrites | fPendingReads); } 788d034a154fec81167ecb696c07da389b98cc02a7bsalomon 796d4488c5e03010c94200b3706631d34ec3201411bsalomon bool internalHasRef() const { return SkToBool(fRefCnt); } 806d4488c5e03010c94200b3706631d34ec3201411bsalomon 8100b76bd750e668a6989dd497313e715d1b476fdcbsalomonprivate: 8200b76bd750e668a6989dd497313e715d1b476fdcbsalomon void addPendingRead() const { 8300b76bd750e668a6989dd497313e715d1b476fdcbsalomon this->validate(); 8400b76bd750e668a6989dd497313e715d1b476fdcbsalomon ++fPendingReads; 8500b76bd750e668a6989dd497313e715d1b476fdcbsalomon } 8600b76bd750e668a6989dd497313e715d1b476fdcbsalomon 8700b76bd750e668a6989dd497313e715d1b476fdcbsalomon void completedRead() const { 8800b76bd750e668a6989dd497313e715d1b476fdcbsalomon this->validate(); 8900b76bd750e668a6989dd497313e715d1b476fdcbsalomon --fPendingReads; 90bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon this->didUnref(); 9100b76bd750e668a6989dd497313e715d1b476fdcbsalomon } 9200b76bd750e668a6989dd497313e715d1b476fdcbsalomon 9300b76bd750e668a6989dd497313e715d1b476fdcbsalomon void addPendingWrite() const { 9400b76bd750e668a6989dd497313e715d1b476fdcbsalomon this->validate(); 9500b76bd750e668a6989dd497313e715d1b476fdcbsalomon ++fPendingWrites; 9600b76bd750e668a6989dd497313e715d1b476fdcbsalomon } 9700b76bd750e668a6989dd497313e715d1b476fdcbsalomon 9800b76bd750e668a6989dd497313e715d1b476fdcbsalomon void completedWrite() const { 9900b76bd750e668a6989dd497313e715d1b476fdcbsalomon this->validate(); 10000b76bd750e668a6989dd497313e715d1b476fdcbsalomon --fPendingWrites; 101bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon this->didUnref(); 10200b76bd750e668a6989dd497313e715d1b476fdcbsalomon } 10300b76bd750e668a6989dd497313e715d1b476fdcbsalomon 10400b76bd750e668a6989dd497313e715d1b476fdcbsalomonprivate: 105bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon void didUnref() const { 106bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon if (0 == fPendingReads && 0 == fPendingWrites) { 107bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon if (0 == fRefCnt) { 108ac211af359667dd1afcc375e688c3aae46cb13e8bsalomon // Must call derived destructor since this is not a virtual class. 109ac211af359667dd1afcc375e688c3aae46cb13e8bsalomon SkDELETE(static_cast<const DERIVED*>(this)); 110bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon } else if (1 == fRefCnt) { 111bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon // The one ref is the cache's 112bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon static_cast<const DERIVED*>(this)->notifyIsPurgable(); 113bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon } 114bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon } 115bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon } 116bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon 11700b76bd750e668a6989dd497313e715d1b476fdcbsalomon mutable int32_t fRefCnt; 11800b76bd750e668a6989dd497313e715d1b476fdcbsalomon mutable int32_t fPendingReads; 11900b76bd750e668a6989dd497313e715d1b476fdcbsalomon mutable int32_t fPendingWrites; 12000b76bd750e668a6989dd497313e715d1b476fdcbsalomon 121ac8d6193eaa29e02d1786fe56efa98eefee74e50bsalomon // This class is used to manage conversion of refs to pending reads/writes. 122f96ba02513eadd9fa24d75396ec9f2d6682e464cbsalomon friend class GrGpuResourceRef; 1231e2530babb65a883a01df5ee87147432f6707ce3bsalomon friend class GrResourceCache2; // to check IO ref counts. 124bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon 125bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon template <typename, GrIOType> friend class GrPendingIOResource; 12600b76bd750e668a6989dd497313e715d1b476fdcbsalomon}; 12700b76bd750e668a6989dd497313e715d1b476fdcbsalomon 12800b76bd750e668a6989dd497313e715d1b476fdcbsalomon/** 12900b76bd750e668a6989dd497313e715d1b476fdcbsalomon * Base class for objects that can be kept in the GrResourceCache. 13000b76bd750e668a6989dd497313e715d1b476fdcbsalomon */ 131544fe2338ff7459dbd887549aca31b8fc4cde7f4bsalomonclass SK_API GrGpuResource : public GrIORef<GrGpuResource> { 13200b76bd750e668a6989dd497313e715d1b476fdcbsalomonpublic: 13300b76bd750e668a6989dd497313e715d1b476fdcbsalomon SK_DECLARE_INST_COUNT(GrGpuResource) 134977b9c8af3ef1b9a2fa2a0037cf3734cf2ba13d9robertphillips@google.com 1358fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com /** 136089a780c3355129eefc942246534bc1f126b8ccbcommit-bot@chromium.org * Frees the object in the underlying 3D API. It must be safe to call this 137089a780c3355129eefc942246534bc1f126b8ccbcommit-bot@chromium.org * when the object has been previously abandoned. 1388fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com */ 1398fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com void release(); 1408fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com 1418fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com /** 1428fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com * Removes references to objects in the underlying 3D API without freeing 1438fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com * them. Used when the API context has been torn down before the GrContext. 1448fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com */ 1458fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com void abandon(); 1468fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com 1478fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com /** 148089a780c3355129eefc942246534bc1f126b8ccbcommit-bot@chromium.org * Tests whether a object has been abandoned or released. All objects will 149089a780c3355129eefc942246534bc1f126b8ccbcommit-bot@chromium.org * be in this state after their creating GrContext is destroyed or has 150089a780c3355129eefc942246534bc1f126b8ccbcommit-bot@chromium.org * contextLost called. It's up to the client to test wasDestroyed() before 151089a780c3355129eefc942246534bc1f126b8ccbcommit-bot@chromium.org * attempting to use an object if it holds refs on objects across 1528fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com * ~GrContext, freeResources with the force flag, or contextLost. 1538fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com * 154089a780c3355129eefc942246534bc1f126b8ccbcommit-bot@chromium.org * @return true if the object has been released or abandoned, 1558fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com * false otherwise. 1568fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com */ 157089a780c3355129eefc942246534bc1f126b8ccbcommit-bot@chromium.org bool wasDestroyed() const { return NULL == fGpu; } 1588fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com 159cee661af926cc977addc6e039b7022975a448acebsalomon@google.com /** 160089a780c3355129eefc942246534bc1f126b8ccbcommit-bot@chromium.org * Retrieves the context that owns the object. Note that it is possible for 161089a780c3355129eefc942246534bc1f126b8ccbcommit-bot@chromium.org * this to return NULL. When objects have been release()ed or abandon()ed 162089a780c3355129eefc942246534bc1f126b8ccbcommit-bot@chromium.org * they no longer have an owning context. Destroying a GrContext 163089a780c3355129eefc942246534bc1f126b8ccbcommit-bot@chromium.org * automatically releases all its resources. 164838f6e18fb13cd295f2c4d1e673cb03458f4e0a8bsalomon@google.com */ 1651f47f4f7325971dd53991e2bb02da94fa7c6d962robertphillips@google.com const GrContext* getContext() const; 1661f47f4f7325971dd53991e2bb02da94fa7c6d962robertphillips@google.com GrContext* getContext(); 1671f47f4f7325971dd53991e2bb02da94fa7c6d962robertphillips@google.com 168c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon /** 169c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon * Retrieves the amount of GPU memory used by this resource in bytes. It is 170c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon * approximate since we aren't aware of additional padding or copies made 171c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon * by the driver. 172c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon * 173c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon * @return the amount of GPU memory used in bytes 174c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon */ 175c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon virtual size_t gpuMemorySize() const = 0; 176c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon 1776d4488c5e03010c94200b3706631d34ec3201411bsalomon // TODO(bsalomon): Move this stuff to GrGpuResourcePriv. 1786d4488c5e03010c94200b3706631d34ec3201411bsalomon bool setContentKey(const GrResourceKey& contentKey); 1796d4488c5e03010c94200b3706631d34ec3201411bsalomon void setCacheEntry(GrResourceCacheEntry* cacheEntry); 180bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon GrResourceCacheEntry* getCacheEntry() const { return fCacheEntry; } 1811e2530babb65a883a01df5ee87147432f6707ce3bsalomon bool isScratch() const; 182744998e666073166307d2522847b2536000a7619bsalomon /** 183744998e666073166307d2522847b2536000a7619bsalomon * If this resource can be used as a scratch resource this returns a valid 184744998e666073166307d2522847b2536000a7619bsalomon * scratch key. Otherwise it returns a key for which isNullScratch is true. 1856d4488c5e03010c94200b3706631d34ec3201411bsalomon * The resource may currently be used as content resource rather than scratch. 1866d4488c5e03010c94200b3706631d34ec3201411bsalomon * Check isScratch(). 187744998e666073166307d2522847b2536000a7619bsalomon */ 188744998e666073166307d2522847b2536000a7619bsalomon const GrResourceKey& getScratchKey() const { return fScratchKey; } 1891e2530babb65a883a01df5ee87147432f6707ce3bsalomon /** 1901e2530babb65a883a01df5ee87147432f6707ce3bsalomon * If this resource is currently cached by its contents then this will return 1911e2530babb65a883a01df5ee87147432f6707ce3bsalomon * the content key. Otherwise, NULL is returned. 1921e2530babb65a883a01df5ee87147432f6707ce3bsalomon */ 1931e2530babb65a883a01df5ee87147432f6707ce3bsalomon const GrResourceKey* getContentKey() const; 1941e2530babb65a883a01df5ee87147432f6707ce3bsalomon 195728302281920727b96e6cec0bfc7575900f34a8bbsalomon@google.com /** 19652e9d63f7110ac691609660342cdab32082a4235bsalomon * Gets an id that is unique for this GrGpuResource object. It is static in that it does 19752e9d63f7110ac691609660342cdab32082a4235bsalomon * not change when the content of the GrGpuResource object changes. This will never return 198c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon * 0. 199728302281920727b96e6cec0bfc7575900f34a8bbsalomon@google.com */ 200c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon uint32_t getUniqueID() const { return fUniqueID; } 201c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon 202c44be0e9e4cee5402909c06370a630eee188a8f3bsalomonprotected: 203169612621f00b3fe9f71014079991287d311751absalomon // This must be called by every GrGpuObject. It should be called once the object is fully 204169612621f00b3fe9f71014079991287d311751absalomon // initialized (i.e. not in a base class constructor). 205169612621f00b3fe9f71014079991287d311751absalomon void registerWithCache(); 206169612621f00b3fe9f71014079991287d311751absalomon 2076d3fe022d68fd6dd32c0fab30e24fa5a4f048946bsalomon GrGpuResource(GrGpu*, bool isWrapped); 2086d3fe022d68fd6dd32c0fab30e24fa5a4f048946bsalomon virtual ~GrGpuResource(); 20976b7fcc79ee47db6ebea4f27e0070c467684418absalomon@google.com 21049f085dddff10473b6ebf832a974288300224e60bsalomon bool isInCache() const { return SkToBool(fCacheEntry); } 211c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon 21276b7fcc79ee47db6ebea4f27e0070c467684418absalomon@google.com GrGpu* getGpu() const { return fGpu; } 2138fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com 214d364554bcfd391c3b6111af8bff963a35ab87ba7robertphillips@google.com // Derived classes should always call their parent class' onRelease 215d364554bcfd391c3b6111af8bff963a35ab87ba7robertphillips@google.com // and onAbandon methods in their overrides. 216d364554bcfd391c3b6111af8bff963a35ab87ba7robertphillips@google.com virtual void onRelease() {}; 217d364554bcfd391c3b6111af8bff963a35ab87ba7robertphillips@google.com virtual void onAbandon() {}; 2188fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com 2199ef0426e7c126f6ad6ba833d4543b92a197c95afrobertphillips@google.com bool isWrapped() const { return kWrapped_FlagBit & fFlags; } 220a292112154f803feb9f5cc002bbfab559f7cb633bsalomon@google.com 221c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon /** 222c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon * This entry point should be called whenever gpuMemorySize() begins 223c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon * reporting a different size. If the object is in the cache, it will call 224c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon * gpuMemorySize() immediately and pass the new size on to the resource 225c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon * cache. 226c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon */ 227c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon void didChangeGpuMemorySize() const; 228c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon 229744998e666073166307d2522847b2536000a7619bsalomon /** 230744998e666073166307d2522847b2536000a7619bsalomon * Optionally called by the GrGpuResource subclass if the resource can be used as scratch. 231744998e666073166307d2522847b2536000a7619bsalomon * By default resources are not usable as scratch. This should only be called once. 232744998e666073166307d2522847b2536000a7619bsalomon **/ 233744998e666073166307d2522847b2536000a7619bsalomon void setScratchKey(const GrResourceKey& scratchKey); 234744998e666073166307d2522847b2536000a7619bsalomon 2358fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.comprivate: 236bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon void notifyIsPurgable() const; 237bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon 238515dcd36032997ce335daa0163c6d67e851bcad1commit-bot@chromium.org#ifdef SK_DEBUG 2399474ed06176fe24c77091b0d75f35442e851073frobertphillips@google.com friend class GrGpu; // for assert in GrGpu to access getGpu 2409474ed06176fe24c77091b0d75f35442e851073frobertphillips@google.com#endif 2418fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com 242c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon static uint32_t CreateUniqueID(); 243c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon 244c8dc1f74b6cdda9a43a638292a608c59c1d72d80bsalomon // We're in an internal doubly linked list owned by GrResourceCache2 2456d3fe022d68fd6dd32c0fab30e24fa5a4f048946bsalomon SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrGpuResource); 2468fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com 247c8dc1f74b6cdda9a43a638292a608c59c1d72d80bsalomon // This is not ref'ed but abandon() or release() will be called before the GrGpu object 248c8dc1f74b6cdda9a43a638292a608c59c1d72d80bsalomon // is destroyed. Those calls set will this to NULL. 249c8dc1f74b6cdda9a43a638292a608c59c1d72d80bsalomon GrGpu* fGpu; 250c8dc1f74b6cdda9a43a638292a608c59c1d72d80bsalomon 251728302281920727b96e6cec0bfc7575900f34a8bbsalomon@google.com enum Flags { 2529ef0426e7c126f6ad6ba833d4543b92a197c95afrobertphillips@google.com /** 253089a780c3355129eefc942246534bc1f126b8ccbcommit-bot@chromium.org * This object wraps a GPU object given to us by the user. 254b77f0f4ae560e97cc4cd2758752d955549017c3cskia.committer@gmail.com * Lifetime management is left up to the user (i.e., we will not 2559ef0426e7c126f6ad6ba833d4543b92a197c95afrobertphillips@google.com * free it). 2569ef0426e7c126f6ad6ba833d4543b92a197c95afrobertphillips@google.com */ 2579ef0426e7c126f6ad6ba833d4543b92a197c95afrobertphillips@google.com kWrapped_FlagBit = 0x1, 258728302281920727b96e6cec0bfc7575900f34a8bbsalomon@google.com }; 259728302281920727b96e6cec0bfc7575900f34a8bbsalomon@google.com 260c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon uint32_t fFlags; 261c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon 262c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon GrResourceCacheEntry* fCacheEntry; // NULL if not in cache 263c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon const uint32_t fUniqueID; 264c44be0e9e4cee5402909c06370a630eee188a8f3bsalomon 2656d4488c5e03010c94200b3706631d34ec3201411bsalomon // TODO(bsalomon): Remove GrResourceKey and use different simpler types for content and scratch 2666d4488c5e03010c94200b3706631d34ec3201411bsalomon // keys. 267744998e666073166307d2522847b2536000a7619bsalomon GrResourceKey fScratchKey; 2686d4488c5e03010c94200b3706631d34ec3201411bsalomon GrResourceKey fContentKey; 2696d4488c5e03010c94200b3706631d34ec3201411bsalomon bool fContentKeySet; 270744998e666073166307d2522847b2536000a7619bsalomon 271bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon typedef GrIORef<GrGpuResource> INHERITED; 272bcf0a52d4f4221b158e68a06ba0c4cc4db011060bsalomon friend class GrIORef<GrGpuResource>; // to access notifyIsPurgable. 2738fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com}; 2748fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com 2758fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com#endif 276