blob: faf535f55397c14e5f1b568944629659ecc84c38 [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"
21#include "GrGpu.h"
22#include "GrTextureCache.h"
23#include "GrPaint.h"
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +000024#include "GrPathRenderer.h"
bsalomon@google.com27847de2011-02-22 20:59:41 +000025
26class GrFontCache;
27class GrPathIter;
28class 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 */
37 static GrContext* Create(GrGpu::Engine engine,
38 GrGpu::Platform3DContext context3D);
39
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.com5877ffd2011-04-11 17:58:48 +0000211 int width, int height) {
212 #if GR_DEBUG
213 GrPrintf("Using deprecated createPlatformRenderTarget API.");
214 #endif
215 return fGpu->createPlatformRenderTarget(platformRenderTarget,
216 stencilBits, isMultisampled,
217 width, height);
218 }
bsalomon@google.com27847de2011-02-22 20:59:41 +0000219
220 /**
bsalomon@google.com5877ffd2011-04-11 17:58:48 +0000221 * DEPRECATED, WILL BE REMOVED SOON. USE createPlatformSurface.
222 *
bsalomon@google.com27847de2011-02-22 20:59:41 +0000223 * Reads the current target object (e.g. FBO or IDirect3DSurface9*) and
224 * viewport state from the underlying 3D API and wraps it in a
225 * GrRenderTarget. The GrRenderTarget will not attempt to delete/destroy the
226 * underlying object in its destructor and it is up to caller to guarantee
227 * that it remains valid while the GrRenderTarget is used.
228 *
229 * @return the newly created GrRenderTarget
230 */
231 GrRenderTarget* createRenderTargetFrom3DApiState() {
bsalomon@google.com5877ffd2011-04-11 17:58:48 +0000232 #if GR_DEBUG
233 GrPrintf("Using deprecated createRenderTargetFrom3DApiState API.");
234 #endif
bsalomon@google.com27847de2011-02-22 20:59:41 +0000235 return fGpu->createRenderTargetFrom3DApiState();
236 }
237
bsalomon@google.com27847de2011-02-22 20:59:41 +0000238 ///////////////////////////////////////////////////////////////////////////
239 // Matrix state
240
241 /**
242 * Gets the current transformation matrix.
243 * @return the current matrix.
244 */
245 const GrMatrix& getMatrix() const;
246
247 /**
248 * Sets the transformation matrix.
249 * @param m the matrix to set.
250 */
251 void setMatrix(const GrMatrix& m);
252
253 /**
254 * Concats the current matrix. The passed matrix is applied before the
255 * current matrix.
256 * @param m the matrix to concat.
257 */
258 void concatMatrix(const GrMatrix& m) const;
259
260
261 ///////////////////////////////////////////////////////////////////////////
262 // Clip state
263 /**
264 * Gets the current clip.
265 * @return the current clip.
266 */
267 const GrClip& getClip() const { return fGpu->getClip(); }
268
269 /**
270 * Sets the clip.
271 * @param clip the clip to set.
272 */
273 void setClip(const GrClip& clip);
274
275 /**
276 * Convenience method for setting the clip to a rect.
277 * @param rect the rect to set as the new clip.
278 */
279 void setClip(const GrIRect& rect);
280
281 ///////////////////////////////////////////////////////////////////////////
282 // Draws
283
284 /**
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000285 * Clear the entire or rect of the render target, ignoring any clips.
286 * @param rect the rect to clear or the whole thing if rect is NULL.
287 * @param color the color to clear to.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000288 */
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000289 void clear(const GrIRect* rect, GrColor color);
bsalomon@google.com27847de2011-02-22 20:59:41 +0000290
291 /**
292 * Draw everywhere (respecting the clip) with the paint.
293 */
294 void drawPaint(const GrPaint& paint);
295
296 /**
297 * Draw the rect using a paint.
298 * @param paint describes how to color pixels.
299 * @param strokeWidth If strokeWidth < 0, then the rect is filled, else
300 * the rect is mitered stroked based on strokeWidth. If
301 * strokeWidth == 0, then the stroke is always a single
302 * pixel thick.
303 * @param matrix Optional matrix applied to the rect. Applied before
304 * context's matrix or the paint's matrix.
305 * The rects coords are used to access the paint (through texture matrix)
306 */
307 void drawRect(const GrPaint& paint,
308 const GrRect&,
309 GrScalar strokeWidth = -1,
310 const GrMatrix* matrix = NULL);
311
312 /**
313 * Maps a rect of paint coordinates onto the a rect of destination
314 * coordinates. Each rect can optionally be transformed. The srcRect
315 * is stretched over the dstRect. The dstRect is transformed by the
316 * context's matrix and the srcRect is transformed by the paint's matrix.
317 * Additional optional matrices can be provided by parameters.
318 *
319 * @param paint describes how to color pixels.
320 * @param dstRect the destination rect to draw.
321 * @param srcRect rect of paint coordinates to be mapped onto dstRect
322 * @param dstMatrix Optional matrix to transform dstRect. Applied before
323 * context's matrix.
324 * @param srcMatrix Optional matrix to transform srcRect Applied before
325 * paint's matrix.
326 */
327 void drawRectToRect(const GrPaint& paint,
328 const GrRect& dstRect,
329 const GrRect& srcRect,
330 const GrMatrix* dstMatrix = NULL,
331 const GrMatrix* srcMatrix = NULL);
332
333 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +0000334 * Draws a path.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000335 *
336 * @param paint describes how to color pixels.
bsalomon@google.comd302f142011-03-03 13:54:13 +0000337 * @param pathIter the path to draw
bsalomon@google.com27847de2011-02-22 20:59:41 +0000338 * @param fill the path filling rule to use.
339 * @param translate optional additional translation applied to the
340 * path.
341 */
342 void drawPath(const GrPaint& paint,
bsalomon@google.comd302f142011-03-03 13:54:13 +0000343 GrPathIter* pathIter,
344 GrPathFill fill,
345 const GrPoint* translate = NULL);
346 /**
347 * Helper version of drawPath that takes a GrPath
348 */
349 void drawPath(const GrPaint& paint,
350 const GrPath& path,
bsalomon@google.com27847de2011-02-22 20:59:41 +0000351 GrPathFill fill,
352 const GrPoint* translate = NULL);
353 /**
354 * Draws vertices with a paint.
355 *
356 * @param paint describes how to color pixels.
357 * @param primitiveType primitives type to draw.
358 * @param vertexCount number of vertices.
359 * @param positions array of vertex positions, required.
360 * @param texCoords optional array of texture coordinates used
361 * to access the paint.
362 * @param colors optional array of per-vertex colors, supercedes
363 * the paint's color field.
364 * @param indices optional array of indices. If NULL vertices
365 * are drawn non-indexed.
366 * @param indexCount if indices is non-null then this is the
367 * number of indices.
368 */
369 void drawVertices(const GrPaint& paint,
370 GrPrimitiveType primitiveType,
371 int vertexCount,
372 const GrPoint positions[],
373 const GrPoint texs[],
374 const GrColor colors[],
375 const uint16_t indices[],
376 int indexCount);
377
378 /**
379 * Similar to drawVertices but caller provides objects that convert to Gr
380 * types. The count of vertices is given by posSrc.
381 *
382 * @param paint describes how to color pixels.
383 * @param primitiveType primitives type to draw.
384 * @param posSrc Source of vertex positions. Must implement
385 * int count() const;
386 * void writeValue(int i, GrPoint* point) const;
387 * count returns the total number of vertices and
388 * writeValue writes a vertex position to point.
389 * @param texSrc optional, pass NULL to not use explicit tex
390 * coords. If present provides tex coords with
391 * method:
392 * void writeValue(int i, GrPoint* point) const;
393 * @param texSrc optional, pass NULL to not use per-vertex colors
394 * If present provides colors with method:
395 * void writeValue(int i, GrColor* point) const;
396 * @param indices optional, pass NULL for non-indexed drawing. If
397 * present supplies indices for indexed drawing
398 * with following methods:
399 * int count() const;
400 * void writeValue(int i, uint16_t* point) const;
401 * count returns the number of indices and
402 * writeValue supplies each index.
403 */
404 template <typename POS_SRC,
405 typename TEX_SRC,
406 typename COL_SRC,
407 typename IDX_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 const IDX_SRC* idxSrc);
414 /**
415 * To avoid the problem of having to create a typename for NULL parameters,
416 * these reduced versions of drawCustomVertices are provided.
417 */
418 template <typename POS_SRC>
419 void drawCustomVertices(const GrPaint& paint,
420 GrPrimitiveType primitiveType,
421 const POS_SRC& posSrc);
422 template <typename POS_SRC, typename TEX_SRC>
423 void drawCustomVertices(const GrPaint& paint,
424 GrPrimitiveType primitiveType,
425 const POS_SRC& posSrc,
426 const TEX_SRC* texCoordSrc);
427 template <typename POS_SRC, typename TEX_SRC, typename COL_SRC>
428 void drawCustomVertices(const GrPaint& paint,
429 GrPrimitiveType primitiveType,
430 const POS_SRC& posSrc,
431 const TEX_SRC* texCoordSrc,
432 const COL_SRC* colorSrc);
433
434
435 ///////////////////////////////////////////////////////////////////////////
436 // Misc.
437
438 /**
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000439 * Flags that affect flush() behavior.
440 */
441 enum FlushBits {
442 /**
443 * A client may want Gr to bind a GrRenderTarget in the 3D API so that
444 * it can be rendered to directly. However, Gr lazily sets state. Simply
445 * calling setRenderTarget() followed by flush() without flags may not
446 * bind the render target. This flag forces the context to bind the last
447 * set render target in the 3D API.
448 */
449 kForceCurrentRenderTarget_FlushBit = 0x1,
450 /**
451 * A client may reach a point where it has partially rendered a frame
452 * through a GrContext that it knows the user will never see. This flag
453 * causes the flush to skip submission of deferred content to the 3D API
454 * during the flush.
455 */
456 kDiscard_FlushBit = 0x2,
457 };
458
459 /**
bsalomon@google.com27847de2011-02-22 20:59:41 +0000460 * Call to ensure all drawing to the context has been issued to the
461 * underlying 3D API.
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000462 * @param flagsBitfield flags that control the flushing behavior. See
463 * FlushBits.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000464 */
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000465 void flush(int flagsBitfield = 0);
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000466
bsalomon@google.com27847de2011-02-22 20:59:41 +0000467 /**
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000468 * Reads a rectangle of pixels from a render target.
469 * @param renderTarget the render target to read from. NULL means the
470 * current render target.
471 * @param left left edge of the rectangle to read (inclusive)
472 * @param top top edge of the rectangle to read (inclusive)
473 * @param width width of rectangle to read in pixels.
474 * @param height height of rectangle to read in pixels.
475 * @param config the pixel config of the destination buffer
476 * @param buffer memory to read the rectangle into.
477 *
478 * @return true if the read succeeded, false if not. The read can fail
479 * because of a unsupported pixel config or because no render
480 * target is currently set.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000481 */
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000482 bool readRenderTargetPixels(GrRenderTarget* target,
483 int left, int top, int width, int height,
484 GrPixelConfig config, void* buffer);
485
486 /**
487 * Reads a rectangle of pixels from a texture.
488 * @param texture the render target to read from.
489 * @param left left edge of the rectangle to read (inclusive)
490 * @param top top edge of the rectangle to read (inclusive)
491 * @param width width of rectangle to read in pixels.
492 * @param height height of rectangle to read in pixels.
493 * @param config the pixel config of the destination buffer
494 * @param buffer memory to read the rectangle into.
495 *
496 * @return true if the read succeeded, false if not. The read can fail
497 * because of a unsupported pixel config.
498 */
499 bool readTexturePixels(GrTexture* target,
500 int left, int top, int width, int height,
501 GrPixelConfig config, void* buffer);
bsalomon@google.com27847de2011-02-22 20:59:41 +0000502
503 /**
504 * Copy the src pixels [buffer, stride, pixelconfig] into the current
505 * render-target at the specified rectangle.
506 */
507 void writePixels(int left, int top, int width, int height,
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000508 GrPixelConfig, const void* buffer, size_t stride);
bsalomon@google.com27847de2011-02-22 20:59:41 +0000509
510
511 ///////////////////////////////////////////////////////////////////////////
512 // Statistics
513
514 void resetStats();
515
516 const GrGpu::Stats& getStats() const;
517
518 void printStats() const;
519
520 ///////////////////////////////////////////////////////////////////////////
521 // Helpers
522
523 class AutoRenderTarget : ::GrNoncopyable {
524 public:
525 AutoRenderTarget(GrContext* context, GrRenderTarget* target) {
526 fContext = NULL;
527 fPrevTarget = context->getRenderTarget();
528 if (fPrevTarget != target) {
529 context->setRenderTarget(target);
530 fContext = context;
531 }
532 }
533 ~AutoRenderTarget() {
534 if (fContext) {
535 fContext->setRenderTarget(fPrevTarget);
536 }
537 }
538 private:
539 GrContext* fContext;
540 GrRenderTarget* fPrevTarget;
541 };
542
543
544 ///////////////////////////////////////////////////////////////////////////
545 // Functions intended for internal use only.
546 GrGpu* getGpu() { return fGpu; }
547 GrFontCache* getFontCache() { return fFontCache; }
548 GrDrawTarget* getTextTarget(const GrPaint& paint);
549 void flushText();
550 const GrIndexBuffer* getQuadIndexBuffer() const;
551
552private:
553 // used to keep track of when we need to flush the draw buffer
554 enum DrawCategory {
555 kBuffered_DrawCategory, // last draw was inserted in draw buffer
556 kUnbuffered_DrawCategory, // last draw was not inserted in the draw buffer
557 kText_DrawCategory // text context was last to draw
558 };
559 DrawCategory fLastDrawCategory;
560
561 GrGpu* fGpu;
562 GrTextureCache* fTextureCache;
563 GrFontCache* fFontCache;
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000564
565 GrPathRenderer* fCustomPathRenderer;
566 GrDefaultPathRenderer fDefaultPathRenderer;
bsalomon@google.com27847de2011-02-22 20:59:41 +0000567
568 GrVertexBufferAllocPool* fDrawBufferVBAllocPool;
569 GrIndexBufferAllocPool* fDrawBufferIBAllocPool;
570 GrInOrderDrawBuffer* fDrawBuffer;
571
bsalomon@google.com205d4602011-04-25 12:43:45 +0000572 GrIndexBuffer* fAAFillRectIndexBuffer;
573 GrIndexBuffer* fAAStrokeRectIndexBuffer;
574
bsalomon@google.com27847de2011-02-22 20:59:41 +0000575 GrContext(GrGpu* gpu);
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000576
bsalomon@google.com205d4602011-04-25 12:43:45 +0000577 void fillAARect(GrDrawTarget* target,
578 const GrPaint& paint,
579 const GrRect& devRect);
580
581 void strokeAARect(GrDrawTarget* target,
582 const GrPaint& paint,
583 const GrRect& devRect,
584 const GrVec& devStrokeSize);
585
586 inline int aaFillRectIndexCount() const;
587 GrIndexBuffer* aaFillRectIndexBuffer();
588
589 inline int aaStrokeRectIndexCount() const;
590 GrIndexBuffer* aaStrokeRectIndexBuffer();
591
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000592 void setupDrawBuffer();
593
bsalomon@google.com27847de2011-02-22 20:59:41 +0000594 void flushDrawBuffer();
595
596 static void SetPaint(const GrPaint& paint, GrDrawTarget* target);
597
bsalomon@google.comfea37b52011-04-25 15:51:06 +0000598 bool finalizeTextureKey(GrTextureKey*,
599 const GrSamplerState&,
600 bool keyless) const;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000601
bsalomon@google.com27847de2011-02-22 20:59:41 +0000602 GrDrawTarget* prepareToDraw(const GrPaint& paint, DrawCategory drawType);
603
604 void drawClipIntoStencil();
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000605
606 GrPathRenderer* getPathRenderer(const GrDrawTarget* target,
607 GrPathIter* path,
608 GrPathFill fill);
609
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000610 struct OffscreenRecord;
611 // we currently only expose stage 0 through the paint so use stage 1. We
612 // use stage 1 for the offscreen.
613 enum {
614 kOffscreenStage = 1,
615 };
616
bsalomon@google.com8295dc12011-05-02 12:53:34 +0000617 bool doOffscreenAA(GrDrawTarget* target,
618 const GrPaint& paint,
619 bool isLines) const;
620
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000621 // sets up target to draw coverage to the supersampled render target
622 bool setupOffscreenAAPass1(GrDrawTarget* target,
623 bool requireStencil,
bsalomon@google.com8295dc12011-05-02 12:53:34 +0000624 const GrIRect& boundRect,
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000625 OffscreenRecord* record);
626
627 // sets up target to sample coverage of supersampled render target back
628 // to the main render target using stage kOffscreenStage.
bsalomon@google.com8295dc12011-05-02 12:53:34 +0000629 void offscreenAAPass2(GrDrawTarget* target,
630 const GrPaint& paint,
631 const GrIRect& boundRect,
632 OffscreenRecord* record);
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000633
bsalomon@google.com27847de2011-02-22 20:59:41 +0000634};
635
636/**
637 * Save/restore the view-matrix in the context.
638 */
639class GrAutoMatrix : GrNoncopyable {
640public:
641 GrAutoMatrix(GrContext* ctx) : fContext(ctx) {
642 fMatrix = ctx->getMatrix();
643 }
644 GrAutoMatrix(GrContext* ctx, const GrMatrix& matrix) : fContext(ctx) {
645 fMatrix = ctx->getMatrix();
646 ctx->setMatrix(matrix);
647 }
648 ~GrAutoMatrix() {
649 fContext->setMatrix(fMatrix);
650 }
651
652private:
653 GrContext* fContext;
654 GrMatrix fMatrix;
655};
656
657#endif
658
659#include "GrContext_impl.h"
bsalomon@google.com8295dc12011-05-02 12:53:34 +0000660