Line data Source code
1 : /*
2 : * Copyright 2012 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 :
9 : #ifndef GrSurface_DEFINED
10 : #define GrSurface_DEFINED
11 :
12 : #include "GrTypes.h"
13 : #include "GrGpuResource.h"
14 : #include "SkImageInfo.h"
15 : #include "SkRect.h"
16 :
17 : class GrOpList;
18 : class GrRenderTarget;
19 : class GrSurfacePriv;
20 : class GrTexture;
21 :
22 : class SK_API GrSurface : public GrGpuResource {
23 : public:
24 : /**
25 : * Retrieves the width of the surface.
26 : */
27 0 : int width() const { return fDesc.fWidth; }
28 :
29 : /**
30 : * Retrieves the height of the surface.
31 : */
32 0 : int height() const { return fDesc.fHeight; }
33 :
34 : /**
35 : * Helper that gets the width and height of the surface as a bounding rectangle.
36 : */
37 0 : SkRect getBoundsRect() const { return SkRect::MakeIWH(this->width(), this->height()); }
38 :
39 0 : GrSurfaceOrigin origin() const {
40 0 : SkASSERT(kTopLeft_GrSurfaceOrigin == fDesc.fOrigin || kBottomLeft_GrSurfaceOrigin == fDesc.fOrigin);
41 0 : return fDesc.fOrigin;
42 : }
43 :
44 : /**
45 : * Retrieves the pixel config specified when the surface was created.
46 : * For render targets this can be kUnknown_GrPixelConfig
47 : * if client asked us to render to a target that has a pixel
48 : * config that isn't equivalent with one of our configs.
49 : */
50 0 : GrPixelConfig config() const { return fDesc.fConfig; }
51 :
52 : /**
53 : * Return the descriptor describing the surface
54 : */
55 0 : const GrSurfaceDesc& desc() const { return fDesc; }
56 :
57 : /**
58 : * @return the texture associated with the surface, may be NULL.
59 : */
60 0 : virtual GrTexture* asTexture() { return NULL; }
61 0 : virtual const GrTexture* asTexture() const { return NULL; }
62 :
63 : /**
64 : * @return the render target underlying this surface, may be NULL.
65 : */
66 0 : virtual GrRenderTarget* asRenderTarget() { return NULL; }
67 0 : virtual const GrRenderTarget* asRenderTarget() const { return NULL; }
68 :
69 : /** Access methods that are only to be used within Skia code. */
70 : inline GrSurfacePriv surfacePriv();
71 : inline const GrSurfacePriv surfacePriv() const;
72 :
73 : typedef void* ReleaseCtx;
74 : typedef void (*ReleaseProc)(ReleaseCtx);
75 :
76 0 : void setRelease(ReleaseProc proc, ReleaseCtx ctx) {
77 0 : fReleaseProc = proc;
78 0 : fReleaseCtx = ctx;
79 0 : }
80 :
81 : void setLastOpList(GrOpList* opList);
82 0 : GrOpList* getLastOpList() { return fLastOpList; }
83 :
84 : static size_t WorstCaseSize(const GrSurfaceDesc& desc, bool useNextPow2 = false);
85 : static size_t ComputeSize(const GrSurfaceDesc& desc, int colorSamplesPerPixel,
86 : bool hasMIPMaps, bool useNextPow2 = false);
87 :
88 : protected:
89 : // Methods made available via GrSurfacePriv
90 : bool hasPendingRead() const;
91 : bool hasPendingWrite() const;
92 : bool hasPendingIO() const;
93 :
94 : // Provides access to methods that should be public within Skia code.
95 : friend class GrSurfacePriv;
96 :
97 0 : GrSurface(GrGpu* gpu, const GrSurfaceDesc& desc)
98 0 : : INHERITED(gpu)
99 : , fDesc(desc)
100 : , fReleaseProc(NULL)
101 : , fReleaseCtx(NULL)
102 0 : , fLastOpList(nullptr) {
103 0 : }
104 : ~GrSurface() override;
105 :
106 : GrSurfaceDesc fDesc;
107 :
108 : void onRelease() override;
109 : void onAbandon() override;
110 :
111 : private:
112 0 : void invokeReleaseProc() {
113 0 : if (fReleaseProc) {
114 0 : fReleaseProc(fReleaseCtx);
115 0 : fReleaseProc = NULL;
116 : }
117 0 : }
118 :
119 : ReleaseProc fReleaseProc;
120 : ReleaseCtx fReleaseCtx;
121 :
122 : // The last opList that wrote to or is currently going to write to this surface
123 : // The opList can be closed (e.g., no render target or texture context is currently bound
124 : // to this renderTarget or texture).
125 : // This back-pointer is required so that we can add a dependancy between
126 : // the opList used to create the current contents of this surface
127 : // and the opList of a destination surface to which this one is being drawn or copied.
128 : GrOpList* fLastOpList;
129 :
130 : typedef GrGpuResource INHERITED;
131 : };
132 :
133 : #endif
|