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