blob: 58c53ba27e3b977cea6ab5d736bd9d3b929cd11e [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);
bsalomon@google.com5877ffd2011-04-11 17:58:48 +0000193 /**
bsalomon@google.com27847de2011-02-22 20:59:41 +0000194 * Reads the current target object (e.g. FBO or IDirect3DSurface9*) and
195 * viewport state from the underlying 3D API and wraps it in a
196 * GrRenderTarget. The GrRenderTarget will not attempt to delete/destroy the
197 * underlying object in its destructor and it is up to caller to guarantee
198 * that it remains valid while the GrRenderTarget is used.
199 *
bsalomon@google.com2368f6f2011-05-19 21:22:39 +0000200 * Will not detect that the render target is also a texture. If you need
201 * to also use the render target as a GrTexture use createPlatformSurface.
202 *
bsalomon@google.com27847de2011-02-22 20:59:41 +0000203 * @return the newly created GrRenderTarget
204 */
bsalomon@google.com05ef5102011-05-02 21:14:59 +0000205 GrRenderTarget* createRenderTargetFrom3DApiState();
bsalomon@google.com27847de2011-02-22 20:59:41 +0000206
bsalomon@google.com27847de2011-02-22 20:59:41 +0000207 ///////////////////////////////////////////////////////////////////////////
208 // Matrix state
209
210 /**
211 * Gets the current transformation matrix.
212 * @return the current matrix.
213 */
214 const GrMatrix& getMatrix() const;
215
216 /**
217 * Sets the transformation matrix.
218 * @param m the matrix to set.
219 */
220 void setMatrix(const GrMatrix& m);
221
222 /**
223 * Concats the current matrix. The passed matrix is applied before the
224 * current matrix.
225 * @param m the matrix to concat.
226 */
227 void concatMatrix(const GrMatrix& m) const;
228
229
230 ///////////////////////////////////////////////////////////////////////////
231 // Clip state
232 /**
233 * Gets the current clip.
234 * @return the current clip.
235 */
bsalomon@google.com05ef5102011-05-02 21:14:59 +0000236 const GrClip& getClip() const;
bsalomon@google.com27847de2011-02-22 20:59:41 +0000237
238 /**
239 * Sets the clip.
240 * @param clip the clip to set.
241 */
242 void setClip(const GrClip& clip);
243
244 /**
245 * Convenience method for setting the clip to a rect.
246 * @param rect the rect to set as the new clip.
247 */
248 void setClip(const GrIRect& rect);
249
250 ///////////////////////////////////////////////////////////////////////////
251 // Draws
252
253 /**
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000254 * Clear the entire or rect of the render target, ignoring any clips.
255 * @param rect the rect to clear or the whole thing if rect is NULL.
256 * @param color the color to clear to.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000257 */
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000258 void clear(const GrIRect* rect, GrColor color);
bsalomon@google.com27847de2011-02-22 20:59:41 +0000259
260 /**
261 * Draw everywhere (respecting the clip) with the paint.
262 */
263 void drawPaint(const GrPaint& paint);
264
265 /**
266 * Draw the rect using a paint.
267 * @param paint describes how to color pixels.
268 * @param strokeWidth If strokeWidth < 0, then the rect is filled, else
269 * the rect is mitered stroked based on strokeWidth. If
270 * strokeWidth == 0, then the stroke is always a single
271 * pixel thick.
272 * @param matrix Optional matrix applied to the rect. Applied before
273 * context's matrix or the paint's matrix.
274 * The rects coords are used to access the paint (through texture matrix)
275 */
276 void drawRect(const GrPaint& paint,
277 const GrRect&,
278 GrScalar strokeWidth = -1,
279 const GrMatrix* matrix = NULL);
280
281 /**
282 * Maps a rect of paint coordinates onto the a rect of destination
283 * coordinates. Each rect can optionally be transformed. The srcRect
284 * is stretched over the dstRect. The dstRect is transformed by the
285 * context's matrix and the srcRect is transformed by the paint's matrix.
286 * Additional optional matrices can be provided by parameters.
287 *
288 * @param paint describes how to color pixels.
289 * @param dstRect the destination rect to draw.
290 * @param srcRect rect of paint coordinates to be mapped onto dstRect
291 * @param dstMatrix Optional matrix to transform dstRect. Applied before
292 * context's matrix.
293 * @param srcMatrix Optional matrix to transform srcRect Applied before
294 * paint's matrix.
295 */
296 void drawRectToRect(const GrPaint& paint,
297 const GrRect& dstRect,
298 const GrRect& srcRect,
299 const GrMatrix* dstMatrix = NULL,
300 const GrMatrix* srcMatrix = NULL);
301
302 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +0000303 * Draws a path.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000304 *
305 * @param paint describes how to color pixels.
reed@google.com07f3ee12011-05-16 17:21:57 +0000306 * @param path the path to draw
bsalomon@google.com27847de2011-02-22 20:59:41 +0000307 * @param fill the path filling rule to use.
308 * @param translate optional additional translation applied to the
309 * path.
310 */
reed@google.com07f3ee12011-05-16 17:21:57 +0000311 void drawPath(const GrPaint& paint, const GrPath& path, GrPathFill fill,
bsalomon@google.comd302f142011-03-03 13:54:13 +0000312 const GrPoint* translate = NULL);
reed@google.com07f3ee12011-05-16 17:21:57 +0000313
bsalomon@google.com27847de2011-02-22 20:59:41 +0000314 /**
315 * Draws vertices with a paint.
316 *
317 * @param paint describes how to color pixels.
318 * @param primitiveType primitives type to draw.
319 * @param vertexCount number of vertices.
320 * @param positions array of vertex positions, required.
321 * @param texCoords optional array of texture coordinates used
322 * to access the paint.
323 * @param colors optional array of per-vertex colors, supercedes
324 * the paint's color field.
325 * @param indices optional array of indices. If NULL vertices
326 * are drawn non-indexed.
327 * @param indexCount if indices is non-null then this is the
328 * number of indices.
329 */
330 void drawVertices(const GrPaint& paint,
331 GrPrimitiveType primitiveType,
332 int vertexCount,
333 const GrPoint positions[],
334 const GrPoint texs[],
335 const GrColor colors[],
336 const uint16_t indices[],
337 int indexCount);
338
339 /**
340 * Similar to drawVertices but caller provides objects that convert to Gr
341 * types. The count of vertices is given by posSrc.
342 *
343 * @param paint describes how to color pixels.
344 * @param primitiveType primitives type to draw.
345 * @param posSrc Source of vertex positions. Must implement
346 * int count() const;
347 * void writeValue(int i, GrPoint* point) const;
348 * count returns the total number of vertices and
349 * writeValue writes a vertex position to point.
350 * @param texSrc optional, pass NULL to not use explicit tex
351 * coords. If present provides tex coords with
352 * method:
353 * void writeValue(int i, GrPoint* point) const;
354 * @param texSrc optional, pass NULL to not use per-vertex colors
355 * If present provides colors with method:
356 * void writeValue(int i, GrColor* point) const;
357 * @param indices optional, pass NULL for non-indexed drawing. If
358 * present supplies indices for indexed drawing
359 * with following methods:
360 * int count() const;
361 * void writeValue(int i, uint16_t* point) const;
362 * count returns the number of indices and
363 * writeValue supplies each index.
364 */
365 template <typename POS_SRC,
366 typename TEX_SRC,
367 typename COL_SRC,
368 typename IDX_SRC>
369 void drawCustomVertices(const GrPaint& paint,
370 GrPrimitiveType primitiveType,
371 const POS_SRC& posSrc,
372 const TEX_SRC* texCoordSrc,
373 const COL_SRC* colorSrc,
374 const IDX_SRC* idxSrc);
375 /**
376 * To avoid the problem of having to create a typename for NULL parameters,
377 * these reduced versions of drawCustomVertices are provided.
378 */
379 template <typename POS_SRC>
380 void drawCustomVertices(const GrPaint& paint,
381 GrPrimitiveType primitiveType,
382 const POS_SRC& posSrc);
383 template <typename POS_SRC, typename TEX_SRC>
384 void drawCustomVertices(const GrPaint& paint,
385 GrPrimitiveType primitiveType,
386 const POS_SRC& posSrc,
387 const TEX_SRC* texCoordSrc);
388 template <typename POS_SRC, typename TEX_SRC, typename COL_SRC>
389 void drawCustomVertices(const GrPaint& paint,
390 GrPrimitiveType primitiveType,
391 const POS_SRC& posSrc,
392 const TEX_SRC* texCoordSrc,
393 const COL_SRC* colorSrc);
394
395
396 ///////////////////////////////////////////////////////////////////////////
397 // Misc.
398
399 /**
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000400 * Flags that affect flush() behavior.
401 */
402 enum FlushBits {
403 /**
404 * A client may want Gr to bind a GrRenderTarget in the 3D API so that
405 * it can be rendered to directly. However, Gr lazily sets state. Simply
406 * calling setRenderTarget() followed by flush() without flags may not
407 * bind the render target. This flag forces the context to bind the last
408 * set render target in the 3D API.
409 */
410 kForceCurrentRenderTarget_FlushBit = 0x1,
411 /**
412 * A client may reach a point where it has partially rendered a frame
413 * through a GrContext that it knows the user will never see. This flag
414 * causes the flush to skip submission of deferred content to the 3D API
415 * during the flush.
416 */
417 kDiscard_FlushBit = 0x2,
418 };
419
420 /**
bsalomon@google.com27847de2011-02-22 20:59:41 +0000421 * Call to ensure all drawing to the context has been issued to the
422 * underlying 3D API.
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000423 * @param flagsBitfield flags that control the flushing behavior. See
424 * FlushBits.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000425 */
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000426 void flush(int flagsBitfield = 0);
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000427
bsalomon@google.com27847de2011-02-22 20:59:41 +0000428 /**
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000429 * Reads a rectangle of pixels from a render target.
430 * @param renderTarget the render target to read from. NULL means the
431 * current render target.
432 * @param left left edge of the rectangle to read (inclusive)
433 * @param top top edge of the rectangle to read (inclusive)
434 * @param width width of rectangle to read in pixels.
435 * @param height height of rectangle to read in pixels.
436 * @param config the pixel config of the destination buffer
437 * @param buffer memory to read the rectangle into.
438 *
439 * @return true if the read succeeded, false if not. The read can fail
440 * because of a unsupported pixel config or because no render
441 * target is currently set.
bsalomon@google.com27847de2011-02-22 20:59:41 +0000442 */
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000443 bool readRenderTargetPixels(GrRenderTarget* target,
444 int left, int top, int width, int height,
445 GrPixelConfig config, void* buffer);
446
447 /**
448 * Reads a rectangle of pixels from a texture.
449 * @param texture the render target to read from.
450 * @param left left edge of the rectangle to read (inclusive)
451 * @param top top edge of the rectangle to read (inclusive)
452 * @param width width of rectangle to read in pixels.
453 * @param height height of rectangle to read in pixels.
454 * @param config the pixel config of the destination buffer
455 * @param buffer memory to read the rectangle into.
456 *
457 * @return true if the read succeeded, false if not. The read can fail
458 * because of a unsupported pixel config.
459 */
460 bool readTexturePixels(GrTexture* target,
461 int left, int top, int width, int height,
462 GrPixelConfig config, void* buffer);
bsalomon@google.com27847de2011-02-22 20:59:41 +0000463
464 /**
465 * Copy the src pixels [buffer, stride, pixelconfig] into the current
466 * render-target at the specified rectangle.
467 */
468 void writePixels(int left, int top, int width, int height,
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000469 GrPixelConfig, const void* buffer, size_t stride);
bsalomon@google.com27847de2011-02-22 20:59:41 +0000470
bsalomon@google.com27847de2011-02-22 20:59:41 +0000471 ///////////////////////////////////////////////////////////////////////////
472 // Helpers
473
474 class AutoRenderTarget : ::GrNoncopyable {
475 public:
476 AutoRenderTarget(GrContext* context, GrRenderTarget* target) {
477 fContext = NULL;
478 fPrevTarget = context->getRenderTarget();
479 if (fPrevTarget != target) {
480 context->setRenderTarget(target);
481 fContext = context;
482 }
483 }
484 ~AutoRenderTarget() {
485 if (fContext) {
486 fContext->setRenderTarget(fPrevTarget);
487 }
488 }
489 private:
490 GrContext* fContext;
491 GrRenderTarget* fPrevTarget;
492 };
493
494
495 ///////////////////////////////////////////////////////////////////////////
496 // Functions intended for internal use only.
497 GrGpu* getGpu() { return fGpu; }
498 GrFontCache* getFontCache() { return fFontCache; }
499 GrDrawTarget* getTextTarget(const GrPaint& paint);
500 void flushText();
501 const GrIndexBuffer* getQuadIndexBuffer() const;
bsalomon@google.com05ef5102011-05-02 21:14:59 +0000502 void resetStats();
503 const GrGpuStats& getStats() const;
504 void printStats() const;
bsalomon@google.com27847de2011-02-22 20:59:41 +0000505
506private:
507 // used to keep track of when we need to flush the draw buffer
508 enum DrawCategory {
509 kBuffered_DrawCategory, // last draw was inserted in draw buffer
510 kUnbuffered_DrawCategory, // last draw was not inserted in the draw buffer
511 kText_DrawCategory // text context was last to draw
512 };
513 DrawCategory fLastDrawCategory;
514
515 GrGpu* fGpu;
516 GrTextureCache* fTextureCache;
517 GrFontCache* fFontCache;
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000518
519 GrPathRenderer* fCustomPathRenderer;
520 GrDefaultPathRenderer fDefaultPathRenderer;
bsalomon@google.com27847de2011-02-22 20:59:41 +0000521
522 GrVertexBufferAllocPool* fDrawBufferVBAllocPool;
523 GrIndexBufferAllocPool* fDrawBufferIBAllocPool;
524 GrInOrderDrawBuffer* fDrawBuffer;
525
bsalomon@google.com205d4602011-04-25 12:43:45 +0000526 GrIndexBuffer* fAAFillRectIndexBuffer;
527 GrIndexBuffer* fAAStrokeRectIndexBuffer;
528
bsalomon@google.com27847de2011-02-22 20:59:41 +0000529 GrContext(GrGpu* gpu);
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000530
bsalomon@google.com205d4602011-04-25 12:43:45 +0000531 void fillAARect(GrDrawTarget* target,
532 const GrPaint& paint,
533 const GrRect& devRect);
534
535 void strokeAARect(GrDrawTarget* target,
536 const GrPaint& paint,
537 const GrRect& devRect,
538 const GrVec& devStrokeSize);
539
540 inline int aaFillRectIndexCount() const;
541 GrIndexBuffer* aaFillRectIndexBuffer();
542
543 inline int aaStrokeRectIndexCount() const;
544 GrIndexBuffer* aaStrokeRectIndexBuffer();
545
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000546 void setupDrawBuffer();
547
bsalomon@google.com27847de2011-02-22 20:59:41 +0000548 void flushDrawBuffer();
549
550 static void SetPaint(const GrPaint& paint, GrDrawTarget* target);
551
bsalomon@google.comfea37b52011-04-25 15:51:06 +0000552 bool finalizeTextureKey(GrTextureKey*,
553 const GrSamplerState&,
554 bool keyless) const;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000555
bsalomon@google.com27847de2011-02-22 20:59:41 +0000556 GrDrawTarget* prepareToDraw(const GrPaint& paint, DrawCategory drawType);
557
558 void drawClipIntoStencil();
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000559
reed@google.com07f3ee12011-05-16 17:21:57 +0000560 GrPathRenderer* getPathRenderer(const GrDrawTarget*, const GrPath&, GrPathFill);
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000561
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000562 struct OffscreenRecord;
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000563
bsalomon@google.com8295dc12011-05-02 12:53:34 +0000564 bool doOffscreenAA(GrDrawTarget* target,
565 const GrPaint& paint,
566 bool isLines) const;
567
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000568 // sets up target to draw coverage to the supersampled render target
569 bool setupOffscreenAAPass1(GrDrawTarget* target,
570 bool requireStencil,
bsalomon@google.com8295dc12011-05-02 12:53:34 +0000571 const GrIRect& boundRect,
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000572 OffscreenRecord* record);
573
574 // sets up target to sample coverage of supersampled render target back
575 // to the main render target using stage kOffscreenStage.
bsalomon@google.com8295dc12011-05-02 12:53:34 +0000576 void offscreenAAPass2(GrDrawTarget* target,
577 const GrPaint& paint,
578 const GrIRect& boundRect,
579 OffscreenRecord* record);
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000580
bsalomon@google.com26c2d0a2011-05-17 20:15:30 +0000581 // computes vertex layout bits based on the paint. If paint expresses
582 // a texture for a stage, the stage coords will be bound to postitions
583 // unless hasTexCoords[s]==true in which case stage s's input coords
584 // are bound to tex coord index s. hasTexCoords == NULL is a shortcut
585 // for an array where all the values are false.
586 static int PaintStageVertexLayoutBits(
587 const GrPaint& paint,
588 const bool hasTexCoords[GrPaint::kTotalStages]);
589
bsalomon@google.com27847de2011-02-22 20:59:41 +0000590};
591
592/**
593 * Save/restore the view-matrix in the context.
594 */
595class GrAutoMatrix : GrNoncopyable {
596public:
597 GrAutoMatrix(GrContext* ctx) : fContext(ctx) {
598 fMatrix = ctx->getMatrix();
599 }
600 GrAutoMatrix(GrContext* ctx, const GrMatrix& matrix) : fContext(ctx) {
601 fMatrix = ctx->getMatrix();
602 ctx->setMatrix(matrix);
603 }
604 ~GrAutoMatrix() {
605 fContext->setMatrix(fMatrix);
606 }
607
608private:
609 GrContext* fContext;
610 GrMatrix fMatrix;
611};
612
613#endif
614
615#include "GrContext_impl.h"
bsalomon@google.com8295dc12011-05-02 12:53:34 +0000616