blob: 69656fe4f57cdb9a40c63852207177565f157bb6 [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
14class GrTextureProxy;
15class GrRenderTargetProxy;
16
17class GrSurfaceProxy : public GrIORef<GrSurfaceProxy> {
18public:
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 /**
robertphillips13a7eee2016-08-31 15:06:24 -070033 * 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 /**
robertphillips76948d42016-05-04 12:47:41 -070038 * @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
robertphillips13a7eee2016-08-31 15:06:24 -070049 /**
50 * Does the resource count against the resource budget?
51 */
52 SkBudgeted isBudgeted() const { return fBudgeted; }
53
robertphillips76948d42016-05-04 12:47:41 -070054protected:
robertphillips8abb3702016-08-31 14:04:06 -070055 // Deferred version
robertphillips76948d42016-05-04 12:47:41 -070056 GrSurfaceProxy(const GrSurfaceDesc& desc, SkBackingFit fit, SkBudgeted budgeted)
57 : fDesc(desc)
58 , fFit(fit)
59 , fBudgeted(budgeted)
robertphillips8abb3702016-08-31 14:04:06 -070060 , 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) {
robertphillips76948d42016-05-04 12:47:41 -070070 }
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
robertphillips8abb3702016-08-31 14:04:06 -070078 const uint32_t fUniqueID; // set from the backing resource for wrapped resources
robertphillips76948d42016-05-04 12:47:41 -070079
80private:
robertphillips76948d42016-05-04 12:47:41 -070081
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