blob: 2fecca5ebd9668ecab37d6d5a54ded1b4c4dc40a [file] [log] [blame]
bsalomon@google.com27847de2011-02-22 20:59:41 +00001/*
2 Copyright 2010 Google Inc.
3
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
17#ifndef GrContext_DEFINED
18#define GrContext_DEFINED
19
20#include "GrClip.h"
bsalomon@google.com27847de2011-02-22 20:59:41 +000021#include "GrTextureCache.h"
22#include "GrPaint.h"
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +000023#include "GrPathRenderer.h"
bsalomon@google.com27847de2011-02-22 20:59:41 +000024
25class GrFontCache;
bsalomon@google.com05ef5102011-05-02 21:14:59 +000026class GrGpu;
27struct GrGpuStats;
bsalomon@google.com27847de2011-02-22 20:59:41 +000028class GrVertexBufferAllocPool;
29class GrIndexBufferAllocPool;
30class GrInOrderDrawBuffer;
bsalomon@google.com27847de2011-02-22 20:59:41 +000031
bsalomon@google.com91826102011-03-21 19:51:57 +000032class GR_API GrContext : public GrRefCnt {
bsalomon@google.com27847de2011-02-22 20:59:41 +000033public:
34 /**
35 * Creates a GrContext from within a 3D context.
36 */
bsalomon@google.com05ef5102011-05-02 21:14:59 +000037 static GrContext* Create(GrEngine engine,
38 GrPlatform3DContext context3D);
bsalomon@google.com27847de2011-02-22 20:59:41 +000039
40 /**
41 * Helper to create a opengl-shader based context
42 */
43 static GrContext* CreateGLShaderContext();
44
45 virtual ~GrContext();
46
47 /**
48 * The GrContext normally assumes that no outsider is setting state
49 * within the underlying 3D API's context/device/whatever. This call informs
50 * the context that the state was modified and it should resend. Shouldn't
51 * be called frequently for good performance.
52 */
53 void resetContext();
54
bsalomon@google.com8fe72472011-03-30 21:26:44 +000055 /**
56 * Abandons all gpu resources, assumes 3D API state is unknown. Call this
57 * if you have lost the associated GPU context, and thus internal texture,
58 * buffer, etc. references/IDs are now invalid. Should be called even when
59 * GrContext is no longer going to be used for two reasons:
60 * 1) ~GrContext will not try to free the objects in the 3D API.
61 * 2) If you've created GrResources that outlive the GrContext they will
62 * be marked as invalid (GrResource::isValid()) and won't attempt to
63 * free their underlying resource in the 3D API.
64 * Content drawn since the last GrContext::flush() may be lost.
65 */
66 void contextLost();
bsalomon@google.com27847de2011-02-22 20:59:41 +000067
68 /**
bsalomon@google.com8fe72472011-03-30 21:26:44 +000069 * Frees gpu created by the context. Can be called to reduce GPU memory
70 * pressure.
bsalomon@google.com27847de2011-02-22 20:59:41 +000071 */
bsalomon@google.com8fe72472011-03-30 21:26:44 +000072 void freeGpuResources();
73
74 ///////////////////////////////////////////////////////////////////////////
75 // Textures
bsalomon@google.com27847de2011-02-22 20:59:41 +000076
77 /**
78 * Search for an entry with the same Key. If found, "lock" it and return it.
79 * If not found, return null.
80 */
81 GrTextureEntry* findAndLockTexture(GrTextureKey*,
82 const GrSamplerState&);
83
84
85 /**
86 * Create a new entry, based on the specified key and texture, and return
87 * its "locked" entry.
88 *
89 * Ownership of the texture is transferred to the Entry, which will unref()
90 * it when we are purged or deleted.
91 */
92 GrTextureEntry* createAndLockTexture(GrTextureKey* key,
93 const GrSamplerState&,
bsalomon@google.comfea37b52011-04-25 15:51:06 +000094 const GrTextureDesc&,
bsalomon@google.com27847de2011-02-22 20:59:41 +000095 void* srcData, size_t rowBytes);
96
97 /**
bsalomon@google.comfea37b52011-04-25 15:51:06 +000098 * Returns a texture matching the desc. It's contents are unknown. Subsequent
99 * requests with the same descriptor are not guaranteed to return the same
100 * texture. The same texture is guaranteed not be returned again until it is
101 * unlocked.
bsalomon@google.coma39f4042011-04-26 13:18:16 +0000102 *
103 * Textures created by createAndLockTexture() hide the complications of
104 * tiling non-power-of-two textures on APIs that don't support this (e.g.
105 * unextended GLES2). Tiling a npot texture created by lockKeylessTexture on
106 * such an API will create gaps in the tiling pattern. This includes clamp
107 * mode. (This may be addressed in a future update.)
bsalomon@google.comfea37b52011-04-25 15:51:06 +0000108 */
bsalomon@google.coma39f4042011-04-26 13:18:16 +0000109 GrTextureEntry* lockKeylessTexture(const GrTextureDesc& desc);
bsalomon@google.comfea37b52011-04-25 15:51:06 +0000110
111 /**
bsalomon@google.com27847de2011-02-22 20:59:41 +0000112 * When done with an entry, call unlockTexture(entry) on it, which returns
113 * it to the cache, where it may be purged.
114 */
115 void unlockTexture(GrTextureEntry* entry);
116
117 /**
bsalomon@google.com27847de2011-02-22 20:59:41 +0000118 * Creates a texture that is outside the cache. Does not count against
119 * cache's budget.
120 */
bsalomon@google.comfea37b52011-04-25 15:51:06 +0000121 GrTexture* createUncachedTexture(const GrTextureDesc&,
bsalomon@google.com27847de2011-02-22 20:59:41 +0000122 void* srcData,
123 size_t rowBytes);
124
125 /**
126 * Returns true if the specified use of an indexed texture is supported.
127 */
128 bool supportsIndex8PixelConfig(const GrSamplerState&, int width, int height);
129
130 /**
131 * Return the current texture cache limits.
132 *
133 * @param maxTextures If non-null, returns maximum number of textures that
134 * can be held in the cache.
135 * @param maxTextureBytes If non-null, returns maximum number of bytes of
136 * texture memory that can be held in the cache.
137 */
138 void getTextureCacheLimits(int* maxTextures, size_t* maxTextureBytes) const;
139
140 /**
141 * Specify the texture cache limits. If the current cache exceeds either
142 * of these, it will be purged (LRU) to keep the cache within these limits.
143 *
144 * @param maxTextures The maximum number of textures that can be held in
145 * the cache.
146 * @param maxTextureBytes The maximum number of bytes of texture memory
147 * that can be held in the cache.
148 */
149 void setTextureCacheLimits(int maxTextures, size_t maxTextureBytes);
150
151 /**
152 * Return the max width or height of a texture supported by the current gpu
153 */
154 int getMaxTextureDimension();
155
156 ///////////////////////////////////////////////////////////////////////////
157 // Render targets
158
159 /**
bsalomon@google.com5877ffd2011-04-11 17:58:48 +0000160 * Sets the render target.
161 * @param target the render target to set. (should not be NULL.)
162 */
163 void setRenderTarget(GrRenderTarget* target);
164
165 /**
166 * Gets the current render target.
167 * @return the currently bound render target. Should never be NULL.
168 */
169 const GrRenderTarget* getRenderTarget() const;
170 GrRenderTarget* getRenderTarget();
171
172 ///////////////////////////////////////////////////////////////////////////
173 // Platform Surfaces
174
175 // GrContext provides an interface for wrapping externally created textures
176 // and rendertargets in their Gr-equivalents.
177
178 /**
179 * Wraps an existing 3D API surface in a GrObject. desc.fFlags determines
180 * the type of object returned. If kIsTexture is set the returned object
181 * will be a GrTexture*. Otherwise, it will be a GrRenderTarget*. If both
182 * are set the render target object is accessible by
183 * GrTexture::asRenderTarget().
184 *
185 * GL: if the object is a texture Gr may change its GL texture parameters
186 * when it is drawn.
187 *
188 * @param desc description of the object to create.
189 * @return either a GrTexture* or GrRenderTarget* depending on desc. NULL
190 * on failure.
191 */
192 GrResource* createPlatformSurface(const GrPlatformSurfaceDesc& desc);
193
194 /**
195 * DEPRECATED, WILL BE REMOVED SOON. USE createPlatformSurface.
196 *
bsalomon@google.com27847de2011-02-22 20:59:41 +0000197 * Wraps an externally-created rendertarget in a GrRenderTarget.
198 * @param platformRenderTarget 3D API-specific render target identifier
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000199 * e.g. in GL platforamRenderTarget is an FBO
bsalomon@google.com27847de2011-02-22 20:59:41 +0000200 * id.
201 * @param stencilBits the number of stencil bits that the render
202 * target has.
bsalomon@google.comf954d8d2011-04-06 17:50:02 +0000203 * @param isMultisampled specify whether the render target is
204 * multisampled.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000205 * @param width width of the render target.
206 * @param height height of the render target.
207 */
208 GrRenderTarget* createPlatformRenderTarget(intptr_t platformRenderTarget,
209 int stencilBits,
bsalomon@google.comf954d8d2011-04-06 17:50:02 +0000210 bool isMultisampled,
bsalomon@google.com05ef5102011-05-02 21:14:59 +0000211 int width, int height);
bsalomon@google.com27847de2011-02-22 20:59:41 +0000212
213 /**
bsalomon@google.com5877ffd2011-04-11 17:58:48 +0000214 * DEPRECATED, WILL BE REMOVED SOON. USE createPlatformSurface.
215 *
bsalomon@google.com27847de2011-02-22 20:59:41 +0000216 * Reads the current target object (e.g. FBO or IDirect3DSurface9*) and
217 * viewport state from the underlying 3D API and wraps it in a
218 * GrRenderTarget. The GrRenderTarget will not attempt to delete/destroy the
219 * underlying object in its destructor and it is up to caller to guarantee
220 * that it remains valid while the GrRenderTarget is used.
221 *
222 * @return the newly created GrRenderTarget
223 */
bsalomon@google.com05ef5102011-05-02 21:14:59 +0000224 GrRenderTarget* createRenderTargetFrom3DApiState();
bsalomon@google.com27847de2011-02-22 20:59:41 +0000225
bsalomon@google.com27847de2011-02-22 20:59:41 +0000226 ///////////////////////////////////////////////////////////////////////////
227 // Matrix state
228
229 /**
230 * Gets the current transformation matrix.
231 * @return the current matrix.
232 */
233 const GrMatrix& getMatrix() const;
234
235 /**
236 * Sets the transformation matrix.
237 * @param m the matrix to set.
238 */
239 void setMatrix(const GrMatrix& m);
240
241 /**
242 * Concats the current matrix. The passed matrix is applied before the
243 * current matrix.
244 * @param m the matrix to concat.
245 */
246 void concatMatrix(const GrMatrix& m) const;
247
248
249 ///////////////////////////////////////////////////////////////////////////
250 // Clip state
251 /**
252 * Gets the current clip.
253 * @return the current clip.
254 */
bsalomon@google.com05ef5102011-05-02 21:14:59 +0000255 const GrClip& getClip() const;
bsalomon@google.com27847de2011-02-22 20:59:41 +0000256
257 /**
258 * Sets the clip.
259 * @param clip the clip to set.
260 */
261 void setClip(const GrClip& clip);
262
263 /**
264 * Convenience method for setting the clip to a rect.
265 * @param rect the rect to set as the new clip.
266 */
267 void setClip(const GrIRect& rect);
268
269 ///////////////////////////////////////////////////////////////////////////
270 // Draws
271
272 /**
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000273 * Clear the entire or rect of the render target, ignoring any clips.
274 * @param rect the rect to clear or the whole thing if rect is NULL.
275 * @param color the color to clear to.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000276 */
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000277 void clear(const GrIRect* rect, GrColor color);
bsalomon@google.com27847de2011-02-22 20:59:41 +0000278
279 /**
280 * Draw everywhere (respecting the clip) with the paint.
281 */
282 void drawPaint(const GrPaint& paint);
283
284 /**
285 * Draw the rect using a paint.
286 * @param paint describes how to color pixels.
287 * @param strokeWidth If strokeWidth < 0, then the rect is filled, else
288 * the rect is mitered stroked based on strokeWidth. If
289 * strokeWidth == 0, then the stroke is always a single
290 * pixel thick.
291 * @param matrix Optional matrix applied to the rect. Applied before
292 * context's matrix or the paint's matrix.
293 * The rects coords are used to access the paint (through texture matrix)
294 */
295 void drawRect(const GrPaint& paint,
296 const GrRect&,
297 GrScalar strokeWidth = -1,
298 const GrMatrix* matrix = NULL);
299
300 /**
301 * Maps a rect of paint coordinates onto the a rect of destination
302 * coordinates. Each rect can optionally be transformed. The srcRect
303 * is stretched over the dstRect. The dstRect is transformed by the
304 * context's matrix and the srcRect is transformed by the paint's matrix.
305 * Additional optional matrices can be provided by parameters.
306 *
307 * @param paint describes how to color pixels.
308 * @param dstRect the destination rect to draw.
309 * @param srcRect rect of paint coordinates to be mapped onto dstRect
310 * @param dstMatrix Optional matrix to transform dstRect. Applied before
311 * context's matrix.
312 * @param srcMatrix Optional matrix to transform srcRect Applied before
313 * paint's matrix.
314 */
315 void drawRectToRect(const GrPaint& paint,
316 const GrRect& dstRect,
317 const GrRect& srcRect,
318 const GrMatrix* dstMatrix = NULL,
319 const GrMatrix* srcMatrix = NULL);
320
321 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +0000322 * Draws a path.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000323 *
324 * @param paint describes how to color pixels.
reed@google.com07f3ee12011-05-16 17:21:57 +0000325 * @param path the path to draw
bsalomon@google.com27847de2011-02-22 20:59:41 +0000326 * @param fill the path filling rule to use.
327 * @param translate optional additional translation applied to the
328 * path.
329 */
reed@google.com07f3ee12011-05-16 17:21:57 +0000330 void drawPath(const GrPaint& paint, const GrPath& path, GrPathFill fill,
bsalomon@google.comd302f142011-03-03 13:54:13 +0000331 const GrPoint* translate = NULL);
reed@google.com07f3ee12011-05-16 17:21:57 +0000332
bsalomon@google.com27847de2011-02-22 20:59:41 +0000333 /**
334 * Draws vertices with a paint.
335 *
336 * @param paint describes how to color pixels.
337 * @param primitiveType primitives type to draw.
338 * @param vertexCount number of vertices.
339 * @param positions array of vertex positions, required.
340 * @param texCoords optional array of texture coordinates used
341 * to access the paint.
342 * @param colors optional array of per-vertex colors, supercedes
343 * the paint's color field.
344 * @param indices optional array of indices. If NULL vertices
345 * are drawn non-indexed.
346 * @param indexCount if indices is non-null then this is the
347 * number of indices.
348 */
349 void drawVertices(const GrPaint& paint,
350 GrPrimitiveType primitiveType,
351 int vertexCount,
352 const GrPoint positions[],
353 const GrPoint texs[],
354 const GrColor colors[],
355 const uint16_t indices[],
356 int indexCount);
357
358 /**
359 * Similar to drawVertices but caller provides objects that convert to Gr
360 * types. The count of vertices is given by posSrc.
361 *
362 * @param paint describes how to color pixels.
363 * @param primitiveType primitives type to draw.
364 * @param posSrc Source of vertex positions. Must implement
365 * int count() const;
366 * void writeValue(int i, GrPoint* point) const;
367 * count returns the total number of vertices and
368 * writeValue writes a vertex position to point.
369 * @param texSrc optional, pass NULL to not use explicit tex
370 * coords. If present provides tex coords with
371 * method:
372 * void writeValue(int i, GrPoint* point) const;
373 * @param texSrc optional, pass NULL to not use per-vertex colors
374 * If present provides colors with method:
375 * void writeValue(int i, GrColor* point) const;
376 * @param indices optional, pass NULL for non-indexed drawing. If
377 * present supplies indices for indexed drawing
378 * with following methods:
379 * int count() const;
380 * void writeValue(int i, uint16_t* point) const;
381 * count returns the number of indices and
382 * writeValue supplies each index.
383 */
384 template <typename POS_SRC,
385 typename TEX_SRC,
386 typename COL_SRC,
387 typename IDX_SRC>
388 void drawCustomVertices(const GrPaint& paint,
389 GrPrimitiveType primitiveType,
390 const POS_SRC& posSrc,
391 const TEX_SRC* texCoordSrc,
392 const COL_SRC* colorSrc,
393 const IDX_SRC* idxSrc);
394 /**
395 * To avoid the problem of having to create a typename for NULL parameters,
396 * these reduced versions of drawCustomVertices are provided.
397 */
398 template <typename POS_SRC>
399 void drawCustomVertices(const GrPaint& paint,
400 GrPrimitiveType primitiveType,
401 const POS_SRC& posSrc);
402 template <typename POS_SRC, typename TEX_SRC>
403 void drawCustomVertices(const GrPaint& paint,
404 GrPrimitiveType primitiveType,
405 const POS_SRC& posSrc,
406 const TEX_SRC* texCoordSrc);
407 template <typename POS_SRC, typename TEX_SRC, typename COL_SRC>
408 void drawCustomVertices(const GrPaint& paint,
409 GrPrimitiveType primitiveType,
410 const POS_SRC& posSrc,
411 const TEX_SRC* texCoordSrc,
412 const COL_SRC* colorSrc);
413
414
415 ///////////////////////////////////////////////////////////////////////////
416 // Misc.
417
418 /**
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000419 * Flags that affect flush() behavior.
420 */
421 enum FlushBits {
422 /**
423 * A client may want Gr to bind a GrRenderTarget in the 3D API so that
424 * it can be rendered to directly. However, Gr lazily sets state. Simply
425 * calling setRenderTarget() followed by flush() without flags may not
426 * bind the render target. This flag forces the context to bind the last
427 * set render target in the 3D API.
428 */
429 kForceCurrentRenderTarget_FlushBit = 0x1,
430 /**
431 * A client may reach a point where it has partially rendered a frame
432 * through a GrContext that it knows the user will never see. This flag
433 * causes the flush to skip submission of deferred content to the 3D API
434 * during the flush.
435 */
436 kDiscard_FlushBit = 0x2,
437 };
438
439 /**
bsalomon@google.com27847de2011-02-22 20:59:41 +0000440 * Call to ensure all drawing to the context has been issued to the
441 * underlying 3D API.
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000442 * @param flagsBitfield flags that control the flushing behavior. See
443 * FlushBits.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000444 */
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000445 void flush(int flagsBitfield = 0);
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000446
bsalomon@google.com27847de2011-02-22 20:59:41 +0000447 /**
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000448 * Reads a rectangle of pixels from a render target.
449 * @param renderTarget the render target to read from. NULL means the
450 * current render target.
451 * @param left left edge of the rectangle to read (inclusive)
452 * @param top top edge of the rectangle to read (inclusive)
453 * @param width width of rectangle to read in pixels.
454 * @param height height of rectangle to read in pixels.
455 * @param config the pixel config of the destination buffer
456 * @param buffer memory to read the rectangle into.
457 *
458 * @return true if the read succeeded, false if not. The read can fail
459 * because of a unsupported pixel config or because no render
460 * target is currently set.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000461 */
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000462 bool readRenderTargetPixels(GrRenderTarget* target,
463 int left, int top, int width, int height,
464 GrPixelConfig config, void* buffer);
465
466 /**
467 * Reads a rectangle of pixels from a texture.
468 * @param texture the render target to read from.
469 * @param left left edge of the rectangle to read (inclusive)
470 * @param top top edge of the rectangle to read (inclusive)
471 * @param width width of rectangle to read in pixels.
472 * @param height height of rectangle to read in pixels.
473 * @param config the pixel config of the destination buffer
474 * @param buffer memory to read the rectangle into.
475 *
476 * @return true if the read succeeded, false if not. The read can fail
477 * because of a unsupported pixel config.
478 */
479 bool readTexturePixels(GrTexture* target,
480 int left, int top, int width, int height,
481 GrPixelConfig config, void* buffer);
bsalomon@google.com27847de2011-02-22 20:59:41 +0000482
483 /**
484 * Copy the src pixels [buffer, stride, pixelconfig] into the current
485 * render-target at the specified rectangle.
486 */
487 void writePixels(int left, int top, int width, int height,
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000488 GrPixelConfig, const void* buffer, size_t stride);
bsalomon@google.com27847de2011-02-22 20:59:41 +0000489
bsalomon@google.com27847de2011-02-22 20:59:41 +0000490 ///////////////////////////////////////////////////////////////////////////
491 // Helpers
492
493 class AutoRenderTarget : ::GrNoncopyable {
494 public:
495 AutoRenderTarget(GrContext* context, GrRenderTarget* target) {
496 fContext = NULL;
497 fPrevTarget = context->getRenderTarget();
498 if (fPrevTarget != target) {
499 context->setRenderTarget(target);
500 fContext = context;
501 }
502 }
503 ~AutoRenderTarget() {
504 if (fContext) {
505 fContext->setRenderTarget(fPrevTarget);
506 }
507 }
508 private:
509 GrContext* fContext;
510 GrRenderTarget* fPrevTarget;
511 };
512
513
514 ///////////////////////////////////////////////////////////////////////////
515 // Functions intended for internal use only.
516 GrGpu* getGpu() { return fGpu; }
517 GrFontCache* getFontCache() { return fFontCache; }
518 GrDrawTarget* getTextTarget(const GrPaint& paint);
519 void flushText();
520 const GrIndexBuffer* getQuadIndexBuffer() const;
bsalomon@google.com05ef5102011-05-02 21:14:59 +0000521 void resetStats();
522 const GrGpuStats& getStats() const;
523 void printStats() const;
bsalomon@google.com27847de2011-02-22 20:59:41 +0000524
525private:
526 // used to keep track of when we need to flush the draw buffer
527 enum DrawCategory {
528 kBuffered_DrawCategory, // last draw was inserted in draw buffer
529 kUnbuffered_DrawCategory, // last draw was not inserted in the draw buffer
530 kText_DrawCategory // text context was last to draw
531 };
532 DrawCategory fLastDrawCategory;
533
534 GrGpu* fGpu;
535 GrTextureCache* fTextureCache;
536 GrFontCache* fFontCache;
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000537
538 GrPathRenderer* fCustomPathRenderer;
539 GrDefaultPathRenderer fDefaultPathRenderer;
bsalomon@google.com27847de2011-02-22 20:59:41 +0000540
541 GrVertexBufferAllocPool* fDrawBufferVBAllocPool;
542 GrIndexBufferAllocPool* fDrawBufferIBAllocPool;
543 GrInOrderDrawBuffer* fDrawBuffer;
544
bsalomon@google.com205d4602011-04-25 12:43:45 +0000545 GrIndexBuffer* fAAFillRectIndexBuffer;
546 GrIndexBuffer* fAAStrokeRectIndexBuffer;
547
bsalomon@google.com27847de2011-02-22 20:59:41 +0000548 GrContext(GrGpu* gpu);
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000549
bsalomon@google.com205d4602011-04-25 12:43:45 +0000550 void fillAARect(GrDrawTarget* target,
551 const GrPaint& paint,
552 const GrRect& devRect);
553
554 void strokeAARect(GrDrawTarget* target,
555 const GrPaint& paint,
556 const GrRect& devRect,
557 const GrVec& devStrokeSize);
558
559 inline int aaFillRectIndexCount() const;
560 GrIndexBuffer* aaFillRectIndexBuffer();
561
562 inline int aaStrokeRectIndexCount() const;
563 GrIndexBuffer* aaStrokeRectIndexBuffer();
564
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000565 void setupDrawBuffer();
566
bsalomon@google.com27847de2011-02-22 20:59:41 +0000567 void flushDrawBuffer();
568
569 static void SetPaint(const GrPaint& paint, GrDrawTarget* target);
570
bsalomon@google.comfea37b52011-04-25 15:51:06 +0000571 bool finalizeTextureKey(GrTextureKey*,
572 const GrSamplerState&,
573 bool keyless) const;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000574
bsalomon@google.com27847de2011-02-22 20:59:41 +0000575 GrDrawTarget* prepareToDraw(const GrPaint& paint, DrawCategory drawType);
576
577 void drawClipIntoStencil();
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000578
reed@google.com07f3ee12011-05-16 17:21:57 +0000579 GrPathRenderer* getPathRenderer(const GrDrawTarget*, const GrPath&, GrPathFill);
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000580
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000581 struct OffscreenRecord;
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000582
bsalomon@google.com8295dc12011-05-02 12:53:34 +0000583 bool doOffscreenAA(GrDrawTarget* target,
584 const GrPaint& paint,
585 bool isLines) const;
586
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000587 // sets up target to draw coverage to the supersampled render target
588 bool setupOffscreenAAPass1(GrDrawTarget* target,
589 bool requireStencil,
bsalomon@google.com8295dc12011-05-02 12:53:34 +0000590 const GrIRect& boundRect,
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000591 OffscreenRecord* record);
592
593 // sets up target to sample coverage of supersampled render target back
594 // to the main render target using stage kOffscreenStage.
bsalomon@google.com8295dc12011-05-02 12:53:34 +0000595 void offscreenAAPass2(GrDrawTarget* target,
596 const GrPaint& paint,
597 const GrIRect& boundRect,
598 OffscreenRecord* record);
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000599
bsalomon@google.com26c2d0a2011-05-17 20:15:30 +0000600 // computes vertex layout bits based on the paint. If paint expresses
601 // a texture for a stage, the stage coords will be bound to postitions
602 // unless hasTexCoords[s]==true in which case stage s's input coords
603 // are bound to tex coord index s. hasTexCoords == NULL is a shortcut
604 // for an array where all the values are false.
605 static int PaintStageVertexLayoutBits(
606 const GrPaint& paint,
607 const bool hasTexCoords[GrPaint::kTotalStages]);
608
bsalomon@google.com27847de2011-02-22 20:59:41 +0000609};
610
611/**
612 * Save/restore the view-matrix in the context.
613 */
614class GrAutoMatrix : GrNoncopyable {
615public:
616 GrAutoMatrix(GrContext* ctx) : fContext(ctx) {
617 fMatrix = ctx->getMatrix();
618 }
619 GrAutoMatrix(GrContext* ctx, const GrMatrix& matrix) : fContext(ctx) {
620 fMatrix = ctx->getMatrix();
621 ctx->setMatrix(matrix);
622 }
623 ~GrAutoMatrix() {
624 fContext->setMatrix(fMatrix);
625 }
626
627private:
628 GrContext* fContext;
629 GrMatrix fMatrix;
630};
631
632#endif
633
634#include "GrContext_impl.h"
bsalomon@google.com8295dc12011-05-02 12:53:34 +0000635