epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2011 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. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 10 | #ifndef GrGpu_DEFINED |
| 11 | #define GrGpu_DEFINED |
| 12 | |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 13 | #include "GrDrawTarget.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 14 | #include "GrRect.h" |
| 15 | #include "GrRefCnt.h" |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 16 | #include "GrClipMaskManager.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 17 | |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 18 | class GrContext; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 19 | class GrIndexBufferAllocPool; |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 20 | class GrPath; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 21 | class GrPathRenderer; |
| 22 | class GrPathRendererChain; |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 23 | class GrResource; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 24 | class GrStencilBuffer; |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 25 | class GrVertexBufferAllocPool; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 26 | |
| 27 | class GrGpu : public GrDrawTarget { |
| 28 | |
| 29 | public: |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 30 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 31 | /** |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 32 | * Additional blend coefficients for dual source blending, not exposed |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 33 | * through GrPaint/GrContext. |
| 34 | */ |
| 35 | enum ExtendedBlendCoeffs { |
| 36 | // source 2 refers to second output color when |
| 37 | // using dual source blending. |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 38 | kS2C_GrBlendCoeff = kPublicGrBlendCoeffCount, |
| 39 | kIS2C_GrBlendCoeff, |
| 40 | kS2A_GrBlendCoeff, |
| 41 | kIS2A_GrBlendCoeff, |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 42 | |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 43 | kTotalGrBlendCoeffCount |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | /** |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 47 | * Create an instance of GrGpu that matches the specified backend. If the requested backend is |
| 48 | * not supported (at compile-time or run-time) this returns NULL. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 49 | */ |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 50 | static GrGpu* Create(GrBackend, GrBackendContext); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 51 | |
| 52 | //////////////////////////////////////////////////////////////////////////// |
| 53 | |
| 54 | GrGpu(); |
| 55 | virtual ~GrGpu(); |
| 56 | |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 57 | // The GrContext sets itself as the owner of this Gpu object |
| 58 | void setContext(GrContext* context) { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 59 | GrAssert(NULL == fContext); |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 60 | fContext = context; |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 61 | fClipMaskManager.setContext(context); |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 62 | } |
| 63 | GrContext* getContext() { return fContext; } |
| 64 | const GrContext* getContext() const { return fContext; } |
| 65 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 66 | /** |
| 67 | * The GrGpu object normally assumes that no outsider is setting state |
| 68 | * within the underlying 3D API's context/device/whatever. This call informs |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 69 | * the GrGpu that the state was modified and it shouldn't make assumptions |
| 70 | * about the state. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 71 | */ |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 72 | void markContextDirty() { fContextIsDirty = true; } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 73 | |
| 74 | void unimpl(const char[]); |
| 75 | |
| 76 | /** |
bsalomon@google.com | 0748f21 | 2011-02-01 22:56:16 +0000 | [diff] [blame] | 77 | * Creates a texture object. If desc width or height is not a power of |
| 78 | * two but underlying API requires a power of two texture then srcData |
| 79 | * will be embedded in a power of two texture. The extra width and height |
| 80 | * is filled as though srcData were rendered clamped into the texture. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 81 | * |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 82 | * If kRenderTarget_TextureFlag is specified the GrRenderTarget is |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 83 | * accessible via GrTexture::asRenderTarget(). The texture will hold a ref |
| 84 | * on the render target until its releaseRenderTarget() is called or it is |
| 85 | * destroyed. |
| 86 | * |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 87 | * @param desc describes the texture to be created. |
| 88 | * @param srcData texel data to load texture. Begins with full-size |
| 89 | * palette data for paletted textures. Contains width* |
| 90 | * height texels. If NULL texture data is uninitialized. |
| 91 | * |
| 92 | * @return The texture object if successful, otherwise NULL. |
| 93 | */ |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 94 | GrTexture* createTexture(const GrTextureDesc& desc, |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 95 | const void* srcData, size_t rowBytes); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 96 | |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 97 | /** |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 98 | * Implements GrContext::wrapBackendTexture |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 99 | */ |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 100 | GrTexture* wrapBackendTexture(const GrBackendTextureDesc&); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 101 | |
| 102 | /** |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 103 | * Implements GrContext::wrapBackendTexture |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 104 | */ |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 105 | GrRenderTarget* wrapBackendRenderTarget(const GrBackendRenderTargetDesc&); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 106 | |
| 107 | /** |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 108 | * Creates a vertex buffer. |
| 109 | * |
| 110 | * @param size size in bytes of the vertex buffer |
| 111 | * @param dynamic hints whether the data will be frequently changed |
| 112 | * by either GrVertexBuffer::lock or |
| 113 | * GrVertexBuffer::updateData. |
| 114 | * |
| 115 | * @return The vertex buffer if successful, otherwise NULL. |
| 116 | */ |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 117 | GrVertexBuffer* createVertexBuffer(uint32_t size, bool dynamic); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 118 | |
| 119 | /** |
| 120 | * Creates an index buffer. |
| 121 | * |
| 122 | * @param size size in bytes of the index buffer |
| 123 | * @param dynamic hints whether the data will be frequently changed |
| 124 | * by either GrIndexBuffer::lock or |
| 125 | * GrIndexBuffer::updateData. |
| 126 | * |
| 127 | * @return The index buffer if successful, otherwise NULL. |
| 128 | */ |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 129 | GrIndexBuffer* createIndexBuffer(uint32_t size, bool dynamic); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 130 | |
| 131 | /** |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 132 | * Creates a path object that can be stenciled using stencilPath(). It is |
| 133 | * only legal to call this if the caps report support for path stenciling. |
| 134 | */ |
| 135 | GrPath* createPath(const SkPath& path); |
| 136 | |
| 137 | /** |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 138 | * Returns an index buffer that can be used to render quads. |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 139 | * Six indices per quad: 0, 1, 2, 0, 2, 3, etc. |
| 140 | * The max number of quads can be queried using GrIndexBuffer::maxQuads(). |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 141 | * Draw with kTriangles_GrPrimitiveType |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 142 | * @ return the quad index buffer |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 143 | */ |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 144 | const GrIndexBuffer* getQuadIndexBuffer() const; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 145 | |
| 146 | /** |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 147 | * Returns a vertex buffer with four position-only vertices [(0,0), (1,0), |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 148 | * (1,1), (0,1)]. |
| 149 | * @ return unit square vertex buffer |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 150 | */ |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 151 | const GrVertexBuffer* getUnitSquareVertexBuffer() const; |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 152 | |
| 153 | /** |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 154 | * Resolves MSAA. |
| 155 | */ |
| 156 | void resolveRenderTarget(GrRenderTarget* target); |
| 157 | |
| 158 | /** |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 159 | * Ensures that the current render target is actually set in the |
| 160 | * underlying 3D API. Used when client wants to use 3D API to directly |
| 161 | * render to the RT. |
| 162 | */ |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 163 | void forceRenderTargetFlush(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 164 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 165 | /** |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 166 | * readPixels with some configs may be slow. Given a desired config this |
| 167 | * function returns a fast-path config. The returned config must have the |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 168 | * same components and component sizes. The caller is free to ignore the |
| 169 | * result and call readPixels with the original config. |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 170 | */ |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 171 | virtual GrPixelConfig preferredReadPixelsConfig(GrPixelConfig config) |
| 172 | const { |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 173 | return config; |
| 174 | } |
| 175 | |
| 176 | /** |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 177 | * Same as above but applies to writeTexturePixels |
| 178 | */ |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 179 | virtual GrPixelConfig preferredWritePixelsConfig(GrPixelConfig config) |
| 180 | const { |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 181 | return config; |
| 182 | } |
| 183 | |
| 184 | /** |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 185 | * OpenGL's readPixels returns the result bottom-to-top while the skia |
| 186 | * API is top-to-bottom. Thus we have to do a y-axis flip. The obvious |
| 187 | * solution is to have the subclass do the flip using either the CPU or GPU. |
| 188 | * However, the caller (GrContext) may have transformations to apply and can |
| 189 | * simply fold in the y-flip for free. On the other hand, the subclass may |
| 190 | * be able to do it for free itself. For example, the subclass may have to |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 191 | * do memcpys to handle rowBytes that aren't tight. It could do the y-flip |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 192 | * concurrently. |
| 193 | * |
| 194 | * This function returns true if a y-flip is required to put the pixels in |
| 195 | * top-to-bottom order and the subclass cannot do it for free. |
| 196 | * |
| 197 | * See read pixels for the params |
| 198 | * @return true if calling readPixels with the same set of params will |
| 199 | * produce bottom-to-top data |
| 200 | */ |
| 201 | virtual bool readPixelsWillPayForYFlip(GrRenderTarget* renderTarget, |
| 202 | int left, int top, |
| 203 | int width, int height, |
| 204 | GrPixelConfig config, |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 205 | size_t rowBytes) const = 0; |
| 206 | /** |
| 207 | * This should return true if reading a NxM rectangle of pixels from a |
| 208 | * render target is faster if the target has dimensons N and M and the read |
| 209 | * rectangle has its top-left at 0,0. |
| 210 | */ |
| 211 | virtual bool fullReadPixelsIsFasterThanPartial() const { return false; }; |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 212 | |
| 213 | /** |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 214 | * Reads a rectangle of pixels from a render target. |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 215 | * |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 216 | * @param renderTarget the render target to read from. NULL means the |
| 217 | * current render target. |
| 218 | * @param left left edge of the rectangle to read (inclusive) |
| 219 | * @param top top edge of the rectangle to read (inclusive) |
| 220 | * @param width width of rectangle to read in pixels. |
| 221 | * @param height height of rectangle to read in pixels. |
| 222 | * @param config the pixel config of the destination buffer |
| 223 | * @param buffer memory to read the rectangle into. |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 224 | * @param rowBytes the number of bytes between consecutive rows. Zero |
| 225 | * means rows are tightly packed. |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 226 | * @param invertY buffer should be populated bottom-to-top as opposed |
| 227 | * to top-to-bottom (skia's usual order) |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 228 | * |
| 229 | * @return true if the read succeeded, false if not. The read can fail |
| 230 | * because of a unsupported pixel config or because no render |
| 231 | * target is currently set. |
| 232 | */ |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 233 | bool readPixels(GrRenderTarget* renderTarget, |
| 234 | int left, int top, int width, int height, |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 235 | GrPixelConfig config, void* buffer, size_t rowBytes, |
| 236 | bool invertY); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 237 | |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 238 | /** |
| 239 | * Updates the pixels in a rectangle of a texture. |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 240 | * |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 241 | * @param left left edge of the rectangle to write (inclusive) |
| 242 | * @param top top edge of the rectangle to write (inclusive) |
| 243 | * @param width width of rectangle to write in pixels. |
| 244 | * @param height height of rectangle to write in pixels. |
| 245 | * @param config the pixel config of the source buffer |
| 246 | * @param buffer memory to read pixels from |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 247 | * @param rowBytes number of bytes between consecutive rows. Zero |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 248 | * means rows are tightly packed. |
| 249 | */ |
| 250 | void writeTexturePixels(GrTexture* texture, |
| 251 | int left, int top, int width, int height, |
| 252 | GrPixelConfig config, const void* buffer, |
| 253 | size_t rowBytes); |
| 254 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 255 | /** |
| 256 | * Called to tell Gpu object that all GrResources have been lost and should |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 257 | * be abandoned. Overrides must call INHERITED::abandonResources(). |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 258 | */ |
junov@google.com | 53a5584 | 2011-06-08 22:55:10 +0000 | [diff] [blame] | 259 | virtual void abandonResources(); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 260 | |
| 261 | /** |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 262 | * Called to tell Gpu object to release all GrResources. Overrides must call |
| 263 | * INHERITED::releaseResources(). |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 264 | */ |
| 265 | void releaseResources(); |
| 266 | |
| 267 | /** |
| 268 | * Add resource to list of resources. Should only be called by GrResource. |
| 269 | * @param resource the resource to add. |
| 270 | */ |
| 271 | void insertResource(GrResource* resource); |
| 272 | |
| 273 | /** |
| 274 | * Remove resource from list of resources. Should only be called by |
| 275 | * GrResource. |
| 276 | * @param resource the resource to remove. |
| 277 | */ |
| 278 | void removeResource(GrResource* resource); |
| 279 | |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 280 | // GrDrawTarget overrides |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 281 | virtual void clear(const GrIRect* rect, |
robertphillips@google.com | c82a8b7 | 2012-06-21 20:15:48 +0000 | [diff] [blame] | 282 | GrColor color, |
| 283 | GrRenderTarget* renderTarget = NULL) SK_OVERRIDE; |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 284 | |
robertphillips@google.com | ff17584 | 2012-05-14 19:31:39 +0000 | [diff] [blame] | 285 | virtual void purgeResources() SK_OVERRIDE { |
| 286 | // The clip mask manager can rebuild all its clip masks so just |
| 287 | // get rid of them all. |
| 288 | fClipMaskManager.releaseResources(); |
| 289 | } |
| 290 | |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 291 | // After the client interacts directly with the 3D context state the GrGpu |
| 292 | // must resync its internal state and assumptions about 3D context state. |
| 293 | // Each time this occurs the GrGpu bumps a timestamp. |
| 294 | // state of the 3D context |
| 295 | // At 10 resets / frame and 60fps a 64bit timestamp will overflow in about |
| 296 | // a billion years. |
| 297 | typedef uint64_t ResetTimestamp; |
| 298 | |
| 299 | // This timestamp is always older than the current timestamp |
| 300 | static const ResetTimestamp kExpiredTimestamp = 0; |
| 301 | // Returns a timestamp based on the number of times the context was reset. |
| 302 | // This timestamp can be used to lazily detect when cached 3D context state |
| 303 | // is dirty. |
| 304 | ResetTimestamp getResetTimestamp() const { |
| 305 | return fResetTimestamp; |
| 306 | } |
| 307 | |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 308 | /** |
| 309 | * Can the provided configuration act as a color render target? |
| 310 | */ |
| 311 | bool isConfigRenderable(GrPixelConfig config) const { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 312 | GrAssert(kGrPixelConfigCount > config); |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 313 | return fConfigRenderSupport[config]; |
| 314 | } |
| 315 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 316 | /** |
| 317 | * These methods are called by the clip manager's setupClipping function |
| 318 | * which (called as part of GrGpu's implementation of onDraw* and |
| 319 | * onStencilPath member functions.) The GrGpu subclass should flush the |
| 320 | * stencil state to the 3D API in its implementation of flushGraphicsState. |
| 321 | */ |
| 322 | void enableScissor(const GrIRect& rect) { |
| 323 | fScissorState.fEnabled = true; |
| 324 | fScissorState.fRect = rect; |
| 325 | } |
| 326 | void disableScissor() { fScissorState.fEnabled = false; } |
| 327 | |
| 328 | /** |
| 329 | * Like the scissor methods above this is called by setupClipping and |
| 330 | * should be flushed by the GrGpu subclass in flushGraphicsState. These |
| 331 | * stencil settings should be used in place of those on the GrDrawState. |
| 332 | * They have been adjusted to account for any interactions between the |
| 333 | * GrDrawState's stencil settings and stencil clipping. |
| 334 | */ |
| 335 | void setStencilSettings(const GrStencilSettings& settings) { |
| 336 | fStencilSettings = settings; |
| 337 | } |
| 338 | void disableStencil() { fStencilSettings.setDisabled(); } |
robertphillips@google.com | 730ebe5 | 2012-04-16 16:33:13 +0000 | [diff] [blame] | 339 | |
| 340 | // GrGpu subclass sets clip bit in the stencil buffer. The subclass is |
| 341 | // free to clear the remaining bits to zero if masked clears are more |
| 342 | // expensive than clearing all bits. |
| 343 | virtual void clearStencilClip(const GrIRect& rect, bool insideClip) = 0; |
| 344 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 345 | enum PrivateDrawStateStateBits { |
| 346 | kFirstBit = (GrDrawState::kLastPublicStateBit << 1), |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 347 | |
| 348 | kModifyStencilClip_StateBit = kFirstBit, // allows draws to modify |
| 349 | // stencil bits used for |
| 350 | // clipping. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 351 | }; |
| 352 | |
robertphillips@google.com | 730ebe5 | 2012-04-16 16:33:13 +0000 | [diff] [blame] | 353 | protected: |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 354 | enum DrawType { |
| 355 | kDrawPoints_DrawType, |
| 356 | kDrawLines_DrawType, |
| 357 | kDrawTriangles_DrawType, |
| 358 | kStencilPath_DrawType, |
| 359 | }; |
| 360 | |
| 361 | DrawType PrimTypeToDrawType(GrPrimitiveType type) { |
| 362 | switch (type) { |
| 363 | case kTriangles_GrPrimitiveType: |
| 364 | case kTriangleStrip_GrPrimitiveType: |
| 365 | case kTriangleFan_GrPrimitiveType: |
| 366 | return kDrawTriangles_DrawType; |
| 367 | case kPoints_GrPrimitiveType: |
| 368 | return kDrawPoints_DrawType; |
| 369 | case kLines_GrPrimitiveType: |
| 370 | case kLineStrip_GrPrimitiveType: |
| 371 | return kDrawLines_DrawType; |
| 372 | default: |
| 373 | GrCrash("Unexpected primitive type"); |
| 374 | return kDrawTriangles_DrawType; |
| 375 | } |
| 376 | } |
| 377 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 378 | // prepares clip flushes gpu state before a draw |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 379 | bool setupClipAndFlushState(DrawType); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 380 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 381 | // Functions used to map clip-respecting stencil tests into normal |
| 382 | // stencil funcs supported by GPUs. |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 383 | static GrStencilFunc ConvertStencilFunc(bool stencilInClip, |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 384 | GrStencilFunc func); |
| 385 | static void ConvertStencilFuncAndMask(GrStencilFunc func, |
| 386 | bool clipInStencil, |
| 387 | unsigned int clipBit, |
| 388 | unsigned int userBits, |
| 389 | unsigned int* ref, |
| 390 | unsigned int* mask); |
| 391 | |
robertphillips@google.com | 730ebe5 | 2012-04-16 16:33:13 +0000 | [diff] [blame] | 392 | GrClipMaskManager fClipMaskManager; |
| 393 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 394 | struct GeometryPoolState { |
| 395 | const GrVertexBuffer* fPoolVertexBuffer; |
| 396 | int fPoolStartVertex; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 397 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 398 | const GrIndexBuffer* fPoolIndexBuffer; |
| 399 | int fPoolStartIndex; |
| 400 | }; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 401 | const GeometryPoolState& getGeomPoolState() { |
| 402 | return fGeomPoolStateStack.back(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 403 | } |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 404 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 405 | // The state of the scissor is controlled by the clip manager |
| 406 | struct ScissorState { |
| 407 | bool fEnabled; |
| 408 | GrIRect fRect; |
| 409 | } fScissorState; |
| 410 | |
| 411 | // The final stencil settings to use as determined by the clip manager. |
| 412 | GrStencilSettings fStencilSettings; |
| 413 | |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 414 | // Derived classes need access to this so they can fill it out in their |
| 415 | // constructors |
| 416 | bool fConfigRenderSupport[kGrPixelConfigCount]; |
| 417 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 418 | // GrDrawTarget overrides |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 419 | virtual bool onReserveVertexSpace(GrVertexLayout vertexLayout, |
| 420 | int vertexCount, |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 421 | void** vertices) SK_OVERRIDE; |
| 422 | virtual bool onReserveIndexSpace(int indexCount, |
| 423 | void** indices) SK_OVERRIDE; |
| 424 | virtual void releaseReservedVertexSpace() SK_OVERRIDE; |
| 425 | virtual void releaseReservedIndexSpace() SK_OVERRIDE; |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 426 | virtual void onSetVertexSourceToArray(const void* vertexArray, |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 427 | int vertexCount) SK_OVERRIDE; |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 428 | virtual void onSetIndexSourceToArray(const void* indexArray, |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 429 | int indexCount) SK_OVERRIDE; |
| 430 | virtual void releaseVertexArray() SK_OVERRIDE; |
| 431 | virtual void releaseIndexArray() SK_OVERRIDE; |
| 432 | virtual void geometrySourceWillPush() SK_OVERRIDE; |
| 433 | virtual void geometrySourceWillPop( |
| 434 | const GeometrySrcState& restoredState) SK_OVERRIDE; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 435 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 436 | // Helpers for setting up geometry state |
| 437 | void finalizeReservedVertices(); |
| 438 | void finalizeReservedIndices(); |
| 439 | |
bsalomon@google.com | b635d39 | 2011-11-05 12:47:43 +0000 | [diff] [blame] | 440 | // called when the 3D context state is unknown. Subclass should emit any |
bsalomon@google.com | c8f7f47 | 2012-06-18 13:44:51 +0000 | [diff] [blame] | 441 | // assumed 3D context state and dirty any state cache. |
bsalomon@google.com | 1bf1c21 | 2011-11-05 12:18:58 +0000 | [diff] [blame] | 442 | virtual void onResetContext() = 0; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 443 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 444 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 445 | // overridden by backend-specific derived class to create objects. |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 446 | virtual GrTexture* onCreateTexture(const GrTextureDesc& desc, |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 447 | const void* srcData, |
| 448 | size_t rowBytes) = 0; |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 449 | virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&) = 0; |
| 450 | virtual GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) = 0; |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 451 | virtual GrVertexBuffer* onCreateVertexBuffer(uint32_t size, |
| 452 | bool dynamic) = 0; |
| 453 | virtual GrIndexBuffer* onCreateIndexBuffer(uint32_t size, |
| 454 | bool dynamic) = 0; |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 455 | virtual GrPath* onCreatePath(const SkPath& path) = 0; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 456 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 457 | // overridden by backend-specific derived class to perform the clear and |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 458 | // clearRect. NULL rect means clear whole target. |
| 459 | virtual void onClear(const GrIRect* rect, GrColor color) = 0; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 460 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 461 | // overridden by backend-specific derived class to perform the draw call. |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 462 | virtual void onGpuDrawIndexed(GrPrimitiveType type, |
| 463 | uint32_t startVertex, |
| 464 | uint32_t startIndex, |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 465 | uint32_t vertexCount, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 466 | uint32_t indexCount) = 0; |
| 467 | |
| 468 | virtual void onGpuDrawNonIndexed(GrPrimitiveType type, |
| 469 | uint32_t vertexCount, |
| 470 | uint32_t numVertices) = 0; |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 471 | // when GrDrawTarget::stencilPath is called the draw state's current stencil |
| 472 | // settings are ignored. Instead the GrGpu decides the stencil rules |
| 473 | // necessary to stencil the path. These are still subject to filtering by |
| 474 | // the clip mask manager. |
| 475 | virtual void setStencilPathSettings(const GrPath&, |
| 476 | GrPathFill, |
| 477 | GrStencilSettings* settings) = 0; |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 478 | // overridden by backend-specific derived class to perform the path stenciling. |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 479 | virtual void onGpuStencilPath(const GrPath*, GrPathFill) = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 480 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 481 | // overridden by backend-specific derived class to perform flush |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 482 | virtual void onForceRenderTargetFlush() = 0; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 483 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 484 | // overridden by backend-specific derived class to perform the read pixels. |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 485 | virtual bool onReadPixels(GrRenderTarget* target, |
| 486 | int left, int top, int width, int height, |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 487 | GrPixelConfig, |
| 488 | void* buffer, |
| 489 | size_t rowBytes, |
| 490 | bool invertY) = 0; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 491 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 492 | // overridden by backend-specific derived class to perform the texture update |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 493 | virtual void onWriteTexturePixels(GrTexture* texture, |
| 494 | int left, int top, int width, int height, |
| 495 | GrPixelConfig config, const void* buffer, |
| 496 | size_t rowBytes) = 0; |
| 497 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 498 | // overridden by backend-specific derived class to perform the resolve |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 499 | virtual void onResolveRenderTarget(GrRenderTarget* target) = 0; |
| 500 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 501 | // called to program the vertex data, indexCount will be 0 if drawing non- |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 502 | // indexed geometry. The subclass may adjust the startVertex and/or |
| 503 | // startIndex since it may have already accounted for these in the setup. |
| 504 | virtual void setupGeometry(int* startVertex, |
| 505 | int* startIndex, |
| 506 | int vertexCount, |
| 507 | int indexCount) = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 508 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 509 | // width and height may be larger than rt (if underlying API allows it). |
| 510 | // Should attach the SB to the RT. Returns false if compatible sb could |
| 511 | // not be created. |
| 512 | virtual bool createStencilBufferForRenderTarget(GrRenderTarget* rt, |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 513 | int width, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 514 | int height) = 0; |
| 515 | |
| 516 | // attaches an existing SB to an existing RT. |
| 517 | virtual bool attachStencilBufferToRenderTarget(GrStencilBuffer* sb, |
| 518 | GrRenderTarget* rt) = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 519 | |
| 520 | // The GrGpu typically records the clients requested state and then flushes |
| 521 | // deltas from previous state at draw time. This function does the |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 522 | // backend-specific flush of the state |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 523 | // returns false if current state is unsupported. |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 524 | virtual bool flushGraphicsState(DrawType) = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 525 | |
bsalomon@google.com | edc177d | 2011-08-05 15:46:40 +0000 | [diff] [blame] | 526 | // clears the entire stencil buffer to 0 |
| 527 | virtual void clearStencil() = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 528 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 529 | private: |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 530 | GrContext* fContext; // not reffed (context refs gpu) |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 531 | |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 532 | ResetTimestamp fResetTimestamp; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 533 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 534 | GrVertexBufferAllocPool* fVertexPool; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 535 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 536 | GrIndexBufferAllocPool* fIndexPool; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 537 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 538 | // counts number of uses of vertex/index pool in the geometry stack |
| 539 | int fVertexPoolUseCnt; |
| 540 | int fIndexPoolUseCnt; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 541 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 542 | enum { |
| 543 | kPreallocGeomPoolStateStackCnt = 4, |
| 544 | }; |
bsalomon@google.com | 9266901 | 2011-09-27 19:10:05 +0000 | [diff] [blame] | 545 | SkSTArray<kPreallocGeomPoolStateStackCnt, |
| 546 | GeometryPoolState, true> fGeomPoolStateStack; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 547 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 548 | mutable GrIndexBuffer* fQuadIndexBuffer; // mutable so it can be |
| 549 | // created on-demand |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 550 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 551 | mutable GrVertexBuffer* fUnitSquareVertexBuffer; // mutable so it can be |
| 552 | // created on-demand |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 553 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 554 | bool fContextIsDirty; |
| 555 | |
robertphillips@google.com | 9474ed0 | 2012-09-04 13:34:32 +0000 | [diff] [blame] | 556 | typedef SkTDLinkedList<GrResource> ResourceList; |
| 557 | ResourceList fResourceList; |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 558 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 559 | // Given a rt, find or create a stencil buffer and attach it |
| 560 | bool attachStencilBufferToRenderTarget(GrRenderTarget* target); |
| 561 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 562 | // GrDrawTarget overrides |
| 563 | virtual void onDrawIndexed(GrPrimitiveType type, |
| 564 | int startVertex, |
| 565 | int startIndex, |
| 566 | int vertexCount, |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 567 | int indexCount) SK_OVERRIDE; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 568 | virtual void onDrawNonIndexed(GrPrimitiveType type, |
| 569 | int startVertex, |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 570 | int vertexCount) SK_OVERRIDE; |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 571 | virtual void onStencilPath(const GrPath* path, GrPathFill fill) SK_OVERRIDE; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 572 | |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 573 | // readies the pools to provide vertex/index data. |
| 574 | void prepareVertexPool(); |
| 575 | void prepareIndexPool(); |
| 576 | |
bsalomon@google.com | b635d39 | 2011-11-05 12:47:43 +0000 | [diff] [blame] | 577 | void resetContext() { |
bsalomon@google.com | c8f7f47 | 2012-06-18 13:44:51 +0000 | [diff] [blame] | 578 | // We call this because the client may have messed with the |
| 579 | // stencil buffer. Perhaps we should detect whether it is a |
| 580 | // internally created stencil buffer and if so skip the invalidate. |
| 581 | fClipMaskManager.invalidateStencilMask(); |
bsalomon@google.com | b635d39 | 2011-11-05 12:47:43 +0000 | [diff] [blame] | 582 | this->onResetContext(); |
| 583 | ++fResetTimestamp; |
| 584 | } |
| 585 | |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 586 | void handleDirtyContext() { |
| 587 | if (fContextIsDirty) { |
| 588 | this->resetContext(); |
| 589 | fContextIsDirty = false; |
| 590 | } |
| 591 | } |
| 592 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 593 | typedef GrDrawTarget INHERITED; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 594 | }; |
| 595 | |
| 596 | #endif |