reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 1 | /*
|
| 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 |
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 17 | #ifndef GrContext_DEFINED
|
| 18 | #define GrContext_DEFINED
|
| 19 |
|
| 20 | #include "GrClip.h"
|
| 21 | #include "GrGpu.h"
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 22 | #include "GrTextureCache.h"
|
| 23 | #include "GrInOrderDrawBuffer.h"
|
| 24 | #include "GrVertexBufferAllocPool.h"
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 25 | #include "GrPaint.h"
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 26 |
|
| 27 | class GrFontCache;
|
| 28 | class GrPathIter;
|
| 29 |
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 30 | class GrContext : public GrRefCnt {
|
| 31 | public:
|
| 32 | /**
|
| 33 | * Creates a GrContext from within a 3D context.
|
| 34 | */
|
| 35 | static GrContext* Create(GrGpu::Engine engine,
|
| 36 | GrGpu::Platform3DContext context3D);
|
| 37 |
|
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 38 | /**
|
| 39 | * Helper to create a opengl-shader based context
|
| 40 | */
|
| 41 | static GrContext* CreateGLShaderContext();
|
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 42 |
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 43 | virtual ~GrContext();
|
| 44 |
|
| 45 | /**
|
| 46 | * The GrContext normally assumes that no outsider is setting state
|
| 47 | * within the underlying 3D API's context/device/whatever. This call informs
|
| 48 | * the context that the state was modified and it should resend. Shouldn't
|
| 49 | * be called frequently for good performance.
|
| 50 | */
|
| 51 | void resetContext();
|
| 52 |
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 53 | ///////////////////////////////////////////////////////////////////////////
|
| 54 | // Textures
|
| 55 |
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 56 | /**
|
| 57 | * Abandons all textures. Call this if you have lost the associated GPU
|
| 58 | * context, and thus internal texture references/IDs are now invalid.
|
| 59 | */
|
| 60 | void abandonAllTextures();
|
| 61 |
|
| 62 | /**
|
| 63 | * Search for an entry with the same Key. If found, "lock" it and return it.
|
| 64 | * If not found, return null.
|
| 65 | */
|
| 66 | GrTextureEntry* findAndLockTexture(GrTextureKey*,
|
| 67 | const GrSamplerState&);
|
| 68 |
|
| 69 |
|
| 70 | /**
|
| 71 | * Create a new entry, based on the specified key and texture, and return
|
| 72 | * its "locked" entry.
|
| 73 | *
|
| 74 | * Ownership of the texture is transferred to the Entry, which will unref()
|
| 75 | * it when we are purged or deleted.
|
| 76 | */
|
| 77 | GrTextureEntry* createAndLockTexture(GrTextureKey* key,
|
| 78 | const GrSamplerState&,
|
| 79 | const GrGpu::TextureDesc&,
|
| 80 | void* srcData, size_t rowBytes);
|
| 81 |
|
| 82 | /**
|
| 83 | * When done with an entry, call unlockTexture(entry) on it, which returns
|
| 84 | * it to the cache, where it may be purged.
|
| 85 | */
|
| 86 | void unlockTexture(GrTextureEntry* entry);
|
| 87 |
|
| 88 | /**
|
| 89 | * Removes an texture from the cache. This prevents the texture from
|
| 90 | * being found by a subsequent findAndLockTexture() until it is
|
| 91 | * reattached. The entry still counts against the cache's budget and should
|
| 92 | * be reattached when exclusive access is no longer needed.
|
| 93 | */
|
| 94 | void detachCachedTexture(GrTextureEntry*);
|
| 95 |
|
| 96 | /**
|
| 97 | * Reattaches a texture to the cache and unlocks it. Allows it to be found
|
| 98 | * by a subsequent findAndLock or be purged (provided its lock count is
|
| 99 | * now 0.)
|
| 100 | */
|
| 101 | void reattachAndUnlockCachedTexture(GrTextureEntry*);
|
| 102 |
|
| 103 | /**
|
| 104 | * Creates a texture that is outside the cache. Does not count against
|
| 105 | * cache's budget.
|
| 106 | */
|
| 107 | GrTexture* createUncachedTexture(const GrGpu::TextureDesc&,
|
| 108 | void* srcData,
|
| 109 | size_t rowBytes);
|
| 110 |
|
| 111 | /**
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 112 | * Returns true if the specified use of an indexed texture is supported.
|
| 113 | */
|
| 114 | bool supportsIndex8PixelConfig(const GrSamplerState&, int width, int height);
|
| 115 |
|
| 116 | /**
|
| 117 | * Return the current texture cache limits.
|
| 118 | *
|
| 119 | * @param maxTextures If non-null, returns maximum number of textures that
|
| 120 | * can be held in the cache.
|
| 121 | * @param maxTextureBytes If non-null, returns maximum number of bytes of
|
| 122 | * texture memory that can be held in the cache.
|
| 123 | */
|
| 124 | void getTextureCacheLimits(int* maxTextures, size_t* maxTextureBytes) const;
|
| 125 |
|
| 126 | /**
|
| 127 | * Specify the texture cache limits. If the current cache exceeds either
|
| 128 | * of these, it will be purged (LRU) to keep the cache within these limits.
|
| 129 | *
|
| 130 | * @param maxTextures The maximum number of textures that can be held in
|
| 131 | * the cache.
|
| 132 | * @param maxTextureBytes The maximum number of bytes of texture memory
|
| 133 | * that can be held in the cache.
|
| 134 | */
|
| 135 | void setTextureCacheLimits(int maxTextures, size_t maxTextureBytes);
|
| 136 |
|
reed@google.com | 02a7e6c | 2011-01-28 21:21:49 +0000 | [diff] [blame] | 137 | /**
|
| 138 | * Return the max width or height of a texture supported by the current gpu
|
| 139 | */
|
| 140 | int getMaxTextureDimension();
|
| 141 |
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 142 | ///////////////////////////////////////////////////////////////////////////
|
| 143 | // Render targets
|
| 144 |
|
| 145 | /**
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 146 | * Wraps an externally-created rendertarget in a GrRenderTarget.
|
| 147 | * e.g. in GL platforamRenderTarget is an FBO id.
|
| 148 | */
|
| 149 | GrRenderTarget* createPlatformRenderTarget(intptr_t platformRenderTarget,
|
| 150 | int width, int height);
|
| 151 |
|
| 152 | /**
|
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 153 | * Reads the current target object (e.g. FBO or IDirect3DSurface9*) and
|
| 154 | * viewport state from the underlying 3D API and wraps it in a
|
| 155 | * GrRenderTarget. The GrRenderTarget will not attempt to delete/destroy the
|
| 156 | * underlying object in its destructor and it is up to caller to guarantee
|
| 157 | * that it remains valid while the GrRenderTarget is used.
|
| 158 | *
|
| 159 | * @return the newly created GrRenderTarget
|
| 160 | */
|
| 161 | GrRenderTarget* createRenderTargetFrom3DApiState() {
|
| 162 | return fGpu->createRenderTargetFrom3DApiState();
|
| 163 | }
|
| 164 |
|
| 165 | /**
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 166 | * Sets the render target.
|
| 167 | * @param target the render target to set. (should not be NULL.)
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 168 | */
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 169 | void setRenderTarget(GrRenderTarget* target);
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 170 |
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 171 | /**
|
| 172 | * Gets the current render target.
|
| 173 | * @return the currently bound render target. Should never be NULL.
|
| 174 | */
|
| 175 | const GrRenderTarget* getRenderTarget() const;
|
| 176 | GrRenderTarget* getRenderTarget();
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 177 |
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 178 | ///////////////////////////////////////////////////////////////////////////
|
| 179 | // Matrix state
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 180 |
|
| 181 | /**
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 182 | * Gets the current transformation matrix.
|
| 183 | * @return the current matrix.
|
| 184 | */
|
| 185 | const GrMatrix& getMatrix() const;
|
| 186 |
|
| 187 | /**
|
| 188 | * Sets the transformation matrix.
|
| 189 | * @param m the matrix to set.
|
| 190 | */
|
| 191 | void setMatrix(const GrMatrix& m);
|
| 192 |
|
| 193 | /**
|
| 194 | * Concats the current matrix. The passed matrix is applied before the
|
| 195 | * current matrix.
|
| 196 | * @param m the matrix to concat.
|
| 197 | */
|
| 198 | void concatMatrix(const GrMatrix& m) const;
|
| 199 |
|
| 200 |
|
| 201 | ///////////////////////////////////////////////////////////////////////////
|
| 202 | // Clip state
|
| 203 | /**
|
| 204 | * Gets the current clip.
|
| 205 | * @return the current clip.
|
| 206 | */
|
| 207 | const GrClip& getClip() const { return fGpu->getClip(); }
|
| 208 |
|
| 209 | /**
|
| 210 | * Sets the clip.
|
| 211 | * @param clip the clip to set.
|
| 212 | */
|
| 213 | void setClip(const GrClip& clip);
|
| 214 |
|
| 215 | /**
|
| 216 | * Convenience method for setting the clip to a rect.
|
| 217 | * @param rect the rect to set as the new clip.
|
| 218 | */
|
| 219 | void setClip(const GrIRect& rect);
|
| 220 |
|
| 221 | ///////////////////////////////////////////////////////////////////////////
|
| 222 | // Draws
|
| 223 |
|
| 224 | /**
|
| 225 | * Erase the entire render target, ignoring any clips
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 226 | */
|
| 227 | void eraseColor(GrColor color);
|
| 228 |
|
| 229 | /**
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 230 | * Draw everywhere (respecting the clip) with the paint.
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 231 | */
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 232 | void drawPaint(const GrPaint& paint);
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 233 |
|
| 234 | /**
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 235 | * Draw the rect using a paint.
|
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 236 | * @param paint describes how to color pixels.
|
| 237 | * @param strokeWidth If strokeWidth < 0, then the rect is filled, else
|
| 238 | * the rect is mitered stroked based on strokeWidth. If
|
| 239 | * strokeWidth == 0, then the stroke is always a single
|
| 240 | * pixel thick.
|
| 241 | * @param matrix Optional matrix applied to the rect. Applied before
|
| 242 | * context's matrix or the paint's matrix.
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 243 | * The rects coords are used to access the paint (through texture matrix)
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 244 | */
|
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 245 | void drawRect(const GrPaint& paint,
|
| 246 | const GrRect&,
|
| 247 | GrScalar strokeWidth = -1,
|
| 248 | const GrMatrix* matrix = NULL);
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 249 |
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 250 | /**
|
| 251 | * Maps a rect of paint coordinates onto the a rect of destination
|
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 252 | * coordinates. Each rect can optionally be transformed. The srcRect
|
| 253 | * is stretched over the dstRect. The dstRect is transformed by the
|
| 254 | * context's matrix and the srcRect is transformed by the paint's matrix.
|
| 255 | * Additional optional matrices can be provided by parameters.
|
| 256 | *
|
| 257 | * @param paint describes how to color pixels.
|
| 258 | * @param dstRect the destination rect to draw.
|
| 259 | * @param srcRect rect of paint coordinates to be mapped onto dstRect
|
| 260 | * @param dstMatrix Optional matrix to transform dstRect. Applied before
|
| 261 | * context's matrix.
|
| 262 | * @param srcMatrix Optional matrix to transform srcRect Applied before
|
| 263 | * paint's matrix.
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 264 | */
|
| 265 | void drawRectToRect(const GrPaint& paint,
|
| 266 | const GrRect& dstRect,
|
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 267 | const GrRect& srcRect,
|
| 268 | const GrMatrix* dstMatrix = NULL,
|
| 269 | const GrMatrix* srcMatrix = NULL);
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 270 |
|
| 271 | /**
|
| 272 | * Path filling rules
|
| 273 | */
|
| 274 | enum PathFills {
|
| 275 | kWinding_PathFill,
|
| 276 | kEvenOdd_PathFill,
|
| 277 | kInverseWinding_PathFill,
|
| 278 | kInverseEvenOdd_PathFill,
|
| 279 | kHairLine_PathFill,
|
| 280 |
|
| 281 | kPathFillCount
|
| 282 | };
|
| 283 |
|
| 284 | /**
|
| 285 | * Tessellates and draws a path.
|
| 286 | *
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 287 | * @param paint describes how to color pixels.
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 288 | * @param path the path to draw
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 289 | * @param fill the path filling rule to use.
|
| 290 | * @param translate optional additional translation applied to the
|
| 291 | * path.
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 292 | */
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 293 | void drawPath(const GrPaint& paint,
|
| 294 | GrPathIter* path,
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 295 | PathFills fill,
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 296 | const GrPoint* translate = NULL);
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 297 | /**
|
| 298 | * Draws vertices with a paint.
|
| 299 | *
|
| 300 | * @param paint describes how to color pixels.
|
| 301 | * @param primitiveType primitives type to draw.
|
| 302 | * @param vertexCount number of vertices.
|
| 303 | * @param positions array of vertex positions, required.
|
| 304 | * @param texCoords optional array of texture coordinates used
|
| 305 | * to access the paint.
|
| 306 | * @param colors optional array of per-vertex colors, supercedes
|
| 307 | * the paint's color field.
|
| 308 | * @param indices optional array of indices. If NULL vertices
|
| 309 | * are drawn non-indexed.
|
| 310 | * @param indexCount if indices is non-null then this is the
|
| 311 | * number of indices.
|
| 312 | */
|
| 313 | void drawVertices(const GrPaint& paint,
|
| 314 | GrDrawTarget::PrimitiveType primitiveType,
|
| 315 | int vertexCount,
|
| 316 | const GrPoint positions[],
|
| 317 | const GrPoint texs[],
|
| 318 | const GrColor colors[],
|
| 319 | const uint16_t indices[],
|
| 320 | int indexCount);
|
| 321 |
|
| 322 | /**
|
| 323 | * Similar to drawVertices but caller provides objects that convert to Gr
|
| 324 | * types. The count of vertices is given by posSrc.
|
| 325 | *
|
| 326 | * @param paint describes how to color pixels.
|
| 327 | * @param primitiveType primitives type to draw.
|
| 328 | * @param posSrc Source of vertex positions. Must implement
|
| 329 | * int count() const;
|
| 330 | * void writeValue(int i, GrPoint* point) const;
|
| 331 | * count returns the total number of vertices and
|
| 332 | * writeValue writes a vertex position to point.
|
| 333 | * @param texSrc optional, pass NULL to not use explicit tex
|
| 334 | * coords. If present provides tex coords with
|
| 335 | * method:
|
| 336 | * void writeValue(int i, GrPoint* point) const;
|
| 337 | * @param texSrc optional, pass NULL to not use per-vertex colors
|
| 338 | * If present provides colors with method:
|
| 339 | * void writeValue(int i, GrColor* point) const;
|
| 340 | * @param indices optional, pass NULL for non-indexed drawing. If
|
| 341 | * present supplies indices for indexed drawing
|
| 342 | * with following methods:
|
| 343 | * int count() const;
|
| 344 | * void writeValue(int i, uint16_t* point) const;
|
| 345 | * count returns the number of indices and
|
| 346 | * writeValue supplies each index.
|
| 347 | */
|
| 348 | template <typename POS_SRC,
|
| 349 | typename TEX_SRC,
|
| 350 | typename COL_SRC,
|
| 351 | typename IDX_SRC>
|
| 352 | void drawCustomVertices(const GrPaint& paint,
|
| 353 | GrDrawTarget::PrimitiveType primitiveType,
|
| 354 | const POS_SRC& posSrc,
|
| 355 | const TEX_SRC* texCoordSrc,
|
| 356 | const COL_SRC* colorSrc,
|
| 357 | const IDX_SRC* idxSrc);
|
| 358 | /**
|
| 359 | * To avoid the problem of having to create a typename for NULL parameters,
|
| 360 | * these reduced versions of drawCustomVertices are provided.
|
| 361 | */
|
| 362 | template <typename POS_SRC>
|
| 363 | void drawCustomVertices(const GrPaint& paint,
|
| 364 | GrDrawTarget::PrimitiveType primitiveType,
|
| 365 | const POS_SRC& posSrc);
|
| 366 | template <typename POS_SRC, typename TEX_SRC>
|
| 367 | void drawCustomVertices(const GrPaint& paint,
|
| 368 | GrDrawTarget::PrimitiveType primitiveType,
|
| 369 | const POS_SRC& posSrc,
|
| 370 | const TEX_SRC* texCoordSrc);
|
| 371 | template <typename POS_SRC, typename TEX_SRC, typename COL_SRC>
|
| 372 | void drawCustomVertices(const GrPaint& paint,
|
| 373 | GrDrawTarget::PrimitiveType primitiveType,
|
| 374 | const POS_SRC& posSrc,
|
| 375 | const TEX_SRC* texCoordSrc,
|
| 376 | const COL_SRC* colorSrc);
|
| 377 |
|
| 378 |
|
| 379 | ///////////////////////////////////////////////////////////////////////////
|
| 380 | // Misc.
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 381 |
|
| 382 | /**
|
| 383 | * Call to ensure all drawing to the context has been issued to the
|
| 384 | * underlying 3D API.
|
| 385 | * if flushRenderTarget is true then after the call the last
|
| 386 | * rendertarget set will be current in the underlying 3D API, otherwise
|
| 387 | * it may not be. It is useful to set if the caller plans to use the 3D
|
| 388 | * context outside of Ganesh to render into the current RT.
|
| 389 | */
|
| 390 | void flush(bool flushRenderTarget);
|
| 391 |
|
| 392 | /**
|
| 393 | * Return true on success, i.e. if we could copy the specified range of
|
| 394 | * pixels from the current render-target into the buffer, converting into
|
| 395 | * the specified pixel-config.
|
| 396 | */
|
| 397 | bool readPixels(int left, int top, int width, int height,
|
| 398 | GrTexture::PixelConfig, void* buffer);
|
| 399 |
|
| 400 | /**
|
| 401 | * Copy the src pixels [buffer, stride, pixelconfig] into the current
|
| 402 | * render-target at the specified rectangle.
|
| 403 | */
|
| 404 | void writePixels(int left, int top, int width, int height,
|
| 405 | GrTexture::PixelConfig, const void* buffer, size_t stride);
|
| 406 |
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 407 |
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 408 | ///////////////////////////////////////////////////////////////////////////
|
| 409 | // Statistics
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 410 |
|
| 411 | void resetStats();
|
| 412 |
|
| 413 | const GrGpu::Stats& getStats() const;
|
| 414 |
|
| 415 | void printStats() const;
|
| 416 |
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 417 | ///////////////////////////////////////////////////////////////////////////
|
| 418 | // Helpers
|
| 419 |
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 420 | class AutoRenderTarget : ::GrNoncopyable {
|
| 421 | public:
|
| 422 | AutoRenderTarget(GrContext* context, GrRenderTarget* target) {
|
| 423 | fContext = NULL;
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 424 | fPrevTarget = context->getRenderTarget();
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 425 | if (fPrevTarget != target) {
|
| 426 | context->setRenderTarget(target);
|
| 427 | fContext = context;
|
| 428 | }
|
| 429 | }
|
| 430 | ~AutoRenderTarget() {
|
| 431 | if (fContext) {
|
| 432 | fContext->setRenderTarget(fPrevTarget);
|
| 433 | }
|
| 434 | }
|
| 435 | private:
|
| 436 | GrContext* fContext;
|
| 437 | GrRenderTarget* fPrevTarget;
|
| 438 | };
|
| 439 |
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 440 |
|
reed@google.com | 01804b4 | 2011-01-18 21:50:41 +0000 | [diff] [blame] | 441 | ///////////////////////////////////////////////////////////////////////////
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 442 | // Functions intended for internal use only.
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 443 | GrGpu* getGpu() { return fGpu; }
|
| 444 | GrFontCache* getFontCache() { return fFontCache; }
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 445 | GrDrawTarget* getTextTarget(const GrPaint& paint);
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 446 | void flushText();
|
| 447 |
|
| 448 | const GrIndexBuffer* quadIndexBuffer() const;
|
| 449 | int maxQuadsInIndexBuffer() const;
|
| 450 |
|
| 451 | private:
|
| 452 | GrGpu* fGpu;
|
| 453 | GrTextureCache* fTextureCache;
|
| 454 | GrFontCache* fFontCache;
|
| 455 |
|
| 456 | GrVertexBufferAllocPool fVBAllocPool;
|
| 457 | GrInOrderDrawBuffer fTextDrawBuffer;
|
| 458 |
|
| 459 | GrContext(GrGpu* gpu);
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 460 |
|
| 461 | static void SetPaint(const GrPaint& paint, GrDrawTarget* target);
|
| 462 |
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 463 | bool finalizeTextureKey(GrTextureKey*, const GrSamplerState&) const;
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 464 | void prepareToDraw(const GrPaint& paint);
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 465 |
|
| 466 | void drawClipIntoStencil();
|
| 467 | };
|
| 468 |
|
| 469 | /**
|
| 470 | * Save/restore the view-matrix in the context.
|
| 471 | */
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 472 | class GrAutoMatrix : GrNoncopyable {
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 473 | public:
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 474 | GrAutoMatrix(GrContext* ctx) : fContext(ctx) {
|
| 475 | fMatrix = ctx->getMatrix();
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 476 | }
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 477 | GrAutoMatrix(GrContext* ctx, const GrMatrix& matrix) : fContext(ctx) {
|
| 478 | fMatrix = ctx->getMatrix();
|
| 479 | ctx->setMatrix(matrix);
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 480 | }
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 481 | ~GrAutoMatrix() {
|
| 482 | fContext->setMatrix(fMatrix);
|
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 483 | }
|
| 484 |
|
| 485 | private:
|
| 486 | GrContext* fContext;
|
| 487 | GrMatrix fMatrix;
|
| 488 | };
|
| 489 |
|
| 490 | #endif
|
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 491 |
|
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 492 | #include "GrContext_impl.h"
|