blob: ad2ea919735bd64edd69b458ed167524da8b406e [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 /**
32 * @return the texture proxy associated with the surface proxy, may be NULL.
33 */
34 virtual GrTextureProxy* asTextureProxy() { return nullptr; }
35 virtual const GrTextureProxy* asTextureProxy() const { return nullptr; }
36
37 /**
38 * @return the render target proxy associated with the surface proxy, may be NULL.
39 */
40 virtual GrRenderTargetProxy* asRenderTargetProxy() { return nullptr; }
41 virtual const GrRenderTargetProxy* asRenderTargetProxy() const { return nullptr; }
42
43protected:
robertphillips8abb3702016-08-31 14:04:06 -070044 // Deferred version
robertphillips76948d42016-05-04 12:47:41 -070045 GrSurfaceProxy(const GrSurfaceDesc& desc, SkBackingFit fit, SkBudgeted budgeted)
46 : fDesc(desc)
47 , fFit(fit)
48 , fBudgeted(budgeted)
robertphillips8abb3702016-08-31 14:04:06 -070049 , fUniqueID(GrGpuResource::CreateUniqueID()) {
50 }
51
52 // Wrapped version
53 GrSurfaceProxy(const GrSurfaceDesc& desc, SkBackingFit fit,
54 SkBudgeted budgeted, uint32_t uniqueID)
55 : fDesc(desc)
56 , fFit(fit)
57 , fBudgeted(budgeted)
58 , fUniqueID(uniqueID) {
robertphillips76948d42016-05-04 12:47:41 -070059 }
60
61 virtual ~GrSurfaceProxy() {}
62
63 // For wrapped resources, 'fDesc' will always be filled in from the wrapped resource.
64 const GrSurfaceDesc fDesc;
65 const SkBackingFit fFit; // always exact for wrapped resources
66 const SkBudgeted fBudgeted; // set from the backing resource for wrapped resources
robertphillips8abb3702016-08-31 14:04:06 -070067 const uint32_t fUniqueID; // set from the backing resource for wrapped resources
robertphillips76948d42016-05-04 12:47:41 -070068
69private:
robertphillips76948d42016-05-04 12:47:41 -070070
71 // See comment in GrGpuResource.h.
72 void notifyAllCntsAreZero(CntType) const { delete this; }
73 bool notifyRefCountIsZero() const { return true; }
74
75 typedef GrIORef<GrSurfaceProxy> INHERITED;
76
77 // to access notifyAllCntsAreZero and notifyRefCntIsZero.
78 friend class GrIORef<GrSurfaceProxy>;
79};
80
81#endif