blob: 7e12456d097da535c8f4070ea1ef60694180a8cc [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
bsalomon@google.com1da07462011-03-10 14:51:57 +00002 Copyright 2011 Google Inc.
reed@google.comac10a2d2010-12-22 21:39:39 +00003
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
reed@google.comac10a2d2010-12-22 21:39:39 +000017#ifndef GrGpu_DEFINED
18#define GrGpu_DEFINED
19
20#include "GrRect.h"
21#include "GrRefCnt.h"
22#include "GrDrawTarget.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000023#include "GrTexture.h"
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +000024#include "GrPathRenderer.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000025
bsalomon@google.com1c13c962011-02-14 16:51:21 +000026class GrVertexBufferAllocPool;
27class GrIndexBufferAllocPool;
reed@google.comac10a2d2010-12-22 21:39:39 +000028
29class GrGpu : public GrDrawTarget {
30
31public:
32 /**
33 * Possible 3D APIs that may be used by Ganesh.
34 */
35 enum Engine {
36 kOpenGL_Shaders_Engine,
37 kOpenGL_Fixed_Engine,
38 kDirect3D9_Engine
39 };
40
41 /**
42 * Platform specific 3D context.
43 * For
44 * kOpenGL_Shaders_Engine use NULL
45 * kOpenGL_Fixed_Engine use NULL
46 * kDirect3D9_Engine use an IDirect3DDevice9*
47 */
48 typedef void* Platform3DContext;
49
50 /**
51 * Create an instance of GrGpu that matches the specified Engine backend.
52 * If the requested engine is not supported (at compile-time or run-time)
53 * this returns NULL.
54 */
55 static GrGpu* Create(Engine, Platform3DContext context3D);
56
57 /**
reed@google.comac10a2d2010-12-22 21:39:39 +000058 * Used to control the level of antialiasing available for a rendertarget.
59 * Anti-alias quality levels depend on the underlying API/GPU capabilities.
60 */
61 enum AALevels {
62 kNone_AALevel, //<! No antialiasing available.
63 kLow_AALevel, //<! Low quality antialiased rendering. Actual
64 // interpretation is platform-dependent.
65 kMed_AALevel, //<! Medium quality antialiased rendering. Actual
66 // interpretation is platform-dependent.
67 kHigh_AALevel, //<! High quality antialiased rendering. Actual
68 // interpretation is platform-dependent.
69 };
70
71
72 /**
73 * Optional bitfield flags that can be passed to createTexture.
74 */
75 enum TextureFlags {
76 kRenderTarget_TextureFlag = 0x1, //<! Creates a texture that can be
77 // rendered to by calling
78 // GrGpu::setRenderTarget() with
79 // GrTexture::asRenderTarget().
bsalomon@google.comf6a7c112011-03-24 16:14:10 +000080 kNoStencil_TextureFlag = 0x2, //<! If the texture is used as a
81 // rendertarget but a stencil
82 // buffer is not required. Stencil
83 // may be required for clipping and
84 // path rendering.
reed@google.comac10a2d2010-12-22 21:39:39 +000085 kDynamicUpdate_TextureFlag = 0x4 //!< Hint that the CPU may modify
86 // this texture after creation
87 };
88
89 enum {
90 /**
91 * For Index8 pixel config, the colortable must be 256 entries
92 */
93 kColorTableSize = 256 * sizeof(GrColor)
94 };
95 /**
96 * Describes a texture to be created.
97 */
98 struct TextureDesc {
99 uint32_t fFlags; //!< bitfield of TextureFlags
100 GrGpu::AALevels fAALevel;//!< The level of antialiasing available
101 // for a rendertarget texture. Only
102 // flags contains
103 // kRenderTarget_TextureFlag.
104 uint32_t fWidth; //!< Width of the texture
105 uint32_t fHeight; //!< Height of the texture
106 GrTexture::PixelConfig fFormat; //!< Format of source data of the
107 // texture. Not guaraunteed to be the
108 // same as internal format used by
109 // 3D API.
110 };
111
112 /**
113 * Gpu usage statistics.
114 */
115 struct Stats {
116 uint32_t fVertexCnt; //<! Number of vertices drawn
117 uint32_t fIndexCnt; //<! Number of indices drawn
118 uint32_t fDrawCnt; //<! Number of draws
119
120 uint32_t fProgChngCnt;//<! Number of program changes (N/A for fixed)
121
122 /*
123 * Number of times the texture is set in 3D API
124 */
125 uint32_t fTextureChngCnt;
126 /*
127 * Number of times the render target is set in 3D API
128 */
129 uint32_t fRenderTargetChngCnt;
130 /*
131 * Number of textures created (includes textures that are rendertargets).
132 */
133 uint32_t fTextureCreateCnt;
134 /*
135 * Number of rendertargets created.
136 */
137 uint32_t fRenderTargetCreateCnt;
138 };
139
140 ////////////////////////////////////////////////////////////////////////////
141
142 GrGpu();
143 virtual ~GrGpu();
144
145 /**
146 * The GrGpu object normally assumes that no outsider is setting state
147 * within the underlying 3D API's context/device/whatever. This call informs
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000148 * the GrGpu that the state was modified and it shouldn't make assumptions
149 * about the state.
reed@google.comac10a2d2010-12-22 21:39:39 +0000150 */
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000151 void markContextDirty() { fContextIsDirty = true; }
reed@google.comac10a2d2010-12-22 21:39:39 +0000152
153 void unimpl(const char[]);
154
155 /**
bsalomon@google.com0748f212011-02-01 22:56:16 +0000156 * Creates a texture object. If desc width or height is not a power of
157 * two but underlying API requires a power of two texture then srcData
158 * will be embedded in a power of two texture. The extra width and height
159 * is filled as though srcData were rendered clamped into the texture.
reed@google.comac10a2d2010-12-22 21:39:39 +0000160 *
bsalomon@google.com1da07462011-03-10 14:51:57 +0000161 * If kRenderTarget_TextureFlag is specified the GrRenderTarget is
162 * accessible via GrTexture::asRenderTarget(). The texture will hold a ref
163 * on the render target until its releaseRenderTarget() is called or it is
164 * destroyed.
165 *
reed@google.comac10a2d2010-12-22 21:39:39 +0000166 * @param desc describes the texture to be created.
167 * @param srcData texel data to load texture. Begins with full-size
168 * palette data for paletted textures. Contains width*
169 * height texels. If NULL texture data is uninitialized.
170 *
171 * @return The texture object if successful, otherwise NULL.
172 */
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000173 GrTexture* createTexture(const TextureDesc& desc,
174 const void* srcData, size_t rowBytes);
reed@google.comac10a2d2010-12-22 21:39:39 +0000175 /**
176 * Wraps an externally-created rendertarget in a GrRenderTarget.
177 * @param platformRenderTarget handle to the the render target in the
178 * underlying 3D API. Interpretation depends on
179 * GrGpu subclass in use.
bsalomon@google.com8895a7a2011-02-18 16:09:55 +0000180 * @param stencilBits number of stencil bits the target has
reed@google.comac10a2d2010-12-22 21:39:39 +0000181 * @param width width of the render target
182 * @param height height of the render target
183 */
184 virtual GrRenderTarget* createPlatformRenderTarget(
185 intptr_t platformRenderTarget,
bsalomon@google.com8895a7a2011-02-18 16:09:55 +0000186 int stencilBits,
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000187 int width, int height);
reed@google.comac10a2d2010-12-22 21:39:39 +0000188
189 /**
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000190 * Reads the current target object (e.g. FBO or IDirect3DSurface9*) and
191 * viewport state from the underlying 3D API and wraps it in a
192 * GrRenderTarget. The GrRenderTarget will not attempt to delete/destroy the
193 * underlying object in its destructor and it is up to caller to guarantee
194 * that it remains valid while the GrRenderTarget is used.
195 *
196 * @return the newly created GrRenderTarget
197 */
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000198 GrRenderTarget* createRenderTargetFrom3DApiState();
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000199
200 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000201 * Creates a vertex buffer.
202 *
203 * @param size size in bytes of the vertex buffer
204 * @param dynamic hints whether the data will be frequently changed
205 * by either GrVertexBuffer::lock or
206 * GrVertexBuffer::updateData.
207 *
208 * @return The vertex buffer if successful, otherwise NULL.
209 */
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000210 GrVertexBuffer* createVertexBuffer(uint32_t size, bool dynamic);
reed@google.comac10a2d2010-12-22 21:39:39 +0000211
212 /**
213 * Creates an index buffer.
214 *
215 * @param size size in bytes of the index buffer
216 * @param dynamic hints whether the data will be frequently changed
217 * by either GrIndexBuffer::lock or
218 * GrIndexBuffer::updateData.
219 *
220 * @return The index buffer if successful, otherwise NULL.
221 */
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000222 GrIndexBuffer* createIndexBuffer(uint32_t size, bool dynamic);
reed@google.comac10a2d2010-12-22 21:39:39 +0000223
224 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000225 * Erase the entire render target, ignoring any clips/scissors.
226 *
227 * This is issued to the GPU driver immediately.
228 */
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000229 void eraseColor(GrColor color);
reed@google.comac10a2d2010-12-22 21:39:39 +0000230
231 /**
232 * Are 8 bit paletted textures supported.
233 *
234 * @return true if 8bit palette textures are supported, false otherwise
235 */
236 bool supports8BitPalette() const { return f8bitPaletteSupport; }
237
238 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +0000239 * returns true if two sided stenciling is supported. If false then only
240 * the front face values of the GrStencilSettings
reed@google.comac10a2d2010-12-22 21:39:39 +0000241 * @return true if only a single stencil pass is needed.
242 */
bsalomon@google.comd302f142011-03-03 13:54:13 +0000243 bool supportsTwoSidedStencil() const
244 { return fTwoSidedStencilSupport; }
245
246 /**
247 * returns true if stencil wrap is supported. If false then
248 * kIncWrap_StencilOp and kDecWrap_StencilOp are treated as
249 * kIncClamp_StencilOp and kDecClamp_StencilOp, respectively.
250 * @return true if stencil wrap ops are supported.
251 */
252 bool supportsStencilWrapOps() const
253 { return fStencilWrapOpsSupport; }
reed@google.comac10a2d2010-12-22 21:39:39 +0000254
255 /**
256 * Checks whether locking vertex and index buffers is supported.
257 *
258 * @return true if locking is supported.
259 */
260 bool supportsBufferLocking() const { return fBufferLockSupport; }
261
262 /**
263 * Gets the minimum width of a render target. If a texture/rt is created
264 * with a width less than this size the GrGpu object will clamp it to this
265 * value.
266 */
267 int minRenderTargetWidth() const { return fMinRenderTargetWidth; }
268
269 /**
270 * Gets the minimum width of a render target. If a texture/rt is created
271 * with a height less than this size the GrGpu object will clamp it to this
272 * value.
273 */
274 int minRenderTargetHeight() const { return fMinRenderTargetHeight; }
275
276 /**
bsalomon@google.com0748f212011-02-01 22:56:16 +0000277 * Returns true if NPOT textures can be created
reed@google.comac10a2d2010-12-22 21:39:39 +0000278 *
bsalomon@google.com0748f212011-02-01 22:56:16 +0000279 * @return true if NPOT textures can be created
reed@google.comac10a2d2010-12-22 21:39:39 +0000280 */
bsalomon@google.com0748f212011-02-01 22:56:16 +0000281 bool npotTextureSupport() const { return fNPOTTextureSupport; }
282
283 /**
284 * Returns true if NPOT textures can be repeat/mirror tiled.
285 *
286 * @return true if NPOT textures can be tiled
287 */
288 bool npotTextureTileSupport() const { return fNPOTTextureTileSupport; }
289
290 /**
291 * Returns true if a NPOT texture can be a rendertarget
292 *
293 * @return the true if NPOT texture/rendertarget can be created.
294 */
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000295 bool npotRenderTargetSupport() const { return fNPOTRenderTargetSupport; }
reed@google.comac10a2d2010-12-22 21:39:39 +0000296
reed@google.com02a7e6c2011-01-28 21:21:49 +0000297 int maxTextureDimension() const { return fMaxTextureDimension; }
298
reed@google.comac10a2d2010-12-22 21:39:39 +0000299 // GrDrawTarget overrides
bsalomon@google.comffca4002011-02-22 20:34:01 +0000300 virtual void drawIndexed(GrPrimitiveType type,
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000301 int startVertex,
302 int startIndex,
303 int vertexCount,
304 int indexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000305
bsalomon@google.comffca4002011-02-22 20:34:01 +0000306 virtual void drawNonIndexed(GrPrimitiveType type,
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000307 int startVertex,
308 int vertexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000309
310 /**
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000311 * Installs a path renderer that will be used to draw paths that are
312 * part of the clip.
313 */
314 void setClipPathRenderer(GrPathRenderer* pathRenderer) {
315 GrSafeAssign(fClientPathRenderer, pathRenderer);
316 }
317
318 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000319 * Returns an index buffer that can be used to render quads.
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000320 * Six indices per quad: 0, 1, 2, 0, 2, 3, etc.
321 * The max number of quads can be queried using GrIndexBuffer::maxQuads().
reed@google.comac10a2d2010-12-22 21:39:39 +0000322 * Draw with kTriangles_PrimitiveType
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000323 * @ return the quad index buffer
reed@google.comac10a2d2010-12-22 21:39:39 +0000324 */
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000325 const GrIndexBuffer* getQuadIndexBuffer() const;
reed@google.comac10a2d2010-12-22 21:39:39 +0000326
327 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +0000328 * Returns a vertex buffer with four position-only vertices [(0,0), (1,0),
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000329 * (1,1), (0,1)].
330 * @ return unit square vertex buffer
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000331 */
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000332 const GrVertexBuffer* getUnitSquareVertexBuffer() const;
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000333
334 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000335 * Ensures that the current render target is actually set in the
336 * underlying 3D API. Used when client wants to use 3D API to directly
337 * render to the RT.
338 */
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000339 void forceRenderTargetFlush();
reed@google.comac10a2d2010-12-22 21:39:39 +0000340
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000341 /**
342 * Reads a rectangle of pixels from the current render target.
343 * @param left left edge of the rectangle to read (inclusive)
344 * @param top top edge of the rectangle to read (inclusive)
345 * @param width width of rectangle to read in pixels.
346 * @param height height of rectangle to read in pixels.
347 * @param buffer memory to read the rectangle into.
348 *
349 * @return true if the read succeeded, false if not. The read can fail
350 * because of a unsupported pixel config or because no render
351 * target is currently set.
352 */
353 bool readPixels(int left, int top, int width, int height,
354 GrTexture::PixelConfig, void* buffer);
reed@google.comac10a2d2010-12-22 21:39:39 +0000355
356
357 const Stats& getStats() const;
358 void resetStats();
359 void printStats() const;
360
361protected:
bsalomon@google.comd302f142011-03-03 13:54:13 +0000362 enum PrivateStateBits {
363 kFirstBit = (kLastPublicStateBit << 1),
364
365 kModifyStencilClip_StateBit = kFirstBit, // allows draws to modify
366 // stencil bits used for
367 // clipping.
reed@google.comac10a2d2010-12-22 21:39:39 +0000368 };
369
370 /**
371 * Extensions to GrDrawTarget::StateBits to implement stencil clipping
372 */
373 struct ClipState {
374 bool fClipInStencil;
375 bool fClipIsDirty;
reed@google.comac10a2d2010-12-22 21:39:39 +0000376 } fClipState;
377
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000378 // GrDrawTarget override
379 virtual void clipWillBeSet(const GrClip& newClip);
380
381 // prepares clip flushes gpu state before a draw
bsalomon@google.comffca4002011-02-22 20:34:01 +0000382 bool setupClipAndFlushState(GrPrimitiveType type);
reed@google.comac10a2d2010-12-22 21:39:39 +0000383
bsalomon@google.comd302f142011-03-03 13:54:13 +0000384 // Functions used to map clip-respecting stencil tests into normal
385 // stencil funcs supported by GPUs.
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000386 static GrStencilFunc ConvertStencilFunc(bool stencilInClip,
bsalomon@google.comd302f142011-03-03 13:54:13 +0000387 GrStencilFunc func);
388 static void ConvertStencilFuncAndMask(GrStencilFunc func,
389 bool clipInStencil,
390 unsigned int clipBit,
391 unsigned int userBits,
392 unsigned int* ref,
393 unsigned int* mask);
394
395 // stencil settings to clip drawing when stencil clipping is in effect
396 // and the client isn't using the stencil test.
397 static const GrStencilSettings gClipStencilSettings;
398
reed@google.comac10a2d2010-12-22 21:39:39 +0000399 // defaults to false, subclass can set true to support palleted textures
400 bool f8bitPaletteSupport;
401
bsalomon@google.com0748f212011-02-01 22:56:16 +0000402 // set by subclass
403 bool fNPOTTextureSupport;
404 bool fNPOTTextureTileSupport;
405 bool fNPOTRenderTargetSupport;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000406 bool fTwoSidedStencilSupport;
407 bool fStencilWrapOpsSupport;
reed@google.comac10a2d2010-12-22 21:39:39 +0000408
409 // set by subclass to true if index and vertex buffers can be locked, false
410 // otherwise.
411 bool fBufferLockSupport;
412
413 // set by subclass
414 int fMinRenderTargetWidth;
415 int fMinRenderTargetHeight;
reed@google.com02a7e6c2011-01-28 21:21:49 +0000416 int fMaxTextureDimension;
reed@google.comac10a2d2010-12-22 21:39:39 +0000417
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000418 Stats fStats;
419
420 const GrVertexBuffer* fCurrPoolVertexBuffer;
421 int fCurrPoolStartVertex;
422
423 const GrIndexBuffer* fCurrPoolIndexBuffer;
424 int fCurrPoolStartIndex;
425
426 // GrDrawTarget overrides
427 virtual bool acquireGeometryHelper(GrVertexLayout vertexLayout,
428 void** vertices,
429 void** indices);
430 virtual void releaseGeometryHelper();
431
432 virtual void setVertexSourceToArrayHelper(const void* vertexArray,
433 int vertexCount);
434
435 virtual void setIndexSourceToArrayHelper(const void* indexArray,
436 int indexCount);
437 // Helpers for setting up geometry state
438 void finalizeReservedVertices();
439 void finalizeReservedIndices();
440
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000441 // overridden by API-specific derived class to handle re-emitting 3D API
442 // preample and dirtying state cache.
443 virtual void resetContext() = 0;
444
445 // overridden by API-specific derived class to create objects.
446 virtual GrTexture* createTextureHelper(const TextureDesc& desc,
447 const void* srcData,
448 size_t rowBytes) = 0;
449 virtual GrRenderTarget* createPlatformRenderTargetHelper(
450 intptr_t platformRenderTarget,
451 int stencilBits,
452 int width, int height) = 0;
453 virtual GrRenderTarget* createRenderTargetFrom3DApiStateHelper() = 0;
454 virtual GrVertexBuffer* createVertexBufferHelper(uint32_t size,
455 bool dynamic) = 0;
456 virtual GrIndexBuffer* createIndexBufferHelper(uint32_t size,
457 bool dynamic) = 0;
458
459 // overridden by API-specific derivated class to perform the erase.
460 virtual void eraseColorHelper(GrColor color) = 0;
461
462 // overridden by API-specific derived class to perform the draw call.
bsalomon@google.comffca4002011-02-22 20:34:01 +0000463 virtual void drawIndexedHelper(GrPrimitiveType type,
reed@google.comac10a2d2010-12-22 21:39:39 +0000464 uint32_t startVertex,
465 uint32_t startIndex,
466 uint32_t vertexCount,
467 uint32_t indexCount) = 0;
468
bsalomon@google.comffca4002011-02-22 20:34:01 +0000469 virtual void drawNonIndexedHelper(GrPrimitiveType type,
reed@google.comac10a2d2010-12-22 21:39:39 +0000470 uint32_t vertexCount,
471 uint32_t numVertices) = 0;
472
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000473 // overridden by API-specific derived class to perform flush
474 virtual void forceRenderTargetFlushHelper() = 0;
475
476 // overridden by API-specific derived class to perform the read pixels.
477 virtual bool readPixelsHelper(int left, int top, int width, int height,
478 GrTexture::PixelConfig, void* buffer) = 0;
479
reed@google.comac10a2d2010-12-22 21:39:39 +0000480 // called to program the vertex data, indexCount will be 0 if drawing non-
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000481 // indexed geometry. The subclass may adjust the startVertex and/or
482 // startIndex since it may have already accounted for these in the setup.
483 virtual void setupGeometry(int* startVertex,
484 int* startIndex,
485 int vertexCount,
486 int indexCount) = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000487
488
489 // The GrGpu typically records the clients requested state and then flushes
490 // deltas from previous state at draw time. This function does the
491 // API-specific flush of the state
492 // returns false if current state is unsupported.
bsalomon@google.comffca4002011-02-22 20:34:01 +0000493 virtual bool flushGraphicsState(GrPrimitiveType type) = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000494
495 // Sets the scissor rect, or disables if rect is NULL.
496 virtual void flushScissor(const GrIRect* rect) = 0;
497
498 // GrGpu subclass removes the clip from the stencil buffer
bsalomon@google.comd302f142011-03-03 13:54:13 +0000499 virtual void eraseStencilClip(const GrIRect& rect) = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000500
reed@google.comac10a2d2010-12-22 21:39:39 +0000501private:
bsalomon@google.comd302f142011-03-03 13:54:13 +0000502 // readies the pools to provide vertex/index data.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000503 void prepareVertexPool();
504 void prepareIndexPool();
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000505
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000506 // determines the path renderer used to draw a clip path element.
507 GrPathRenderer* getClipPathRenderer(GrPathIter* path,
508 GrPathFill fill);
bsalomon@google.comd302f142011-03-03 13:54:13 +0000509
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000510 void handleDirtyContext() {
511 if (fContextIsDirty) {
512 this->resetContext();
513 fContextIsDirty = false;
514 }
515 }
516
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000517 GrVertexBufferAllocPool* fVertexPool;
reed@google.comac10a2d2010-12-22 21:39:39 +0000518
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000519 GrIndexBufferAllocPool* fIndexPool;
reed@google.comac10a2d2010-12-22 21:39:39 +0000520
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000521 mutable GrIndexBuffer* fQuadIndexBuffer; // mutable so it can be
522 // created on-demand
reed@google.comac10a2d2010-12-22 21:39:39 +0000523
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000524 mutable GrVertexBuffer* fUnitSquareVertexBuffer; // mutable so it can be
525 // created on-demand
bsalomon@google.comd302f142011-03-03 13:54:13 +0000526
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000527 GrDefaultPathRenderer* fDefaultPathRenderer;
528 GrPathRenderer* fClientPathRenderer;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000529
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000530 bool fContextIsDirty;
531
bsalomon@google.comd302f142011-03-03 13:54:13 +0000532 // when in an internal draw these indicate whether the pools are in use
533 // by one of the outer draws. If false then it is safe to reset the
534 // pool.
535 bool fVertexPoolInUse;
536 bool fIndexPoolInUse;
537
538 // used to save and restore state when the GrGpu needs
539 // to make its geometry pools available internally
540 class AutoInternalDrawGeomRestore {
541 public:
542 AutoInternalDrawGeomRestore(GrGpu* gpu) : fAgsr(gpu) {
543 fGpu = gpu;
544
545 fVertexPoolWasInUse = gpu->fVertexPoolInUse;
546 fIndexPoolWasInUse = gpu->fIndexPoolInUse;
547
548 gpu->fVertexPoolInUse = fVertexPoolWasInUse ||
549 (kBuffer_GeometrySrcType !=
550 gpu->fGeometrySrc.fVertexSrc);
551 gpu->fIndexPoolInUse = fIndexPoolWasInUse ||
552 (kBuffer_GeometrySrcType !=
553 gpu->fGeometrySrc.fIndexSrc);;
554
555 fSavedPoolVertexBuffer = gpu->fCurrPoolVertexBuffer;
556 fSavedPoolStartVertex = gpu->fCurrPoolStartVertex;
557 fSavedPoolIndexBuffer = gpu->fCurrPoolIndexBuffer;
558 fSavedPoolStartIndex = gpu->fCurrPoolStartIndex;
559
560 fSavedReservedGeometry = gpu->fReservedGeometry;
561 gpu->fReservedGeometry.fLocked = false;
562 }
563 ~AutoInternalDrawGeomRestore() {
564 fGpu->fCurrPoolVertexBuffer = fSavedPoolVertexBuffer;
565 fGpu->fCurrPoolStartVertex = fSavedPoolStartVertex;
566 fGpu->fCurrPoolIndexBuffer = fSavedPoolIndexBuffer;
567 fGpu->fCurrPoolStartIndex = fSavedPoolStartIndex;
568 fGpu->fVertexPoolInUse = fVertexPoolWasInUse;
569 fGpu->fIndexPoolInUse = fIndexPoolWasInUse;
570 fGpu->fReservedGeometry = fSavedReservedGeometry;
571 }
572 private:
573 AutoGeometrySrcRestore fAgsr;
574 GrGpu* fGpu;
575 const GrVertexBuffer* fSavedPoolVertexBuffer;
576 int fSavedPoolStartVertex;
577 const GrIndexBuffer* fSavedPoolIndexBuffer;
578 int fSavedPoolStartIndex;
579 bool fVertexPoolWasInUse;
580 bool fIndexPoolWasInUse;
581 ReservedGeometry fSavedReservedGeometry;
582 };
583
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000584 typedef GrDrawTarget INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +0000585};
586
587#endif