blob: cbe9e1244263d6db534e32002b23c5fee72897f4 [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.com398109c2011-04-14 18:40:27 +0000285 * Clear the entire render target, ignoring any clips
bsalomon@google.com27847de2011-02-22 20:59:41 +0000286 */
bsalomon@google.com398109c2011-04-14 18:40:27 +0000287 void clear(GrColor color);
bsalomon@google.com27847de2011-02-22 20:59:41 +0000288
289 /**
290 * Draw everywhere (respecting the clip) with the paint.
291 */
292 void drawPaint(const GrPaint& paint);
293
294 /**
295 * Draw the rect using a paint.
296 * @param paint describes how to color pixels.
297 * @param strokeWidth If strokeWidth < 0, then the rect is filled, else
298 * the rect is mitered stroked based on strokeWidth. If
299 * strokeWidth == 0, then the stroke is always a single
300 * pixel thick.
301 * @param matrix Optional matrix applied to the rect. Applied before
302 * context's matrix or the paint's matrix.
303 * The rects coords are used to access the paint (through texture matrix)
304 */
305 void drawRect(const GrPaint& paint,
306 const GrRect&,
307 GrScalar strokeWidth = -1,
308 const GrMatrix* matrix = NULL);
309
310 /**
311 * Maps a rect of paint coordinates onto the a rect of destination
312 * coordinates. Each rect can optionally be transformed. The srcRect
313 * is stretched over the dstRect. The dstRect is transformed by the
314 * context's matrix and the srcRect is transformed by the paint's matrix.
315 * Additional optional matrices can be provided by parameters.
316 *
317 * @param paint describes how to color pixels.
318 * @param dstRect the destination rect to draw.
319 * @param srcRect rect of paint coordinates to be mapped onto dstRect
320 * @param dstMatrix Optional matrix to transform dstRect. Applied before
321 * context's matrix.
322 * @param srcMatrix Optional matrix to transform srcRect Applied before
323 * paint's matrix.
324 */
325 void drawRectToRect(const GrPaint& paint,
326 const GrRect& dstRect,
327 const GrRect& srcRect,
328 const GrMatrix* dstMatrix = NULL,
329 const GrMatrix* srcMatrix = NULL);
330
331 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +0000332 * Draws a path.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000333 *
334 * @param paint describes how to color pixels.
bsalomon@google.comd302f142011-03-03 13:54:13 +0000335 * @param pathIter the path to draw
bsalomon@google.com27847de2011-02-22 20:59:41 +0000336 * @param fill the path filling rule to use.
337 * @param translate optional additional translation applied to the
338 * path.
339 */
340 void drawPath(const GrPaint& paint,
bsalomon@google.comd302f142011-03-03 13:54:13 +0000341 GrPathIter* pathIter,
342 GrPathFill fill,
343 const GrPoint* translate = NULL);
344 /**
345 * Helper version of drawPath that takes a GrPath
346 */
347 void drawPath(const GrPaint& paint,
348 const GrPath& path,
bsalomon@google.com27847de2011-02-22 20:59:41 +0000349 GrPathFill fill,
350 const GrPoint* translate = NULL);
351 /**
352 * Draws vertices with a paint.
353 *
354 * @param paint describes how to color pixels.
355 * @param primitiveType primitives type to draw.
356 * @param vertexCount number of vertices.
357 * @param positions array of vertex positions, required.
358 * @param texCoords optional array of texture coordinates used
359 * to access the paint.
360 * @param colors optional array of per-vertex colors, supercedes
361 * the paint's color field.
362 * @param indices optional array of indices. If NULL vertices
363 * are drawn non-indexed.
364 * @param indexCount if indices is non-null then this is the
365 * number of indices.
366 */
367 void drawVertices(const GrPaint& paint,
368 GrPrimitiveType primitiveType,
369 int vertexCount,
370 const GrPoint positions[],
371 const GrPoint texs[],
372 const GrColor colors[],
373 const uint16_t indices[],
374 int indexCount);
375
376 /**
377 * Similar to drawVertices but caller provides objects that convert to Gr
378 * types. The count of vertices is given by posSrc.
379 *
380 * @param paint describes how to color pixels.
381 * @param primitiveType primitives type to draw.
382 * @param posSrc Source of vertex positions. Must implement
383 * int count() const;
384 * void writeValue(int i, GrPoint* point) const;
385 * count returns the total number of vertices and
386 * writeValue writes a vertex position to point.
387 * @param texSrc optional, pass NULL to not use explicit tex
388 * coords. If present provides tex coords with
389 * method:
390 * void writeValue(int i, GrPoint* point) const;
391 * @param texSrc optional, pass NULL to not use per-vertex colors
392 * If present provides colors with method:
393 * void writeValue(int i, GrColor* point) const;
394 * @param indices optional, pass NULL for non-indexed drawing. If
395 * present supplies indices for indexed drawing
396 * with following methods:
397 * int count() const;
398 * void writeValue(int i, uint16_t* point) const;
399 * count returns the number of indices and
400 * writeValue supplies each index.
401 */
402 template <typename POS_SRC,
403 typename TEX_SRC,
404 typename COL_SRC,
405 typename IDX_SRC>
406 void drawCustomVertices(const GrPaint& paint,
407 GrPrimitiveType primitiveType,
408 const POS_SRC& posSrc,
409 const TEX_SRC* texCoordSrc,
410 const COL_SRC* colorSrc,
411 const IDX_SRC* idxSrc);
412 /**
413 * To avoid the problem of having to create a typename for NULL parameters,
414 * these reduced versions of drawCustomVertices are provided.
415 */
416 template <typename POS_SRC>
417 void drawCustomVertices(const GrPaint& paint,
418 GrPrimitiveType primitiveType,
419 const POS_SRC& posSrc);
420 template <typename POS_SRC, typename TEX_SRC>
421 void drawCustomVertices(const GrPaint& paint,
422 GrPrimitiveType primitiveType,
423 const POS_SRC& posSrc,
424 const TEX_SRC* texCoordSrc);
425 template <typename POS_SRC, typename TEX_SRC, typename COL_SRC>
426 void drawCustomVertices(const GrPaint& paint,
427 GrPrimitiveType primitiveType,
428 const POS_SRC& posSrc,
429 const TEX_SRC* texCoordSrc,
430 const COL_SRC* colorSrc);
431
432
433 ///////////////////////////////////////////////////////////////////////////
434 // Misc.
435
436 /**
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000437 * Flags that affect flush() behavior.
438 */
439 enum FlushBits {
440 /**
441 * A client may want Gr to bind a GrRenderTarget in the 3D API so that
442 * it can be rendered to directly. However, Gr lazily sets state. Simply
443 * calling setRenderTarget() followed by flush() without flags may not
444 * bind the render target. This flag forces the context to bind the last
445 * set render target in the 3D API.
446 */
447 kForceCurrentRenderTarget_FlushBit = 0x1,
448 /**
449 * A client may reach a point where it has partially rendered a frame
450 * through a GrContext that it knows the user will never see. This flag
451 * causes the flush to skip submission of deferred content to the 3D API
452 * during the flush.
453 */
454 kDiscard_FlushBit = 0x2,
455 };
456
457 /**
bsalomon@google.com27847de2011-02-22 20:59:41 +0000458 * Call to ensure all drawing to the context has been issued to the
459 * underlying 3D API.
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000460 * @param flagsBitfield flags that control the flushing behavior. See
461 * FlushBits.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000462 */
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000463 void flush(int flagsBitfield = 0);
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000464
bsalomon@google.com27847de2011-02-22 20:59:41 +0000465 /**
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000466 * Reads a rectangle of pixels from a render target.
467 * @param renderTarget the render target to read from. NULL means the
468 * current render target.
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 or because no render
478 * target is currently set.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000479 */
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000480 bool readRenderTargetPixels(GrRenderTarget* target,
481 int left, int top, int width, int height,
482 GrPixelConfig config, void* buffer);
483
484 /**
485 * Reads a rectangle of pixels from a texture.
486 * @param texture the render target to read from.
487 * @param left left edge of the rectangle to read (inclusive)
488 * @param top top edge of the rectangle to read (inclusive)
489 * @param width width of rectangle to read in pixels.
490 * @param height height of rectangle to read in pixels.
491 * @param config the pixel config of the destination buffer
492 * @param buffer memory to read the rectangle into.
493 *
494 * @return true if the read succeeded, false if not. The read can fail
495 * because of a unsupported pixel config.
496 */
497 bool readTexturePixels(GrTexture* target,
498 int left, int top, int width, int height,
499 GrPixelConfig config, void* buffer);
bsalomon@google.com27847de2011-02-22 20:59:41 +0000500
501 /**
502 * Copy the src pixels [buffer, stride, pixelconfig] into the current
503 * render-target at the specified rectangle.
504 */
505 void writePixels(int left, int top, int width, int height,
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000506 GrPixelConfig, const void* buffer, size_t stride);
bsalomon@google.com27847de2011-02-22 20:59:41 +0000507
508
509 ///////////////////////////////////////////////////////////////////////////
510 // Statistics
511
512 void resetStats();
513
514 const GrGpu::Stats& getStats() const;
515
516 void printStats() const;
517
518 ///////////////////////////////////////////////////////////////////////////
519 // Helpers
520
521 class AutoRenderTarget : ::GrNoncopyable {
522 public:
523 AutoRenderTarget(GrContext* context, GrRenderTarget* target) {
524 fContext = NULL;
525 fPrevTarget = context->getRenderTarget();
526 if (fPrevTarget != target) {
527 context->setRenderTarget(target);
528 fContext = context;
529 }
530 }
531 ~AutoRenderTarget() {
532 if (fContext) {
533 fContext->setRenderTarget(fPrevTarget);
534 }
535 }
536 private:
537 GrContext* fContext;
538 GrRenderTarget* fPrevTarget;
539 };
540
541
542 ///////////////////////////////////////////////////////////////////////////
543 // Functions intended for internal use only.
544 GrGpu* getGpu() { return fGpu; }
545 GrFontCache* getFontCache() { return fFontCache; }
546 GrDrawTarget* getTextTarget(const GrPaint& paint);
547 void flushText();
548 const GrIndexBuffer* getQuadIndexBuffer() const;
549
550private:
551 // used to keep track of when we need to flush the draw buffer
552 enum DrawCategory {
553 kBuffered_DrawCategory, // last draw was inserted in draw buffer
554 kUnbuffered_DrawCategory, // last draw was not inserted in the draw buffer
555 kText_DrawCategory // text context was last to draw
556 };
557 DrawCategory fLastDrawCategory;
558
559 GrGpu* fGpu;
560 GrTextureCache* fTextureCache;
561 GrFontCache* fFontCache;
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000562
563 GrPathRenderer* fCustomPathRenderer;
564 GrDefaultPathRenderer fDefaultPathRenderer;
bsalomon@google.com27847de2011-02-22 20:59:41 +0000565
566 GrVertexBufferAllocPool* fDrawBufferVBAllocPool;
567 GrIndexBufferAllocPool* fDrawBufferIBAllocPool;
568 GrInOrderDrawBuffer* fDrawBuffer;
569
bsalomon@google.com205d4602011-04-25 12:43:45 +0000570 GrIndexBuffer* fAAFillRectIndexBuffer;
571 GrIndexBuffer* fAAStrokeRectIndexBuffer;
572
bsalomon@google.com27847de2011-02-22 20:59:41 +0000573 GrContext(GrGpu* gpu);
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000574
bsalomon@google.com205d4602011-04-25 12:43:45 +0000575 void fillAARect(GrDrawTarget* target,
576 const GrPaint& paint,
577 const GrRect& devRect);
578
579 void strokeAARect(GrDrawTarget* target,
580 const GrPaint& paint,
581 const GrRect& devRect,
582 const GrVec& devStrokeSize);
583
584 inline int aaFillRectIndexCount() const;
585 GrIndexBuffer* aaFillRectIndexBuffer();
586
587 inline int aaStrokeRectIndexCount() const;
588 GrIndexBuffer* aaStrokeRectIndexBuffer();
589
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000590 void setupDrawBuffer();
591
bsalomon@google.com27847de2011-02-22 20:59:41 +0000592 void flushDrawBuffer();
593
594 static void SetPaint(const GrPaint& paint, GrDrawTarget* target);
595
bsalomon@google.comfea37b52011-04-25 15:51:06 +0000596 bool finalizeTextureKey(GrTextureKey*,
597 const GrSamplerState&,
598 bool keyless) const;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000599
bsalomon@google.com27847de2011-02-22 20:59:41 +0000600 GrDrawTarget* prepareToDraw(const GrPaint& paint, DrawCategory drawType);
601
602 void drawClipIntoStencil();
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000603
604 GrPathRenderer* getPathRenderer(const GrDrawTarget* target,
605 GrPathIter* path,
606 GrPathFill fill);
607
bsalomon@google.com27847de2011-02-22 20:59:41 +0000608};
609
610/**
611 * Save/restore the view-matrix in the context.
612 */
613class GrAutoMatrix : GrNoncopyable {
614public:
615 GrAutoMatrix(GrContext* ctx) : fContext(ctx) {
616 fMatrix = ctx->getMatrix();
617 }
618 GrAutoMatrix(GrContext* ctx, const GrMatrix& matrix) : fContext(ctx) {
619 fMatrix = ctx->getMatrix();
620 ctx->setMatrix(matrix);
621 }
622 ~GrAutoMatrix() {
623 fContext->setMatrix(fMatrix);
624 }
625
626private:
627 GrContext* fContext;
628 GrMatrix fMatrix;
629};
630
631#endif
632
633#include "GrContext_impl.h"