blob: 98979ac8192f6adfbc7f2e24dafcc9a5c0025c32 [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"
12
13class GrTextureProxy;
14class GrRenderTargetProxy;
15
16class GrSurfaceProxy : public GrIORef<GrSurfaceProxy> {
17public:
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 /**
robertphillips13a7eee2016-08-31 15:06:24 -070032 * 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 /**
robertphillips76948d42016-05-04 12:47:41 -070037 * @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
robertphillips13a7eee2016-08-31 15:06:24 -070048 /**
49 * Does the resource count against the resource budget?
50 */
51 SkBudgeted isBudgeted() const { return fBudgeted; }
52
robertphillips76948d42016-05-04 12:47:41 -070053protected:
robertphillips8abb3702016-08-31 14:04:06 -070054 // Deferred version
robertphillips76948d42016-05-04 12:47:41 -070055 GrSurfaceProxy(const GrSurfaceDesc& desc, SkBackingFit fit, SkBudgeted budgeted)
56 : fDesc(desc)
57 , fFit(fit)
58 , fBudgeted(budgeted)
robertphillips8abb3702016-08-31 14:04:06 -070059 , 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) {
robertphillips76948d42016-05-04 12:47:41 -070069 }
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
robertphillips8abb3702016-08-31 14:04:06 -070077 const uint32_t fUniqueID; // set from the backing resource for wrapped resources
robertphillips76948d42016-05-04 12:47:41 -070078
79private:
robertphillips76948d42016-05-04 12:47:41 -070080
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