blob: 395eb563e0132f7396fb6ee0c7aea56c603fd51f [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.
102 */
103 GrTextureEntry* lockKeylessTexture(const GrTextureDesc& desc,
104 const GrSamplerState& state);
105
106 /**
bsalomon@google.com27847de2011-02-22 20:59:41 +0000107 * When done with an entry, call unlockTexture(entry) on it, which returns
108 * it to the cache, where it may be purged.
109 */
110 void unlockTexture(GrTextureEntry* entry);
111
112 /**
bsalomon@google.com27847de2011-02-22 20:59:41 +0000113 * Creates a texture that is outside the cache. Does not count against
114 * cache's budget.
115 */
bsalomon@google.comfea37b52011-04-25 15:51:06 +0000116 GrTexture* createUncachedTexture(const GrTextureDesc&,
bsalomon@google.com27847de2011-02-22 20:59:41 +0000117 void* srcData,
118 size_t rowBytes);
119
120 /**
121 * Returns true if the specified use of an indexed texture is supported.
122 */
123 bool supportsIndex8PixelConfig(const GrSamplerState&, int width, int height);
124
125 /**
126 * Return the current texture cache limits.
127 *
128 * @param maxTextures If non-null, returns maximum number of textures that
129 * can be held in the cache.
130 * @param maxTextureBytes If non-null, returns maximum number of bytes of
131 * texture memory that can be held in the cache.
132 */
133 void getTextureCacheLimits(int* maxTextures, size_t* maxTextureBytes) const;
134
135 /**
136 * Specify the texture cache limits. If the current cache exceeds either
137 * of these, it will be purged (LRU) to keep the cache within these limits.
138 *
139 * @param maxTextures The maximum number of textures that can be held in
140 * the cache.
141 * @param maxTextureBytes The maximum number of bytes of texture memory
142 * that can be held in the cache.
143 */
144 void setTextureCacheLimits(int maxTextures, size_t maxTextureBytes);
145
146 /**
147 * Return the max width or height of a texture supported by the current gpu
148 */
149 int getMaxTextureDimension();
150
151 ///////////////////////////////////////////////////////////////////////////
152 // Render targets
153
154 /**
bsalomon@google.com5877ffd2011-04-11 17:58:48 +0000155 * Sets the render target.
156 * @param target the render target to set. (should not be NULL.)
157 */
158 void setRenderTarget(GrRenderTarget* target);
159
160 /**
161 * Gets the current render target.
162 * @return the currently bound render target. Should never be NULL.
163 */
164 const GrRenderTarget* getRenderTarget() const;
165 GrRenderTarget* getRenderTarget();
166
167 ///////////////////////////////////////////////////////////////////////////
168 // Platform Surfaces
169
170 // GrContext provides an interface for wrapping externally created textures
171 // and rendertargets in their Gr-equivalents.
172
173 /**
174 * Wraps an existing 3D API surface in a GrObject. desc.fFlags determines
175 * the type of object returned. If kIsTexture is set the returned object
176 * will be a GrTexture*. Otherwise, it will be a GrRenderTarget*. If both
177 * are set the render target object is accessible by
178 * GrTexture::asRenderTarget().
179 *
180 * GL: if the object is a texture Gr may change its GL texture parameters
181 * when it is drawn.
182 *
183 * @param desc description of the object to create.
184 * @return either a GrTexture* or GrRenderTarget* depending on desc. NULL
185 * on failure.
186 */
187 GrResource* createPlatformSurface(const GrPlatformSurfaceDesc& desc);
188
189 /**
190 * DEPRECATED, WILL BE REMOVED SOON. USE createPlatformSurface.
191 *
bsalomon@google.com27847de2011-02-22 20:59:41 +0000192 * Wraps an externally-created rendertarget in a GrRenderTarget.
193 * @param platformRenderTarget 3D API-specific render target identifier
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000194 * e.g. in GL platforamRenderTarget is an FBO
bsalomon@google.com27847de2011-02-22 20:59:41 +0000195 * id.
196 * @param stencilBits the number of stencil bits that the render
197 * target has.
bsalomon@google.comf954d8d2011-04-06 17:50:02 +0000198 * @param isMultisampled specify whether the render target is
199 * multisampled.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000200 * @param width width of the render target.
201 * @param height height of the render target.
202 */
203 GrRenderTarget* createPlatformRenderTarget(intptr_t platformRenderTarget,
204 int stencilBits,
bsalomon@google.comf954d8d2011-04-06 17:50:02 +0000205 bool isMultisampled,
bsalomon@google.com5877ffd2011-04-11 17:58:48 +0000206 int width, int height) {
207 #if GR_DEBUG
208 GrPrintf("Using deprecated createPlatformRenderTarget API.");
209 #endif
210 return fGpu->createPlatformRenderTarget(platformRenderTarget,
211 stencilBits, isMultisampled,
212 width, height);
213 }
bsalomon@google.com27847de2011-02-22 20:59:41 +0000214
215 /**
bsalomon@google.com5877ffd2011-04-11 17:58:48 +0000216 * DEPRECATED, WILL BE REMOVED SOON. USE createPlatformSurface.
217 *
bsalomon@google.com27847de2011-02-22 20:59:41 +0000218 * Reads the current target object (e.g. FBO or IDirect3DSurface9*) and
219 * viewport state from the underlying 3D API and wraps it in a
220 * GrRenderTarget. The GrRenderTarget will not attempt to delete/destroy the
221 * underlying object in its destructor and it is up to caller to guarantee
222 * that it remains valid while the GrRenderTarget is used.
223 *
224 * @return the newly created GrRenderTarget
225 */
226 GrRenderTarget* createRenderTargetFrom3DApiState() {
bsalomon@google.com5877ffd2011-04-11 17:58:48 +0000227 #if GR_DEBUG
228 GrPrintf("Using deprecated createRenderTargetFrom3DApiState API.");
229 #endif
bsalomon@google.com27847de2011-02-22 20:59:41 +0000230 return fGpu->createRenderTargetFrom3DApiState();
231 }
232
bsalomon@google.com27847de2011-02-22 20:59:41 +0000233 ///////////////////////////////////////////////////////////////////////////
234 // Matrix state
235
236 /**
237 * Gets the current transformation matrix.
238 * @return the current matrix.
239 */
240 const GrMatrix& getMatrix() const;
241
242 /**
243 * Sets the transformation matrix.
244 * @param m the matrix to set.
245 */
246 void setMatrix(const GrMatrix& m);
247
248 /**
249 * Concats the current matrix. The passed matrix is applied before the
250 * current matrix.
251 * @param m the matrix to concat.
252 */
253 void concatMatrix(const GrMatrix& m) const;
254
255
256 ///////////////////////////////////////////////////////////////////////////
257 // Clip state
258 /**
259 * Gets the current clip.
260 * @return the current clip.
261 */
262 const GrClip& getClip() const { return fGpu->getClip(); }
263
264 /**
265 * Sets the clip.
266 * @param clip the clip to set.
267 */
268 void setClip(const GrClip& clip);
269
270 /**
271 * Convenience method for setting the clip to a rect.
272 * @param rect the rect to set as the new clip.
273 */
274 void setClip(const GrIRect& rect);
275
276 ///////////////////////////////////////////////////////////////////////////
277 // Draws
278
279 /**
bsalomon@google.com398109c2011-04-14 18:40:27 +0000280 * Clear the entire render target, ignoring any clips
bsalomon@google.com27847de2011-02-22 20:59:41 +0000281 */
bsalomon@google.com398109c2011-04-14 18:40:27 +0000282 void clear(GrColor color);
bsalomon@google.com27847de2011-02-22 20:59:41 +0000283
284 /**
285 * Draw everywhere (respecting the clip) with the paint.
286 */
287 void drawPaint(const GrPaint& paint);
288
289 /**
290 * Draw the rect using a paint.
291 * @param paint describes how to color pixels.
292 * @param strokeWidth If strokeWidth < 0, then the rect is filled, else
293 * the rect is mitered stroked based on strokeWidth. If
294 * strokeWidth == 0, then the stroke is always a single
295 * pixel thick.
296 * @param matrix Optional matrix applied to the rect. Applied before
297 * context's matrix or the paint's matrix.
298 * The rects coords are used to access the paint (through texture matrix)
299 */
300 void drawRect(const GrPaint& paint,
301 const GrRect&,
302 GrScalar strokeWidth = -1,
303 const GrMatrix* matrix = NULL);
304
305 /**
306 * Maps a rect of paint coordinates onto the a rect of destination
307 * coordinates. Each rect can optionally be transformed. The srcRect
308 * is stretched over the dstRect. The dstRect is transformed by the
309 * context's matrix and the srcRect is transformed by the paint's matrix.
310 * Additional optional matrices can be provided by parameters.
311 *
312 * @param paint describes how to color pixels.
313 * @param dstRect the destination rect to draw.
314 * @param srcRect rect of paint coordinates to be mapped onto dstRect
315 * @param dstMatrix Optional matrix to transform dstRect. Applied before
316 * context's matrix.
317 * @param srcMatrix Optional matrix to transform srcRect Applied before
318 * paint's matrix.
319 */
320 void drawRectToRect(const GrPaint& paint,
321 const GrRect& dstRect,
322 const GrRect& srcRect,
323 const GrMatrix* dstMatrix = NULL,
324 const GrMatrix* srcMatrix = NULL);
325
326 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +0000327 * Draws a path.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000328 *
329 * @param paint describes how to color pixels.
bsalomon@google.comd302f142011-03-03 13:54:13 +0000330 * @param pathIter the path to draw
bsalomon@google.com27847de2011-02-22 20:59:41 +0000331 * @param fill the path filling rule to use.
332 * @param translate optional additional translation applied to the
333 * path.
334 */
335 void drawPath(const GrPaint& paint,
bsalomon@google.comd302f142011-03-03 13:54:13 +0000336 GrPathIter* pathIter,
337 GrPathFill fill,
338 const GrPoint* translate = NULL);
339 /**
340 * Helper version of drawPath that takes a GrPath
341 */
342 void drawPath(const GrPaint& paint,
343 const GrPath& path,
bsalomon@google.com27847de2011-02-22 20:59:41 +0000344 GrPathFill fill,
345 const GrPoint* translate = NULL);
346 /**
347 * Draws vertices with a paint.
348 *
349 * @param paint describes how to color pixels.
350 * @param primitiveType primitives type to draw.
351 * @param vertexCount number of vertices.
352 * @param positions array of vertex positions, required.
353 * @param texCoords optional array of texture coordinates used
354 * to access the paint.
355 * @param colors optional array of per-vertex colors, supercedes
356 * the paint's color field.
357 * @param indices optional array of indices. If NULL vertices
358 * are drawn non-indexed.
359 * @param indexCount if indices is non-null then this is the
360 * number of indices.
361 */
362 void drawVertices(const GrPaint& paint,
363 GrPrimitiveType primitiveType,
364 int vertexCount,
365 const GrPoint positions[],
366 const GrPoint texs[],
367 const GrColor colors[],
368 const uint16_t indices[],
369 int indexCount);
370
371 /**
372 * Similar to drawVertices but caller provides objects that convert to Gr
373 * types. The count of vertices is given by posSrc.
374 *
375 * @param paint describes how to color pixels.
376 * @param primitiveType primitives type to draw.
377 * @param posSrc Source of vertex positions. Must implement
378 * int count() const;
379 * void writeValue(int i, GrPoint* point) const;
380 * count returns the total number of vertices and
381 * writeValue writes a vertex position to point.
382 * @param texSrc optional, pass NULL to not use explicit tex
383 * coords. If present provides tex coords with
384 * method:
385 * void writeValue(int i, GrPoint* point) const;
386 * @param texSrc optional, pass NULL to not use per-vertex colors
387 * If present provides colors with method:
388 * void writeValue(int i, GrColor* point) const;
389 * @param indices optional, pass NULL for non-indexed drawing. If
390 * present supplies indices for indexed drawing
391 * with following methods:
392 * int count() const;
393 * void writeValue(int i, uint16_t* point) const;
394 * count returns the number of indices and
395 * writeValue supplies each index.
396 */
397 template <typename POS_SRC,
398 typename TEX_SRC,
399 typename COL_SRC,
400 typename IDX_SRC>
401 void drawCustomVertices(const GrPaint& paint,
402 GrPrimitiveType primitiveType,
403 const POS_SRC& posSrc,
404 const TEX_SRC* texCoordSrc,
405 const COL_SRC* colorSrc,
406 const IDX_SRC* idxSrc);
407 /**
408 * To avoid the problem of having to create a typename for NULL parameters,
409 * these reduced versions of drawCustomVertices are provided.
410 */
411 template <typename POS_SRC>
412 void drawCustomVertices(const GrPaint& paint,
413 GrPrimitiveType primitiveType,
414 const POS_SRC& posSrc);
415 template <typename POS_SRC, typename TEX_SRC>
416 void drawCustomVertices(const GrPaint& paint,
417 GrPrimitiveType primitiveType,
418 const POS_SRC& posSrc,
419 const TEX_SRC* texCoordSrc);
420 template <typename POS_SRC, typename TEX_SRC, typename COL_SRC>
421 void drawCustomVertices(const GrPaint& paint,
422 GrPrimitiveType primitiveType,
423 const POS_SRC& posSrc,
424 const TEX_SRC* texCoordSrc,
425 const COL_SRC* colorSrc);
426
427
428 ///////////////////////////////////////////////////////////////////////////
429 // Misc.
430
431 /**
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000432 * Flags that affect flush() behavior.
433 */
434 enum FlushBits {
435 /**
436 * A client may want Gr to bind a GrRenderTarget in the 3D API so that
437 * it can be rendered to directly. However, Gr lazily sets state. Simply
438 * calling setRenderTarget() followed by flush() without flags may not
439 * bind the render target. This flag forces the context to bind the last
440 * set render target in the 3D API.
441 */
442 kForceCurrentRenderTarget_FlushBit = 0x1,
443 /**
444 * A client may reach a point where it has partially rendered a frame
445 * through a GrContext that it knows the user will never see. This flag
446 * causes the flush to skip submission of deferred content to the 3D API
447 * during the flush.
448 */
449 kDiscard_FlushBit = 0x2,
450 };
451
452 /**
bsalomon@google.com27847de2011-02-22 20:59:41 +0000453 * Call to ensure all drawing to the context has been issued to the
454 * underlying 3D API.
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000455 * @param flagsBitfield flags that control the flushing behavior. See
456 * FlushBits.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000457 */
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000458 void flush(int flagsBitfield = 0);
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000459
bsalomon@google.com27847de2011-02-22 20:59:41 +0000460 /**
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000461 * Reads a rectangle of pixels from a render target.
462 * @param renderTarget the render target to read from. NULL means the
463 * current render target.
464 * @param left left edge of the rectangle to read (inclusive)
465 * @param top top edge of the rectangle to read (inclusive)
466 * @param width width of rectangle to read in pixels.
467 * @param height height of rectangle to read in pixels.
468 * @param config the pixel config of the destination buffer
469 * @param buffer memory to read the rectangle into.
470 *
471 * @return true if the read succeeded, false if not. The read can fail
472 * because of a unsupported pixel config or because no render
473 * target is currently set.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000474 */
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000475 bool readRenderTargetPixels(GrRenderTarget* target,
476 int left, int top, int width, int height,
477 GrPixelConfig config, void* buffer);
478
479 /**
480 * Reads a rectangle of pixels from a texture.
481 * @param texture the render target to read from.
482 * @param left left edge of the rectangle to read (inclusive)
483 * @param top top edge of the rectangle to read (inclusive)
484 * @param width width of rectangle to read in pixels.
485 * @param height height of rectangle to read in pixels.
486 * @param config the pixel config of the destination buffer
487 * @param buffer memory to read the rectangle into.
488 *
489 * @return true if the read succeeded, false if not. The read can fail
490 * because of a unsupported pixel config.
491 */
492 bool readTexturePixels(GrTexture* target,
493 int left, int top, int width, int height,
494 GrPixelConfig config, void* buffer);
bsalomon@google.com27847de2011-02-22 20:59:41 +0000495
496 /**
497 * Copy the src pixels [buffer, stride, pixelconfig] into the current
498 * render-target at the specified rectangle.
499 */
500 void writePixels(int left, int top, int width, int height,
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000501 GrPixelConfig, const void* buffer, size_t stride);
bsalomon@google.com27847de2011-02-22 20:59:41 +0000502
503
504 ///////////////////////////////////////////////////////////////////////////
505 // Statistics
506
507 void resetStats();
508
509 const GrGpu::Stats& getStats() const;
510
511 void printStats() const;
512
513 ///////////////////////////////////////////////////////////////////////////
514 // Helpers
515
516 class AutoRenderTarget : ::GrNoncopyable {
517 public:
518 AutoRenderTarget(GrContext* context, GrRenderTarget* target) {
519 fContext = NULL;
520 fPrevTarget = context->getRenderTarget();
521 if (fPrevTarget != target) {
522 context->setRenderTarget(target);
523 fContext = context;
524 }
525 }
526 ~AutoRenderTarget() {
527 if (fContext) {
528 fContext->setRenderTarget(fPrevTarget);
529 }
530 }
531 private:
532 GrContext* fContext;
533 GrRenderTarget* fPrevTarget;
534 };
535
536
537 ///////////////////////////////////////////////////////////////////////////
538 // Functions intended for internal use only.
539 GrGpu* getGpu() { return fGpu; }
540 GrFontCache* getFontCache() { return fFontCache; }
541 GrDrawTarget* getTextTarget(const GrPaint& paint);
542 void flushText();
543 const GrIndexBuffer* getQuadIndexBuffer() const;
544
545private:
546 // used to keep track of when we need to flush the draw buffer
547 enum DrawCategory {
548 kBuffered_DrawCategory, // last draw was inserted in draw buffer
549 kUnbuffered_DrawCategory, // last draw was not inserted in the draw buffer
550 kText_DrawCategory // text context was last to draw
551 };
552 DrawCategory fLastDrawCategory;
553
554 GrGpu* fGpu;
555 GrTextureCache* fTextureCache;
556 GrFontCache* fFontCache;
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000557
558 GrPathRenderer* fCustomPathRenderer;
559 GrDefaultPathRenderer fDefaultPathRenderer;
bsalomon@google.com27847de2011-02-22 20:59:41 +0000560
561 GrVertexBufferAllocPool* fDrawBufferVBAllocPool;
562 GrIndexBufferAllocPool* fDrawBufferIBAllocPool;
563 GrInOrderDrawBuffer* fDrawBuffer;
564
bsalomon@google.com205d4602011-04-25 12:43:45 +0000565 GrIndexBuffer* fAAFillRectIndexBuffer;
566 GrIndexBuffer* fAAStrokeRectIndexBuffer;
567
bsalomon@google.com27847de2011-02-22 20:59:41 +0000568 GrContext(GrGpu* gpu);
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000569
bsalomon@google.com205d4602011-04-25 12:43:45 +0000570 void fillAARect(GrDrawTarget* target,
571 const GrPaint& paint,
572 const GrRect& devRect);
573
574 void strokeAARect(GrDrawTarget* target,
575 const GrPaint& paint,
576 const GrRect& devRect,
577 const GrVec& devStrokeSize);
578
579 inline int aaFillRectIndexCount() const;
580 GrIndexBuffer* aaFillRectIndexBuffer();
581
582 inline int aaStrokeRectIndexCount() const;
583 GrIndexBuffer* aaStrokeRectIndexBuffer();
584
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000585 void setupDrawBuffer();
586
bsalomon@google.com27847de2011-02-22 20:59:41 +0000587 void flushDrawBuffer();
588
589 static void SetPaint(const GrPaint& paint, GrDrawTarget* target);
590
bsalomon@google.comfea37b52011-04-25 15:51:06 +0000591 bool finalizeTextureKey(GrTextureKey*,
592 const GrSamplerState&,
593 bool keyless) const;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000594
bsalomon@google.com27847de2011-02-22 20:59:41 +0000595 GrDrawTarget* prepareToDraw(const GrPaint& paint, DrawCategory drawType);
596
597 void drawClipIntoStencil();
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000598
599 GrPathRenderer* getPathRenderer(const GrDrawTarget* target,
600 GrPathIter* path,
601 GrPathFill fill);
602
bsalomon@google.com27847de2011-02-22 20:59:41 +0000603};
604
605/**
606 * Save/restore the view-matrix in the context.
607 */
608class GrAutoMatrix : GrNoncopyable {
609public:
610 GrAutoMatrix(GrContext* ctx) : fContext(ctx) {
611 fMatrix = ctx->getMatrix();
612 }
613 GrAutoMatrix(GrContext* ctx, const GrMatrix& matrix) : fContext(ctx) {
614 fMatrix = ctx->getMatrix();
615 ctx->setMatrix(matrix);
616 }
617 ~GrAutoMatrix() {
618 fContext->setMatrix(fMatrix);
619 }
620
621private:
622 GrContext* fContext;
623 GrMatrix fMatrix;
624};
625
626#endif
627
628#include "GrContext_impl.h"