robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 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 | |
| 13 | class GrTextureProxy; |
| 14 | class GrRenderTargetProxy; |
| 15 | |
| 16 | class GrSurfaceProxy : public GrIORef<GrSurfaceProxy> { |
| 17 | public: |
| 18 | const GrSurfaceDesc& desc() const { return fDesc; } |
| 19 | |
| 20 | GrSurfaceOrigin origin() const { |
| 21 | SkASSERT(kTopLeft_GrSurfaceOrigin == fDesc.fOrigin || |
| 22 | kBottomLeft_GrSurfaceOrigin == fDesc.fOrigin); |
| 23 | return fDesc.fOrigin; |
| 24 | } |
| 25 | int width() const { return fDesc.fWidth; } |
| 26 | int height() const { return fDesc.fWidth; } |
| 27 | GrPixelConfig config() const { return fDesc.fConfig; } |
| 28 | |
| 29 | uint32_t uniqueID() const { return fUniqueID; } |
| 30 | |
| 31 | /** |
| 32 | * @return the texture proxy associated with the surface proxy, may be NULL. |
| 33 | */ |
| 34 | virtual GrTextureProxy* asTextureProxy() { return nullptr; } |
| 35 | virtual const GrTextureProxy* asTextureProxy() const { return nullptr; } |
| 36 | |
| 37 | /** |
| 38 | * @return the render target proxy associated with the surface proxy, may be NULL. |
| 39 | */ |
| 40 | virtual GrRenderTargetProxy* asRenderTargetProxy() { return nullptr; } |
| 41 | virtual const GrRenderTargetProxy* asRenderTargetProxy() const { return nullptr; } |
| 42 | |
| 43 | protected: |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 44 | // Deferred version |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 45 | GrSurfaceProxy(const GrSurfaceDesc& desc, SkBackingFit fit, SkBudgeted budgeted) |
| 46 | : fDesc(desc) |
| 47 | , fFit(fit) |
| 48 | , fBudgeted(budgeted) |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 49 | , fUniqueID(GrGpuResource::CreateUniqueID()) { |
| 50 | } |
| 51 | |
| 52 | // Wrapped version |
| 53 | GrSurfaceProxy(const GrSurfaceDesc& desc, SkBackingFit fit, |
| 54 | SkBudgeted budgeted, uint32_t uniqueID) |
| 55 | : fDesc(desc) |
| 56 | , fFit(fit) |
| 57 | , fBudgeted(budgeted) |
| 58 | , fUniqueID(uniqueID) { |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | virtual ~GrSurfaceProxy() {} |
| 62 | |
| 63 | // For wrapped resources, 'fDesc' will always be filled in from the wrapped resource. |
| 64 | const GrSurfaceDesc fDesc; |
| 65 | const SkBackingFit fFit; // always exact for wrapped resources |
| 66 | const SkBudgeted fBudgeted; // set from the backing resource for wrapped resources |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 67 | const uint32_t fUniqueID; // set from the backing resource for wrapped resources |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 68 | |
| 69 | private: |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 70 | |
| 71 | // See comment in GrGpuResource.h. |
| 72 | void notifyAllCntsAreZero(CntType) const { delete this; } |
| 73 | bool notifyRefCountIsZero() const { return true; } |
| 74 | |
| 75 | typedef GrIORef<GrSurfaceProxy> INHERITED; |
| 76 | |
| 77 | // to access notifyAllCntsAreZero and notifyRefCntIsZero. |
| 78 | friend class GrIORef<GrSurfaceProxy>; |
| 79 | }; |
| 80 | |
| 81 | #endif |