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