blob: 4e2ad3bf14726303b883347435675984528bb8c2 [file] [log] [blame]
robertphillips76948d42016-05-04 12:47:41 -07001/*
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"
csmartdaltonbf4a8f92016-09-06 10:01:06 -070012#include "SkRect.h"
robertphillips76948d42016-05-04 12:47:41 -070013
Robert Phillipsf2361d22016-10-25 14:20:06 -040014class GrOpList;
robertphillips76948d42016-05-04 12:47:41 -070015class GrTextureProxy;
16class GrRenderTargetProxy;
17
18class GrSurfaceProxy : public GrIORef<GrSurfaceProxy> {
19public:
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 /**
robertphillips13a7eee2016-08-31 15:06:24 -070034 * 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 /**
robertphillips76948d42016-05-04 12:47:41 -070039 * @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
robertphillips13a7eee2016-08-31 15:06:24 -070050 /**
51 * Does the resource count against the resource budget?
52 */
53 SkBudgeted isBudgeted() const { return fBudgeted; }
54
Robert Phillipsf2361d22016-10-25 14:20:06 -040055 void setLastOpList(GrOpList* opList);
56 GrOpList* getLastOpList() { return fLastOpList; }
57
robertphillips76948d42016-05-04 12:47:41 -070058protected:
robertphillips8abb3702016-08-31 14:04:06 -070059 // Deferred version
robertphillips76948d42016-05-04 12:47:41 -070060 GrSurfaceProxy(const GrSurfaceDesc& desc, SkBackingFit fit, SkBudgeted budgeted)
61 : fDesc(desc)
62 , fFit(fit)
63 , fBudgeted(budgeted)
Robert Phillipsf2361d22016-10-25 14:20:06 -040064 , fUniqueID(GrGpuResource::CreateUniqueID())
65 , fLastOpList(nullptr) {
robertphillips8abb3702016-08-31 14:04:06 -070066 }
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 Phillipsf2361d22016-10-25 14:20:06 -040074 , fUniqueID(uniqueID)
75 , fLastOpList(nullptr) {
robertphillips76948d42016-05-04 12:47:41 -070076 }
77
Robert Phillipsf2361d22016-10-25 14:20:06 -040078 virtual ~GrSurfaceProxy();
79
robertphillips76948d42016-05-04 12:47:41 -070080
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
robertphillips8abb3702016-08-31 14:04:06 -070085 const uint32_t fUniqueID; // set from the backing resource for wrapped resources
robertphillips76948d42016-05-04 12:47:41 -070086
87private:
robertphillips76948d42016-05-04 12:47:41 -070088
89 // See comment in GrGpuResource.h.
90 void notifyAllCntsAreZero(CntType) const { delete this; }
91 bool notifyRefCountIsZero() const { return true; }
92
Robert Phillipsf2361d22016-10-25 14:20:06 -040093 // The last opList that wrote to or is currently going to write to this surface
94 // The opList can be closed (e.g., no draw context is currently bound
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
robertphillips76948d42016-05-04 12:47:41 -0700101 typedef GrIORef<GrSurfaceProxy> INHERITED;
102
103 // to access notifyAllCntsAreZero and notifyRefCntIsZero.
104 friend class GrIORef<GrSurfaceProxy>;
105};
106
107#endif