blob: d3629b56f3a42dbf5b5371d2cbba8b34f7df7d55 [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
bsalomon@google.com669fdc42011-04-05 17:08:27 +000020#include "GrDrawTarget.h"
21#include "GrPathRenderer.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000022#include "GrRect.h"
23#include "GrRefCnt.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000024#include "GrTexture.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000025
bsalomon@google.com669fdc42011-04-05 17:08:27 +000026class GrContext;
bsalomon@google.com1c13c962011-02-14 16:51:21 +000027class GrIndexBufferAllocPool;
bsalomon@google.com8fe72472011-03-30 21:26:44 +000028class GrResource;
bsalomon@google.com669fdc42011-04-05 17:08:27 +000029class GrVertexBufferAllocPool;
reed@google.comac10a2d2010-12-22 21:39:39 +000030
bsalomon@google.com05ef5102011-05-02 21:14:59 +000031/**
32 * Gpu usage statistics.
33 */
34struct GrGpuStats {
35 uint32_t fVertexCnt; //<! Number of vertices drawn
36 uint32_t fIndexCnt; //<! Number of indices drawn
37 uint32_t fDrawCnt; //<! Number of draws
38
39 uint32_t fProgChngCnt;//<! Number of program changes (N/A for fixed)
40
41 /*
42 * Number of times the texture is set in 3D API
43 */
44 uint32_t fTextureChngCnt;
45 /*
46 * Number of times the render target is set in 3D API
47 */
48 uint32_t fRenderTargetChngCnt;
49 /*
50 * Number of textures created (includes textures that are rendertargets).
51 */
52 uint32_t fTextureCreateCnt;
53 /*
54 * Number of rendertargets created.
55 */
56 uint32_t fRenderTargetCreateCnt;
57};
58
reed@google.comac10a2d2010-12-22 21:39:39 +000059class GrGpu : public GrDrawTarget {
60
61public:
62 /**
bsalomon@google.com271cffc2011-05-20 14:13:56 +000063 * Additional blend coeffecients for dual source blending, not exposed
64 * through GrPaint/GrContext.
65 */
66 enum ExtendedBlendCoeffs {
67 // source 2 refers to second output color when
68 // using dual source blending.
69 kS2C_BlendCoeff = kPublicBlendCoeffCount,
70 kIS2C_BlendCoeff,
71 kS2A_BlendCoeff,
72 kIS2A_BlendCoeff,
73
74 kTotalBlendCoeffCount
75 };
76
77 /**
reed@google.comac10a2d2010-12-22 21:39:39 +000078 * Create an instance of GrGpu that matches the specified Engine backend.
79 * If the requested engine is not supported (at compile-time or run-time)
80 * this returns NULL.
81 */
bsalomon@google.com05ef5102011-05-02 21:14:59 +000082 static GrGpu* Create(GrEngine, GrPlatform3DContext context3D);
reed@google.comac10a2d2010-12-22 21:39:39 +000083
84 ////////////////////////////////////////////////////////////////////////////
85
86 GrGpu();
87 virtual ~GrGpu();
88
bsalomon@google.com669fdc42011-04-05 17:08:27 +000089 // The GrContext sets itself as the owner of this Gpu object
90 void setContext(GrContext* context) {
91 GrAssert(NULL == fContext);
92 fContext = context;
93 }
94 GrContext* getContext() { return fContext; }
95 const GrContext* getContext() const { return fContext; }
96
reed@google.comac10a2d2010-12-22 21:39:39 +000097 /**
98 * The GrGpu object normally assumes that no outsider is setting state
99 * within the underlying 3D API's context/device/whatever. This call informs
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000100 * the GrGpu that the state was modified and it shouldn't make assumptions
101 * about the state.
reed@google.comac10a2d2010-12-22 21:39:39 +0000102 */
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000103 void markContextDirty() { fContextIsDirty = true; }
reed@google.comac10a2d2010-12-22 21:39:39 +0000104
105 void unimpl(const char[]);
106
107 /**
bsalomon@google.com0748f212011-02-01 22:56:16 +0000108 * Creates a texture object. If desc width or height is not a power of
109 * two but underlying API requires a power of two texture then srcData
110 * will be embedded in a power of two texture. The extra width and height
111 * is filled as though srcData were rendered clamped into the texture.
reed@google.comac10a2d2010-12-22 21:39:39 +0000112 *
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000113 * If kRenderTarget_TextureFlag is specified the GrRenderTarget is
bsalomon@google.com1da07462011-03-10 14:51:57 +0000114 * accessible via GrTexture::asRenderTarget(). The texture will hold a ref
115 * on the render target until its releaseRenderTarget() is called or it is
116 * destroyed.
117 *
reed@google.comac10a2d2010-12-22 21:39:39 +0000118 * @param desc describes the texture to be created.
119 * @param srcData texel data to load texture. Begins with full-size
120 * palette data for paletted textures. Contains width*
121 * height texels. If NULL texture data is uninitialized.
122 *
123 * @return The texture object if successful, otherwise NULL.
124 */
bsalomon@google.comfea37b52011-04-25 15:51:06 +0000125 GrTexture* createTexture(const GrTextureDesc& desc,
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000126 const void* srcData, size_t rowBytes);
reed@google.comac10a2d2010-12-22 21:39:39 +0000127
bsalomon@google.com5877ffd2011-04-11 17:58:48 +0000128 GrResource* createPlatformSurface(const GrPlatformSurfaceDesc& desc);
129
reed@google.comac10a2d2010-12-22 21:39:39 +0000130 /**
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000131 * Reads the current target object (e.g. FBO or IDirect3DSurface9*) and
132 * viewport state from the underlying 3D API and wraps it in a
133 * GrRenderTarget. The GrRenderTarget will not attempt to delete/destroy the
134 * underlying object in its destructor and it is up to caller to guarantee
135 * that it remains valid while the GrRenderTarget is used.
136 *
137 * @return the newly created GrRenderTarget
138 */
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000139 GrRenderTarget* createRenderTargetFrom3DApiState();
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000140
141 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000142 * Creates a vertex buffer.
143 *
144 * @param size size in bytes of the vertex buffer
145 * @param dynamic hints whether the data will be frequently changed
146 * by either GrVertexBuffer::lock or
147 * GrVertexBuffer::updateData.
148 *
149 * @return The vertex buffer if successful, otherwise NULL.
150 */
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000151 GrVertexBuffer* createVertexBuffer(uint32_t size, bool dynamic);
reed@google.comac10a2d2010-12-22 21:39:39 +0000152
153 /**
154 * Creates an index buffer.
155 *
156 * @param size size in bytes of the index buffer
157 * @param dynamic hints whether the data will be frequently changed
158 * by either GrIndexBuffer::lock or
159 * GrIndexBuffer::updateData.
160 *
161 * @return The index buffer if successful, otherwise NULL.
162 */
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000163 GrIndexBuffer* createIndexBuffer(uint32_t size, bool dynamic);
reed@google.comac10a2d2010-12-22 21:39:39 +0000164
165 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000166 * Are 8 bit paletted textures supported.
167 *
168 * @return true if 8bit palette textures are supported, false otherwise
169 */
170 bool supports8BitPalette() const { return f8bitPaletteSupport; }
171
172 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +0000173 * returns true if two sided stenciling is supported. If false then only
174 * the front face values of the GrStencilSettings
reed@google.comac10a2d2010-12-22 21:39:39 +0000175 * @return true if only a single stencil pass is needed.
176 */
bsalomon@google.comd302f142011-03-03 13:54:13 +0000177 bool supportsTwoSidedStencil() const
178 { return fTwoSidedStencilSupport; }
179
180 /**
181 * returns true if stencil wrap is supported. If false then
182 * kIncWrap_StencilOp and kDecWrap_StencilOp are treated as
183 * kIncClamp_StencilOp and kDecClamp_StencilOp, respectively.
184 * @return true if stencil wrap ops are supported.
185 */
186 bool supportsStencilWrapOps() const
187 { return fStencilWrapOpsSupport; }
reed@google.comac10a2d2010-12-22 21:39:39 +0000188
189 /**
190 * Checks whether locking vertex and index buffers is supported.
191 *
192 * @return true if locking is supported.
193 */
194 bool supportsBufferLocking() const { return fBufferLockSupport; }
195
196 /**
bsalomon@google.com205d4602011-04-25 12:43:45 +0000197 * Does the 3D API support anti-aliased lines. If so then line primitive
198 * types will use this functionality when the AA state flag is set.
199 */
200 bool supportsAALines() const { return fAALineSupport; }
201
202 /**
bsalomon@google.com6aef1fb2011-05-05 12:33:22 +0000203 * Does the subclass support GrSamplerState::k4x4Downsample_Filter
204 */
205 bool supports4x4DownsampleFilter() const { return f4X4DownsampleFilterSupport; }
206
207 /**
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000208 * Does this instance support dual-source blending? Required for proper
209 * blending with partial coverage with certain blend modes (dst coeff is
210 * not 1, ISA, or ISC)
211 */
212 bool supportsDualSourceBlending() const {
213 return fDualSourceBlendingSupport;
214 }
215
216 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000217 * Gets the minimum width of a render target. If a texture/rt is created
218 * with a width less than this size the GrGpu object will clamp it to this
219 * value.
220 */
221 int minRenderTargetWidth() const { return fMinRenderTargetWidth; }
222
223 /**
224 * Gets the minimum width of a render target. If a texture/rt is created
225 * with a height less than this size the GrGpu object will clamp it to this
226 * value.
227 */
228 int minRenderTargetHeight() const { return fMinRenderTargetHeight; }
bsalomon@google.com8295dc12011-05-02 12:53:34 +0000229
230 /**
231 * Reports whether full scene anti-aliasing is supported.
232 */
233 bool supportsFullsceneAA() const { return fFSAASupport; }
reed@google.comac10a2d2010-12-22 21:39:39 +0000234
235 /**
bsalomon@google.com0748f212011-02-01 22:56:16 +0000236 * Returns true if NPOT textures can be created
reed@google.comac10a2d2010-12-22 21:39:39 +0000237 *
bsalomon@google.com0748f212011-02-01 22:56:16 +0000238 * @return true if NPOT textures can be created
reed@google.comac10a2d2010-12-22 21:39:39 +0000239 */
bsalomon@google.com0748f212011-02-01 22:56:16 +0000240 bool npotTextureSupport() const { return fNPOTTextureSupport; }
241
242 /**
243 * Returns true if NPOT textures can be repeat/mirror tiled.
244 *
245 * @return true if NPOT textures can be tiled
246 */
247 bool npotTextureTileSupport() const { return fNPOTTextureTileSupport; }
248
249 /**
250 * Returns true if a NPOT texture can be a rendertarget
251 *
252 * @return the true if NPOT texture/rendertarget can be created.
253 */
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000254 bool npotRenderTargetSupport() const { return fNPOTRenderTargetSupport; }
reed@google.comac10a2d2010-12-22 21:39:39 +0000255
bsalomon@google.com91958362011-06-13 17:58:13 +0000256 /**
257 * Gets the largest allowed width and height of a texture.
258 */
259 int maxTextureSize() const { return fMaxTextureSize; }
260 /**
261 * Gets the largest allowed width and height of a render target.
262 */
263 int maxRenderTargetSize() const { return fMaxRenderTargetSize; }
reed@google.com02a7e6c2011-01-28 21:21:49 +0000264
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000265 virtual void clear(const GrIRect* rect, GrColor color);
reed@google.comac10a2d2010-12-22 21:39:39 +0000266
267 /**
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000268 * Installs a path renderer that will be used to draw paths that are
269 * part of the clip.
270 */
271 void setClipPathRenderer(GrPathRenderer* pathRenderer) {
272 GrSafeAssign(fClientPathRenderer, pathRenderer);
273 }
274
275 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000276 * Returns an index buffer that can be used to render quads.
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000277 * Six indices per quad: 0, 1, 2, 0, 2, 3, etc.
278 * The max number of quads can be queried using GrIndexBuffer::maxQuads().
reed@google.comac10a2d2010-12-22 21:39:39 +0000279 * Draw with kTriangles_PrimitiveType
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000280 * @ return the quad index buffer
reed@google.comac10a2d2010-12-22 21:39:39 +0000281 */
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000282 const GrIndexBuffer* getQuadIndexBuffer() const;
reed@google.comac10a2d2010-12-22 21:39:39 +0000283
284 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +0000285 * Returns a vertex buffer with four position-only vertices [(0,0), (1,0),
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000286 * (1,1), (0,1)].
287 * @ return unit square vertex buffer
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000288 */
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000289 const GrVertexBuffer* getUnitSquareVertexBuffer() const;
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000290
291 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000292 * Ensures that the current render target is actually set in the
293 * underlying 3D API. Used when client wants to use 3D API to directly
294 * render to the RT.
295 */
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000296 void forceRenderTargetFlush();
reed@google.comac10a2d2010-12-22 21:39:39 +0000297
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000298 /**
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000299 * Reads a rectangle of pixels from a render target.
300 * @param renderTarget the render target to read from. NULL means the
301 * current render target.
302 * @param left left edge of the rectangle to read (inclusive)
303 * @param top top edge of the rectangle to read (inclusive)
304 * @param width width of rectangle to read in pixels.
305 * @param height height of rectangle to read in pixels.
306 * @param config the pixel config of the destination buffer
307 * @param buffer memory to read the rectangle into.
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000308 *
309 * @return true if the read succeeded, false if not. The read can fail
310 * because of a unsupported pixel config or because no render
311 * target is currently set.
312 */
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000313 bool readPixels(GrRenderTarget* renderTarget,
314 int left, int top, int width, int height,
315 GrPixelConfig config, void* buffer);
reed@google.comac10a2d2010-12-22 21:39:39 +0000316
bsalomon@google.com05ef5102011-05-02 21:14:59 +0000317 const GrGpuStats& getStats() const;
reed@google.comac10a2d2010-12-22 21:39:39 +0000318 void resetStats();
319 void printStats() const;
320
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000321 /**
322 * Called to tell Gpu object that all GrResources have been lost and should
323 * be abandoned.
324 */
junov@google.com53a55842011-06-08 22:55:10 +0000325 virtual void abandonResources();
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000326
327 /**
328 * Called to tell Gpu object to release all GrResources.
329 */
330 void releaseResources();
331
332 /**
333 * Add resource to list of resources. Should only be called by GrResource.
334 * @param resource the resource to add.
335 */
336 void insertResource(GrResource* resource);
337
338 /**
339 * Remove resource from list of resources. Should only be called by
340 * GrResource.
341 * @param resource the resource to remove.
342 */
343 void removeResource(GrResource* resource);
344
reed@google.comac10a2d2010-12-22 21:39:39 +0000345protected:
bsalomon@google.comd302f142011-03-03 13:54:13 +0000346 enum PrivateStateBits {
347 kFirstBit = (kLastPublicStateBit << 1),
348
349 kModifyStencilClip_StateBit = kFirstBit, // allows draws to modify
350 // stencil bits used for
351 // clipping.
reed@google.comac10a2d2010-12-22 21:39:39 +0000352 };
353
354 /**
355 * Extensions to GrDrawTarget::StateBits to implement stencil clipping
356 */
357 struct ClipState {
358 bool fClipInStencil;
359 bool fClipIsDirty;
reed@google.comac10a2d2010-12-22 21:39:39 +0000360 } fClipState;
361
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000362 // GrDrawTarget override
363 virtual void clipWillBeSet(const GrClip& newClip);
364
365 // prepares clip flushes gpu state before a draw
bsalomon@google.comffca4002011-02-22 20:34:01 +0000366 bool setupClipAndFlushState(GrPrimitiveType type);
reed@google.comac10a2d2010-12-22 21:39:39 +0000367
bsalomon@google.comd302f142011-03-03 13:54:13 +0000368 // Functions used to map clip-respecting stencil tests into normal
369 // stencil funcs supported by GPUs.
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000370 static GrStencilFunc ConvertStencilFunc(bool stencilInClip,
bsalomon@google.comd302f142011-03-03 13:54:13 +0000371 GrStencilFunc func);
372 static void ConvertStencilFuncAndMask(GrStencilFunc func,
373 bool clipInStencil,
374 unsigned int clipBit,
375 unsigned int userBits,
376 unsigned int* ref,
377 unsigned int* mask);
378
379 // stencil settings to clip drawing when stencil clipping is in effect
380 // and the client isn't using the stencil test.
381 static const GrStencilSettings gClipStencilSettings;
382
reed@google.comac10a2d2010-12-22 21:39:39 +0000383 // defaults to false, subclass can set true to support palleted textures
384 bool f8bitPaletteSupport;
385
bsalomon@google.com0748f212011-02-01 22:56:16 +0000386 // set by subclass
387 bool fNPOTTextureSupport;
388 bool fNPOTTextureTileSupport;
389 bool fNPOTRenderTargetSupport;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000390 bool fTwoSidedStencilSupport;
391 bool fStencilWrapOpsSupport;
bsalomon@google.com205d4602011-04-25 12:43:45 +0000392 bool fAALineSupport;
bsalomon@google.com8295dc12011-05-02 12:53:34 +0000393 bool fFSAASupport;
bsalomon@google.com6aef1fb2011-05-05 12:33:22 +0000394 bool f4X4DownsampleFilterSupport; // supports GrSamplerState::k4x4Downsample_Filter
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000395 bool fDualSourceBlendingSupport;
reed@google.comac10a2d2010-12-22 21:39:39 +0000396
397 // set by subclass to true if index and vertex buffers can be locked, false
398 // otherwise.
399 bool fBufferLockSupport;
400
401 // set by subclass
402 int fMinRenderTargetWidth;
403 int fMinRenderTargetHeight;
bsalomon@google.com91958362011-06-13 17:58:13 +0000404 int fMaxRenderTargetSize;
405 int fMaxTextureSize;
reed@google.comac10a2d2010-12-22 21:39:39 +0000406
bsalomon@google.com05ef5102011-05-02 21:14:59 +0000407 GrGpuStats fStats;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000408
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000409 struct GeometryPoolState {
410 const GrVertexBuffer* fPoolVertexBuffer;
411 int fPoolStartVertex;
412
413 const GrIndexBuffer* fPoolIndexBuffer;
414 int fPoolStartIndex;
415 };
416 const GeometryPoolState& getGeomPoolState() {
417 return fGeomPoolStateStack.back();
418 }
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000419
420 // GrDrawTarget overrides
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000421 virtual bool onReserveVertexSpace(GrVertexLayout vertexLayout,
422 int vertexCount,
423 void** vertices);
424 virtual bool onReserveIndexSpace(int indexCount, void** indices);
425 virtual void releaseReservedVertexSpace();
426 virtual void releaseReservedIndexSpace();
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000427 virtual void onSetVertexSourceToArray(const void* vertexArray,
428 int vertexCount);
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000429 virtual void onSetIndexSourceToArray(const void* indexArray,
430 int indexCount);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000431 virtual void releaseVertexArray();
432 virtual void releaseIndexArray();
433 virtual void geometrySourceWillPush();
434 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState);
435
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000436 // Helpers for setting up geometry state
437 void finalizeReservedVertices();
438 void finalizeReservedIndices();
439
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000440 // overridden by API-specific derived class to handle re-emitting 3D API
441 // preample and dirtying state cache.
442 virtual void resetContext() = 0;
443
444 // overridden by API-specific derived class to create objects.
bsalomon@google.comfea37b52011-04-25 15:51:06 +0000445 virtual GrTexture* onCreateTexture(const GrTextureDesc& desc,
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000446 const void* srcData,
447 size_t rowBytes) = 0;
bsalomon@google.com5877ffd2011-04-11 17:58:48 +0000448 virtual GrResource* onCreatePlatformSurface(const GrPlatformSurfaceDesc& desc) = 0;
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000449 virtual GrRenderTarget* onCreateRenderTargetFrom3DApiState() = 0;
450 virtual GrVertexBuffer* onCreateVertexBuffer(uint32_t size,
451 bool dynamic) = 0;
452 virtual GrIndexBuffer* onCreateIndexBuffer(uint32_t size,
453 bool dynamic) = 0;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000454
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000455 // overridden by API-specific derivated class to perform the clear and
456 // clearRect. NULL rect means clear whole target.
457 virtual void onClear(const GrIRect* rect, GrColor color) = 0;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000458
459 // overridden by API-specific derived class to perform the draw call.
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000460 virtual void onGpuDrawIndexed(GrPrimitiveType type,
461 uint32_t startVertex,
462 uint32_t startIndex,
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000463 uint32_t vertexCount,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000464 uint32_t indexCount) = 0;
465
466 virtual void onGpuDrawNonIndexed(GrPrimitiveType type,
467 uint32_t vertexCount,
468 uint32_t numVertices) = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000469
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000470 // overridden by API-specific derived class to perform flush
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000471 virtual void onForceRenderTargetFlush() = 0;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000472
473 // overridden by API-specific derived class to perform the read pixels.
bsalomon@google.com5877ffd2011-04-11 17:58:48 +0000474 virtual bool onReadPixels(GrRenderTarget* target,
475 int left, int top, int width, int height,
476 GrPixelConfig, void* buffer) = 0;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000477
reed@google.comac10a2d2010-12-22 21:39:39 +0000478 // called to program the vertex data, indexCount will be 0 if drawing non-
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000479 // indexed geometry. The subclass may adjust the startVertex and/or
480 // startIndex since it may have already accounted for these in the setup.
481 virtual void setupGeometry(int* startVertex,
482 int* startIndex,
483 int vertexCount,
484 int indexCount) = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000485
486
487 // The GrGpu typically records the clients requested state and then flushes
488 // deltas from previous state at draw time. This function does the
489 // API-specific flush of the state
490 // returns false if current state is unsupported.
bsalomon@google.comffca4002011-02-22 20:34:01 +0000491 virtual bool flushGraphicsState(GrPrimitiveType type) = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000492
493 // Sets the scissor rect, or disables if rect is NULL.
494 virtual void flushScissor(const GrIRect* rect) = 0;
495
496 // GrGpu subclass removes the clip from the stencil buffer
bsalomon@google.com398109c2011-04-14 18:40:27 +0000497 virtual void clearStencilClip(const GrIRect& rect) = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000498
reed@google.comac10a2d2010-12-22 21:39:39 +0000499private:
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000500 GrContext* fContext; // not reffed (context refs gpu)
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000501
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000502 GrVertexBufferAllocPool* fVertexPool;
reed@google.comac10a2d2010-12-22 21:39:39 +0000503
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000504 GrIndexBufferAllocPool* fIndexPool;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000505
506 // counts number of uses of vertex/index pool in the geometry stack
507 int fVertexPoolUseCnt;
508 int fIndexPoolUseCnt;
509
510 enum {
511 kPreallocGeomPoolStateStackCnt = 4,
512 };
513 GrAlignedSTStorage<kPreallocGeomPoolStateStackCnt,
514 GeometryPoolState> fGeoSrcStateStackStorage;
515 GrTArray<GeometryPoolState, true> fGeomPoolStateStack;
516
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000517 mutable GrIndexBuffer* fQuadIndexBuffer; // mutable so it can be
518 // created on-demand
reed@google.comac10a2d2010-12-22 21:39:39 +0000519
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000520 mutable GrVertexBuffer* fUnitSquareVertexBuffer; // mutable so it can be
521 // created on-demand
bsalomon@google.comd302f142011-03-03 13:54:13 +0000522
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000523 GrDefaultPathRenderer* fDefaultPathRenderer;
524 GrPathRenderer* fClientPathRenderer;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000525
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000526 bool fContextIsDirty;
527
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000528 GrResource* fResourceHead;
529
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000530 // GrDrawTarget overrides
531 virtual void onDrawIndexed(GrPrimitiveType type,
532 int startVertex,
533 int startIndex,
534 int vertexCount,
535 int indexCount);
536 virtual void onDrawNonIndexed(GrPrimitiveType type,
537 int startVertex,
538 int vertexCount);
539
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000540 // readies the pools to provide vertex/index data.
541 void prepareVertexPool();
542 void prepareIndexPool();
543
544 // determines the path renderer used to draw a clip path element.
reed@google.com07f3ee12011-05-16 17:21:57 +0000545 GrPathRenderer* getClipPathRenderer(const SkPath& path, GrPathFill fill);
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000546
547 void handleDirtyContext() {
548 if (fContextIsDirty) {
549 this->resetContext();
550 fContextIsDirty = false;
551 }
552 }
553
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000554 typedef GrDrawTarget INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +0000555};
556
557#endif