OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrGLGpu_DEFINED | 8 #ifndef GrGLGpu_DEFINED |
9 #define GrGLGpu_DEFINED | 9 #define GrGLGpu_DEFINED |
10 | 10 |
11 #include "GrGLContext.h" | 11 #include "GrGLContext.h" |
12 #include "GrGLIRect.h" | 12 #include "GrGLIRect.h" |
13 #include "GrGLIndexBuffer.h" | 13 #include "GrGLIndexBuffer.h" |
14 #include "GrGLPathRendering.h" | 14 #include "GrGLPathRendering.h" |
15 #include "GrGLProgram.h" | 15 #include "GrGLProgram.h" |
16 #include "GrGLRenderTarget.h" | 16 #include "GrGLRenderTarget.h" |
17 #include "GrGLStencilAttachment.h" | 17 #include "GrGLStencilAttachment.h" |
18 #include "GrGLTexture.h" | 18 #include "GrGLTexture.h" |
19 #include "GrGLVertexArray.h" | 19 #include "GrGLVertexArray.h" |
20 #include "GrGLVertexBuffer.h" | 20 #include "GrGLVertexBuffer.h" |
21 #include "GrGpu.h" | 21 #include "GrGpu.h" |
| 22 #include "SkMipMapLevel.h" |
22 #include "GrPipelineBuilder.h" | 23 #include "GrPipelineBuilder.h" |
| 24 #include "SkTArray.h" |
23 #include "GrXferProcessor.h" | 25 #include "GrXferProcessor.h" |
24 #include "SkTypes.h" | 26 #include "SkTypes.h" |
25 | 27 |
26 class GrPipeline; | 28 class GrPipeline; |
27 class GrNonInstancedVertices; | 29 class GrNonInstancedVertices; |
28 | 30 |
29 #ifdef SK_DEVELOPER | 31 #ifdef SK_DEVELOPER |
30 #define PROGRAM_CACHE_STATS | 32 #define PROGRAM_CACHE_STATS |
31 #endif | 33 #endif |
32 | 34 |
(...skipping 22 matching lines...) Expand all Loading... |
55 void discard(GrRenderTarget*) override; | 57 void discard(GrRenderTarget*) override; |
56 | 58 |
57 // Used by GrGLProgram to configure OpenGL state. | 59 // Used by GrGLProgram to configure OpenGL state. |
58 void bindTexture(int unitIdx, const GrTextureParams& params, GrGLTexture* te
xture); | 60 void bindTexture(int unitIdx, const GrTextureParams& params, GrGLTexture* te
xture); |
59 | 61 |
60 bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeigh
t, size_t rowBytes, | 62 bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeigh
t, size_t rowBytes, |
61 GrPixelConfig readConfig, DrawPreference*, | 63 GrPixelConfig readConfig, DrawPreference*, |
62 ReadPixelTempDrawInfo*) override; | 64 ReadPixelTempDrawInfo*) override; |
63 | 65 |
64 bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height, | 66 bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height, |
65 size_t rowBytes, GrPixelConfig srcConfig, DrawPref
erence*, | 67 GrPixelConfig srcConfig, DrawPreference*, |
66 WritePixelTempDrawInfo*) override; | 68 WritePixelTempDrawInfo*) override; |
67 | 69 |
68 bool initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) const
override; | 70 bool initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) const
override; |
69 | 71 |
70 // These functions should be used to bind GL objects. They track the GL stat
e and skip redundant | 72 // These functions should be used to bind GL objects. They track the GL stat
e and skip redundant |
71 // bindings. Making the equivalent glBind calls directly will confuse the st
ate tracking. | 73 // bindings. Making the equivalent glBind calls directly will confuse the st
ate tracking. |
72 void bindVertexArray(GrGLuint id) { | 74 void bindVertexArray(GrGLuint id) { |
73 fHWGeometryState.setVertexArrayID(this, id); | 75 fHWGeometryState.setVertexArrayID(this, id); |
74 } | 76 } |
75 void bindIndexBufferAndDefaultVertexArray(GrGLuint id) { | 77 void bindIndexBufferAndDefaultVertexArray(GrGLuint id) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 118 |
117 private: | 119 private: |
118 GrGLGpu(GrGLContext* ctx, GrContext* context); | 120 GrGLGpu(GrGLContext* ctx, GrContext* context); |
119 | 121 |
120 // GrGpu overrides | 122 // GrGpu overrides |
121 void onResetContext(uint32_t resetBits) override; | 123 void onResetContext(uint32_t resetBits) override; |
122 | 124 |
123 void xferBarrier(GrRenderTarget*, GrXferBarrierType) override; | 125 void xferBarrier(GrRenderTarget*, GrXferBarrierType) override; |
124 | 126 |
125 GrTexture* onCreateTexture(const GrSurfaceDesc& desc, GrGpuResource::LifeCyc
le lifeCycle, | 127 GrTexture* onCreateTexture(const GrSurfaceDesc& desc, GrGpuResource::LifeCyc
le lifeCycle, |
126 const void* srcData, size_t rowBytes) override; | 128 const SkTArray<SkMipMapLevel>& texels) override; |
127 GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, | 129 GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, |
128 GrGpuResource::LifeCycle lifeCycle, | 130 GrGpuResource::LifeCycle lifeCycle, |
129 const void* srcData) override; | 131 const SkTArray<SkMipMapLevel>& texels)
override; |
| 132 |
130 GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) override; | 133 GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) override; |
131 GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) override; | 134 GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) override; |
132 GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership
) override; | 135 GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership
) override; |
133 GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&, | 136 GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&, |
134 GrWrapOwnership) override; | 137 GrWrapOwnership) override; |
135 // Given a GrPixelConfig return the index into the stencil format array on G
rGLCaps to a | 138 // Given a GrPixelConfig return the index into the stencil format array on G
rGLCaps to a |
136 // compatible stencil format. | 139 // compatible stencil format. |
137 int getCompatibleStencilIndex(GrPixelConfig config); | 140 int getCompatibleStencilIndex(GrPixelConfig config); |
138 | 141 |
139 void onClear(GrRenderTarget*, const SkIRect& rect, GrColor color) override; | 142 void onClear(GrRenderTarget*, const SkIRect& rect, GrColor color) override; |
140 | 143 |
141 void onClearStencilClip(GrRenderTarget*, const SkIRect& rect, bool insideCli
p) override; | 144 void onClearStencilClip(GrRenderTarget*, const SkIRect& rect, bool insideCli
p) override; |
142 | 145 |
143 bool onReadPixels(GrSurface*, | 146 bool onReadPixels(GrSurface*, |
144 int left, int top, | 147 int left, int top, |
145 int width, int height, | 148 int width, int height, |
146 GrPixelConfig, | 149 GrPixelConfig, |
147 void* buffer, | 150 void* buffer, |
148 size_t rowBytes) override; | 151 size_t rowBytes) override; |
149 | 152 |
150 bool onWritePixels(GrSurface*, | 153 bool onWritePixels(GrSurface*, |
151 int left, int top, int width, int height, | 154 int left, int top, int width, int height, |
152 GrPixelConfig config, const void* buffer, | 155 GrPixelConfig config, |
153 size_t rowBytes) override; | 156 const SkTArray<SkMipMapLevel>& texels) override; |
154 | 157 |
155 void onResolveRenderTarget(GrRenderTarget* target) override; | 158 void onResolveRenderTarget(GrRenderTarget* target) override; |
156 | 159 |
157 void onDraw(const DrawArgs&, const GrNonInstancedVertices&) override; | 160 void onDraw(const DrawArgs&, const GrNonInstancedVertices&) override; |
158 | 161 |
159 bool onCopySurface(GrSurface* dst, | 162 bool onCopySurface(GrSurface* dst, |
160 GrSurface* src, | 163 GrSurface* src, |
161 const SkIRect& srcRect, | 164 const SkIRect& srcRect, |
162 const SkIPoint& dstPoint) override; | 165 const SkIPoint& dstPoint) override; |
163 | 166 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 | 251 |
249 void initFSAASupport(); | 252 void initFSAASupport(); |
250 | 253 |
251 // determines valid stencil formats | 254 // determines valid stencil formats |
252 void initStencilFormats(); | 255 void initStencilFormats(); |
253 | 256 |
254 // sets a texture unit to use for texture operations other than binding a te
xture to a program. | 257 // sets a texture unit to use for texture operations other than binding a te
xture to a program. |
255 // ensures that such operations don't negatively interact with tracking boun
d textures. | 258 // ensures that such operations don't negatively interact with tracking boun
d textures. |
256 void setScratchTextureUnit(); | 259 void setScratchTextureUnit(); |
257 | 260 |
| 261 // colocates all samples at pixel center for render target, if MSAA. |
| 262 // allows drawing coverage based AA shapes in MSAA mode. |
| 263 void setColocatedSampleLocations(GrRenderTarget* rt, bool useColocatedSample
Locations); |
| 264 |
258 // bounds is region that may be modified and therefore has to be resolved. | 265 // bounds is region that may be modified and therefore has to be resolved. |
259 // nullptr means whole target. Can be an empty rect. | 266 // nullptr means whole target. Can be an empty rect. |
260 void flushRenderTarget(GrGLRenderTarget*, const SkIRect* bounds); | 267 void flushRenderTarget(GrGLRenderTarget*, const SkIRect* bounds); |
261 | 268 |
262 void flushStencil(const GrStencilSettings&); | 269 void flushStencil(const GrStencilSettings&); |
263 void flushHWAAState(GrRenderTarget* rt, bool useHWAA); | 270 void flushHWAAState(GrRenderTarget* rt, bool useHWAA, bool stencilEnabled); |
264 | 271 |
265 bool configToGLFormats(GrPixelConfig config, | 272 bool configToGLFormats(GrPixelConfig config, |
266 bool getSizedInternal, | 273 bool getSizedInternal, |
267 GrGLenum* internalFormat, | 274 GrGLenum* internalFormat, |
268 GrGLenum* externalFormat, | 275 GrGLenum* externalFormat, |
269 GrGLenum* externalType) const; | 276 GrGLenum* externalType) const; |
270 // helper for onCreateTexture and writeTexturePixels | 277 // helper for onCreateTexture and writeTexturePixels |
271 bool uploadTexData(const GrSurfaceDesc& desc, | 278 bool uploadTexData(const GrSurfaceDesc& desc, |
| 279 GrGLenum target, |
272 bool isNewTexture, | 280 bool isNewTexture, |
273 int left, int top, int width, int height, | 281 int left, int top, int width, int height, |
274 GrPixelConfig dataConfig, | 282 GrPixelConfig dataConfig, |
275 const void* data, | 283 const SkTArray<SkMipMapLevel>& texels); |
276 size_t rowBytes); | |
277 | 284 |
278 // helper for onCreateCompressedTexture. If width and height are | 285 // helper for onCreateCompressedTexture. If width and height are |
279 // set to -1, then this function will use desc.fWidth and desc.fHeight | 286 // set to -1, then this function will use desc.fWidth and desc.fHeight |
280 // for the size of the data. The isNewTexture flag should be set to true | 287 // for the size of the data. The isNewTexture flag should be set to true |
281 // whenever a new texture needs to be created. Otherwise, we assume that | 288 // whenever a new texture needs to be created. Otherwise, we assume that |
282 // the texture is already in GPU memory and that it's going to be updated | 289 // the texture is already in GPU memory and that it's going to be updated |
283 // with new data. | 290 // with new data. |
284 bool uploadCompressedTexData(const GrSurfaceDesc& desc, | 291 bool uploadCompressedTexData(const GrSurfaceDesc& desc, |
285 const void* data, | 292 GrGLenum target, |
| 293 const SkTArray<SkMipMapLevel>& texels, |
286 bool isNewTexture = true, | 294 bool isNewTexture = true, |
287 int left = 0, int top = 0, | 295 int left = 0, int top = 0, |
288 int width = -1, int height = -1); | 296 int width = -1, int height = -1); |
289 | 297 |
290 bool createRenderTargetObjects(const GrSurfaceDesc&, GrGpuResource::LifeCycl
e lifeCycle, | 298 bool createRenderTargetObjects(const GrSurfaceDesc&, GrGpuResource::LifeCycl
e lifeCycle, |
291 GrGLuint texID, GrGLRenderTarget::IDDesc*); | 299 GrGLenum textureTarget, GrGLuint texID, |
| 300 GrGLRenderTarget::IDDesc*); |
292 | 301 |
293 enum TempFBOTarget { | 302 enum TempFBOTarget { |
294 kSrc_TempFBOTarget, | 303 kSrc_TempFBOTarget, |
295 kDst_TempFBOTarget | 304 kDst_TempFBOTarget |
296 }; | 305 }; |
297 | 306 |
298 GrGLuint bindSurfaceAsFBO(GrSurface* surface, GrGLenum fboTarget, GrGLIRect*
viewport, | 307 // Binds a surface as a FBO for a copy operation. If the surface already own
s an FBO ID then |
| 308 // that ID is bound. If not the surface is temporarily bound to a FBO and th
at FBO is bound. |
| 309 // This must be paired with a call to unbindSurfaceFBOForCopy(). |
| 310 void bindSurfaceFBOForCopy(GrSurface* surface, GrGLenum fboTarget, GrGLIRect
* viewport, |
299 TempFBOTarget tempFBOTarget); | 311 TempFBOTarget tempFBOTarget); |
300 | 312 |
301 void unbindTextureFromFBO(GrGLenum fboTarget); | 313 // Must be called if bindSurfaceFBOForCopy was used to bind a surface for co
pying. |
| 314 void unbindTextureFBOForCopy(GrGLenum fboTarget, GrSurface* surface); |
302 | 315 |
303 SkAutoTUnref<GrGLContext> fGLContext; | 316 SkAutoTUnref<GrGLContext> fGLContext; |
304 | 317 |
305 void createCopyProgram(); | 318 void createCopyProgram(); |
306 | 319 |
307 // GL program-related state | 320 // GL program-related state |
308 ProgramCache* fProgramCache; | 321 ProgramCache* fProgramCache; |
309 | 322 |
310 /////////////////////////////////////////////////////////////////////////// | 323 /////////////////////////////////////////////////////////////////////////// |
311 ///@name Caching of GL State | 324 ///@name Caching of GL State |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 | 509 |
497 // Mapping of pixel configs to known supported stencil formats to be used | 510 // Mapping of pixel configs to known supported stencil formats to be used |
498 // when adding a stencil buffer to a framebuffer. | 511 // when adding a stencil buffer to a framebuffer. |
499 int fPixelConfigToStencilIndex[kGrPixelConfigCnt]; | 512 int fPixelConfigToStencilIndex[kGrPixelConfigCnt]; |
500 | 513 |
501 typedef GrGpu INHERITED; | 514 typedef GrGpu INHERITED; |
502 friend class GrGLPathRendering; // For accessing setTextureUnit. | 515 friend class GrGLPathRendering; // For accessing setTextureUnit. |
503 }; | 516 }; |
504 | 517 |
505 #endif | 518 #endif |
OLD | NEW |