From 5756aff40921e700dc40f2a1757291a64acddeaa Mon Sep 17 00:00:00 2001 From: junov Date: Thu, 11 Dec 2014 14:59:31 -0800 Subject: [PATCH] Adding a custom data field to GrGpuResource Motivation: allow Blink to track pre-existing mailbox names for textures that are recycled by the ganesh scratch texture pool. BUG=440462 TBR=bsalomon@google.com Review URL: https://codereview.chromium.org/796163002 --- include/gpu/GrGpuResource.h | 17 +++++++++++++++++ src/gpu/GrGpuResource.cpp | 6 ++++++ 2 files changed, 23 insertions(+) diff --git a/include/gpu/GrGpuResource.h b/include/gpu/GrGpuResource.h index 4670d91..338e161 100644 --- a/include/gpu/GrGpuResource.h +++ b/include/gpu/GrGpuResource.h @@ -10,6 +10,7 @@ #include "GrResourceKey.h" #include "GrTypesPriv.h" +#include "SkData.h" #include "SkInstCnt.h" #include "SkTInternalLList.h" @@ -168,6 +169,20 @@ public: uint32_t getUniqueID() const { return fUniqueID; } /** + * Attach a custom data object to this resource. The data will remain attached + * for the lifetime of this resource (until it is abandoned or released). + * Takes a ref on data. Previously attached data, if any, is unrefed. + * Returns the data argument, for convenience. + */ + const SkData* setCustomData(const SkData* data); + + /** + * Returns the custom data object that was attached to this resource by + * calling setCustomData. + */ + const SkData* getCustomData() const { return fData.get(); } + + /** * Internal-only helper class used for cache manipulations of the reosurce. */ class CacheAccess; @@ -272,6 +287,8 @@ private: uint32_t fFlags; const uint32_t fUniqueID; + SkAutoTUnref fData; + typedef GrIORef INHERITED; friend class GrIORef; // to access notifyIsPurgable. }; diff --git a/src/gpu/GrGpuResource.cpp b/src/gpu/GrGpuResource.cpp index cc24335..2a5718a 100644 --- a/src/gpu/GrGpuResource.cpp +++ b/src/gpu/GrGpuResource.cpp @@ -56,6 +56,12 @@ void GrGpuResource::abandon() { fGpuMemorySize = 0; } +const SkData* GrGpuResource::setCustomData(const SkData* data) { + SkSafeRef(data); + fData.reset(data); + return data; +} + const GrContext* GrGpuResource::getContext() const { if (fGpu) { return fGpu->getContext(); -- 2.7.4