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" |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 12 | #include "SkRect.h" |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 13 | |
| 14 | class GrTextureProxy; |
| 15 | class GrRenderTargetProxy; |
| 16 | |
| 17 | class GrSurfaceProxy : public GrIORef<GrSurfaceProxy> { |
| 18 | public: |
| 19 | const GrSurfaceDesc& desc() const { return fDesc; } |
| 20 | |
| 21 | GrSurfaceOrigin origin() const { |
| 22 | SkASSERT(kTopLeft_GrSurfaceOrigin == fDesc.fOrigin || |
| 23 | kBottomLeft_GrSurfaceOrigin == fDesc.fOrigin); |
| 24 | return fDesc.fOrigin; |
| 25 | } |
| 26 | int width() const { return fDesc.fWidth; } |
| 27 | int height() const { return fDesc.fWidth; } |
| 28 | GrPixelConfig config() const { return fDesc.fConfig; } |
| 29 | |
| 30 | uint32_t uniqueID() const { return fUniqueID; } |
| 31 | |
| 32 | /** |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 33 | * Helper that gets the width and height of the surface as a bounding rectangle. |
| 34 | */ |
| 35 | SkRect getBoundsRect() const { return SkRect::MakeIWH(this->width(), this->height()); } |
| 36 | |
| 37 | /** |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 38 | * @return the texture proxy associated with the surface proxy, may be NULL. |
| 39 | */ |
| 40 | virtual GrTextureProxy* asTextureProxy() { return nullptr; } |
| 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 | */ |
| 46 | virtual GrRenderTargetProxy* asRenderTargetProxy() { return nullptr; } |
| 47 | virtual const GrRenderTargetProxy* asRenderTargetProxy() const { return nullptr; } |
| 48 | |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 49 | /** |
| 50 | * Does the resource count against the resource budget? |
| 51 | */ |
| 52 | SkBudgeted isBudgeted() const { return fBudgeted; } |
| 53 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 54 | protected: |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 55 | // Deferred version |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 56 | GrSurfaceProxy(const GrSurfaceDesc& desc, SkBackingFit fit, SkBudgeted budgeted) |
| 57 | : fDesc(desc) |
| 58 | , fFit(fit) |
| 59 | , fBudgeted(budgeted) |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 60 | , fUniqueID(GrGpuResource::CreateUniqueID()) { |
| 61 | } |
| 62 | |
| 63 | // Wrapped version |
| 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) { |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 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 |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 78 | const uint32_t fUniqueID; // set from the backing resource for wrapped resources |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 79 | |
| 80 | private: |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 81 | |
| 82 | // See comment in GrGpuResource.h. |
| 83 | void notifyAllCntsAreZero(CntType) const { delete this; } |
| 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 |