1 /* 2 * Copyright 2016 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef GrSurfaceProxy_DEFINED 9 #define GrSurfaceProxy_DEFINED 10 11 #include "GrGpuResource.h" 12 #include "SkRect.h" 13 14 class GrTextureProxy; 15 class GrRenderTargetProxy; 16 17 class GrSurfaceProxy : public GrIORef<GrSurfaceProxy> { 18 public: desc()19 const GrSurfaceDesc& desc() const { return fDesc; } 20 origin()21 GrSurfaceOrigin origin() const { 22 SkASSERT(kTopLeft_GrSurfaceOrigin == fDesc.fOrigin || 23 kBottomLeft_GrSurfaceOrigin == fDesc.fOrigin); 24 return fDesc.fOrigin; 25 } width()26 int width() const { return fDesc.fWidth; } height()27 int height() const { return fDesc.fWidth; } config()28 GrPixelConfig config() const { return fDesc.fConfig; } 29 uniqueID()30 uint32_t uniqueID() const { return fUniqueID; } 31 32 /** 33 * Helper that gets the width and height of the surface as a bounding rectangle. 34 */ getBoundsRect()35 SkRect getBoundsRect() const { return SkRect::MakeIWH(this->width(), this->height()); } 36 37 /** 38 * @return the texture proxy associated with the surface proxy, may be NULL. 39 */ asTextureProxy()40 virtual GrTextureProxy* asTextureProxy() { return nullptr; } asTextureProxy()41 virtual const GrTextureProxy* asTextureProxy() const { return nullptr; } 42 43 /** 44 * @return the render target proxy associated with the surface proxy, may be NULL. 45 */ asRenderTargetProxy()46 virtual GrRenderTargetProxy* asRenderTargetProxy() { return nullptr; } asRenderTargetProxy()47 virtual const GrRenderTargetProxy* asRenderTargetProxy() const { return nullptr; } 48 49 /** 50 * Does the resource count against the resource budget? 51 */ isBudgeted()52 SkBudgeted isBudgeted() const { return fBudgeted; } 53 54 protected: 55 // Deferred version GrSurfaceProxy(const GrSurfaceDesc & desc,SkBackingFit fit,SkBudgeted budgeted)56 GrSurfaceProxy(const GrSurfaceDesc& desc, SkBackingFit fit, SkBudgeted budgeted) 57 : fDesc(desc) 58 , fFit(fit) 59 , fBudgeted(budgeted) 60 , fUniqueID(GrGpuResource::CreateUniqueID()) { 61 } 62 63 // Wrapped version GrSurfaceProxy(const GrSurfaceDesc & desc,SkBackingFit fit,SkBudgeted budgeted,uint32_t uniqueID)64 GrSurfaceProxy(const GrSurfaceDesc& desc, SkBackingFit fit, 65 SkBudgeted budgeted, uint32_t uniqueID) 66 : fDesc(desc) 67 , fFit(fit) 68 , fBudgeted(budgeted) 69 , fUniqueID(uniqueID) { 70 } 71 ~GrSurfaceProxy()72 virtual ~GrSurfaceProxy() {} 73 74 // For wrapped resources, 'fDesc' will always be filled in from the wrapped resource. 75 const GrSurfaceDesc fDesc; 76 const SkBackingFit fFit; // always exact for wrapped resources 77 const SkBudgeted fBudgeted; // set from the backing resource for wrapped resources 78 const uint32_t fUniqueID; // set from the backing resource for wrapped resources 79 80 private: 81 82 // See comment in GrGpuResource.h. notifyAllCntsAreZero(CntType)83 void notifyAllCntsAreZero(CntType) const { delete this; } notifyRefCountIsZero()84 bool notifyRefCountIsZero() const { return true; } 85 86 typedef GrIORef<GrSurfaceProxy> INHERITED; 87 88 // to access notifyAllCntsAreZero and notifyRefCntIsZero. 89 friend class GrIORef<GrSurfaceProxy>; 90 }; 91 92 #endif 93