blob: abeec0c0b8a6f037cf5b786d3b47fd1e203310d9 [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"
reed@google.comac10a2d2010-12-22 21:39:39 +000024
bsalomon@google.com1c13c962011-02-14 16:51:21 +000025class GrVertexBufferAllocPool;
26class GrIndexBufferAllocPool;
bsalomon@google.comd302f142011-03-03 13:54:13 +000027class GrPathRenderer;
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 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000311 * Returns an index buffer that can be used to render quads.
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000312 * Six indices per quad: 0, 1, 2, 0, 2, 3, etc.
313 * The max number of quads can be queried using GrIndexBuffer::maxQuads().
reed@google.comac10a2d2010-12-22 21:39:39 +0000314 * Draw with kTriangles_PrimitiveType
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000315 * @ return the quad index buffer
reed@google.comac10a2d2010-12-22 21:39:39 +0000316 */
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000317 const GrIndexBuffer* getQuadIndexBuffer() const;
reed@google.comac10a2d2010-12-22 21:39:39 +0000318
319 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +0000320 * Returns a vertex buffer with four position-only vertices [(0,0), (1,0),
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000321 * (1,1), (0,1)].
322 * @ return unit square vertex buffer
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000323 */
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000324 const GrVertexBuffer* getUnitSquareVertexBuffer() const;
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000325
326 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000327 * Ensures that the current render target is actually set in the
328 * underlying 3D API. Used when client wants to use 3D API to directly
329 * render to the RT.
330 */
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000331 void forceRenderTargetFlush();
reed@google.comac10a2d2010-12-22 21:39:39 +0000332
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000333 /**
334 * Reads a rectangle of pixels from the current render target.
335 * @param left left edge of the rectangle to read (inclusive)
336 * @param top top edge of the rectangle to read (inclusive)
337 * @param width width of rectangle to read in pixels.
338 * @param height height of rectangle to read in pixels.
339 * @param buffer memory to read the rectangle into.
340 *
341 * @return true if the read succeeded, false if not. The read can fail
342 * because of a unsupported pixel config or because no render
343 * target is currently set.
344 */
345 bool readPixels(int left, int top, int width, int height,
346 GrTexture::PixelConfig, void* buffer);
reed@google.comac10a2d2010-12-22 21:39:39 +0000347
348
349 const Stats& getStats() const;
350 void resetStats();
351 void printStats() const;
352
353protected:
bsalomon@google.comd302f142011-03-03 13:54:13 +0000354 enum PrivateStateBits {
355 kFirstBit = (kLastPublicStateBit << 1),
356
357 kModifyStencilClip_StateBit = kFirstBit, // allows draws to modify
358 // stencil bits used for
359 // clipping.
reed@google.comac10a2d2010-12-22 21:39:39 +0000360 };
361
362 /**
363 * Extensions to GrDrawTarget::StateBits to implement stencil clipping
364 */
365 struct ClipState {
366 bool fClipInStencil;
367 bool fClipIsDirty;
reed@google.comac10a2d2010-12-22 21:39:39 +0000368 } fClipState;
369
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000370 // GrDrawTarget override
371 virtual void clipWillBeSet(const GrClip& newClip);
372
373 // prepares clip flushes gpu state before a draw
bsalomon@google.comffca4002011-02-22 20:34:01 +0000374 bool setupClipAndFlushState(GrPrimitiveType type);
reed@google.comac10a2d2010-12-22 21:39:39 +0000375
bsalomon@google.comd302f142011-03-03 13:54:13 +0000376 // Functions used to map clip-respecting stencil tests into normal
377 // stencil funcs supported by GPUs.
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000378 static GrStencilFunc ConvertStencilFunc(bool stencilInClip,
bsalomon@google.comd302f142011-03-03 13:54:13 +0000379 GrStencilFunc func);
380 static void ConvertStencilFuncAndMask(GrStencilFunc func,
381 bool clipInStencil,
382 unsigned int clipBit,
383 unsigned int userBits,
384 unsigned int* ref,
385 unsigned int* mask);
386
387 // stencil settings to clip drawing when stencil clipping is in effect
388 // and the client isn't using the stencil test.
389 static const GrStencilSettings gClipStencilSettings;
390
reed@google.comac10a2d2010-12-22 21:39:39 +0000391 // defaults to false, subclass can set true to support palleted textures
392 bool f8bitPaletteSupport;
393
bsalomon@google.com0748f212011-02-01 22:56:16 +0000394 // set by subclass
395 bool fNPOTTextureSupport;
396 bool fNPOTTextureTileSupport;
397 bool fNPOTRenderTargetSupport;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000398 bool fTwoSidedStencilSupport;
399 bool fStencilWrapOpsSupport;
reed@google.comac10a2d2010-12-22 21:39:39 +0000400
401 // set by subclass to true if index and vertex buffers can be locked, false
402 // otherwise.
403 bool fBufferLockSupport;
404
405 // set by subclass
406 int fMinRenderTargetWidth;
407 int fMinRenderTargetHeight;
reed@google.com02a7e6c2011-01-28 21:21:49 +0000408 int fMaxTextureDimension;
reed@google.comac10a2d2010-12-22 21:39:39 +0000409
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000410 Stats fStats;
411
412 const GrVertexBuffer* fCurrPoolVertexBuffer;
413 int fCurrPoolStartVertex;
414
415 const GrIndexBuffer* fCurrPoolIndexBuffer;
416 int fCurrPoolStartIndex;
417
418 // GrDrawTarget overrides
419 virtual bool acquireGeometryHelper(GrVertexLayout vertexLayout,
420 void** vertices,
421 void** indices);
422 virtual void releaseGeometryHelper();
423
424 virtual void setVertexSourceToArrayHelper(const void* vertexArray,
425 int vertexCount);
426
427 virtual void setIndexSourceToArrayHelper(const void* indexArray,
428 int indexCount);
429 // Helpers for setting up geometry state
430 void finalizeReservedVertices();
431 void finalizeReservedIndices();
432
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000433 // overridden by API-specific derived class to handle re-emitting 3D API
434 // preample and dirtying state cache.
435 virtual void resetContext() = 0;
436
437 // overridden by API-specific derived class to create objects.
438 virtual GrTexture* createTextureHelper(const TextureDesc& desc,
439 const void* srcData,
440 size_t rowBytes) = 0;
441 virtual GrRenderTarget* createPlatformRenderTargetHelper(
442 intptr_t platformRenderTarget,
443 int stencilBits,
444 int width, int height) = 0;
445 virtual GrRenderTarget* createRenderTargetFrom3DApiStateHelper() = 0;
446 virtual GrVertexBuffer* createVertexBufferHelper(uint32_t size,
447 bool dynamic) = 0;
448 virtual GrIndexBuffer* createIndexBufferHelper(uint32_t size,
449 bool dynamic) = 0;
450
451 // overridden by API-specific derivated class to perform the erase.
452 virtual void eraseColorHelper(GrColor color) = 0;
453
454 // overridden by API-specific derived class to perform the draw call.
bsalomon@google.comffca4002011-02-22 20:34:01 +0000455 virtual void drawIndexedHelper(GrPrimitiveType type,
reed@google.comac10a2d2010-12-22 21:39:39 +0000456 uint32_t startVertex,
457 uint32_t startIndex,
458 uint32_t vertexCount,
459 uint32_t indexCount) = 0;
460
bsalomon@google.comffca4002011-02-22 20:34:01 +0000461 virtual void drawNonIndexedHelper(GrPrimitiveType type,
reed@google.comac10a2d2010-12-22 21:39:39 +0000462 uint32_t vertexCount,
463 uint32_t numVertices) = 0;
464
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000465 // overridden by API-specific derived class to perform flush
466 virtual void forceRenderTargetFlushHelper() = 0;
467
468 // overridden by API-specific derived class to perform the read pixels.
469 virtual bool readPixelsHelper(int left, int top, int width, int height,
470 GrTexture::PixelConfig, void* buffer) = 0;
471
reed@google.comac10a2d2010-12-22 21:39:39 +0000472 // called to program the vertex data, indexCount will be 0 if drawing non-
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000473 // indexed geometry. The subclass may adjust the startVertex and/or
474 // startIndex since it may have already accounted for these in the setup.
475 virtual void setupGeometry(int* startVertex,
476 int* startIndex,
477 int vertexCount,
478 int indexCount) = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000479
480
481 // The GrGpu typically records the clients requested state and then flushes
482 // deltas from previous state at draw time. This function does the
483 // API-specific flush of the state
484 // returns false if current state is unsupported.
bsalomon@google.comffca4002011-02-22 20:34:01 +0000485 virtual bool flushGraphicsState(GrPrimitiveType type) = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000486
487 // Sets the scissor rect, or disables if rect is NULL.
488 virtual void flushScissor(const GrIRect* rect) = 0;
489
490 // GrGpu subclass removes the clip from the stencil buffer
bsalomon@google.comd302f142011-03-03 13:54:13 +0000491 virtual void eraseStencilClip(const GrIRect& rect) = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000492
reed@google.comac10a2d2010-12-22 21:39:39 +0000493private:
bsalomon@google.comd302f142011-03-03 13:54:13 +0000494 // readies the pools to provide vertex/index data.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000495 void prepareVertexPool();
496 void prepareIndexPool();
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000497
bsalomon@google.comd302f142011-03-03 13:54:13 +0000498 GrPathRenderer* getPathRenderer();
499
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000500 void handleDirtyContext() {
501 if (fContextIsDirty) {
502 this->resetContext();
503 fContextIsDirty = false;
504 }
505 }
506
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000507 GrVertexBufferAllocPool* fVertexPool;
reed@google.comac10a2d2010-12-22 21:39:39 +0000508
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000509 GrIndexBufferAllocPool* fIndexPool;
reed@google.comac10a2d2010-12-22 21:39:39 +0000510
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000511 mutable GrIndexBuffer* fQuadIndexBuffer; // mutable so it can be
512 // created on-demand
reed@google.comac10a2d2010-12-22 21:39:39 +0000513
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000514 mutable GrVertexBuffer* fUnitSquareVertexBuffer; // mutable so it can be
515 // created on-demand
bsalomon@google.comd302f142011-03-03 13:54:13 +0000516
517 GrPathRenderer* fPathRenderer;
518
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000519 bool fContextIsDirty;
520
bsalomon@google.comd302f142011-03-03 13:54:13 +0000521 // when in an internal draw these indicate whether the pools are in use
522 // by one of the outer draws. If false then it is safe to reset the
523 // pool.
524 bool fVertexPoolInUse;
525 bool fIndexPoolInUse;
526
527 // used to save and restore state when the GrGpu needs
528 // to make its geometry pools available internally
529 class AutoInternalDrawGeomRestore {
530 public:
531 AutoInternalDrawGeomRestore(GrGpu* gpu) : fAgsr(gpu) {
532 fGpu = gpu;
533
534 fVertexPoolWasInUse = gpu->fVertexPoolInUse;
535 fIndexPoolWasInUse = gpu->fIndexPoolInUse;
536
537 gpu->fVertexPoolInUse = fVertexPoolWasInUse ||
538 (kBuffer_GeometrySrcType !=
539 gpu->fGeometrySrc.fVertexSrc);
540 gpu->fIndexPoolInUse = fIndexPoolWasInUse ||
541 (kBuffer_GeometrySrcType !=
542 gpu->fGeometrySrc.fIndexSrc);;
543
544 fSavedPoolVertexBuffer = gpu->fCurrPoolVertexBuffer;
545 fSavedPoolStartVertex = gpu->fCurrPoolStartVertex;
546 fSavedPoolIndexBuffer = gpu->fCurrPoolIndexBuffer;
547 fSavedPoolStartIndex = gpu->fCurrPoolStartIndex;
548
549 fSavedReservedGeometry = gpu->fReservedGeometry;
550 gpu->fReservedGeometry.fLocked = false;
551 }
552 ~AutoInternalDrawGeomRestore() {
553 fGpu->fCurrPoolVertexBuffer = fSavedPoolVertexBuffer;
554 fGpu->fCurrPoolStartVertex = fSavedPoolStartVertex;
555 fGpu->fCurrPoolIndexBuffer = fSavedPoolIndexBuffer;
556 fGpu->fCurrPoolStartIndex = fSavedPoolStartIndex;
557 fGpu->fVertexPoolInUse = fVertexPoolWasInUse;
558 fGpu->fIndexPoolInUse = fIndexPoolWasInUse;
559 fGpu->fReservedGeometry = fSavedReservedGeometry;
560 }
561 private:
562 AutoGeometrySrcRestore fAgsr;
563 GrGpu* fGpu;
564 const GrVertexBuffer* fSavedPoolVertexBuffer;
565 int fSavedPoolStartVertex;
566 const GrIndexBuffer* fSavedPoolIndexBuffer;
567 int fSavedPoolStartIndex;
568 bool fVertexPoolWasInUse;
569 bool fIndexPoolWasInUse;
570 ReservedGeometry fSavedReservedGeometry;
571 };
572
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000573 typedef GrDrawTarget INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +0000574};
575
576#endif