epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2010 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 10 | #ifndef GrContext_DEFINED |
| 11 | #define GrContext_DEFINED |
| 12 | |
| 13 | #include "GrClip.h" |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 14 | #include "GrPaint.h" |
bsalomon@google.com | c287a89 | 2011-08-19 14:49:36 +0000 | [diff] [blame] | 15 | // not strictly needed but requires WK change in LayerTextureUpdaterCanvas to |
| 16 | // remove. |
| 17 | #include "GrRenderTarget.h" |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 18 | |
bsalomon@google.com | 583a1e3 | 2011-08-17 13:42:46 +0000 | [diff] [blame] | 19 | class GrDrawTarget; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 20 | class GrFontCache; |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 21 | class GrGpu; |
| 22 | struct GrGpuStats; |
bsalomon@google.com | 583a1e3 | 2011-08-17 13:42:46 +0000 | [diff] [blame] | 23 | class GrIndexBuffer; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 24 | class GrIndexBufferAllocPool; |
| 25 | class GrInOrderDrawBuffer; |
bsalomon@google.com | 583a1e3 | 2011-08-17 13:42:46 +0000 | [diff] [blame] | 26 | class GrPathRenderer; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 27 | class GrPathRendererChain; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 28 | class GrResourceEntry; |
| 29 | class GrResourceCache; |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 30 | class GrStencilBuffer; |
bsalomon@google.com | 583a1e3 | 2011-08-17 13:42:46 +0000 | [diff] [blame] | 31 | class GrVertexBuffer; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 32 | class GrVertexBufferAllocPool; |
| 33 | |
bsalomon@google.com | 9182610 | 2011-03-21 19:51:57 +0000 | [diff] [blame] | 34 | class GR_API GrContext : public GrRefCnt { |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 35 | public: |
| 36 | /** |
| 37 | * Creates a GrContext from within a 3D context. |
| 38 | */ |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 39 | static GrContext* Create(GrEngine engine, |
| 40 | GrPlatform3DContext context3D); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 41 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 42 | virtual ~GrContext(); |
| 43 | |
| 44 | /** |
| 45 | * The GrContext normally assumes that no outsider is setting state |
| 46 | * within the underlying 3D API's context/device/whatever. This call informs |
| 47 | * the context that the state was modified and it should resend. Shouldn't |
| 48 | * be called frequently for good performance. |
| 49 | */ |
| 50 | void resetContext(); |
| 51 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 52 | /** |
| 53 | * Abandons all gpu resources, assumes 3D API state is unknown. Call this |
| 54 | * if you have lost the associated GPU context, and thus internal texture, |
| 55 | * buffer, etc. references/IDs are now invalid. Should be called even when |
| 56 | * GrContext is no longer going to be used for two reasons: |
| 57 | * 1) ~GrContext will not try to free the objects in the 3D API. |
| 58 | * 2) If you've created GrResources that outlive the GrContext they will |
| 59 | * be marked as invalid (GrResource::isValid()) and won't attempt to |
| 60 | * free their underlying resource in the 3D API. |
| 61 | * Content drawn since the last GrContext::flush() may be lost. |
| 62 | */ |
| 63 | void contextLost(); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 64 | |
| 65 | /** |
junov@google.com | 53a5584 | 2011-06-08 22:55:10 +0000 | [diff] [blame] | 66 | * Similar to contextLost, but makes no attempt to reset state. |
| 67 | * Use this method when GrContext destruction is pending, but |
| 68 | * the graphics context is destroyed first. |
| 69 | */ |
| 70 | void contextDestroyed(); |
| 71 | |
| 72 | /** |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 73 | * Frees gpu created by the context. Can be called to reduce GPU memory |
| 74 | * pressure. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 75 | */ |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 76 | void freeGpuResources(); |
| 77 | |
twiz@google.com | 05e7024 | 2012-01-27 19:12:00 +0000 | [diff] [blame] | 78 | /** |
| 79 | * Returns the number of bytes of GPU memory hosted by the texture cache. |
| 80 | */ |
| 81 | size_t getGpuTextureCacheBytes() const; |
| 82 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 83 | /////////////////////////////////////////////////////////////////////////// |
| 84 | // Textures |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 85 | |
| 86 | /** |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 87 | * Token that refers to an entry in the texture cache. Returned by |
| 88 | * functions that lock textures. Passed to unlockTexture. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 89 | */ |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 90 | class TextureCacheEntry { |
| 91 | public: |
| 92 | TextureCacheEntry() : fEntry(NULL) {} |
| 93 | TextureCacheEntry(const TextureCacheEntry& e) : fEntry(e.fEntry) {} |
| 94 | TextureCacheEntry& operator= (const TextureCacheEntry& e) { |
| 95 | fEntry = e.fEntry; |
| 96 | return *this; |
| 97 | } |
| 98 | GrTexture* texture() const; |
| 99 | void reset() { fEntry = NULL; } |
| 100 | private: |
| 101 | explicit TextureCacheEntry(GrResourceEntry* entry) { fEntry = entry; } |
| 102 | void set(GrResourceEntry* entry) { fEntry = entry; } |
| 103 | GrResourceEntry* cacheEntry() { return fEntry; } |
| 104 | GrResourceEntry* fEntry; |
| 105 | friend class GrContext; |
| 106 | }; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 107 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 108 | /** |
| 109 | * Key generated by client. Should be a unique key on the texture data. |
| 110 | * Does not need to consider that width and height of the texture. Two |
| 111 | * textures with the same TextureKey but different bounds will not collide. |
| 112 | */ |
| 113 | typedef uint64_t TextureKey; |
| 114 | |
| 115 | /** |
bsalomon@google.com | 1fadb20 | 2011-12-12 16:10:08 +0000 | [diff] [blame] | 116 | * Create a new entry, based on the specified key and texture, and return |
| 117 | * its "locked" entry. Must call be balanced with an unlockTexture() call. |
| 118 | * |
| 119 | * @param key A client-generated key that identifies the contents |
| 120 | * of the texture. Respecified to findAndLockTexture |
| 121 | * for subsequent uses of the texture. |
| 122 | * @param sampler The sampler state used to draw a texture may be used |
| 123 | * to determine how to store the pixel data in the texture |
| 124 | * cache. (e.g. different versions may exist for different |
| 125 | * wrap modes on GPUs with limited or no NPOT texture |
| 126 | * support). Only the wrap and filter fields are used. NULL |
| 127 | * implies clamp wrap modes and nearest filtering. |
| 128 | * @param desc Description of the texture properties. |
| 129 | * @param srcData Pointer to the pixel values. |
| 130 | * @param rowBytes The number of bytes between rows of the texture. Zero |
| 131 | * implies tightly packed rows. |
| 132 | */ |
| 133 | TextureCacheEntry createAndLockTexture(TextureKey key, |
| 134 | const GrSamplerState* sampler, |
| 135 | const GrTextureDesc& desc, |
| 136 | void* srcData, size_t rowBytes); |
| 137 | |
| 138 | /** |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 139 | * Search for an entry based on key and dimensions. If found, "lock" it and |
| 140 | * return it. The entry's texture() function will return NULL if not found. |
bsalomon@google.com | 1fadb20 | 2011-12-12 16:10:08 +0000 | [diff] [blame] | 141 | * Must be balanced with an unlockTexture() call. |
| 142 | * |
| 143 | * @param key A client-generated key that identifies the contents |
| 144 | * of the texture. |
| 145 | * @param width The width of the texture in pixels as specifed in |
| 146 | * the GrTextureDesc originally passed to |
| 147 | * createAndLockTexture |
| 148 | * @param width The height of the texture in pixels as specifed in |
| 149 | * the GrTextureDesc originally passed to |
| 150 | * createAndLockTexture |
| 151 | * @param sampler The sampler state used to draw a texture may be used |
| 152 | * to determine the cache entry used. (e.g. different |
| 153 | * versions may exist for different wrap modes on GPUs with |
| 154 | * limited or no NPOT texture support). Only the wrap and |
| 155 | * filter fields are used. NULL implies clamp wrap modes |
| 156 | * and nearest filtering. |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 157 | */ |
| 158 | TextureCacheEntry findAndLockTexture(TextureKey key, |
| 159 | int width, |
| 160 | int height, |
bsalomon@google.com | 1fadb20 | 2011-12-12 16:10:08 +0000 | [diff] [blame] | 161 | const GrSamplerState* sampler); |
bsalomon@google.com | fb30951 | 2011-11-30 14:13:48 +0000 | [diff] [blame] | 162 | /** |
| 163 | * Determines whether a texture is in the cache. If the texture is found it |
| 164 | * will not be locked or returned. This call does not affect the priority of |
| 165 | * the texture for deletion. |
| 166 | */ |
| 167 | bool isTextureInCache(TextureKey key, |
| 168 | int width, |
| 169 | int height, |
bsalomon@google.com | 1fadb20 | 2011-12-12 16:10:08 +0000 | [diff] [blame] | 170 | const GrSamplerState*) const; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 171 | |
| 172 | /** |
| 173 | * Enum that determines how closely a returned scratch texture must match |
| 174 | * a provided GrTextureDesc. |
| 175 | */ |
| 176 | enum ScratchTexMatch { |
| 177 | /** |
| 178 | * Finds a texture that exactly matches the descriptor. |
| 179 | */ |
| 180 | kExact_ScratchTexMatch, |
| 181 | /** |
| 182 | * Finds a texture that approximately matches the descriptor. Will be |
| 183 | * at least as large in width and height as desc specifies. If desc |
| 184 | * specifies that texture is a render target then result will be a |
| 185 | * render target. If desc specifies a render target and doesn't set the |
| 186 | * no stencil flag then result will have a stencil. Format and aa level |
| 187 | * will always match. |
| 188 | */ |
| 189 | kApprox_ScratchTexMatch |
| 190 | }; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 191 | |
| 192 | /** |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 193 | * Returns a texture matching the desc. It's contents are unknown. Subsequent |
| 194 | * requests with the same descriptor are not guaranteed to return the same |
| 195 | * texture. The same texture is guaranteed not be returned again until it is |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 196 | * unlocked. Must call be balanced with an unlockTexture() call. |
bsalomon@google.com | a39f404 | 2011-04-26 13:18:16 +0000 | [diff] [blame] | 197 | * |
| 198 | * Textures created by createAndLockTexture() hide the complications of |
| 199 | * tiling non-power-of-two textures on APIs that don't support this (e.g. |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 200 | * unextended GLES2). Tiling a npot texture created by lockScratchTexture on |
bsalomon@google.com | a39f404 | 2011-04-26 13:18:16 +0000 | [diff] [blame] | 201 | * such an API will create gaps in the tiling pattern. This includes clamp |
| 202 | * mode. (This may be addressed in a future update.) |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 203 | */ |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 204 | TextureCacheEntry lockScratchTexture(const GrTextureDesc& desc, ScratchTexMatch match); |
bsalomon@google.com | b5b3168 | 2011-06-16 18:05:35 +0000 | [diff] [blame] | 205 | |
| 206 | /** |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 207 | * When done with an entry, call unlockTexture(entry) on it, which returns |
| 208 | * it to the cache, where it may be purged. |
| 209 | */ |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 210 | void unlockTexture(TextureCacheEntry entry); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 211 | |
| 212 | /** |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 213 | * Creates a texture that is outside the cache. Does not count against |
| 214 | * cache's budget. |
| 215 | */ |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 216 | GrTexture* createUncachedTexture(const GrTextureDesc&, |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 217 | void* srcData, |
| 218 | size_t rowBytes); |
| 219 | |
| 220 | /** |
| 221 | * Returns true if the specified use of an indexed texture is supported. |
| 222 | */ |
bsalomon@google.com | 1fadb20 | 2011-12-12 16:10:08 +0000 | [diff] [blame] | 223 | bool supportsIndex8PixelConfig(const GrSamplerState*, |
bsalomon@google.com | 1f221a7 | 2011-08-23 20:54:07 +0000 | [diff] [blame] | 224 | int width, |
| 225 | int height) const; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 226 | |
| 227 | /** |
| 228 | * Return the current texture cache limits. |
| 229 | * |
| 230 | * @param maxTextures If non-null, returns maximum number of textures that |
| 231 | * can be held in the cache. |
| 232 | * @param maxTextureBytes If non-null, returns maximum number of bytes of |
| 233 | * texture memory that can be held in the cache. |
| 234 | */ |
| 235 | void getTextureCacheLimits(int* maxTextures, size_t* maxTextureBytes) const; |
| 236 | |
| 237 | /** |
| 238 | * Specify the texture cache limits. If the current cache exceeds either |
| 239 | * of these, it will be purged (LRU) to keep the cache within these limits. |
| 240 | * |
| 241 | * @param maxTextures The maximum number of textures that can be held in |
| 242 | * the cache. |
| 243 | * @param maxTextureBytes The maximum number of bytes of texture memory |
| 244 | * that can be held in the cache. |
| 245 | */ |
| 246 | void setTextureCacheLimits(int maxTextures, size_t maxTextureBytes); |
| 247 | |
| 248 | /** |
| 249 | * Return the max width or height of a texture supported by the current gpu |
| 250 | */ |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 251 | int getMaxTextureSize() const; |
| 252 | |
| 253 | /** |
| 254 | * Return the max width or height of a render target supported by the |
| 255 | * current gpu |
| 256 | */ |
| 257 | int getMaxRenderTargetSize() const; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 258 | |
| 259 | /////////////////////////////////////////////////////////////////////////// |
| 260 | // Render targets |
| 261 | |
| 262 | /** |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 263 | * Sets the render target. |
| 264 | * @param target the render target to set. (should not be NULL.) |
| 265 | */ |
| 266 | void setRenderTarget(GrRenderTarget* target); |
| 267 | |
| 268 | /** |
| 269 | * Gets the current render target. |
| 270 | * @return the currently bound render target. Should never be NULL. |
| 271 | */ |
| 272 | const GrRenderTarget* getRenderTarget() const; |
| 273 | GrRenderTarget* getRenderTarget(); |
| 274 | |
| 275 | /////////////////////////////////////////////////////////////////////////// |
| 276 | // Platform Surfaces |
| 277 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 278 | /** |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 279 | * Wraps an existing texture with a GrTexture object. |
| 280 | * |
| 281 | * OpenGL: if the object is a texture Gr may change its GL texture params |
| 282 | * when it is drawn. |
| 283 | * |
| 284 | * @param desc description of the object to create. |
| 285 | * |
| 286 | * @return GrTexture object or NULL on failure. |
| 287 | */ |
| 288 | GrTexture* createPlatformTexture(const GrPlatformTextureDesc& desc); |
| 289 | |
| 290 | /** |
| 291 | * Wraps an existing render target with a GrRenderTarget object. It is |
| 292 | * similar to createPlatformTexture but can be used to draw into surfaces |
| 293 | * that are not also textures (e.g. FBO 0 in OpenGL, or an MSAA buffer that |
| 294 | * the client will resolve to a texture). |
| 295 | * |
| 296 | * @param desc description of the object to create. |
| 297 | * |
| 298 | * @return GrTexture object or NULL on failure. |
| 299 | */ |
| 300 | GrRenderTarget* createPlatformRenderTarget( |
| 301 | const GrPlatformRenderTargetDesc& desc); |
| 302 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 303 | /////////////////////////////////////////////////////////////////////////// |
| 304 | // Matrix state |
| 305 | |
| 306 | /** |
| 307 | * Gets the current transformation matrix. |
| 308 | * @return the current matrix. |
| 309 | */ |
| 310 | const GrMatrix& getMatrix() const; |
| 311 | |
| 312 | /** |
| 313 | * Sets the transformation matrix. |
| 314 | * @param m the matrix to set. |
| 315 | */ |
| 316 | void setMatrix(const GrMatrix& m); |
| 317 | |
| 318 | /** |
| 319 | * Concats the current matrix. The passed matrix is applied before the |
| 320 | * current matrix. |
| 321 | * @param m the matrix to concat. |
| 322 | */ |
| 323 | void concatMatrix(const GrMatrix& m) const; |
| 324 | |
| 325 | |
| 326 | /////////////////////////////////////////////////////////////////////////// |
| 327 | // Clip state |
| 328 | /** |
| 329 | * Gets the current clip. |
| 330 | * @return the current clip. |
| 331 | */ |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 332 | const GrClip& getClip() const; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 333 | |
| 334 | /** |
| 335 | * Sets the clip. |
| 336 | * @param clip the clip to set. |
| 337 | */ |
| 338 | void setClip(const GrClip& clip); |
| 339 | |
| 340 | /** |
| 341 | * Convenience method for setting the clip to a rect. |
| 342 | * @param rect the rect to set as the new clip. |
| 343 | */ |
| 344 | void setClip(const GrIRect& rect); |
| 345 | |
| 346 | /////////////////////////////////////////////////////////////////////////// |
| 347 | // Draws |
| 348 | |
| 349 | /** |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 350 | * Clear the entire or rect of the render target, ignoring any clips. |
| 351 | * @param rect the rect to clear or the whole thing if rect is NULL. |
| 352 | * @param color the color to clear to. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 353 | */ |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 354 | void clear(const GrIRect* rect, GrColor color); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 355 | |
| 356 | /** |
| 357 | * Draw everywhere (respecting the clip) with the paint. |
| 358 | */ |
| 359 | void drawPaint(const GrPaint& paint); |
| 360 | |
| 361 | /** |
| 362 | * Draw the rect using a paint. |
| 363 | * @param paint describes how to color pixels. |
| 364 | * @param strokeWidth If strokeWidth < 0, then the rect is filled, else |
| 365 | * the rect is mitered stroked based on strokeWidth. If |
| 366 | * strokeWidth == 0, then the stroke is always a single |
| 367 | * pixel thick. |
| 368 | * @param matrix Optional matrix applied to the rect. Applied before |
| 369 | * context's matrix or the paint's matrix. |
| 370 | * The rects coords are used to access the paint (through texture matrix) |
| 371 | */ |
| 372 | void drawRect(const GrPaint& paint, |
| 373 | const GrRect&, |
| 374 | GrScalar strokeWidth = -1, |
| 375 | const GrMatrix* matrix = NULL); |
| 376 | |
| 377 | /** |
| 378 | * Maps a rect of paint coordinates onto the a rect of destination |
| 379 | * coordinates. Each rect can optionally be transformed. The srcRect |
| 380 | * is stretched over the dstRect. The dstRect is transformed by the |
| 381 | * context's matrix and the srcRect is transformed by the paint's matrix. |
| 382 | * Additional optional matrices can be provided by parameters. |
| 383 | * |
| 384 | * @param paint describes how to color pixels. |
| 385 | * @param dstRect the destination rect to draw. |
| 386 | * @param srcRect rect of paint coordinates to be mapped onto dstRect |
| 387 | * @param dstMatrix Optional matrix to transform dstRect. Applied before |
| 388 | * context's matrix. |
| 389 | * @param srcMatrix Optional matrix to transform srcRect Applied before |
| 390 | * paint's matrix. |
| 391 | */ |
| 392 | void drawRectToRect(const GrPaint& paint, |
| 393 | const GrRect& dstRect, |
| 394 | const GrRect& srcRect, |
| 395 | const GrMatrix* dstMatrix = NULL, |
| 396 | const GrMatrix* srcMatrix = NULL); |
| 397 | |
| 398 | /** |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 399 | * Draws a path. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 400 | * |
| 401 | * @param paint describes how to color pixels. |
reed@google.com | 07f3ee1 | 2011-05-16 17:21:57 +0000 | [diff] [blame] | 402 | * @param path the path to draw |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 403 | * @param fill the path filling rule to use. |
| 404 | * @param translate optional additional translation applied to the |
| 405 | * path. |
| 406 | */ |
reed@google.com | 07f3ee1 | 2011-05-16 17:21:57 +0000 | [diff] [blame] | 407 | void drawPath(const GrPaint& paint, const GrPath& path, GrPathFill fill, |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 408 | const GrPoint* translate = NULL); |
reed@google.com | 07f3ee1 | 2011-05-16 17:21:57 +0000 | [diff] [blame] | 409 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 410 | /** |
| 411 | * Draws vertices with a paint. |
| 412 | * |
| 413 | * @param paint describes how to color pixels. |
| 414 | * @param primitiveType primitives type to draw. |
| 415 | * @param vertexCount number of vertices. |
| 416 | * @param positions array of vertex positions, required. |
| 417 | * @param texCoords optional array of texture coordinates used |
| 418 | * to access the paint. |
| 419 | * @param colors optional array of per-vertex colors, supercedes |
| 420 | * the paint's color field. |
| 421 | * @param indices optional array of indices. If NULL vertices |
| 422 | * are drawn non-indexed. |
| 423 | * @param indexCount if indices is non-null then this is the |
| 424 | * number of indices. |
| 425 | */ |
| 426 | void drawVertices(const GrPaint& paint, |
| 427 | GrPrimitiveType primitiveType, |
| 428 | int vertexCount, |
| 429 | const GrPoint positions[], |
| 430 | const GrPoint texs[], |
| 431 | const GrColor colors[], |
| 432 | const uint16_t indices[], |
| 433 | int indexCount); |
| 434 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 435 | /////////////////////////////////////////////////////////////////////////// |
| 436 | // Misc. |
| 437 | |
| 438 | /** |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 439 | * Flags that affect flush() behavior. |
| 440 | */ |
| 441 | enum FlushBits { |
| 442 | /** |
| 443 | * A client may want Gr to bind a GrRenderTarget in the 3D API so that |
| 444 | * it can be rendered to directly. However, Gr lazily sets state. Simply |
| 445 | * calling setRenderTarget() followed by flush() without flags may not |
| 446 | * bind the render target. This flag forces the context to bind the last |
| 447 | * set render target in the 3D API. |
| 448 | */ |
| 449 | kForceCurrentRenderTarget_FlushBit = 0x1, |
| 450 | /** |
| 451 | * A client may reach a point where it has partially rendered a frame |
| 452 | * through a GrContext that it knows the user will never see. This flag |
| 453 | * causes the flush to skip submission of deferred content to the 3D API |
| 454 | * during the flush. |
| 455 | */ |
| 456 | kDiscard_FlushBit = 0x2, |
| 457 | }; |
| 458 | |
| 459 | /** |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 460 | * Call to ensure all drawing to the context has been issued to the |
| 461 | * underlying 3D API. |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 462 | * @param flagsBitfield flags that control the flushing behavior. See |
| 463 | * FlushBits. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 464 | */ |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 465 | void flush(int flagsBitfield = 0); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 466 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 467 | /** |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 468 | * Reads a rectangle of pixels from a render target. |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 469 | * @param target the render target to read from. NULL means the |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 470 | * current render target. |
| 471 | * @param left left edge of the rectangle to read (inclusive) |
| 472 | * @param top top edge of the rectangle to read (inclusive) |
| 473 | * @param width width of rectangle to read in pixels. |
| 474 | * @param height height of rectangle to read in pixels. |
| 475 | * @param config the pixel config of the destination buffer |
| 476 | * @param buffer memory to read the rectangle into. |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 477 | * @param rowBytes number of bytes bewtween consecutive rows. Zero |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 478 | * means rows are tightly packed. |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 479 | * |
| 480 | * @return true if the read succeeded, false if not. The read can fail |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 481 | * because of an unsupported pixel config or because no render |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 482 | * target is currently set. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 483 | */ |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 484 | bool readRenderTargetPixels(GrRenderTarget* target, |
| 485 | int left, int top, int width, int height, |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 486 | GrPixelConfig config, void* buffer, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 487 | size_t rowBytes) { |
| 488 | return this->internalReadRenderTargetPixels(target, left, top, |
| 489 | width, height, |
| 490 | config, buffer, |
| 491 | rowBytes, 0); |
| 492 | } |
| 493 | |
| 494 | /** |
| 495 | * Copy the src pixels [buffer, rowbytes, pixelconfig] into a render target |
| 496 | * at the specified rectangle. |
| 497 | * @param target the render target to write into. NULL means the |
| 498 | * current render target. |
| 499 | * @param left left edge of the rectangle to write (inclusive) |
| 500 | * @param top top edge of the rectangle to write (inclusive) |
| 501 | * @param width width of rectangle to write in pixels. |
| 502 | * @param height height of rectangle to write in pixels. |
| 503 | * @param config the pixel config of the source buffer |
| 504 | * @param buffer memory to read the rectangle from. |
| 505 | * @param rowBytes number of bytes bewtween consecutive rows. Zero |
| 506 | * means rows are tightly packed. |
| 507 | */ |
| 508 | void writeRenderTargetPixels(GrRenderTarget* target, |
| 509 | int left, int top, int width, int height, |
| 510 | GrPixelConfig config, const void* buffer, |
| 511 | size_t rowBytes) { |
| 512 | this->internalWriteRenderTargetPixels(target, left, top, width, height, |
| 513 | config, buffer, rowBytes, 0); |
| 514 | } |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 515 | |
| 516 | /** |
| 517 | * Reads a rectangle of pixels from a texture. |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 518 | * @param texture the texture to read from. |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 519 | * @param left left edge of the rectangle to read (inclusive) |
| 520 | * @param top top edge of the rectangle to read (inclusive) |
| 521 | * @param width width of rectangle to read in pixels. |
| 522 | * @param height height of rectangle to read in pixels. |
| 523 | * @param config the pixel config of the destination buffer |
| 524 | * @param buffer memory to read the rectangle into. |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 525 | * @param rowBytes number of bytes bewtween consecutive rows. Zero |
| 526 | * means rows are tightly packed. |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 527 | * |
| 528 | * @return true if the read succeeded, false if not. The read can fail |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 529 | * because of an unsupported pixel config. |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 530 | */ |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 531 | bool readTexturePixels(GrTexture* texture, |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 532 | int left, int top, int width, int height, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 533 | GrPixelConfig config, void* buffer, |
| 534 | size_t rowBytes) { |
| 535 | return this->internalReadTexturePixels(texture, left, top, |
| 536 | width, height, |
| 537 | config, buffer, rowBytes, 0); |
| 538 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 539 | |
| 540 | /** |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 541 | * Writes a rectangle of pixels to a texture. |
| 542 | * @param texture the render target to read from. |
| 543 | * @param left left edge of the rectangle to write (inclusive) |
| 544 | * @param top top edge of the rectangle to write (inclusive) |
| 545 | * @param width width of rectangle to write in pixels. |
| 546 | * @param height height of rectangle to write in pixels. |
| 547 | * @param config the pixel config of the source buffer |
| 548 | * @param buffer memory to read pixels from |
| 549 | * @param rowBytes number of bytes bewtween consecutive rows. Zero |
| 550 | * means rows are tightly packed. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 551 | */ |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 552 | void writeTexturePixels(GrTexture* texture, |
| 553 | int left, int top, int width, int height, |
| 554 | GrPixelConfig config, const void* buffer, |
| 555 | size_t rowBytes) { |
| 556 | this->internalWriteTexturePixels(texture, left, top, width, height, |
| 557 | config, buffer, rowBytes, 0); |
| 558 | } |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 559 | /** |
senorblanco@chromium.org | ef843cd | 2011-12-02 19:11:17 +0000 | [diff] [blame] | 560 | * Copies all texels from one texture to another. |
| 561 | * @param src the texture to copy from. |
| 562 | * @param dst the render target to copy to. |
| 563 | */ |
| 564 | void copyTexture(GrTexture* src, GrRenderTarget* dst); |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 565 | |
| 566 | /** |
| 567 | * Resolves a render target that has MSAA. The intermediate MSAA buffer is |
| 568 | * downsampled to the associated GrTexture (accessible via |
| 569 | * GrRenderTarget::asTexture()). Any pending draws to the render target will |
| 570 | * be executed before the resolve. |
| 571 | * |
| 572 | * This is only necessary when a client wants to access the object directly |
| 573 | * using the underlying graphics API. GrContext will detect when it must |
| 574 | * perform a resolve to a GrTexture used as the source of a draw or before |
| 575 | * reading pixels back from a GrTexture or GrRenderTarget. |
| 576 | */ |
| 577 | void resolveRenderTarget(GrRenderTarget* target); |
| 578 | |
senorblanco@chromium.org | ef843cd | 2011-12-02 19:11:17 +0000 | [diff] [blame] | 579 | /** |
senorblanco@chromium.org | aadd9f8 | 2011-07-12 19:44:51 +0000 | [diff] [blame] | 580 | * Applies a 1D convolution kernel in the X direction to a rectangle of |
| 581 | * pixels from a given texture. |
| 582 | * @param texture the texture to read from |
| 583 | * @param rect the destination rectangle |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 584 | * @param kernel the convolution kernel (kernelWidth elements) |
| 585 | * @param kernelWidth the width of the convolution kernel |
| 586 | */ |
senorblanco@chromium.org | aadd9f8 | 2011-07-12 19:44:51 +0000 | [diff] [blame] | 587 | void convolveInX(GrTexture* texture, |
| 588 | const SkRect& rect, |
| 589 | const float* kernel, |
| 590 | int kernelWidth); |
| 591 | /** |
| 592 | * Applies a 1D convolution kernel in the Y direction to a rectangle of |
| 593 | * pixels from a given texture. |
| 594 | * direction. |
| 595 | * @param texture the texture to read from |
| 596 | * @param rect the destination rectangle |
| 597 | * @param kernel the convolution kernel (kernelWidth elements) |
| 598 | * @param kernelWidth the width of the convolution kernel |
| 599 | */ |
| 600 | void convolveInY(GrTexture* texture, |
| 601 | const SkRect& rect, |
| 602 | const float* kernel, |
| 603 | int kernelWidth); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 604 | /////////////////////////////////////////////////////////////////////////// |
| 605 | // Helpers |
| 606 | |
| 607 | class AutoRenderTarget : ::GrNoncopyable { |
| 608 | public: |
| 609 | AutoRenderTarget(GrContext* context, GrRenderTarget* target) { |
| 610 | fContext = NULL; |
| 611 | fPrevTarget = context->getRenderTarget(); |
| 612 | if (fPrevTarget != target) { |
| 613 | context->setRenderTarget(target); |
| 614 | fContext = context; |
| 615 | } |
| 616 | } |
| 617 | ~AutoRenderTarget() { |
| 618 | if (fContext) { |
| 619 | fContext->setRenderTarget(fPrevTarget); |
| 620 | } |
| 621 | } |
| 622 | private: |
| 623 | GrContext* fContext; |
| 624 | GrRenderTarget* fPrevTarget; |
| 625 | }; |
| 626 | |
| 627 | |
| 628 | /////////////////////////////////////////////////////////////////////////// |
| 629 | // Functions intended for internal use only. |
| 630 | GrGpu* getGpu() { return fGpu; } |
bsalomon@google.com | 1f221a7 | 2011-08-23 20:54:07 +0000 | [diff] [blame] | 631 | const GrGpu* getGpu() const { return fGpu; } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 632 | GrFontCache* getFontCache() { return fFontCache; } |
| 633 | GrDrawTarget* getTextTarget(const GrPaint& paint); |
| 634 | void flushText(); |
| 635 | const GrIndexBuffer* getQuadIndexBuffer() const; |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 636 | void resetStats(); |
| 637 | const GrGpuStats& getStats() const; |
| 638 | void printStats() const; |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 639 | /** |
| 640 | * Stencil buffers add themselves to the cache using |
| 641 | * addAndLockStencilBuffer. When a SB's RT-attachment count |
| 642 | * reaches zero the SB unlocks itself using unlockStencilBuffer and is |
| 643 | * eligible for purging. findStencilBuffer is called to check the cache for |
| 644 | * a SB that matching an RT's criteria. If a match is found that has been |
| 645 | * unlocked (its attachment count has reached 0) then it will be relocked. |
| 646 | */ |
| 647 | GrResourceEntry* addAndLockStencilBuffer(GrStencilBuffer* sb); |
| 648 | void unlockStencilBuffer(GrResourceEntry* sbEntry); |
| 649 | GrStencilBuffer* findStencilBuffer(int width, int height, int sampleCnt); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 650 | |
| 651 | private: |
| 652 | // used to keep track of when we need to flush the draw buffer |
| 653 | enum DrawCategory { |
| 654 | kBuffered_DrawCategory, // last draw was inserted in draw buffer |
| 655 | kUnbuffered_DrawCategory, // last draw was not inserted in the draw buffer |
| 656 | kText_DrawCategory // text context was last to draw |
| 657 | }; |
| 658 | DrawCategory fLastDrawCategory; |
| 659 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 660 | GrGpu* fGpu; |
| 661 | GrResourceCache* fTextureCache; |
| 662 | GrFontCache* fFontCache; |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 663 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 664 | GrPathRendererChain* fPathRendererChain; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 665 | |
| 666 | GrVertexBufferAllocPool* fDrawBufferVBAllocPool; |
| 667 | GrIndexBufferAllocPool* fDrawBufferIBAllocPool; |
| 668 | GrInOrderDrawBuffer* fDrawBuffer; |
| 669 | |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 670 | GrIndexBuffer* fAAFillRectIndexBuffer; |
| 671 | GrIndexBuffer* fAAStrokeRectIndexBuffer; |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 672 | int fMaxOffscreenAASize; |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 673 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 674 | GrContext(GrGpu* gpu); |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 675 | |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 676 | void fillAARect(GrDrawTarget* target, |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 677 | const GrRect& devRect, |
| 678 | bool useVertexCoverage); |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 679 | |
| 680 | void strokeAARect(GrDrawTarget* target, |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 681 | const GrRect& devRect, |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 682 | const GrVec& devStrokeSize, |
| 683 | bool useVertexCoverage); |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 684 | |
| 685 | inline int aaFillRectIndexCount() const; |
| 686 | GrIndexBuffer* aaFillRectIndexBuffer(); |
| 687 | |
| 688 | inline int aaStrokeRectIndexCount() const; |
| 689 | GrIndexBuffer* aaStrokeRectIndexBuffer(); |
| 690 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 691 | void setupDrawBuffer(); |
| 692 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 693 | void flushDrawBuffer(); |
| 694 | |
bsalomon@google.com | bc4b654 | 2011-11-19 13:56:11 +0000 | [diff] [blame] | 695 | void setPaint(const GrPaint& paint, GrDrawTarget* target); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 696 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 697 | GrDrawTarget* prepareToDraw(const GrPaint& paint, DrawCategory drawType); |
| 698 | |
bsalomon@google.com | 289533a | 2011-10-27 12:34:25 +0000 | [diff] [blame] | 699 | GrPathRenderer* getPathRenderer(const GrPath& path, |
| 700 | GrPathFill fill, |
| 701 | bool antiAlias); |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 702 | |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 703 | struct OffscreenRecord; |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 704 | |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 705 | // determines whether offscreen AA should be applied |
bsalomon@google.com | d46e242 | 2011-09-23 17:40:07 +0000 | [diff] [blame] | 706 | bool doOffscreenAA(GrDrawTarget* target, |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 707 | bool isHairLines) const; |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 708 | |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 709 | // attempts to setup offscreen AA. All paint state must be transferred to |
| 710 | // target by the time this is called. |
| 711 | bool prepareForOffscreenAA(GrDrawTarget* target, |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 712 | bool requireStencil, |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 713 | const GrIRect& boundRect, |
tomhudson@google.com | d22b6e4 | 2011-06-24 15:53:40 +0000 | [diff] [blame] | 714 | GrPathRenderer* pr, |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 715 | OffscreenRecord* record); |
| 716 | |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 717 | // sets up target to draw coverage to the supersampled render target |
| 718 | void setupOffscreenAAPass1(GrDrawTarget* target, |
| 719 | const GrIRect& boundRect, |
| 720 | int tileX, int tileY, |
| 721 | OffscreenRecord* record); |
| 722 | |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 723 | // sets up target to sample coverage of supersampled render target back |
| 724 | // to the main render target using stage kOffscreenStage. |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 725 | void doOffscreenAAPass2(GrDrawTarget* target, |
| 726 | const GrPaint& paint, |
| 727 | const GrIRect& boundRect, |
| 728 | int tileX, int tileY, |
| 729 | OffscreenRecord* record); |
| 730 | |
| 731 | // restored the draw target state and releases offscreen target to cache |
tomhudson@google.com | d22b6e4 | 2011-06-24 15:53:40 +0000 | [diff] [blame] | 732 | void cleanupOffscreenAA(GrDrawTarget* target, |
| 733 | GrPathRenderer* pr, |
| 734 | OffscreenRecord* record); |
senorblanco@chromium.org | aadd9f8 | 2011-07-12 19:44:51 +0000 | [diff] [blame] | 735 | |
| 736 | void convolve(GrTexture* texture, |
| 737 | const SkRect& rect, |
| 738 | float imageIncrement[2], |
| 739 | const float* kernel, |
| 740 | int kernelWidth); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 741 | |
| 742 | /** |
| 743 | * Flags to the internal read/write pixels funcs |
| 744 | */ |
| 745 | enum PixelOpsFlags { |
| 746 | kDontFlush_PixelOpsFlag = 0x1, |
| 747 | }; |
| 748 | |
| 749 | bool internalReadRenderTargetPixels(GrRenderTarget* target, |
| 750 | int left, int top, |
| 751 | int width, int height, |
| 752 | GrPixelConfig config, void* buffer, |
| 753 | size_t rowBytes, uint32_t flags); |
| 754 | |
| 755 | void internalWriteRenderTargetPixels(GrRenderTarget* target, |
| 756 | int left, int top, |
| 757 | int width, int height, |
| 758 | GrPixelConfig, const void* buffer, |
| 759 | size_t rowBytes, uint32_t flags); |
| 760 | |
| 761 | bool internalReadTexturePixels(GrTexture* texture, |
| 762 | int left, int top, |
| 763 | int width, int height, |
| 764 | GrPixelConfig config, void* buffer, |
| 765 | size_t rowBytes, uint32_t flags); |
| 766 | |
| 767 | void internalWriteTexturePixels(GrTexture* texture, |
| 768 | int left, int top, |
| 769 | int width, int height, |
| 770 | GrPixelConfig config, const void* buffer, |
| 771 | size_t rowBytes, uint32_t flags); |
| 772 | // needed for access to internalWriteTexturePixels. TODO: make GrContext |
| 773 | // be a facade for an internal class. Then functions that are public on the |
| 774 | // internal class would have only be callable in src/gpu. The facade would |
| 775 | // only have to functions necessary for clients. |
| 776 | friend class GrAtlas; |
| 777 | |
bsalomon@google.com | 26c2d0a | 2011-05-17 20:15:30 +0000 | [diff] [blame] | 778 | // computes vertex layout bits based on the paint. If paint expresses |
| 779 | // a texture for a stage, the stage coords will be bound to postitions |
| 780 | // unless hasTexCoords[s]==true in which case stage s's input coords |
| 781 | // are bound to tex coord index s. hasTexCoords == NULL is a shortcut |
| 782 | // for an array where all the values are false. |
| 783 | static int PaintStageVertexLayoutBits( |
| 784 | const GrPaint& paint, |
| 785 | const bool hasTexCoords[GrPaint::kTotalStages]); |
| 786 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 787 | }; |
| 788 | |
| 789 | /** |
| 790 | * Save/restore the view-matrix in the context. |
| 791 | */ |
| 792 | class GrAutoMatrix : GrNoncopyable { |
| 793 | public: |
bsalomon@google.com | 4f83be8 | 2011-09-12 13:52:51 +0000 | [diff] [blame] | 794 | GrAutoMatrix() : fContext(NULL) {} |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 795 | GrAutoMatrix(GrContext* ctx) : fContext(ctx) { |
| 796 | fMatrix = ctx->getMatrix(); |
| 797 | } |
| 798 | GrAutoMatrix(GrContext* ctx, const GrMatrix& matrix) : fContext(ctx) { |
| 799 | fMatrix = ctx->getMatrix(); |
| 800 | ctx->setMatrix(matrix); |
| 801 | } |
bsalomon@google.com | 4f83be8 | 2011-09-12 13:52:51 +0000 | [diff] [blame] | 802 | void set(GrContext* ctx) { |
| 803 | if (NULL != fContext) { |
| 804 | fContext->setMatrix(fMatrix); |
| 805 | } |
| 806 | fMatrix = ctx->getMatrix(); |
| 807 | fContext = ctx; |
| 808 | } |
| 809 | void set(GrContext* ctx, const GrMatrix& matrix) { |
| 810 | if (NULL != fContext) { |
| 811 | fContext->setMatrix(fMatrix); |
| 812 | } |
| 813 | fMatrix = ctx->getMatrix(); |
| 814 | ctx->setMatrix(matrix); |
| 815 | fContext = ctx; |
| 816 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 817 | ~GrAutoMatrix() { |
bsalomon@google.com | 4f83be8 | 2011-09-12 13:52:51 +0000 | [diff] [blame] | 818 | if (NULL != fContext) { |
| 819 | fContext->setMatrix(fMatrix); |
| 820 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | private: |
| 824 | GrContext* fContext; |
| 825 | GrMatrix fMatrix; |
| 826 | }; |
| 827 | |
senorblanco@chromium.org | aadd9f8 | 2011-07-12 19:44:51 +0000 | [diff] [blame] | 828 | /** |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 829 | * Gets and locks a scratch texture from a descriptor using |
| 830 | * either exact or approximate criteria. Unlocks texture in |
| 831 | * the destructor. |
senorblanco@chromium.org | aadd9f8 | 2011-07-12 19:44:51 +0000 | [diff] [blame] | 832 | */ |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 833 | class GrAutoScratchTexture : ::GrNoncopyable { |
senorblanco@chromium.org | aadd9f8 | 2011-07-12 19:44:51 +0000 | [diff] [blame] | 834 | public: |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 835 | GrAutoScratchTexture() |
| 836 | : fContext(NULL) { |
senorblanco@chromium.org | aadd9f8 | 2011-07-12 19:44:51 +0000 | [diff] [blame] | 837 | } |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 838 | |
| 839 | GrAutoScratchTexture(GrContext* context, |
| 840 | const GrTextureDesc& desc, |
| 841 | GrContext::ScratchTexMatch match = |
| 842 | GrContext::kApprox_ScratchTexMatch) |
| 843 | : fContext(NULL) { |
| 844 | this->set(context, desc, match); |
| 845 | } |
| 846 | |
| 847 | ~GrAutoScratchTexture() { |
| 848 | if (NULL != fContext) { |
senorblanco@chromium.org | aadd9f8 | 2011-07-12 19:44:51 +0000 | [diff] [blame] | 849 | fContext->unlockTexture(fEntry); |
| 850 | } |
| 851 | } |
bsalomon@google.com | 8422311 | 2011-07-14 14:45:44 +0000 | [diff] [blame] | 852 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 853 | GrTexture* set(GrContext* context, |
| 854 | const GrTextureDesc& desc, |
| 855 | GrContext::ScratchTexMatch match = |
| 856 | GrContext::kApprox_ScratchTexMatch) { |
| 857 | if (NULL != fContext) { |
| 858 | fContext->unlockTexture(fEntry); |
| 859 | } |
| 860 | fContext = context; |
| 861 | if (NULL != fContext) { |
| 862 | fEntry = fContext->lockScratchTexture(desc, match); |
| 863 | GrTexture* ret = fEntry.texture(); |
| 864 | if (NULL == ret) { |
| 865 | fContext = NULL; |
| 866 | } |
| 867 | return ret; |
| 868 | } else { |
| 869 | return NULL; |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | GrTexture* texture() { return fEntry.texture(); } |
senorblanco@chromium.org | aadd9f8 | 2011-07-12 19:44:51 +0000 | [diff] [blame] | 874 | private: |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 875 | GrContext* fContext; |
| 876 | GrContext::TextureCacheEntry fEntry; |
senorblanco@chromium.org | aadd9f8 | 2011-07-12 19:44:51 +0000 | [diff] [blame] | 877 | }; |
| 878 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 879 | #endif |