blob: 2ec10aec66d2f626ea12d3f9f67eecc57f964e7b [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"
14#include "GrPathRenderer.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000015#include "GrRect.h"
16#include "GrRefCnt.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000017#include "GrTexture.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000018
bsalomon@google.com669fdc42011-04-05 17:08:27 +000019class GrContext;
bsalomon@google.com1c13c962011-02-14 16:51:21 +000020class GrIndexBufferAllocPool;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000021class GrResource;
bsalomon@google.com669fdc42011-04-05 17:08:27 +000022class GrVertexBufferAllocPool;
reed@google.comac10a2d2010-12-22 21:39:39 +000023
bsalomon@google.com05ef5102011-05-02 21:14:59 +000024/**
25 * Gpu usage statistics.
26 */
27struct GrGpuStats {
28 uint32_t fVertexCnt; //<! Number of vertices drawn
29 uint32_t fIndexCnt; //<! Number of indices drawn
30 uint32_t fDrawCnt; //<! Number of draws
31
32 uint32_t fProgChngCnt;//<! Number of program changes (N/A for fixed)
33
34 /*
35 * Number of times the texture is set in 3D API
36 */
37 uint32_t fTextureChngCnt;
38 /*
39 * Number of times the render target is set in 3D API
40 */
41 uint32_t fRenderTargetChngCnt;
42 /*
43 * Number of textures created (includes textures that are rendertargets).
44 */
45 uint32_t fTextureCreateCnt;
46 /*
47 * Number of rendertargets created.
48 */
49 uint32_t fRenderTargetCreateCnt;
50};
51
reed@google.comac10a2d2010-12-22 21:39:39 +000052class GrGpu : public GrDrawTarget {
53
54public:
55 /**
bsalomon@google.com271cffc2011-05-20 14:13:56 +000056 * Additional blend coeffecients for dual source blending, not exposed
57 * through GrPaint/GrContext.
58 */
59 enum ExtendedBlendCoeffs {
60 // source 2 refers to second output color when
61 // using dual source blending.
62 kS2C_BlendCoeff = kPublicBlendCoeffCount,
63 kIS2C_BlendCoeff,
64 kS2A_BlendCoeff,
65 kIS2A_BlendCoeff,
66
67 kTotalBlendCoeffCount
68 };
69
70 /**
reed@google.comac10a2d2010-12-22 21:39:39 +000071 * Create an instance of GrGpu that matches the specified Engine backend.
72 * If the requested engine is not supported (at compile-time or run-time)
73 * this returns NULL.
74 */
bsalomon@google.com05ef5102011-05-02 21:14:59 +000075 static GrGpu* Create(GrEngine, GrPlatform3DContext context3D);
reed@google.comac10a2d2010-12-22 21:39:39 +000076
77 ////////////////////////////////////////////////////////////////////////////
78
79 GrGpu();
80 virtual ~GrGpu();
81
bsalomon@google.com669fdc42011-04-05 17:08:27 +000082 // The GrContext sets itself as the owner of this Gpu object
83 void setContext(GrContext* context) {
84 GrAssert(NULL == fContext);
85 fContext = context;
86 }
87 GrContext* getContext() { return fContext; }
88 const GrContext* getContext() const { return fContext; }
89
reed@google.comac10a2d2010-12-22 21:39:39 +000090 /**
91 * The GrGpu object normally assumes that no outsider is setting state
92 * within the underlying 3D API's context/device/whatever. This call informs
bsalomon@google.coma7f84e12011-03-10 14:13:19 +000093 * the GrGpu that the state was modified and it shouldn't make assumptions
94 * about the state.
reed@google.comac10a2d2010-12-22 21:39:39 +000095 */
bsalomon@google.coma7f84e12011-03-10 14:13:19 +000096 void markContextDirty() { fContextIsDirty = true; }
reed@google.comac10a2d2010-12-22 21:39:39 +000097
98 void unimpl(const char[]);
99
100 /**
bsalomon@google.com0748f212011-02-01 22:56:16 +0000101 * Creates a texture object. If desc width or height is not a power of
102 * two but underlying API requires a power of two texture then srcData
103 * will be embedded in a power of two texture. The extra width and height
104 * is filled as though srcData were rendered clamped into the texture.
reed@google.comac10a2d2010-12-22 21:39:39 +0000105 *
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000106 * If kRenderTarget_TextureFlag is specified the GrRenderTarget is
bsalomon@google.com1da07462011-03-10 14:51:57 +0000107 * accessible via GrTexture::asRenderTarget(). The texture will hold a ref
108 * on the render target until its releaseRenderTarget() is called or it is
109 * destroyed.
110 *
reed@google.comac10a2d2010-12-22 21:39:39 +0000111 * @param desc describes the texture to be created.
112 * @param srcData texel data to load texture. Begins with full-size
113 * palette data for paletted textures. Contains width*
114 * height texels. If NULL texture data is uninitialized.
115 *
116 * @return The texture object if successful, otherwise NULL.
117 */
bsalomon@google.comfea37b52011-04-25 15:51:06 +0000118 GrTexture* createTexture(const GrTextureDesc& desc,
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000119 const void* srcData, size_t rowBytes);
reed@google.comac10a2d2010-12-22 21:39:39 +0000120
bsalomon@google.com5877ffd2011-04-11 17:58:48 +0000121 GrResource* createPlatformSurface(const GrPlatformSurfaceDesc& desc);
122
reed@google.comac10a2d2010-12-22 21:39:39 +0000123 /**
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000124 * Reads the current target object (e.g. FBO or IDirect3DSurface9*) and
125 * viewport state from the underlying 3D API and wraps it in a
126 * GrRenderTarget. The GrRenderTarget will not attempt to delete/destroy the
127 * underlying object in its destructor and it is up to caller to guarantee
128 * that it remains valid while the GrRenderTarget is used.
129 *
130 * @return the newly created GrRenderTarget
131 */
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000132 GrRenderTarget* createRenderTargetFrom3DApiState();
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000133
134 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000135 * Creates a vertex buffer.
136 *
137 * @param size size in bytes of the vertex buffer
138 * @param dynamic hints whether the data will be frequently changed
139 * by either GrVertexBuffer::lock or
140 * GrVertexBuffer::updateData.
141 *
142 * @return The vertex buffer if successful, otherwise NULL.
143 */
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000144 GrVertexBuffer* createVertexBuffer(uint32_t size, bool dynamic);
reed@google.comac10a2d2010-12-22 21:39:39 +0000145
146 /**
147 * Creates an index buffer.
148 *
149 * @param size size in bytes of the index buffer
150 * @param dynamic hints whether the data will be frequently changed
151 * by either GrIndexBuffer::lock or
152 * GrIndexBuffer::updateData.
153 *
154 * @return The index buffer if successful, otherwise NULL.
155 */
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000156 GrIndexBuffer* createIndexBuffer(uint32_t size, bool dynamic);
reed@google.comac10a2d2010-12-22 21:39:39 +0000157
158 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000159 * Are 8 bit paletted textures supported.
160 *
161 * @return true if 8bit palette textures are supported, false otherwise
162 */
163 bool supports8BitPalette() const { return f8bitPaletteSupport; }
164
165 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +0000166 * returns true if two sided stenciling is supported. If false then only
167 * the front face values of the GrStencilSettings
reed@google.comac10a2d2010-12-22 21:39:39 +0000168 * @return true if only a single stencil pass is needed.
169 */
bsalomon@google.comd302f142011-03-03 13:54:13 +0000170 bool supportsTwoSidedStencil() const
171 { return fTwoSidedStencilSupport; }
172
173 /**
174 * returns true if stencil wrap is supported. If false then
175 * kIncWrap_StencilOp and kDecWrap_StencilOp are treated as
176 * kIncClamp_StencilOp and kDecClamp_StencilOp, respectively.
177 * @return true if stencil wrap ops are supported.
178 */
179 bool supportsStencilWrapOps() const
180 { return fStencilWrapOpsSupport; }
reed@google.comac10a2d2010-12-22 21:39:39 +0000181
182 /**
183 * Checks whether locking vertex and index buffers is supported.
184 *
185 * @return true if locking is supported.
186 */
187 bool supportsBufferLocking() const { return fBufferLockSupport; }
188
189 /**
bsalomon@google.com205d4602011-04-25 12:43:45 +0000190 * Does the 3D API support anti-aliased lines. If so then line primitive
191 * types will use this functionality when the AA state flag is set.
192 */
193 bool supportsAALines() const { return fAALineSupport; }
194
195 /**
bsalomon@google.com6aef1fb2011-05-05 12:33:22 +0000196 * Does the subclass support GrSamplerState::k4x4Downsample_Filter
197 */
198 bool supports4x4DownsampleFilter() const { return f4X4DownsampleFilterSupport; }
199
200 /**
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000201 * Does this instance support dual-source blending? Required for proper
202 * blending with partial coverage with certain blend modes (dst coeff is
203 * not 1, ISA, or ISC)
204 */
205 bool supportsDualSourceBlending() const {
206 return fDualSourceBlendingSupport;
207 }
208
209 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000210 * Gets the minimum width of a render target. If a texture/rt is created
211 * with a width less than this size the GrGpu object will clamp it to this
212 * value.
213 */
214 int minRenderTargetWidth() const { return fMinRenderTargetWidth; }
215
216 /**
217 * Gets the minimum width of a render target. If a texture/rt is created
218 * with a height less than this size the GrGpu object will clamp it to this
219 * value.
220 */
221 int minRenderTargetHeight() const { return fMinRenderTargetHeight; }
bsalomon@google.com8295dc12011-05-02 12:53:34 +0000222
223 /**
224 * Reports whether full scene anti-aliasing is supported.
225 */
226 bool supportsFullsceneAA() const { return fFSAASupport; }
reed@google.comac10a2d2010-12-22 21:39:39 +0000227
228 /**
bsalomon@google.com0748f212011-02-01 22:56:16 +0000229 * Returns true if NPOT textures can be created
reed@google.comac10a2d2010-12-22 21:39:39 +0000230 *
bsalomon@google.com0748f212011-02-01 22:56:16 +0000231 * @return true if NPOT textures can be created
reed@google.comac10a2d2010-12-22 21:39:39 +0000232 */
bsalomon@google.com0748f212011-02-01 22:56:16 +0000233 bool npotTextureSupport() const { return fNPOTTextureSupport; }
234
235 /**
236 * Returns true if NPOT textures can be repeat/mirror tiled.
237 *
238 * @return true if NPOT textures can be tiled
239 */
240 bool npotTextureTileSupport() const { return fNPOTTextureTileSupport; }
241
242 /**
243 * Returns true if a NPOT texture can be a rendertarget
244 *
245 * @return the true if NPOT texture/rendertarget can be created.
246 */
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000247 bool npotRenderTargetSupport() const { return fNPOTRenderTargetSupport; }
reed@google.comac10a2d2010-12-22 21:39:39 +0000248
bsalomon@google.com91958362011-06-13 17:58:13 +0000249 /**
250 * Gets the largest allowed width and height of a texture.
251 */
252 int maxTextureSize() const { return fMaxTextureSize; }
253 /**
254 * Gets the largest allowed width and height of a render target.
255 */
256 int maxRenderTargetSize() const { return fMaxRenderTargetSize; }
reed@google.com02a7e6c2011-01-28 21:21:49 +0000257
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000258 virtual void clear(const GrIRect* rect, GrColor color);
reed@google.comac10a2d2010-12-22 21:39:39 +0000259
260 /**
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000261 * Installs a path renderer that will be used to draw paths that are
262 * part of the clip.
263 */
264 void setClipPathRenderer(GrPathRenderer* pathRenderer) {
265 GrSafeAssign(fClientPathRenderer, pathRenderer);
266 }
267
268 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000269 * Returns an index buffer that can be used to render quads.
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000270 * Six indices per quad: 0, 1, 2, 0, 2, 3, etc.
271 * The max number of quads can be queried using GrIndexBuffer::maxQuads().
reed@google.comac10a2d2010-12-22 21:39:39 +0000272 * Draw with kTriangles_PrimitiveType
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000273 * @ return the quad index buffer
reed@google.comac10a2d2010-12-22 21:39:39 +0000274 */
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000275 const GrIndexBuffer* getQuadIndexBuffer() const;
reed@google.comac10a2d2010-12-22 21:39:39 +0000276
277 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +0000278 * Returns a vertex buffer with four position-only vertices [(0,0), (1,0),
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000279 * (1,1), (0,1)].
280 * @ return unit square vertex buffer
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000281 */
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000282 const GrVertexBuffer* getUnitSquareVertexBuffer() const;
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000283
284 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000285 * Ensures that the current render target is actually set in the
286 * underlying 3D API. Used when client wants to use 3D API to directly
287 * render to the RT.
288 */
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000289 void forceRenderTargetFlush();
reed@google.comac10a2d2010-12-22 21:39:39 +0000290
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000291 /**
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000292 * Reads a rectangle of pixels from a render target.
293 * @param renderTarget the render target to read from. NULL means the
294 * current render target.
295 * @param left left edge of the rectangle to read (inclusive)
296 * @param top top edge of the rectangle to read (inclusive)
297 * @param width width of rectangle to read in pixels.
298 * @param height height of rectangle to read in pixels.
299 * @param config the pixel config of the destination buffer
300 * @param buffer memory to read the rectangle into.
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000301 *
302 * @return true if the read succeeded, false if not. The read can fail
303 * because of a unsupported pixel config or because no render
304 * target is currently set.
305 */
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000306 bool readPixels(GrRenderTarget* renderTarget,
307 int left, int top, int width, int height,
308 GrPixelConfig config, void* buffer);
reed@google.comac10a2d2010-12-22 21:39:39 +0000309
bsalomon@google.com05ef5102011-05-02 21:14:59 +0000310 const GrGpuStats& getStats() const;
reed@google.comac10a2d2010-12-22 21:39:39 +0000311 void resetStats();
312 void printStats() const;
313
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000314 /**
315 * Called to tell Gpu object that all GrResources have been lost and should
316 * be abandoned.
317 */
junov@google.com53a55842011-06-08 22:55:10 +0000318 virtual void abandonResources();
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000319
320 /**
321 * Called to tell Gpu object to release all GrResources.
322 */
323 void releaseResources();
324
325 /**
326 * Add resource to list of resources. Should only be called by GrResource.
327 * @param resource the resource to add.
328 */
329 void insertResource(GrResource* resource);
330
331 /**
332 * Remove resource from list of resources. Should only be called by
333 * GrResource.
334 * @param resource the resource to remove.
335 */
336 void removeResource(GrResource* resource);
337
reed@google.comac10a2d2010-12-22 21:39:39 +0000338protected:
bsalomon@google.comd302f142011-03-03 13:54:13 +0000339 enum PrivateStateBits {
340 kFirstBit = (kLastPublicStateBit << 1),
341
342 kModifyStencilClip_StateBit = kFirstBit, // allows draws to modify
343 // stencil bits used for
344 // clipping.
reed@google.comac10a2d2010-12-22 21:39:39 +0000345 };
346
347 /**
348 * Extensions to GrDrawTarget::StateBits to implement stencil clipping
349 */
350 struct ClipState {
351 bool fClipInStencil;
352 bool fClipIsDirty;
reed@google.comac10a2d2010-12-22 21:39:39 +0000353 } fClipState;
354
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000355 // GrDrawTarget override
356 virtual void clipWillBeSet(const GrClip& newClip);
357
358 // prepares clip flushes gpu state before a draw
bsalomon@google.comffca4002011-02-22 20:34:01 +0000359 bool setupClipAndFlushState(GrPrimitiveType type);
reed@google.comac10a2d2010-12-22 21:39:39 +0000360
bsalomon@google.comd302f142011-03-03 13:54:13 +0000361 // Functions used to map clip-respecting stencil tests into normal
362 // stencil funcs supported by GPUs.
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000363 static GrStencilFunc ConvertStencilFunc(bool stencilInClip,
bsalomon@google.comd302f142011-03-03 13:54:13 +0000364 GrStencilFunc func);
365 static void ConvertStencilFuncAndMask(GrStencilFunc func,
366 bool clipInStencil,
367 unsigned int clipBit,
368 unsigned int userBits,
369 unsigned int* ref,
370 unsigned int* mask);
371
372 // stencil settings to clip drawing when stencil clipping is in effect
373 // and the client isn't using the stencil test.
374 static const GrStencilSettings gClipStencilSettings;
375
reed@google.comac10a2d2010-12-22 21:39:39 +0000376 // defaults to false, subclass can set true to support palleted textures
377 bool f8bitPaletteSupport;
378
bsalomon@google.com0748f212011-02-01 22:56:16 +0000379 // set by subclass
380 bool fNPOTTextureSupport;
381 bool fNPOTTextureTileSupport;
382 bool fNPOTRenderTargetSupport;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000383 bool fTwoSidedStencilSupport;
384 bool fStencilWrapOpsSupport;
bsalomon@google.com205d4602011-04-25 12:43:45 +0000385 bool fAALineSupport;
bsalomon@google.com8295dc12011-05-02 12:53:34 +0000386 bool fFSAASupport;
bsalomon@google.com6aef1fb2011-05-05 12:33:22 +0000387 bool f4X4DownsampleFilterSupport; // supports GrSamplerState::k4x4Downsample_Filter
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000388 bool fDualSourceBlendingSupport;
reed@google.comac10a2d2010-12-22 21:39:39 +0000389
390 // set by subclass to true if index and vertex buffers can be locked, false
391 // otherwise.
392 bool fBufferLockSupport;
393
394 // set by subclass
395 int fMinRenderTargetWidth;
396 int fMinRenderTargetHeight;
bsalomon@google.com91958362011-06-13 17:58:13 +0000397 int fMaxRenderTargetSize;
398 int fMaxTextureSize;
reed@google.comac10a2d2010-12-22 21:39:39 +0000399
bsalomon@google.com05ef5102011-05-02 21:14:59 +0000400 GrGpuStats fStats;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000401
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000402 struct GeometryPoolState {
403 const GrVertexBuffer* fPoolVertexBuffer;
404 int fPoolStartVertex;
405
406 const GrIndexBuffer* fPoolIndexBuffer;
407 int fPoolStartIndex;
408 };
409 const GeometryPoolState& getGeomPoolState() {
410 return fGeomPoolStateStack.back();
411 }
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000412
413 // GrDrawTarget overrides
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000414 virtual bool onReserveVertexSpace(GrVertexLayout vertexLayout,
415 int vertexCount,
416 void** vertices);
417 virtual bool onReserveIndexSpace(int indexCount, void** indices);
418 virtual void releaseReservedVertexSpace();
419 virtual void releaseReservedIndexSpace();
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000420 virtual void onSetVertexSourceToArray(const void* vertexArray,
421 int vertexCount);
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000422 virtual void onSetIndexSourceToArray(const void* indexArray,
423 int indexCount);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000424 virtual void releaseVertexArray();
425 virtual void releaseIndexArray();
426 virtual void geometrySourceWillPush();
427 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState);
428
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000429 // 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.
bsalomon@google.comfea37b52011-04-25 15:51:06 +0000438 virtual GrTexture* onCreateTexture(const GrTextureDesc& desc,
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000439 const void* srcData,
440 size_t rowBytes) = 0;
bsalomon@google.com5877ffd2011-04-11 17:58:48 +0000441 virtual GrResource* onCreatePlatformSurface(const GrPlatformSurfaceDesc& desc) = 0;
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000442 virtual GrRenderTarget* onCreateRenderTargetFrom3DApiState() = 0;
443 virtual GrVertexBuffer* onCreateVertexBuffer(uint32_t size,
444 bool dynamic) = 0;
445 virtual GrIndexBuffer* onCreateIndexBuffer(uint32_t size,
446 bool dynamic) = 0;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000447
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000448 // overridden by API-specific derivated class to perform the clear and
449 // clearRect. NULL rect means clear whole target.
450 virtual void onClear(const GrIRect* rect, GrColor color) = 0;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000451
452 // overridden by API-specific derived class to perform the draw call.
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000453 virtual void onGpuDrawIndexed(GrPrimitiveType type,
454 uint32_t startVertex,
455 uint32_t startIndex,
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000456 uint32_t vertexCount,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000457 uint32_t indexCount) = 0;
458
459 virtual void onGpuDrawNonIndexed(GrPrimitiveType type,
460 uint32_t vertexCount,
461 uint32_t numVertices) = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000462
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000463 // overridden by API-specific derived class to perform flush
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000464 virtual void onForceRenderTargetFlush() = 0;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000465
466 // overridden by API-specific derived class to perform the read pixels.
bsalomon@google.com5877ffd2011-04-11 17:58:48 +0000467 virtual bool onReadPixels(GrRenderTarget* target,
468 int left, int top, int width, int height,
469 GrPixelConfig, void* buffer) = 0;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000470
reed@google.comac10a2d2010-12-22 21:39:39 +0000471 // called to program the vertex data, indexCount will be 0 if drawing non-
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000472 // indexed geometry. The subclass may adjust the startVertex and/or
473 // startIndex since it may have already accounted for these in the setup.
474 virtual void setupGeometry(int* startVertex,
475 int* startIndex,
476 int vertexCount,
477 int indexCount) = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000478
479
480 // The GrGpu typically records the clients requested state and then flushes
481 // deltas from previous state at draw time. This function does the
482 // API-specific flush of the state
483 // returns false if current state is unsupported.
bsalomon@google.comffca4002011-02-22 20:34:01 +0000484 virtual bool flushGraphicsState(GrPrimitiveType type) = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000485
486 // Sets the scissor rect, or disables if rect is NULL.
487 virtual void flushScissor(const GrIRect* rect) = 0;
488
489 // GrGpu subclass removes the clip from the stencil buffer
bsalomon@google.com398109c2011-04-14 18:40:27 +0000490 virtual void clearStencilClip(const GrIRect& rect) = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000491
reed@google.comac10a2d2010-12-22 21:39:39 +0000492private:
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000493 GrContext* fContext; // not reffed (context refs gpu)
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000494
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000495 GrVertexBufferAllocPool* fVertexPool;
reed@google.comac10a2d2010-12-22 21:39:39 +0000496
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000497 GrIndexBufferAllocPool* fIndexPool;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000498
499 // counts number of uses of vertex/index pool in the geometry stack
500 int fVertexPoolUseCnt;
501 int fIndexPoolUseCnt;
502
503 enum {
504 kPreallocGeomPoolStateStackCnt = 4,
505 };
506 GrAlignedSTStorage<kPreallocGeomPoolStateStackCnt,
507 GeometryPoolState> fGeoSrcStateStackStorage;
508 GrTArray<GeometryPoolState, true> fGeomPoolStateStack;
509
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000510 mutable GrIndexBuffer* fQuadIndexBuffer; // mutable so it can be
511 // created on-demand
reed@google.comac10a2d2010-12-22 21:39:39 +0000512
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000513 mutable GrVertexBuffer* fUnitSquareVertexBuffer; // mutable so it can be
514 // created on-demand
bsalomon@google.comd302f142011-03-03 13:54:13 +0000515
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000516 GrDefaultPathRenderer* fDefaultPathRenderer;
517 GrPathRenderer* fClientPathRenderer;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000518
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000519 bool fContextIsDirty;
520
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000521 GrResource* fResourceHead;
522
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000523 // GrDrawTarget overrides
524 virtual void onDrawIndexed(GrPrimitiveType type,
525 int startVertex,
526 int startIndex,
527 int vertexCount,
528 int indexCount);
529 virtual void onDrawNonIndexed(GrPrimitiveType type,
530 int startVertex,
531 int vertexCount);
532
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000533 // readies the pools to provide vertex/index data.
534 void prepareVertexPool();
535 void prepareIndexPool();
536
537 // determines the path renderer used to draw a clip path element.
reed@google.com07f3ee12011-05-16 17:21:57 +0000538 GrPathRenderer* getClipPathRenderer(const SkPath& path, GrPathFill fill);
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000539
540 void handleDirtyContext() {
541 if (fContextIsDirty) {
542 this->resetContext();
543 fContextIsDirty = false;
544 }
545 }
546
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000547 typedef GrDrawTarget INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +0000548};
549
550#endif