blob: 5d9cf4fd482f96747cbcd8177fc0ff57f03328ab [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.comac10a2d2010-12-22 21:39:39 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@google.comac10a2d2010-12-22 21:39:39 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@google.comac10a2d2010-12-22 21:39:39 +000010#ifndef GrGpu_DEFINED
11#define GrGpu_DEFINED
12
bsalomon@google.com669fdc42011-04-05 17:08:27 +000013#include "GrDrawTarget.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000014#include "GrRect.h"
15#include "GrRefCnt.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000016#include "GrTexture.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000017
bsalomon@google.com669fdc42011-04-05 17:08:27 +000018class GrContext;
bsalomon@google.com1c13c962011-02-14 16:51:21 +000019class GrIndexBufferAllocPool;
bsalomon@google.com30085192011-08-19 15:42:31 +000020class GrPathRenderer;
21class GrPathRendererChain;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000022class GrResource;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000023class GrStencilBuffer;
bsalomon@google.com669fdc42011-04-05 17:08:27 +000024class GrVertexBufferAllocPool;
reed@google.comac10a2d2010-12-22 21:39:39 +000025
bsalomon@google.com05ef5102011-05-02 21:14:59 +000026/**
27 * Gpu usage statistics.
28 */
29struct GrGpuStats {
30 uint32_t fVertexCnt; //<! Number of vertices drawn
31 uint32_t fIndexCnt; //<! Number of indices drawn
32 uint32_t fDrawCnt; //<! Number of draws
33
34 uint32_t fProgChngCnt;//<! Number of program changes (N/A for fixed)
35
bsalomon@google.com030302c2011-08-01 17:35:01 +000036 /**
37 * Number of times the texture is set in 3D API
38 */
bsalomon@google.com05ef5102011-05-02 21:14:59 +000039 uint32_t fTextureChngCnt;
bsalomon@google.com030302c2011-08-01 17:35:01 +000040 /**
41 * Number of times the render target is set in 3D API
42 */
bsalomon@google.com05ef5102011-05-02 21:14:59 +000043 uint32_t fRenderTargetChngCnt;
bsalomon@google.com030302c2011-08-01 17:35:01 +000044 /**
45 * Number of textures created (includes textures that are rendertargets).
46 */
bsalomon@google.com05ef5102011-05-02 21:14:59 +000047 uint32_t fTextureCreateCnt;
bsalomon@google.com030302c2011-08-01 17:35:01 +000048 /**
49 * Number of rendertargets created.
50 */
bsalomon@google.com05ef5102011-05-02 21:14:59 +000051 uint32_t fRenderTargetCreateCnt;
52};
53
reed@google.comac10a2d2010-12-22 21:39:39 +000054class GrGpu : public GrDrawTarget {
55
56public:
bsalomon@google.com18c9c192011-09-22 21:01:31 +000057
reed@google.comac10a2d2010-12-22 21:39:39 +000058 /**
bsalomon@google.com271cffc2011-05-20 14:13:56 +000059 * Additional blend coeffecients for dual source blending, not exposed
60 * through GrPaint/GrContext.
61 */
62 enum ExtendedBlendCoeffs {
63 // source 2 refers to second output color when
64 // using dual source blending.
65 kS2C_BlendCoeff = kPublicBlendCoeffCount,
66 kIS2C_BlendCoeff,
67 kS2A_BlendCoeff,
68 kIS2A_BlendCoeff,
69
70 kTotalBlendCoeffCount
71 };
72
73 /**
reed@google.comac10a2d2010-12-22 21:39:39 +000074 * Create an instance of GrGpu that matches the specified Engine backend.
75 * If the requested engine is not supported (at compile-time or run-time)
76 * this returns NULL.
77 */
bsalomon@google.com05ef5102011-05-02 21:14:59 +000078 static GrGpu* Create(GrEngine, GrPlatform3DContext context3D);
reed@google.comac10a2d2010-12-22 21:39:39 +000079
80 ////////////////////////////////////////////////////////////////////////////
81
82 GrGpu();
83 virtual ~GrGpu();
84
bsalomon@google.com669fdc42011-04-05 17:08:27 +000085 // The GrContext sets itself as the owner of this Gpu object
86 void setContext(GrContext* context) {
87 GrAssert(NULL == fContext);
88 fContext = context;
89 }
90 GrContext* getContext() { return fContext; }
91 const GrContext* getContext() const { return fContext; }
92
reed@google.comac10a2d2010-12-22 21:39:39 +000093 /**
94 * The GrGpu object normally assumes that no outsider is setting state
95 * within the underlying 3D API's context/device/whatever. This call informs
bsalomon@google.coma7f84e12011-03-10 14:13:19 +000096 * the GrGpu that the state was modified and it shouldn't make assumptions
97 * about the state.
reed@google.comac10a2d2010-12-22 21:39:39 +000098 */
bsalomon@google.coma7f84e12011-03-10 14:13:19 +000099 void markContextDirty() { fContextIsDirty = true; }
reed@google.comac10a2d2010-12-22 21:39:39 +0000100
101 void unimpl(const char[]);
102
103 /**
bsalomon@google.com0748f212011-02-01 22:56:16 +0000104 * Creates a texture object. If desc width or height is not a power of
105 * two but underlying API requires a power of two texture then srcData
106 * will be embedded in a power of two texture. The extra width and height
107 * is filled as though srcData were rendered clamped into the texture.
reed@google.comac10a2d2010-12-22 21:39:39 +0000108 *
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000109 * If kRenderTarget_TextureFlag is specified the GrRenderTarget is
bsalomon@google.com1da07462011-03-10 14:51:57 +0000110 * accessible via GrTexture::asRenderTarget(). The texture will hold a ref
111 * on the render target until its releaseRenderTarget() is called or it is
112 * destroyed.
113 *
reed@google.comac10a2d2010-12-22 21:39:39 +0000114 * @param desc describes the texture to be created.
115 * @param srcData texel data to load texture. Begins with full-size
116 * palette data for paletted textures. Contains width*
117 * height texels. If NULL texture data is uninitialized.
118 *
119 * @return The texture object if successful, otherwise NULL.
120 */
bsalomon@google.comfea37b52011-04-25 15:51:06 +0000121 GrTexture* createTexture(const GrTextureDesc& desc,
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000122 const void* srcData, size_t rowBytes);
reed@google.comac10a2d2010-12-22 21:39:39 +0000123
bsalomon@google.com5877ffd2011-04-11 17:58:48 +0000124 GrResource* createPlatformSurface(const GrPlatformSurfaceDesc& desc);
125
reed@google.comac10a2d2010-12-22 21:39:39 +0000126 /**
127 * Creates a vertex buffer.
128 *
129 * @param size size in bytes of the vertex buffer
130 * @param dynamic hints whether the data will be frequently changed
131 * by either GrVertexBuffer::lock or
132 * GrVertexBuffer::updateData.
133 *
134 * @return The vertex buffer if successful, otherwise NULL.
135 */
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000136 GrVertexBuffer* createVertexBuffer(uint32_t size, bool dynamic);
reed@google.comac10a2d2010-12-22 21:39:39 +0000137
138 /**
139 * Creates an index buffer.
140 *
141 * @param size size in bytes of the index buffer
142 * @param dynamic hints whether the data will be frequently changed
143 * by either GrIndexBuffer::lock or
144 * GrIndexBuffer::updateData.
145 *
146 * @return The index buffer if successful, otherwise NULL.
147 */
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000148 GrIndexBuffer* createIndexBuffer(uint32_t size, bool dynamic);
reed@google.comac10a2d2010-12-22 21:39:39 +0000149
150 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000151 * Returns an index buffer that can be used to render quads.
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000152 * Six indices per quad: 0, 1, 2, 0, 2, 3, etc.
153 * The max number of quads can be queried using GrIndexBuffer::maxQuads().
reed@google.comac10a2d2010-12-22 21:39:39 +0000154 * Draw with kTriangles_PrimitiveType
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000155 * @ return the quad index buffer
reed@google.comac10a2d2010-12-22 21:39:39 +0000156 */
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000157 const GrIndexBuffer* getQuadIndexBuffer() const;
reed@google.comac10a2d2010-12-22 21:39:39 +0000158
159 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +0000160 * Returns a vertex buffer with four position-only vertices [(0,0), (1,0),
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000161 * (1,1), (0,1)].
162 * @ return unit square vertex buffer
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000163 */
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000164 const GrVertexBuffer* getUnitSquareVertexBuffer() const;
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000165
166 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000167 * Ensures that the current render target is actually set in the
168 * underlying 3D API. Used when client wants to use 3D API to directly
169 * render to the RT.
170 */
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000171 void forceRenderTargetFlush();
reed@google.comac10a2d2010-12-22 21:39:39 +0000172
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000173 /**
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000174 * Reads a rectangle of pixels from a render target.
175 * @param renderTarget the render target to read from. NULL means the
176 * current render target.
177 * @param left left edge of the rectangle to read (inclusive)
178 * @param top top edge of the rectangle to read (inclusive)
179 * @param width width of rectangle to read in pixels.
180 * @param height height of rectangle to read in pixels.
181 * @param config the pixel config of the destination buffer
182 * @param buffer memory to read the rectangle into.
bsalomon@google.comc6980972011-11-02 19:57:21 +0000183 * @param rowBytes the number of bytes between consecutive rows. Zero
184 * means rows are tightly packed.
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000185 *
186 * @return true if the read succeeded, false if not. The read can fail
187 * because of a unsupported pixel config or because no render
188 * target is currently set.
189 */
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000190 bool readPixels(GrRenderTarget* renderTarget,
191 int left, int top, int width, int height,
bsalomon@google.comc6980972011-11-02 19:57:21 +0000192 GrPixelConfig config, void* buffer, size_t rowBytes);
reed@google.comac10a2d2010-12-22 21:39:39 +0000193
bsalomon@google.com05ef5102011-05-02 21:14:59 +0000194 const GrGpuStats& getStats() const;
reed@google.comac10a2d2010-12-22 21:39:39 +0000195 void resetStats();
196 void printStats() const;
197
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000198 /**
199 * Called to tell Gpu object that all GrResources have been lost and should
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000200 * be abandoned. Overrides must call INHERITED::abandonResources().
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000201 */
junov@google.com53a55842011-06-08 22:55:10 +0000202 virtual void abandonResources();
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000203
204 /**
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000205 * Called to tell Gpu object to release all GrResources. Overrides must call
206 * INHERITED::releaseResources().
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000207 */
208 void releaseResources();
209
210 /**
211 * Add resource to list of resources. Should only be called by GrResource.
212 * @param resource the resource to add.
213 */
214 void insertResource(GrResource* resource);
215
216 /**
217 * Remove resource from list of resources. Should only be called by
218 * GrResource.
219 * @param resource the resource to remove.
220 */
221 void removeResource(GrResource* resource);
222
bsalomon@google.com471d4712011-08-23 15:45:25 +0000223 // GrDrawTarget overrides
bsalomon@google.com18c9c192011-09-22 21:01:31 +0000224 virtual void clear(const GrIRect* rect, GrColor color);
bsalomon@google.com471d4712011-08-23 15:45:25 +0000225
bsalomon@google.com80d09b92011-11-05 21:21:13 +0000226 // After the client interacts directly with the 3D context state the GrGpu
227 // must resync its internal state and assumptions about 3D context state.
228 // Each time this occurs the GrGpu bumps a timestamp.
229 // state of the 3D context
230 // At 10 resets / frame and 60fps a 64bit timestamp will overflow in about
231 // a billion years.
232 typedef uint64_t ResetTimestamp;
233
234 // This timestamp is always older than the current timestamp
235 static const ResetTimestamp kExpiredTimestamp = 0;
236 // Returns a timestamp based on the number of times the context was reset.
237 // This timestamp can be used to lazily detect when cached 3D context state
238 // is dirty.
239 ResetTimestamp getResetTimestamp() const {
240 return fResetTimestamp;
241 }
242
reed@google.comac10a2d2010-12-22 21:39:39 +0000243protected:
bsalomon@google.comd302f142011-03-03 13:54:13 +0000244 enum PrivateStateBits {
245 kFirstBit = (kLastPublicStateBit << 1),
246
247 kModifyStencilClip_StateBit = kFirstBit, // allows draws to modify
248 // stencil bits used for
249 // clipping.
reed@google.comac10a2d2010-12-22 21:39:39 +0000250 };
251
bsalomon@google.comdea2f8d2011-08-01 15:51:05 +0000252 // keep track of whether we are using stencil clipping (as opposed to
253 // scissor).
254 bool fClipInStencil;
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000255
256 // prepares clip flushes gpu state before a draw
bsalomon@google.comffca4002011-02-22 20:34:01 +0000257 bool setupClipAndFlushState(GrPrimitiveType type);
reed@google.comac10a2d2010-12-22 21:39:39 +0000258
bsalomon@google.comd302f142011-03-03 13:54:13 +0000259 // Functions used to map clip-respecting stencil tests into normal
260 // stencil funcs supported by GPUs.
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000261 static GrStencilFunc ConvertStencilFunc(bool stencilInClip,
bsalomon@google.comd302f142011-03-03 13:54:13 +0000262 GrStencilFunc func);
263 static void ConvertStencilFuncAndMask(GrStencilFunc func,
264 bool clipInStencil,
265 unsigned int clipBit,
266 unsigned int userBits,
267 unsigned int* ref,
268 unsigned int* mask);
269
270 // stencil settings to clip drawing when stencil clipping is in effect
271 // and the client isn't using the stencil test.
272 static const GrStencilSettings gClipStencilSettings;
273
reed@google.comac10a2d2010-12-22 21:39:39 +0000274
bsalomon@google.com05ef5102011-05-02 21:14:59 +0000275 GrGpuStats fStats;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000276
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000277 struct GeometryPoolState {
278 const GrVertexBuffer* fPoolVertexBuffer;
279 int fPoolStartVertex;
280
281 const GrIndexBuffer* fPoolIndexBuffer;
282 int fPoolStartIndex;
283 };
284 const GeometryPoolState& getGeomPoolState() {
285 return fGeomPoolStateStack.back();
286 }
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000287
288 // GrDrawTarget overrides
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000289 virtual bool onReserveVertexSpace(GrVertexLayout vertexLayout,
290 int vertexCount,
291 void** vertices);
292 virtual bool onReserveIndexSpace(int indexCount, void** indices);
293 virtual void releaseReservedVertexSpace();
294 virtual void releaseReservedIndexSpace();
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000295 virtual void onSetVertexSourceToArray(const void* vertexArray,
296 int vertexCount);
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000297 virtual void onSetIndexSourceToArray(const void* indexArray,
298 int indexCount);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000299 virtual void releaseVertexArray();
300 virtual void releaseIndexArray();
301 virtual void geometrySourceWillPush();
302 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState);
303
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000304 // Helpers for setting up geometry state
305 void finalizeReservedVertices();
306 void finalizeReservedIndices();
307
bsalomon@google.comb635d392011-11-05 12:47:43 +0000308 // called when the 3D context state is unknown. Subclass should emit any
309 // assumed 3D context state and dirty any state cache
bsalomon@google.com1bf1c212011-11-05 12:18:58 +0000310 virtual void onResetContext() = 0;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000311
bsalomon@google.comb635d392011-11-05 12:47:43 +0000312
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000313 // overridden by API-specific derived class to create objects.
bsalomon@google.comfea37b52011-04-25 15:51:06 +0000314 virtual GrTexture* onCreateTexture(const GrTextureDesc& desc,
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000315 const void* srcData,
316 size_t rowBytes) = 0;
bsalomon@google.com5877ffd2011-04-11 17:58:48 +0000317 virtual GrResource* onCreatePlatformSurface(const GrPlatformSurfaceDesc& desc) = 0;
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000318 virtual GrVertexBuffer* onCreateVertexBuffer(uint32_t size,
319 bool dynamic) = 0;
320 virtual GrIndexBuffer* onCreateIndexBuffer(uint32_t size,
321 bool dynamic) = 0;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000322
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000323 // overridden by API-specific derivated class to perform the clear and
324 // clearRect. NULL rect means clear whole target.
325 virtual void onClear(const GrIRect* rect, GrColor color) = 0;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000326
327 // overridden by API-specific derived class to perform the draw call.
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000328 virtual void onGpuDrawIndexed(GrPrimitiveType type,
329 uint32_t startVertex,
330 uint32_t startIndex,
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000331 uint32_t vertexCount,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000332 uint32_t indexCount) = 0;
333
334 virtual void onGpuDrawNonIndexed(GrPrimitiveType type,
335 uint32_t vertexCount,
336 uint32_t numVertices) = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000337
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000338 // overridden by API-specific derived class to perform flush
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000339 virtual void onForceRenderTargetFlush() = 0;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000340
341 // overridden by API-specific derived class to perform the read pixels.
bsalomon@google.com5877ffd2011-04-11 17:58:48 +0000342 virtual bool onReadPixels(GrRenderTarget* target,
343 int left, int top, int width, int height,
bsalomon@google.comc6980972011-11-02 19:57:21 +0000344 GrPixelConfig, void* buffer, size_t rowBytes) = 0;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000345
reed@google.comac10a2d2010-12-22 21:39:39 +0000346 // called to program the vertex data, indexCount will be 0 if drawing non-
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000347 // indexed geometry. The subclass may adjust the startVertex and/or
348 // startIndex since it may have already accounted for these in the setup.
349 virtual void setupGeometry(int* startVertex,
350 int* startIndex,
351 int vertexCount,
352 int indexCount) = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000353
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000354 // width and height may be larger than rt (if underlying API allows it).
355 // Should attach the SB to the RT. Returns false if compatible sb could
356 // not be created.
357 virtual bool createStencilBufferForRenderTarget(GrRenderTarget* rt,
358 int width,
359 int height) = 0;
360
361 // attaches an existing SB to an existing RT.
362 virtual bool attachStencilBufferToRenderTarget(GrStencilBuffer* sb,
363 GrRenderTarget* rt) = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000364
365 // The GrGpu typically records the clients requested state and then flushes
366 // deltas from previous state at draw time. This function does the
367 // API-specific flush of the state
368 // returns false if current state is unsupported.
bsalomon@google.comffca4002011-02-22 20:34:01 +0000369 virtual bool flushGraphicsState(GrPrimitiveType type) = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000370
371 // Sets the scissor rect, or disables if rect is NULL.
372 virtual void flushScissor(const GrIRect* rect) = 0;
373
bsalomon@google.comab3dee52011-08-29 15:18:41 +0000374 // GrGpu subclass sets clip bit in the stencil buffer. The subclass is
375 // free to clear the remaining bits to zero if masked clears are more
376 // expensive than clearing all bits.
377 virtual void clearStencilClip(const GrIRect& rect, bool insideClip) = 0;
378
bsalomon@google.comedc177d2011-08-05 15:46:40 +0000379 // clears the entire stencil buffer to 0
380 virtual void clearStencil() = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000381
reed@google.comac10a2d2010-12-22 21:39:39 +0000382private:
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000383 GrContext* fContext; // not reffed (context refs gpu)
bsalomon@google.com1bf1c212011-11-05 12:18:58 +0000384
bsalomon@google.com80d09b92011-11-05 21:21:13 +0000385 ResetTimestamp fResetTimestamp;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000386
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000387 GrVertexBufferAllocPool* fVertexPool;
reed@google.comac10a2d2010-12-22 21:39:39 +0000388
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000389 GrIndexBufferAllocPool* fIndexPool;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000390
391 // counts number of uses of vertex/index pool in the geometry stack
392 int fVertexPoolUseCnt;
393 int fIndexPoolUseCnt;
394
395 enum {
396 kPreallocGeomPoolStateStackCnt = 4,
397 };
bsalomon@google.com92669012011-09-27 19:10:05 +0000398 SkSTArray<kPreallocGeomPoolStateStackCnt,
399 GeometryPoolState, true> fGeomPoolStateStack;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000400
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000401 mutable GrIndexBuffer* fQuadIndexBuffer; // mutable so it can be
402 // created on-demand
reed@google.comac10a2d2010-12-22 21:39:39 +0000403
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000404 mutable GrVertexBuffer* fUnitSquareVertexBuffer; // mutable so it can be
405 // created on-demand
bsalomon@google.comd302f142011-03-03 13:54:13 +0000406
bsalomon@google.com30085192011-08-19 15:42:31 +0000407 // must be instantiated after GrGpu object has been given its owning
408 // GrContext ptr. (GrGpu is constructed first then handed off to GrContext).
409 GrPathRendererChain* fPathRendererChain;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000410
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000411 bool fContextIsDirty;
412
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000413 GrResource* fResourceHead;
414
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000415 // Given a rt, find or create a stencil buffer and attach it
416 bool attachStencilBufferToRenderTarget(GrRenderTarget* target);
417
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000418 // GrDrawTarget overrides
419 virtual void onDrawIndexed(GrPrimitiveType type,
420 int startVertex,
421 int startIndex,
422 int vertexCount,
423 int indexCount);
424 virtual void onDrawNonIndexed(GrPrimitiveType type,
425 int startVertex,
426 int vertexCount);
427
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000428 // readies the pools to provide vertex/index data.
429 void prepareVertexPool();
430 void prepareIndexPool();
431
432 // determines the path renderer used to draw a clip path element.
reed@google.com07f3ee12011-05-16 17:21:57 +0000433 GrPathRenderer* getClipPathRenderer(const SkPath& path, GrPathFill fill);
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000434
bsalomon@google.comb635d392011-11-05 12:47:43 +0000435 void resetContext() {
436 this->onResetContext();
437 ++fResetTimestamp;
438 }
439
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000440 void handleDirtyContext() {
441 if (fContextIsDirty) {
442 this->resetContext();
443 fContextIsDirty = false;
444 }
445 }
446
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000447 typedef GrDrawTarget INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +0000448};
449
450#endif