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 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 14 | class GrOpList; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 15 | class GrTextureProxy; |
| 16 | class GrRenderTargetProxy; |
| 17 | |
| 18 | class GrSurfaceProxy : public GrIORef<GrSurfaceProxy> { |
| 19 | public: |
| 20 | const GrSurfaceDesc& desc() const { return fDesc; } |
| 21 | |
| 22 | GrSurfaceOrigin origin() const { |
| 23 | SkASSERT(kTopLeft_GrSurfaceOrigin == fDesc.fOrigin || |
| 24 | kBottomLeft_GrSurfaceOrigin == fDesc.fOrigin); |
| 25 | return fDesc.fOrigin; |
| 26 | } |
| 27 | int width() const { return fDesc.fWidth; } |
| 28 | int height() const { return fDesc.fWidth; } |
| 29 | GrPixelConfig config() const { return fDesc.fConfig; } |
| 30 | |
| 31 | uint32_t uniqueID() const { return fUniqueID; } |
| 32 | |
| 33 | /** |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 34 | * Helper that gets the width and height of the surface as a bounding rectangle. |
| 35 | */ |
| 36 | SkRect getBoundsRect() const { return SkRect::MakeIWH(this->width(), this->height()); } |
| 37 | |
| 38 | /** |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 39 | * @return the texture proxy associated with the surface proxy, may be NULL. |
| 40 | */ |
| 41 | virtual GrTextureProxy* asTextureProxy() { return nullptr; } |
| 42 | virtual const GrTextureProxy* asTextureProxy() const { return nullptr; } |
| 43 | |
| 44 | /** |
| 45 | * @return the render target proxy associated with the surface proxy, may be NULL. |
| 46 | */ |
| 47 | virtual GrRenderTargetProxy* asRenderTargetProxy() { return nullptr; } |
| 48 | virtual const GrRenderTargetProxy* asRenderTargetProxy() const { return nullptr; } |
| 49 | |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 50 | /** |
| 51 | * Does the resource count against the resource budget? |
| 52 | */ |
| 53 | SkBudgeted isBudgeted() const { return fBudgeted; } |
| 54 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 55 | void setLastOpList(GrOpList* opList); |
| 56 | GrOpList* getLastOpList() { return fLastOpList; } |
| 57 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 58 | protected: |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 59 | // Deferred version |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 60 | GrSurfaceProxy(const GrSurfaceDesc& desc, SkBackingFit fit, SkBudgeted budgeted) |
| 61 | : fDesc(desc) |
| 62 | , fFit(fit) |
| 63 | , fBudgeted(budgeted) |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 64 | , fUniqueID(GrGpuResource::CreateUniqueID()) |
| 65 | , fLastOpList(nullptr) { |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | // Wrapped version |
| 69 | GrSurfaceProxy(const GrSurfaceDesc& desc, SkBackingFit fit, |
| 70 | SkBudgeted budgeted, uint32_t uniqueID) |
| 71 | : fDesc(desc) |
| 72 | , fFit(fit) |
| 73 | , fBudgeted(budgeted) |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 74 | , fUniqueID(uniqueID) |
| 75 | , fLastOpList(nullptr) { |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 78 | virtual ~GrSurfaceProxy(); |
| 79 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 80 | |
| 81 | // For wrapped resources, 'fDesc' will always be filled in from the wrapped resource. |
| 82 | const GrSurfaceDesc fDesc; |
| 83 | const SkBackingFit fFit; // always exact for wrapped resources |
| 84 | const SkBudgeted fBudgeted; // set from the backing resource for wrapped resources |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 85 | const uint32_t fUniqueID; // set from the backing resource for wrapped resources |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 86 | |
| 87 | private: |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 88 | |
| 89 | // See comment in GrGpuResource.h. |
| 90 | void notifyAllCntsAreZero(CntType) const { delete this; } |
| 91 | bool notifyRefCountIsZero() const { return true; } |
| 92 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 93 | // The last opList that wrote to or is currently going to write to this surface |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 94 | // The opList can be closed (e.g., no render target context is currently bound |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 95 | // to this renderTarget). |
| 96 | // This back-pointer is required so that we can add a dependancy between |
| 97 | // the opList used to create the current contents of this surface |
| 98 | // and the opList of a destination surface to which this one is being drawn or copied. |
| 99 | GrOpList* fLastOpList; |
| 100 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 101 | typedef GrIORef<GrSurfaceProxy> INHERITED; |
| 102 | |
| 103 | // to access notifyAllCntsAreZero and notifyRefCntIsZero. |
| 104 | friend class GrIORef<GrSurfaceProxy>; |
| 105 | }; |
| 106 | |
| 107 | #endif |