gfx/skia/trunk/include/gpu/GrResource.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /*
michael@0 2 * Copyright 2011 Google Inc.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7
michael@0 8 #ifndef GrResource_DEFINED
michael@0 9 #define GrResource_DEFINED
michael@0 10
michael@0 11 #include "SkRefCnt.h"
michael@0 12 #include "SkTInternalLList.h"
michael@0 13
michael@0 14 class GrGpu;
michael@0 15 class GrContext;
michael@0 16 class GrResourceEntry;
michael@0 17
michael@0 18 /**
michael@0 19 * Base class for the GPU resources created by a GrContext.
michael@0 20 */
michael@0 21 class GrResource : public SkRefCnt {
michael@0 22 public:
michael@0 23 SK_DECLARE_INST_COUNT(GrResource)
michael@0 24
michael@0 25 /**
michael@0 26 * Frees the resource in the underlying 3D API. It must be safe to call this
michael@0 27 * when the resource has been previously abandoned.
michael@0 28 */
michael@0 29 void release();
michael@0 30
michael@0 31 /**
michael@0 32 * Removes references to objects in the underlying 3D API without freeing
michael@0 33 * them. Used when the API context has been torn down before the GrContext.
michael@0 34 */
michael@0 35 void abandon();
michael@0 36
michael@0 37 /**
michael@0 38 * Tests whether a resource has been abandoned or released. All resources
michael@0 39 * will be in this state after their creating GrContext is destroyed or has
michael@0 40 * contextLost called. It's up to the client to test isValid() before
michael@0 41 * attempting to use a resource if it holds refs on resources across
michael@0 42 * ~GrContext, freeResources with the force flag, or contextLost.
michael@0 43 *
michael@0 44 * @return true if the resource has been released or abandoned,
michael@0 45 * false otherwise.
michael@0 46 */
michael@0 47 bool isValid() const { return NULL != fGpu; }
michael@0 48
michael@0 49 /**
michael@0 50 * Retrieves the size of the object in GPU memory. This is approximate since
michael@0 51 * we aren't aware of additional padding or copies made by the driver.
michael@0 52 *
michael@0 53 * @return the size of the buffer in bytes
michael@0 54 */
michael@0 55 virtual size_t sizeInBytes() const = 0;
michael@0 56
michael@0 57 /**
michael@0 58 * Retrieves the context that owns the resource. Note that it is possible
michael@0 59 * for this to return NULL. When resources have been release()ed or
michael@0 60 * abandon()ed they no longer have an owning context. Destroying a
michael@0 61 * GrContext automatically releases all its resources.
michael@0 62 */
michael@0 63 const GrContext* getContext() const;
michael@0 64 GrContext* getContext();
michael@0 65
michael@0 66 void setCacheEntry(GrResourceEntry* cacheEntry) { fCacheEntry = cacheEntry; }
michael@0 67 GrResourceEntry* getCacheEntry() { return fCacheEntry; }
michael@0 68
michael@0 69 void incDeferredRefCount() const {
michael@0 70 SkASSERT(fDeferredRefCount >= 0);
michael@0 71 ++fDeferredRefCount;
michael@0 72 }
michael@0 73
michael@0 74 void decDeferredRefCount() const {
michael@0 75 SkASSERT(fDeferredRefCount > 0);
michael@0 76 --fDeferredRefCount;
michael@0 77 if (0 == fDeferredRefCount && this->needsDeferredUnref()) {
michael@0 78 SkASSERT(this->getRefCnt() > 1);
michael@0 79 this->unref();
michael@0 80 }
michael@0 81 }
michael@0 82
michael@0 83 int getDeferredRefCount() const { return fDeferredRefCount; }
michael@0 84
michael@0 85 void setNeedsDeferredUnref() { fFlags |= kDeferredUnref_FlagBit; }
michael@0 86
michael@0 87 protected:
michael@0 88 /**
michael@0 89 * isWrapped indicates we have wrapped a client-created backend resource in a GrResource. If it
michael@0 90 * is true then the client is responsible for the lifetime of the underlying backend resource.
michael@0 91 * Otherwise, our onRelease() should free the resource.
michael@0 92 */
michael@0 93 GrResource(GrGpu* gpu, bool isWrapped);
michael@0 94 virtual ~GrResource();
michael@0 95
michael@0 96 GrGpu* getGpu() const { return fGpu; }
michael@0 97
michael@0 98 // Derived classes should always call their parent class' onRelease
michael@0 99 // and onAbandon methods in their overrides.
michael@0 100 virtual void onRelease() {};
michael@0 101 virtual void onAbandon() {};
michael@0 102
michael@0 103 bool isInCache() const { return NULL != fCacheEntry; }
michael@0 104 bool isWrapped() const { return kWrapped_FlagBit & fFlags; }
michael@0 105 bool needsDeferredUnref() const { return SkToBool(kDeferredUnref_FlagBit & fFlags); }
michael@0 106
michael@0 107 private:
michael@0 108 #ifdef SK_DEBUG
michael@0 109 friend class GrGpu; // for assert in GrGpu to access getGpu
michael@0 110 #endif
michael@0 111
michael@0 112 // We're in an internal doubly linked list
michael@0 113 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrResource);
michael@0 114
michael@0 115 GrGpu* fGpu; // not reffed. The GrGpu can be deleted while there
michael@0 116 // are still live GrResources. It will call
michael@0 117 // release() on all such resources in its
michael@0 118 // destructor.
michael@0 119 GrResourceEntry* fCacheEntry; // NULL if not in cache
michael@0 120 mutable int fDeferredRefCount; // How many references in deferred drawing buffers.
michael@0 121
michael@0 122 enum Flags {
michael@0 123 /**
michael@0 124 * This resource wraps a GPU resource given to us by the user.
michael@0 125 * Lifetime management is left up to the user (i.e., we will not
michael@0 126 * free it).
michael@0 127 */
michael@0 128 kWrapped_FlagBit = 0x1,
michael@0 129
michael@0 130 /**
michael@0 131 * This texture should be de-refed when the deferred ref count goes
michael@0 132 * to zero. A resource gets into this state when the resource cache
michael@0 133 * is holding a ref-of-obligation (i.e., someone needs to own it but
michael@0 134 * no one else wants to) but doesn't really want to keep it around.
michael@0 135 */
michael@0 136 kDeferredUnref_FlagBit = 0x2,
michael@0 137 };
michael@0 138 uint32_t fFlags;
michael@0 139
michael@0 140 typedef SkRefCnt INHERITED;
michael@0 141 };
michael@0 142
michael@0 143 #endif

mercurial