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 | /** |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 32 | * Helper that gets the width and height of the surface as a bounding rectangle. |
| 33 | */ |
| 34 | SkRect getBoundsRect() const { return SkRect::MakeIWH(this->width(), this->height()); } |
| 35 | |
| 36 | /** |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 37 | * @return the texture proxy associated with the surface proxy, may be NULL. |
| 38 | */ |
| 39 | virtual GrTextureProxy* asTextureProxy() { return nullptr; } |
| 40 | virtual const GrTextureProxy* asTextureProxy() const { return nullptr; } |
| 41 | |
| 42 | /** |
| 43 | * @return the render target proxy associated with the surface proxy, may be NULL. |
| 44 | */ |
| 45 | virtual GrRenderTargetProxy* asRenderTargetProxy() { return nullptr; } |
| 46 | virtual const GrRenderTargetProxy* asRenderTargetProxy() const { return nullptr; } |
| 47 | |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 48 | /** |
| 49 | * Does the resource count against the resource budget? |
| 50 | */ |
| 51 | SkBudgeted isBudgeted() const { return fBudgeted; } |
| 52 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 53 | protected: |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 54 | // Deferred version |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 55 | GrSurfaceProxy(const GrSurfaceDesc& desc, SkBackingFit fit, SkBudgeted budgeted) |
| 56 | : fDesc(desc) |
| 57 | , fFit(fit) |
| 58 | , fBudgeted(budgeted) |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 59 | , fUniqueID(GrGpuResource::CreateUniqueID()) { |
| 60 | } |
| 61 | |
| 62 | // Wrapped version |
| 63 | GrSurfaceProxy(const GrSurfaceDesc& desc, SkBackingFit fit, |
| 64 | SkBudgeted budgeted, uint32_t uniqueID) |
| 65 | : fDesc(desc) |
| 66 | , fFit(fit) |
| 67 | , fBudgeted(budgeted) |
| 68 | , fUniqueID(uniqueID) { |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | virtual ~GrSurfaceProxy() {} |
| 72 | |
| 73 | // For wrapped resources, 'fDesc' will always be filled in from the wrapped resource. |
| 74 | const GrSurfaceDesc fDesc; |
| 75 | const SkBackingFit fFit; // always exact for wrapped resources |
| 76 | const SkBudgeted fBudgeted; // set from the backing resource for wrapped resources |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 77 | const uint32_t fUniqueID; // set from the backing resource for wrapped resources |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 78 | |
| 79 | private: |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 80 | |
| 81 | // See comment in GrGpuResource.h. |
| 82 | void notifyAllCntsAreZero(CntType) const { delete this; } |
| 83 | bool notifyRefCountIsZero() const { return true; } |
| 84 | |
| 85 | typedef GrIORef<GrSurfaceProxy> INHERITED; |
| 86 | |
| 87 | // to access notifyAllCntsAreZero and notifyRefCntIsZero. |
| 88 | friend class GrIORef<GrSurfaceProxy>; |
| 89 | }; |
| 90 | |
| 91 | #endif |