reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 8 | #ifndef GrGpu_DEFINED |
| 9 | #define GrGpu_DEFINED |
| 10 | |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 11 | #include "GrDrawTarget.h" |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 12 | #include "GrPathRendering.h" |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 13 | #include "GrProgramDesc.h" |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 14 | #include "SkPath.h" |
| 15 | |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 16 | class GrContext; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 17 | class GrIndexBufferAllocPool; |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 18 | class GrPath; |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 19 | class GrPathRange; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 20 | class GrPathRenderer; |
| 21 | class GrPathRendererChain; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 22 | class GrStencilBuffer; |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 23 | class GrVertexBufferAllocPool; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 24 | |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame^] | 25 | class GrGpu : public SkRefCnt { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 26 | public: |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 27 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 28 | /** |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 29 | * Additional blend coefficients for dual source blending, not exposed |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 30 | * through GrPaint/GrContext. |
| 31 | */ |
| 32 | enum ExtendedBlendCoeffs { |
| 33 | // source 2 refers to second output color when |
| 34 | // using dual source blending. |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 35 | kS2C_GrBlendCoeff = kPublicGrBlendCoeffCount, |
| 36 | kIS2C_GrBlendCoeff, |
| 37 | kS2A_GrBlendCoeff, |
| 38 | kIS2A_GrBlendCoeff, |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 39 | |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 40 | kTotalGrBlendCoeffCount |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | /** |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 44 | * Create an instance of GrGpu that matches the specified backend. If the requested backend is |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 45 | * not supported (at compile-time or run-time) this returns NULL. The context will not be |
| 46 | * fully constructed and should not be used by GrGpu until after this function returns. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 47 | */ |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 48 | static GrGpu* Create(GrBackend, GrBackendContext, GrContext* context); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 49 | |
| 50 | //////////////////////////////////////////////////////////////////////////// |
| 51 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 52 | GrGpu(GrContext* context); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 53 | virtual ~GrGpu(); |
| 54 | |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame^] | 55 | GrContext* getContext() { return fContext; } |
| 56 | const GrContext* getContext() const { return fContext; } |
| 57 | |
| 58 | /** |
| 59 | * Gets the capabilities of the draw target. |
| 60 | */ |
| 61 | const GrDrawTargetCaps* caps() const { return fCaps.get(); } |
| 62 | |
| 63 | /** |
| 64 | * Sets the draw state object for the gpu. Note that this does not |
| 65 | * make a copy. The GrGpu will take a reference to passed object. |
| 66 | * Passing NULL will cause the GrGpu to use its own internal draw |
| 67 | * state object rather than an externally provided one. |
| 68 | */ |
| 69 | void setDrawState(GrDrawState* drawState); |
| 70 | |
| 71 | /** |
| 72 | * Read-only access to the GrGpu current draw state. |
| 73 | */ |
| 74 | const GrDrawState& getDrawState() const { return *fDrawState; } |
| 75 | |
| 76 | /** |
| 77 | * Read-write access to the GrGpu current draw state. Note that |
| 78 | * this doesn't ref. |
| 79 | */ |
| 80 | GrDrawState* drawState() { return fDrawState; } |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 81 | |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 82 | GrPathRendering* pathRendering() { |
| 83 | return fPathRendering.get(); |
| 84 | } |
| 85 | |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 86 | // Called by GrContext when the underlying backend context has been destroyed. |
| 87 | // GrGpu should use this to ensure that no backend API calls will be made from |
| 88 | // here onward, including in its destructor. Subclasses should call |
robertphillips | e337130 | 2014-09-17 06:01:06 -0700 | [diff] [blame] | 89 | // INHERITED::contextAbandoned() if they override this. |
| 90 | virtual void contextAbandoned(); |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 91 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 92 | /** |
| 93 | * The GrGpu object normally assumes that no outsider is setting state |
| 94 | * 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] | 95 | * the GrGpu that the state was modified and it shouldn't make assumptions |
| 96 | * about the state. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 97 | */ |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 98 | void markContextDirty(uint32_t state = kAll_GrBackendState) { |
| 99 | fResetBits |= state; |
| 100 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 101 | |
| 102 | void unimpl(const char[]); |
| 103 | |
| 104 | /** |
bsalomon@google.com | 0748f21 | 2011-02-01 22:56:16 +0000 | [diff] [blame] | 105 | * Creates a texture object. If desc width or height is not a power of |
| 106 | * two but underlying API requires a power of two texture then srcData |
| 107 | * will be embedded in a power of two texture. The extra width and height |
| 108 | * is filled as though srcData were rendered clamped into the texture. |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 109 | * The exception is when using compressed data formats. In this case, the |
| 110 | * desc width and height must be a multiple of the compressed format block |
| 111 | * size otherwise this function returns NULL. Similarly, if the underlying |
| 112 | * API requires a power of two texture and the source width and height are not |
| 113 | * a power of two, then this function returns NULL. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 114 | * |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 115 | * If kRenderTarget_TextureFlag is specified the GrRenderTarget is |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 116 | * accessible via GrTexture::asRenderTarget(). The texture will hold a ref |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 117 | * on the render target until the texture is destroyed. Compressed textures |
| 118 | * cannot have the kRenderTarget_TextureFlag set. |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 119 | * |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 120 | * @param desc describes the texture to be created. |
| 121 | * @param srcData texel data to load texture. Begins with full-size |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 122 | * palette data for paletted textures. For compressed |
| 123 | * formats it contains the compressed pixel data. Otherwise, |
| 124 | * it contains width*height texels. If NULL texture data |
| 125 | * is uninitialized. |
| 126 | * @param rowBytes the number of bytes between consecutive rows. Zero |
| 127 | * means rows are tightly packed. This field is ignored |
| 128 | * for compressed formats. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 129 | * |
| 130 | * @return The texture object if successful, otherwise NULL. |
| 131 | */ |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 132 | GrTexture* createTexture(const GrSurfaceDesc& desc, |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 133 | const void* srcData, size_t rowBytes); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 134 | |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 135 | /** |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 136 | * Implements GrContext::wrapBackendTexture |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 137 | */ |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 138 | GrTexture* wrapBackendTexture(const GrBackendTextureDesc&); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 139 | |
| 140 | /** |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 141 | * Implements GrContext::wrapBackendTexture |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 142 | */ |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 143 | GrRenderTarget* wrapBackendRenderTarget(const GrBackendRenderTargetDesc&); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 144 | |
| 145 | /** |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 146 | * Creates a vertex buffer. |
| 147 | * |
| 148 | * @param size size in bytes of the vertex buffer |
| 149 | * @param dynamic hints whether the data will be frequently changed |
commit-bot@chromium.org | 8341eb7 | 2014-05-07 20:51:05 +0000 | [diff] [blame] | 150 | * by either GrVertexBuffer::map() or |
| 151 | * GrVertexBuffer::updateData(). |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 152 | * |
| 153 | * @return The vertex buffer if successful, otherwise NULL. |
| 154 | */ |
robertphillips@google.com | adacc70 | 2013-10-14 21:53:24 +0000 | [diff] [blame] | 155 | GrVertexBuffer* createVertexBuffer(size_t size, bool dynamic); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 156 | |
| 157 | /** |
| 158 | * Creates an index buffer. |
| 159 | * |
| 160 | * @param size size in bytes of the index buffer |
| 161 | * @param dynamic hints whether the data will be frequently changed |
commit-bot@chromium.org | 8341eb7 | 2014-05-07 20:51:05 +0000 | [diff] [blame] | 162 | * by either GrIndexBuffer::map() or |
| 163 | * GrIndexBuffer::updateData(). |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 164 | * |
| 165 | * @return The index buffer if successful, otherwise NULL. |
| 166 | */ |
robertphillips@google.com | adacc70 | 2013-10-14 21:53:24 +0000 | [diff] [blame] | 167 | GrIndexBuffer* createIndexBuffer(size_t size, bool dynamic); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 168 | |
| 169 | /** |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 170 | * Creates an index buffer for instance drawing with a specific pattern. |
| 171 | * |
| 172 | * @param pattern the pattern to repeat |
| 173 | * @param patternSize size in bytes of the pattern |
| 174 | * @param reps number of times to repeat the pattern |
| 175 | * @param vertCount number of vertices the pattern references |
| 176 | * @param dynamic hints whether the data will be frequently changed |
| 177 | * by either GrIndexBuffer::map() or |
| 178 | * GrIndexBuffer::updateData(). |
| 179 | * |
| 180 | * @return The index buffer if successful, otherwise NULL. |
| 181 | */ |
| 182 | GrIndexBuffer* createInstancedIndexBuffer(const uint16_t* pattern, |
| 183 | int patternSize, |
| 184 | int reps, |
| 185 | int vertCount, |
| 186 | bool isDynamic = false); |
| 187 | |
| 188 | /** |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 189 | * Returns an index buffer that can be used to render quads. |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 190 | * Six indices per quad: 0, 1, 2, 0, 2, 3, etc. |
| 191 | * The max number of quads can be queried using GrIndexBuffer::maxQuads(). |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 192 | * Draw with kTriangles_GrPrimitiveType |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 193 | * @ return the quad index buffer |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 194 | */ |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 195 | const GrIndexBuffer* getQuadIndexBuffer() const; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 196 | |
| 197 | /** |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 198 | * Resolves MSAA. |
| 199 | */ |
| 200 | void resolveRenderTarget(GrRenderTarget* target); |
| 201 | |
| 202 | /** |
commit-bot@chromium.org | 5d1d79a | 2013-05-24 18:52:52 +0000 | [diff] [blame] | 203 | * Gets a preferred 8888 config to use for writing/reading pixel data to/from a surface with |
| 204 | * config surfaceConfig. The returned config must have at least as many bits per channel as the |
| 205 | * readConfig or writeConfig param. |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 206 | */ |
commit-bot@chromium.org | 5d1d79a | 2013-05-24 18:52:52 +0000 | [diff] [blame] | 207 | virtual GrPixelConfig preferredReadPixelsConfig(GrPixelConfig readConfig, |
| 208 | GrPixelConfig surfaceConfig) const { |
| 209 | return readConfig; |
| 210 | } |
| 211 | virtual GrPixelConfig preferredWritePixelsConfig(GrPixelConfig writeConfig, |
| 212 | GrPixelConfig surfaceConfig) const { |
| 213 | return writeConfig; |
| 214 | } |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 215 | |
| 216 | /** |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 217 | * Called before uploading writing pixels to a GrTexture when the src pixel config doesn't |
| 218 | * match the texture's config. |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 219 | */ |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 220 | virtual bool canWriteTexturePixels(const GrTexture*, GrPixelConfig srcConfig) const = 0; |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 221 | |
| 222 | /** |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 223 | * OpenGL's readPixels returns the result bottom-to-top while the skia |
| 224 | * API is top-to-bottom. Thus we have to do a y-axis flip. The obvious |
| 225 | * solution is to have the subclass do the flip using either the CPU or GPU. |
| 226 | * However, the caller (GrContext) may have transformations to apply and can |
| 227 | * simply fold in the y-flip for free. On the other hand, the subclass may |
| 228 | * 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] | 229 | * 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] | 230 | * concurrently. |
| 231 | * |
| 232 | * This function returns true if a y-flip is required to put the pixels in |
| 233 | * top-to-bottom order and the subclass cannot do it for free. |
| 234 | * |
| 235 | * See read pixels for the params |
| 236 | * @return true if calling readPixels with the same set of params will |
| 237 | * produce bottom-to-top data |
| 238 | */ |
| 239 | virtual bool readPixelsWillPayForYFlip(GrRenderTarget* renderTarget, |
| 240 | int left, int top, |
| 241 | int width, int height, |
| 242 | GrPixelConfig config, |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 243 | size_t rowBytes) const = 0; |
| 244 | /** |
| 245 | * This should return true if reading a NxM rectangle of pixels from a |
| 246 | * render target is faster if the target has dimensons N and M and the read |
| 247 | * rectangle has its top-left at 0,0. |
| 248 | */ |
| 249 | virtual bool fullReadPixelsIsFasterThanPartial() const { return false; }; |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 250 | |
| 251 | /** |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 252 | * Reads a rectangle of pixels from a render target. |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 253 | * |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 254 | * @param renderTarget the render target to read from. NULL means the |
| 255 | * current render target. |
| 256 | * @param left left edge of the rectangle to read (inclusive) |
| 257 | * @param top top edge of the rectangle to read (inclusive) |
| 258 | * @param width width of rectangle to read in pixels. |
| 259 | * @param height height of rectangle to read in pixels. |
| 260 | * @param config the pixel config of the destination buffer |
| 261 | * @param buffer memory to read the rectangle into. |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 262 | * @param rowBytes the number of bytes between consecutive rows. Zero |
| 263 | * means rows are tightly packed. |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 264 | * @param invertY buffer should be populated bottom-to-top as opposed |
| 265 | * to top-to-bottom (skia's usual order) |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 266 | * |
| 267 | * @return true if the read succeeded, false if not. The read can fail |
| 268 | * because of a unsupported pixel config or because no render |
| 269 | * target is currently set. |
| 270 | */ |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 271 | bool readPixels(GrRenderTarget* renderTarget, |
| 272 | int left, int top, int width, int height, |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 273 | GrPixelConfig config, void* buffer, size_t rowBytes); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 274 | |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 275 | /** |
| 276 | * Updates the pixels in a rectangle of a texture. |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 277 | * |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 278 | * @param left left edge of the rectangle to write (inclusive) |
| 279 | * @param top top edge of the rectangle to write (inclusive) |
| 280 | * @param width width of rectangle to write in pixels. |
| 281 | * @param height height of rectangle to write in pixels. |
| 282 | * @param config the pixel config of the source buffer |
| 283 | * @param buffer memory to read pixels from |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 284 | * @param rowBytes number of bytes between consecutive rows. Zero |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 285 | * means rows are tightly packed. |
| 286 | */ |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 287 | bool writeTexturePixels(GrTexture* texture, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 288 | int left, int top, int width, int height, |
| 289 | GrPixelConfig config, const void* buffer, |
| 290 | size_t rowBytes); |
| 291 | |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame^] | 292 | /** |
| 293 | * Clear the passed in render target. Ignores the draw state and clip. Clears the whole thing if |
| 294 | * rect is NULL, otherwise just the rect. If canIgnoreRect is set then the entire render target |
| 295 | * can be optionally cleared. |
| 296 | */ |
| 297 | void clear(const SkIRect* rect, |
| 298 | GrColor color, |
| 299 | bool canIgnoreRect, |
| 300 | GrRenderTarget* renderTarget); |
| 301 | |
| 302 | |
| 303 | void clearStencilClip(const SkIRect& rect, |
| 304 | bool insideClip, |
| 305 | GrRenderTarget* renderTarget = NULL); |
| 306 | |
| 307 | /** |
| 308 | * Discards the contents render target. NULL indicates that the current render target should |
| 309 | * be discarded. |
| 310 | **/ |
| 311 | virtual void discard(GrRenderTarget* = NULL) = 0; |
| 312 | |
| 313 | /** |
| 314 | * This is can be called before allocating a texture to be a dst for copySurface. It will |
| 315 | * populate the origin, config, and flags fields of the desc such that copySurface is more |
| 316 | * likely to succeed and be efficient. |
| 317 | */ |
| 318 | virtual void initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc); |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 319 | |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 320 | // After the client interacts directly with the 3D context state the GrGpu |
| 321 | // must resync its internal state and assumptions about 3D context state. |
| 322 | // Each time this occurs the GrGpu bumps a timestamp. |
| 323 | // state of the 3D context |
| 324 | // At 10 resets / frame and 60fps a 64bit timestamp will overflow in about |
| 325 | // a billion years. |
| 326 | typedef uint64_t ResetTimestamp; |
| 327 | |
| 328 | // This timestamp is always older than the current timestamp |
| 329 | static const ResetTimestamp kExpiredTimestamp = 0; |
| 330 | // Returns a timestamp based on the number of times the context was reset. |
| 331 | // This timestamp can be used to lazily detect when cached 3D context state |
| 332 | // is dirty. |
| 333 | ResetTimestamp getResetTimestamp() const { |
| 334 | return fResetTimestamp; |
| 335 | } |
| 336 | |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 337 | enum DrawType { |
| 338 | kDrawPoints_DrawType, |
| 339 | kDrawLines_DrawType, |
| 340 | kDrawTriangles_DrawType, |
| 341 | kStencilPath_DrawType, |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 342 | kDrawPath_DrawType, |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 343 | kDrawPaths_DrawType, |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 344 | }; |
| 345 | |
kkinnunen | ec56e45 | 2014-08-25 22:21:16 -0700 | [diff] [blame] | 346 | static bool IsPathRenderingDrawType(DrawType type) { |
| 347 | return kDrawPath_DrawType == type || kDrawPaths_DrawType == type; |
| 348 | } |
| 349 | |
robertphillips | 754f4e9 | 2014-09-18 13:52:08 -0700 | [diff] [blame] | 350 | GrContext::GPUStats* gpuStats() { return &fGPUStats; } |
| 351 | |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 352 | virtual void buildProgramDesc(const GrOptDrawState&, |
| 353 | const GrProgramDesc::DescInfo&, |
| 354 | GrGpu::DrawType, |
| 355 | const GrDeviceCoordTexture* dstCopy, |
| 356 | GrProgramDesc*) = 0; |
| 357 | |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame^] | 358 | /** |
| 359 | * Called at start and end of gpu trace marking |
| 360 | * GR_CREATE_GPU_TRACE_MARKER(marker_str, target) will automatically call these at the start |
| 361 | * and end of a code block respectively |
| 362 | */ |
| 363 | void addGpuTraceMarker(const GrGpuTraceMarker* marker); |
| 364 | void removeGpuTraceMarker(const GrGpuTraceMarker* marker); |
| 365 | |
| 366 | /** |
| 367 | * Takes the current active set of markers and stores them for later use. Any current marker |
| 368 | * in the active set is removed from the active set and the targets remove function is called. |
| 369 | * These functions do not work as a stack so you cannot call save a second time before calling |
| 370 | * restore. Also, it is assumed that when restore is called the current active set of markers |
| 371 | * is empty. When the stored markers are added back into the active set, the targets add marker |
| 372 | * is called. |
| 373 | */ |
| 374 | void saveActiveTraceMarkers(); |
| 375 | void restoreActiveTraceMarkers(); |
| 376 | |
| 377 | /** |
| 378 | * Query to find out if the vertex or index source is reserved. |
| 379 | */ |
| 380 | bool hasReservedVerticesOrIndices() const { |
| 381 | return GrDrawTarget::kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc || |
| 382 | GrDrawTarget::kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc; |
| 383 | } |
| 384 | |
| 385 | // Called to determine whether an onCopySurface call would succeed or not. This is useful for |
| 386 | // proxy subclasses to test whether the copy would succeed without executing it yet. Derived |
| 387 | // classes must keep this consistent with their implementation of onCopySurface(). The inputs |
| 388 | // are the same as onCopySurface(), i.e. srcRect and dstPoint are clipped to be inside the src |
| 389 | // and dst bounds. |
| 390 | virtual bool canCopySurface(GrSurface* dst, |
| 391 | GrSurface* src, |
| 392 | const SkIRect& srcRect, |
| 393 | const SkIPoint& dstPoint) = 0; |
| 394 | |
| 395 | // This method is called by copySurface The srcRect is guaranteed to be entirely within the |
| 396 | // src bounds. Likewise, the dst rect implied by dstPoint and srcRect's width and height falls |
| 397 | // entirely within the dst. The default implementation will draw a rect from the src to the |
| 398 | // dst if the src is a texture and the dst is a render target and fail otherwise. |
| 399 | virtual bool copySurface(GrSurface* dst, |
| 400 | GrSurface* src, |
| 401 | const SkIRect& srcRect, |
| 402 | const SkIPoint& dstPoint) = 0; |
| 403 | |
| 404 | /** |
| 405 | * Sets source of vertex data for the next draw. Data does not have to be |
| 406 | * in the buffer until drawIndexed, drawNonIndexed, or drawIndexedInstances. |
| 407 | * |
| 408 | * @param buffer vertex buffer containing vertex data. Must be |
| 409 | * unlocked before draw call. Vertex size is queried |
| 410 | * from current GrDrawState. |
| 411 | */ |
| 412 | void setVertexSourceToBuffer(const GrVertexBuffer* buffer); |
| 413 | |
| 414 | /** |
| 415 | * Sets source of index data for the next indexed draw. Data does not have |
| 416 | * to be in the buffer until drawIndexed. |
| 417 | * |
| 418 | * @param buffer index buffer containing indices. Must be unlocked |
| 419 | * before indexed draw call. |
| 420 | */ |
| 421 | void setIndexSourceToBuffer(const GrIndexBuffer* buffer); |
| 422 | |
| 423 | /** |
| 424 | * Resets vertex source. Drawing from reset vertices is illegal. Set vertex |
| 425 | * source to reserved, array, or buffer before next draw. May be able to free |
| 426 | * up temporary storage allocated by setVertexSourceToArray or |
| 427 | * reserveVertexSpace. |
| 428 | */ |
| 429 | void resetVertexSource(); |
| 430 | |
| 431 | /** |
| 432 | * Resets index source. Indexed Drawing from reset indices is illegal. Set |
| 433 | * index source to reserved, array, or buffer before next indexed draw. May |
| 434 | * be able to free up temporary storage allocated by setIndexSourceToArray |
| 435 | * or reserveIndexSpace. |
| 436 | */ |
| 437 | void resetIndexSource(); |
| 438 | |
| 439 | /** |
| 440 | * Pushes and resets the vertex/index sources. Any reserved vertex / index |
| 441 | * data is finalized (i.e. cannot be updated after the matching pop but can |
| 442 | * be drawn from). Must be balanced by a pop. |
| 443 | */ |
| 444 | void pushGeometrySource(); |
| 445 | |
| 446 | /** |
| 447 | * Pops the vertex / index sources from the matching push. |
| 448 | */ |
| 449 | void popGeometrySource(); |
| 450 | |
commit-bot@chromium.org | 0a6fe71 | 2014-04-23 19:26:26 +0000 | [diff] [blame] | 451 | protected: |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 452 | DrawType PrimTypeToDrawType(GrPrimitiveType type) { |
| 453 | switch (type) { |
| 454 | case kTriangles_GrPrimitiveType: |
| 455 | case kTriangleStrip_GrPrimitiveType: |
| 456 | case kTriangleFan_GrPrimitiveType: |
| 457 | return kDrawTriangles_DrawType; |
| 458 | case kPoints_GrPrimitiveType: |
| 459 | return kDrawPoints_DrawType; |
| 460 | case kLines_GrPrimitiveType: |
| 461 | case kLineStrip_GrPrimitiveType: |
| 462 | return kDrawLines_DrawType; |
| 463 | default: |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 464 | SkFAIL("Unexpected primitive type"); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 465 | return kDrawTriangles_DrawType; |
| 466 | } |
| 467 | } |
| 468 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 469 | // Functions used to map clip-respecting stencil tests into normal |
| 470 | // stencil funcs supported by GPUs. |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 471 | static GrStencilFunc ConvertStencilFunc(bool stencilInClip, |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 472 | GrStencilFunc func); |
| 473 | static void ConvertStencilFuncAndMask(GrStencilFunc func, |
| 474 | bool clipInStencil, |
| 475 | unsigned int clipBit, |
| 476 | unsigned int userBits, |
| 477 | unsigned int* ref, |
| 478 | unsigned int* mask); |
| 479 | |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame^] | 480 | // subclasses must call this in their destructors to ensure all vertex |
| 481 | // and index sources have been released (including those held by |
| 482 | // pushGeometrySource()) |
| 483 | void releaseGeometry(); |
| 484 | |
| 485 | // accessors for derived classes |
| 486 | const GrDrawTarget::GeometrySrcState& getGeomSrc() const { return fGeoSrcStateStack.back(); } |
| 487 | |
| 488 | // it is preferable to call this rather than getGeomSrc()->fVertexSize because of the assert. |
| 489 | size_t getVertexSize() const { |
| 490 | // the vertex layout is only valid if a vertex source has been specified. |
| 491 | SkASSERT(this->getGeomSrc().fVertexSrc != GrDrawTarget::kNone_GeometrySrcType); |
| 492 | return this->getGeomSrc().fVertexSize; |
| 493 | } |
| 494 | |
| 495 | const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers; } |
| 496 | |
robertphillips | 754f4e9 | 2014-09-18 13:52:08 -0700 | [diff] [blame] | 497 | GrContext::GPUStats fGPUStats; |
| 498 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 499 | struct GeometryPoolState { |
| 500 | const GrVertexBuffer* fPoolVertexBuffer; |
| 501 | int fPoolStartVertex; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 502 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 503 | const GrIndexBuffer* fPoolIndexBuffer; |
| 504 | int fPoolStartIndex; |
| 505 | }; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 506 | const GeometryPoolState& getGeomPoolState() { |
| 507 | return fGeomPoolStateStack.back(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 508 | } |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 509 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 510 | // Helpers for setting up geometry state |
| 511 | void finalizeReservedVertices(); |
| 512 | void finalizeReservedIndices(); |
| 513 | |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 514 | SkAutoTDelete<GrPathRendering> fPathRendering; |
| 515 | |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame^] | 516 | // Subclass must initialize this in its constructor. |
| 517 | SkAutoTUnref<const GrDrawTargetCaps> fCaps; |
| 518 | |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 519 | private: |
| 520 | // GrDrawTarget overrides |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame^] | 521 | virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertices); |
| 522 | virtual bool onReserveIndexSpace(int indexCount, void** indices); |
| 523 | virtual void releaseReservedVertexSpace(); |
| 524 | virtual void releaseReservedIndexSpace(); |
| 525 | virtual void geometrySourceWillPush(); |
| 526 | virtual void geometrySourceWillPop(const GrDrawTarget::GeometrySrcState& restoredState); |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 527 | |
bsalomon@google.com | b635d39 | 2011-11-05 12:47:43 +0000 | [diff] [blame] | 528 | // 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] | 529 | // assumed 3D context state and dirty any state cache. |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 530 | virtual void onResetContext(uint32_t resetBits) = 0; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 531 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 532 | // overridden by backend-specific derived class to create objects. |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 533 | virtual GrTexture* onCreateTexture(const GrSurfaceDesc& desc, |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 534 | const void* srcData, |
| 535 | size_t rowBytes) = 0; |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 536 | virtual GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 537 | const void* srcData) = 0; |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 538 | virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&) = 0; |
| 539 | virtual GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) = 0; |
robertphillips@google.com | adacc70 | 2013-10-14 21:53:24 +0000 | [diff] [blame] | 540 | virtual GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) = 0; |
| 541 | virtual GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) = 0; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 542 | |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 543 | // overridden by backend-specific derived class to perform the clear. |
| 544 | virtual void onGpuClear(GrRenderTarget*, const SkIRect* rect, GrColor color, |
| 545 | bool canIgnoreRect) = 0; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 546 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 547 | |
| 548 | // Overridden by backend specific classes to perform a clear of the stencil clip bits. This is |
| 549 | // ONLY used by the the clip target |
| 550 | virtual void onClearStencilClip(GrRenderTarget*, |
| 551 | const SkIRect& rect, |
| 552 | bool insideClip) = 0; |
| 553 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 554 | // overridden by backend-specific derived class to perform the draw call. |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame^] | 555 | virtual void onGpuDraw(const GrDrawTarget::DrawInfo&) = 0; |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 556 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 557 | // overridden by backend-specific derived class to perform the read pixels. |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 558 | virtual bool onReadPixels(GrRenderTarget* target, |
| 559 | int left, int top, int width, int height, |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 560 | GrPixelConfig, |
| 561 | void* buffer, |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 562 | size_t rowBytes) = 0; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 563 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 564 | // overridden by backend-specific derived class to perform the texture update |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 565 | virtual bool onWriteTexturePixels(GrTexture* texture, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 566 | int left, int top, int width, int height, |
| 567 | GrPixelConfig config, const void* buffer, |
| 568 | size_t rowBytes) = 0; |
| 569 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 570 | // overridden by backend-specific derived class to perform the resolve |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 571 | virtual void onResolveRenderTarget(GrRenderTarget* target) = 0; |
| 572 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 573 | // width and height may be larger than rt (if underlying API allows it). |
| 574 | // Should attach the SB to the RT. Returns false if compatible sb could |
| 575 | // not be created. |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 576 | virtual bool createStencilBufferForRenderTarget(GrRenderTarget*, int width, int height) = 0; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 577 | |
| 578 | // attaches an existing SB to an existing RT. |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 579 | virtual bool attachStencilBufferToRenderTarget(GrStencilBuffer*, GrRenderTarget*) = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 580 | |
| 581 | // The GrGpu typically records the clients requested state and then flushes |
| 582 | // deltas from previous state at draw time. This function does the |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 583 | // backend-specific flush of the state. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 584 | // returns false if current state is unsupported. |
joshualitt | 77b1307 | 2014-10-27 14:51:01 -0700 | [diff] [blame] | 585 | virtual bool flushGraphicsState(DrawType, |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 586 | const GrClipMaskManager::ScissorState&, |
joshualitt | 77b1307 | 2014-10-27 14:51:01 -0700 | [diff] [blame] | 587 | const GrDeviceCoordTexture* dstCopy) = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 588 | |
bsalomon | b0bd4f6 | 2014-09-03 07:19:50 -0700 | [diff] [blame] | 589 | // clears target's entire stencil buffer to 0 |
| 590 | virtual void clearStencil(GrRenderTarget* target) = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 591 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 592 | // Given a rt, find or create a stencil buffer and attach it |
| 593 | bool attachStencilBufferToRenderTarget(GrRenderTarget* target); |
| 594 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 595 | // GrDrawTarget overrides |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame^] | 596 | virtual void onDraw(const GrDrawTarget::DrawInfo&, |
| 597 | const GrClipMaskManager::ScissorState&); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 598 | virtual void onStencilPath(const GrPath*, |
| 599 | const GrClipMaskManager::ScissorState&, |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame^] | 600 | const GrStencilSettings&); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 601 | virtual void onDrawPath(const GrPath*, |
| 602 | const GrClipMaskManager::ScissorState&, |
| 603 | const GrStencilSettings&, |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame^] | 604 | const GrDeviceCoordTexture* dstCopy); |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 605 | virtual void onDrawPaths(const GrPathRange*, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 606 | const uint32_t indices[], |
| 607 | int count, |
| 608 | const float transforms[], |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame^] | 609 | GrDrawTarget::PathTransformType, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 610 | const GrClipMaskManager::ScissorState&, |
| 611 | const GrStencilSettings&, |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame^] | 612 | const GrDeviceCoordTexture*); |
| 613 | |
| 614 | virtual void didAddGpuTraceMarker() = 0; |
| 615 | virtual void didRemoveGpuTraceMarker() = 0; |
| 616 | |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 617 | |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 618 | // readies the pools to provide vertex/index data. |
| 619 | void prepareVertexPool(); |
| 620 | void prepareIndexPool(); |
| 621 | |
bsalomon@google.com | b635d39 | 2011-11-05 12:47:43 +0000 | [diff] [blame] | 622 | void resetContext() { |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 623 | this->onResetContext(fResetBits); |
| 624 | fResetBits = 0; |
bsalomon@google.com | b635d39 | 2011-11-05 12:47:43 +0000 | [diff] [blame] | 625 | ++fResetTimestamp; |
| 626 | } |
| 627 | |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 628 | void handleDirtyContext() { |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 629 | if (fResetBits) { |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 630 | this->resetContext(); |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 631 | } |
| 632 | } |
| 633 | |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame^] | 634 | // called when setting a new vert/idx source to unref prev vb/ib |
| 635 | void releasePreviousVertexSource(); |
| 636 | void releasePreviousIndexSource(); |
| 637 | |
| 638 | enum { |
| 639 | kPreallocGeoSrcStateStackCnt = 4, |
| 640 | }; |
| 641 | SkSTArray<kPreallocGeoSrcStateStackCnt, GrDrawTarget::GeometrySrcState, true> fGeoSrcStateStack; |
| 642 | |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 643 | enum { |
| 644 | kPreallocGeomPoolStateStackCnt = 4, |
| 645 | }; |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 646 | SkSTArray<kPreallocGeomPoolStateStackCnt, GeometryPoolState, true> fGeomPoolStateStack; |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 647 | ResetTimestamp fResetTimestamp; |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 648 | uint32_t fResetBits; |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 649 | GrVertexBufferAllocPool* fVertexPool; |
| 650 | GrIndexBufferAllocPool* fIndexPool; |
| 651 | // counts number of uses of vertex/index pool in the geometry stack |
| 652 | int fVertexPoolUseCnt; |
| 653 | int fIndexPoolUseCnt; |
bsalomon@google.com | 6438695 | 2013-02-08 21:22:44 +0000 | [diff] [blame] | 654 | // these are mutable so they can be created on-demand |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 655 | mutable GrIndexBuffer* fQuadIndexBuffer; |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame^] | 656 | GrDrawState fDefaultDrawState; |
| 657 | GrDrawState* fDrawState; |
| 658 | // To keep track that we always have at least as many debug marker adds as removes |
| 659 | int fGpuTraceMarkerCount; |
| 660 | GrTraceMarkerSet fActiveTraceMarkers; |
| 661 | GrTraceMarkerSet fStoredTraceMarkers; |
| 662 | // The context owns us, not vice-versa, so this ptr is not ref'ed by Gpu. |
| 663 | GrContext* fContext; |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 664 | |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame^] | 665 | // TODO fix this |
| 666 | friend class GrInOrderDrawBuffer; |
| 667 | |
| 668 | typedef SkRefCnt INHERITED; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 669 | }; |
| 670 | |
| 671 | #endif |