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 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 11 | #include "GrPipelineBuilder.h" |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 12 | #include "GrProgramDesc.h" |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 13 | #include "GrStencil.h" |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 14 | #include "GrTextureParamsAdjuster.h" |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 15 | #include "GrXferProcessor.h" |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 16 | #include "SkPath.h" |
| 17 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 18 | class GrBatchTracker; |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 19 | class GrContext; |
reed | f9ad558 | 2015-06-25 21:29:25 -0700 | [diff] [blame] | 20 | class GrGLContext; |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 21 | class GrIndexBuffer; |
bsalomon | e64eb57 | 2015-05-07 11:35:55 -0700 | [diff] [blame] | 22 | class GrNonInstancedVertices; |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 23 | class GrPath; |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 24 | class GrPathRange; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 25 | class GrPathRenderer; |
| 26 | class GrPathRendererChain; |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 27 | class GrPathRendering; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 28 | class GrPipeline; |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 29 | class GrPrimitiveProcessor; |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 30 | class GrRenderTarget; |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 31 | class GrStencilAttachment; |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 32 | class GrSurface; |
| 33 | class GrTexture; |
jvanverth | 73063dc | 2015-12-03 09:15:47 -0800 | [diff] [blame] | 34 | class GrTransferBuffer; |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 35 | class GrVertexBuffer; |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 36 | class GrVertices; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 37 | |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 38 | class GrGpu : public SkRefCnt { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 39 | public: |
| 40 | /** |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 41 | * Create an instance of GrGpu that matches the specified backend. If the requested backend is |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 42 | * not supported (at compile-time or run-time) this returns nullptr. The context will not be |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 43 | * 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] | 44 | */ |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 45 | static GrGpu* Create(GrBackend, GrBackendContext, const GrContextOptions&, GrContext* context); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 46 | |
| 47 | //////////////////////////////////////////////////////////////////////////// |
| 48 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 49 | GrGpu(GrContext* context); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 50 | ~GrGpu() override; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 51 | |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 52 | GrContext* getContext() { return fContext; } |
| 53 | const GrContext* getContext() const { return fContext; } |
| 54 | |
| 55 | /** |
| 56 | * Gets the capabilities of the draw target. |
| 57 | */ |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 58 | const GrCaps* caps() const { return fCaps.get(); } |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 59 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 60 | GrPathRendering* pathRendering() { return fPathRendering.get(); } |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 61 | |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 62 | // Called by GrContext when the underlying backend context has been destroyed. |
| 63 | // GrGpu should use this to ensure that no backend API calls will be made from |
| 64 | // here onward, including in its destructor. Subclasses should call |
robertphillips | e337130 | 2014-09-17 06:01:06 -0700 | [diff] [blame] | 65 | // INHERITED::contextAbandoned() if they override this. |
| 66 | virtual void contextAbandoned(); |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 67 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 68 | /** |
| 69 | * The GrGpu object normally assumes that no outsider is setting state |
| 70 | * 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] | 71 | * the GrGpu that the state was modified and it shouldn't make assumptions |
| 72 | * about the state. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 73 | */ |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 74 | void markContextDirty(uint32_t state = kAll_GrBackendState) { fResetBits |= state; } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 75 | |
| 76 | /** |
bsalomon | 6d467ec | 2014-11-18 07:36:19 -0800 | [diff] [blame] | 77 | * Creates a texture object. If kRenderTarget_GrSurfaceFlag the texture can |
| 78 | * be used as a render target by calling GrTexture::asRenderTarget(). Not all |
| 79 | * pixel configs can be used as render targets. Support for configs as textures |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 80 | * or render targets can be checked using GrCaps. |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 81 | * |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 82 | * @param desc describes the texture to be created. |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 83 | * @param budgeted does this texture count against the resource cache budget? |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 84 | * @param srcData texel data to load texture. Begins with full-size |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 85 | * palette data for paletted textures. For compressed |
| 86 | * formats it contains the compressed pixel data. Otherwise, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 87 | * it contains width*height texels. If nullptr texture data |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 88 | * is uninitialized. |
| 89 | * @param rowBytes the number of bytes between consecutive rows. Zero |
| 90 | * means rows are tightly packed. This field is ignored |
| 91 | * for compressed formats. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 92 | * |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 93 | * @return The texture object if successful, otherwise nullptr. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 94 | */ |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 95 | GrTexture* createTexture(const GrSurfaceDesc& desc, bool budgeted, |
| 96 | const void* srcData, size_t rowBytes); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 97 | |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 98 | /** |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 99 | * Implements GrContext::wrapBackendTexture |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 100 | */ |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 101 | GrTexture* wrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 102 | |
| 103 | /** |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 104 | * Implements GrContext::wrapBackendTexture |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 105 | */ |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 106 | GrRenderTarget* wrapBackendRenderTarget(const GrBackendRenderTargetDesc&, GrWrapOwnership); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 107 | |
| 108 | /** |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 109 | * Creates a vertex buffer. |
| 110 | * |
| 111 | * @param size size in bytes of the vertex buffer |
| 112 | * @param dynamic hints whether the data will be frequently changed |
commit-bot@chromium.org | 8341eb7 | 2014-05-07 20:51:05 +0000 | [diff] [blame] | 113 | * by either GrVertexBuffer::map() or |
| 114 | * GrVertexBuffer::updateData(). |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 115 | * |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 116 | * @return The vertex buffer if successful, otherwise nullptr. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 117 | */ |
robertphillips@google.com | adacc70 | 2013-10-14 21:53:24 +0000 | [diff] [blame] | 118 | GrVertexBuffer* createVertexBuffer(size_t size, bool dynamic); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 119 | |
| 120 | /** |
| 121 | * Creates an index buffer. |
| 122 | * |
| 123 | * @param size size in bytes of the index buffer |
| 124 | * @param dynamic hints whether the data will be frequently changed |
commit-bot@chromium.org | 8341eb7 | 2014-05-07 20:51:05 +0000 | [diff] [blame] | 125 | * by either GrIndexBuffer::map() or |
| 126 | * GrIndexBuffer::updateData(). |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 127 | * |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 128 | * @return The index buffer if successful, otherwise nullptr. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 129 | */ |
robertphillips@google.com | adacc70 | 2013-10-14 21:53:24 +0000 | [diff] [blame] | 130 | GrIndexBuffer* createIndexBuffer(size_t size, bool dynamic); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 131 | |
jvanverth | 73063dc | 2015-12-03 09:15:47 -0800 | [diff] [blame] | 132 | /** |
| 133 | * Creates a transfer buffer. |
| 134 | * |
| 135 | * @param size size in bytes of the index buffer |
| 136 | * @param toGpu true if used to transfer from the cpu to the gpu |
| 137 | * otherwise to be used to transfer from the gpu to the cpu |
| 138 | * |
| 139 | * @return The transfer buffer if successful, otherwise nullptr. |
| 140 | */ |
| 141 | GrTransferBuffer* createTransferBuffer(size_t size, TransferType type); |
| 142 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 143 | /** |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 144 | * Resolves MSAA. |
| 145 | */ |
| 146 | void resolveRenderTarget(GrRenderTarget* target); |
| 147 | |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 148 | /** Info struct returned by getReadPixelsInfo about performing intermediate draws before |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 149 | reading pixels for performance or correctness. */ |
| 150 | struct ReadPixelTempDrawInfo { |
| 151 | /** If the GrGpu is requesting that the caller do a draw to an intermediate surface then |
| 152 | this is descriptor for the temp surface. The draw should always be a rect with |
| 153 | dst 0,0,w,h. */ |
| 154 | GrSurfaceDesc fTempSurfaceDesc; |
| 155 | /** Indicates whether there is a performance advantage to using an exact match texture |
| 156 | (in terms of width and height) for the intermediate texture instead of approximate. */ |
| 157 | bool fUseExactScratch; |
| 158 | /** The caller should swap the R and B channel in the temp draw and then instead of reading |
| 159 | the desired config back it should read GrPixelConfigSwapRAndB(readConfig). The swap |
| 160 | during the draw and the swap at readback time cancel and the client gets the correct |
| 161 | data. The swapped read back is either faster for or required by the underlying backend |
| 162 | 3D API. */ |
| 163 | bool fSwapRAndB; |
| 164 | }; |
| 165 | /** Describes why an intermediate draw must/should be performed before readPixels. */ |
| 166 | enum DrawPreference { |
| 167 | /** On input means that the caller would proceed without draw if the GrGpu doesn't request |
| 168 | one. |
| 169 | On output means that the GrGpu is not requesting a draw. */ |
| 170 | kNoDraw_DrawPreference, |
| 171 | /** Means that the client would prefer a draw for performance of the readback but |
| 172 | can satisfy a straight readPixels call on the inputs without an intermediate draw. |
| 173 | getReadPixelsInfo will never set the draw preference to this value but may leave |
| 174 | it set. */ |
| 175 | kCallerPrefersDraw_DrawPreference, |
| 176 | /** On output means that GrGpu would prefer a draw for performance of the readback but |
| 177 | can satisfy a straight readPixels call on the inputs without an intermediate draw. The |
| 178 | caller of getReadPixelsInfo should never specify this on intput. */ |
| 179 | kGpuPrefersDraw_DrawPreference, |
| 180 | /** On input means that the caller requires a draw to do a transformation and there is no |
| 181 | CPU fallback. |
| 182 | On output means that GrGpu can only satisfy the readPixels request if the intermediate |
| 183 | draw is performed. |
| 184 | */ |
| 185 | kRequireDraw_DrawPreference |
| 186 | }; |
| 187 | |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 188 | /** |
| 189 | * Used to negotiate whether and how an intermediate draw should or must be performed before |
| 190 | * a readPixels call. If this returns false then GrGpu could not deduce an intermediate draw |
| 191 | * that would allow a successful readPixels call. The passed width, height, and rowBytes, |
| 192 | * must be non-zero and already reflect clipping to the src bounds. |
| 193 | */ |
| 194 | bool getReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, size_t rowBytes, |
| 195 | GrPixelConfig readConfig, DrawPreference*, ReadPixelTempDrawInfo*); |
| 196 | |
| 197 | /** Info struct returned by getWritePixelsInfo about performing an intermediate draw in order |
| 198 | to write pixels to a GrSurface for either performance or correctness reasons. */ |
| 199 | struct WritePixelTempDrawInfo { |
| 200 | /** If the GrGpu is requesting that the caller upload to an intermediate surface and draw |
| 201 | that to the dst then this is the descriptor for the intermediate surface. The caller |
| 202 | should upload the pixels such that the upper left pixel of the upload rect is at 0,0 in |
| 203 | the intermediate surface.*/ |
| 204 | GrSurfaceDesc fTempSurfaceDesc; |
| 205 | /** If set, fTempSurfaceDesc's config will be a R/B swap of the src pixel config. The caller |
| 206 | should upload the pixels as is such that R and B will be swapped in the intermediate |
| 207 | surface. When the intermediate is drawn to the dst the shader should swap R/B again |
| 208 | such that the correct swizzle results in the dst. This is done to work around either |
| 209 | performance or API restrictions in the backend 3D API implementation. */ |
| 210 | bool fSwapRAndB; |
| 211 | }; |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 212 | |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 213 | /** |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 214 | * Used to negotiate whether and how an intermediate surface should be used to write pixels to |
| 215 | * a GrSurface. If this returns false then GrGpu could not deduce an intermediate draw |
| 216 | * that would allow a successful transfer of the src pixels to the dst. The passed width, |
| 217 | * height, and rowBytes, must be non-zero and already reflect clipping to the dst bounds. |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 218 | */ |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 219 | bool getWritePixelsInfo(GrSurface* dstSurface, int width, int height, size_t rowBytes, |
| 220 | GrPixelConfig srcConfig, DrawPreference*, WritePixelTempDrawInfo*); |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 221 | |
| 222 | /** |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 223 | * Reads a rectangle of pixels from a render target. |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 224 | * |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 225 | * @param surface The surface to read from |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 226 | * @param left left edge of the rectangle to read (inclusive) |
| 227 | * @param top top edge of the rectangle to read (inclusive) |
| 228 | * @param width width of rectangle to read in pixels. |
| 229 | * @param height height of rectangle to read in pixels. |
| 230 | * @param config the pixel config of the destination buffer |
| 231 | * @param buffer memory to read the rectangle into. |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 232 | * @param rowBytes the number of bytes between consecutive rows. Zero |
| 233 | * means rows are tightly packed. |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 234 | * @param invertY buffer should be populated bottom-to-top as opposed |
| 235 | * to top-to-bottom (skia's usual order) |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 236 | * |
| 237 | * @return true if the read succeeded, false if not. The read can fail |
| 238 | * because of a unsupported pixel config or because no render |
| 239 | * target is currently set. |
| 240 | */ |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 241 | bool readPixels(GrSurface* surface, |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 242 | int left, int top, int width, int height, |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 243 | GrPixelConfig config, void* buffer, size_t rowBytes); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 244 | |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 245 | /** |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 246 | * Updates the pixels in a rectangle of a surface. |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 247 | * |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 248 | * @param surface The surface to write to. |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 249 | * @param left left edge of the rectangle to write (inclusive) |
| 250 | * @param top top edge of the rectangle to write (inclusive) |
| 251 | * @param width width of rectangle to write in pixels. |
| 252 | * @param height height of rectangle to write in pixels. |
| 253 | * @param config the pixel config of the source buffer |
| 254 | * @param buffer memory to read pixels from |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 255 | * @param rowBytes number of bytes between consecutive rows. Zero |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 256 | * means rows are tightly packed. |
| 257 | */ |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 258 | bool writePixels(GrSurface* surface, |
| 259 | int left, int top, int width, int height, |
| 260 | GrPixelConfig config, const void* buffer, |
| 261 | size_t rowBytes); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 262 | |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 263 | /** |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 264 | * Updates the pixels in a rectangle of a surface using a GrTransferBuffer |
| 265 | * |
| 266 | * @param surface The surface to write to. |
| 267 | * @param left left edge of the rectangle to write (inclusive) |
| 268 | * @param top top edge of the rectangle to write (inclusive) |
| 269 | * @param width width of rectangle to write in pixels. |
| 270 | * @param height height of rectangle to write in pixels. |
| 271 | * @param config the pixel config of the source buffer |
| 272 | * @param buffer GrTransferBuffer to read pixels from |
| 273 | * @param offset offset from the start of the buffer |
| 274 | * @param rowBytes number of bytes between consecutive rows. Zero |
| 275 | * means rows are tightly packed. |
| 276 | */ |
| 277 | bool transferPixels(GrSurface* surface, |
| 278 | int left, int top, int width, int height, |
| 279 | GrPixelConfig config, GrTransferBuffer* buffer, |
| 280 | size_t offset, size_t rowBytes); |
| 281 | |
| 282 | /** |
egdaniel | 51c8d40 | 2015-08-06 10:54:13 -0700 | [diff] [blame] | 283 | * Clear the passed in render target. Ignores the draw state and clip. |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 284 | */ |
egdaniel | 51c8d40 | 2015-08-06 10:54:13 -0700 | [diff] [blame] | 285 | void clear(const SkIRect& rect, GrColor color, GrRenderTarget* renderTarget); |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 286 | |
| 287 | |
bsalomon | 6d467ec | 2014-11-18 07:36:19 -0800 | [diff] [blame] | 288 | void clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarget* renderTarget); |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 289 | |
| 290 | /** |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 291 | * Discards the contents render target. nullptr indicates that the current render target should |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 292 | * be discarded. |
| 293 | **/ |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 294 | virtual void discard(GrRenderTarget* = nullptr) = 0; |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 295 | |
| 296 | /** |
| 297 | * This is can be called before allocating a texture to be a dst for copySurface. It will |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 298 | * populate the origin, config, and flags fields of the desc such that copySurface can |
| 299 | * efficiently succeed. It should only succeed if it can allow copySurface to perform a copy |
| 300 | * that would be more effecient than drawing the src to a dst render target. |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 301 | */ |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 302 | virtual bool initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) const = 0; |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 303 | |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 304 | // After the client interacts directly with the 3D context state the GrGpu |
| 305 | // must resync its internal state and assumptions about 3D context state. |
| 306 | // Each time this occurs the GrGpu bumps a timestamp. |
| 307 | // state of the 3D context |
| 308 | // At 10 resets / frame and 60fps a 64bit timestamp will overflow in about |
| 309 | // a billion years. |
| 310 | typedef uint64_t ResetTimestamp; |
| 311 | |
| 312 | // This timestamp is always older than the current timestamp |
| 313 | static const ResetTimestamp kExpiredTimestamp = 0; |
| 314 | // Returns a timestamp based on the number of times the context was reset. |
| 315 | // This timestamp can be used to lazily detect when cached 3D context state |
| 316 | // is dirty. |
bsalomon | 6d467ec | 2014-11-18 07:36:19 -0800 | [diff] [blame] | 317 | ResetTimestamp getResetTimestamp() const { return fResetTimestamp; } |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 318 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 319 | virtual void buildProgramDesc(GrProgramDesc*, |
| 320 | const GrPrimitiveProcessor&, |
joshualitt | 465283c | 2015-09-11 08:19:35 -0700 | [diff] [blame] | 321 | const GrPipeline&) const = 0; |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 322 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 323 | // Called to perform a surface to surface copy. Fallbacks to issuing a draw from the src to dst |
| 324 | // take place at the GrDrawTarget level and this function implement faster copy paths. The rect |
| 325 | // and point are pre-clipped. The src rect and implied dst rect are guaranteed to be within the |
| 326 | // src/dst bounds and non-empty. |
joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 327 | bool copySurface(GrSurface* dst, |
| 328 | GrSurface* src, |
| 329 | const SkIRect& srcRect, |
| 330 | const SkIPoint& dstPoint); |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 331 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 332 | struct DrawArgs { |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 333 | DrawArgs(const GrPrimitiveProcessor* primProc, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 334 | const GrPipeline* pipeline, |
joshualitt | 465283c | 2015-09-11 08:19:35 -0700 | [diff] [blame] | 335 | const GrProgramDesc* desc) |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 336 | : fPrimitiveProcessor(primProc) |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 337 | , fPipeline(pipeline) |
joshualitt | 465283c | 2015-09-11 08:19:35 -0700 | [diff] [blame] | 338 | , fDesc(desc) { |
| 339 | SkASSERT(primProc && pipeline && desc); |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 340 | } |
| 341 | const GrPrimitiveProcessor* fPrimitiveProcessor; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 342 | const GrPipeline* fPipeline; |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 343 | const GrProgramDesc* fDesc; |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 344 | }; |
| 345 | |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 346 | void draw(const DrawArgs&, const GrVertices&); |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 347 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 348 | /////////////////////////////////////////////////////////////////////////// |
| 349 | // Debugging and Stats |
| 350 | |
| 351 | class Stats { |
| 352 | public: |
| 353 | #if GR_GPU_STATS |
| 354 | Stats() { this->reset(); } |
| 355 | |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 356 | void reset() { |
| 357 | fRenderTargetBinds = 0; |
| 358 | fShaderCompilations = 0; |
| 359 | fTextureCreates = 0; |
| 360 | fTextureUploads = 0; |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 361 | fTransfersToTexture = 0; |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 362 | fStencilAttachmentCreates = 0; |
joshualitt | 87a5c9f | 2015-09-08 13:42:05 -0700 | [diff] [blame] | 363 | fNumDraws = 0; |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 364 | } |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 365 | |
| 366 | int renderTargetBinds() const { return fRenderTargetBinds; } |
| 367 | void incRenderTargetBinds() { fRenderTargetBinds++; } |
| 368 | int shaderCompilations() const { return fShaderCompilations; } |
| 369 | void incShaderCompilations() { fShaderCompilations++; } |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 370 | int textureCreates() const { return fTextureCreates; } |
| 371 | void incTextureCreates() { fTextureCreates++; } |
| 372 | int textureUploads() const { return fTextureUploads; } |
| 373 | void incTextureUploads() { fTextureUploads++; } |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 374 | int transfersToTexture() const { return fTransfersToTexture; } |
| 375 | void incTransfersToTexture() { fTransfersToTexture++; } |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 376 | void incStencilAttachmentCreates() { fStencilAttachmentCreates++; } |
joshualitt | 87a5c9f | 2015-09-08 13:42:05 -0700 | [diff] [blame] | 377 | void incNumDraws() { fNumDraws++; } |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 378 | void dump(SkString*); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 379 | void dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 380 | |
| 381 | private: |
| 382 | int fRenderTargetBinds; |
| 383 | int fShaderCompilations; |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 384 | int fTextureCreates; |
| 385 | int fTextureUploads; |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 386 | int fTransfersToTexture; |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 387 | int fStencilAttachmentCreates; |
joshualitt | 87a5c9f | 2015-09-08 13:42:05 -0700 | [diff] [blame] | 388 | int fNumDraws; |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 389 | #else |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 390 | void dump(SkString*) {} |
| 391 | void dumpKeyValuePairs(SkTArray<SkString>*, SkTArray<double>*) {} |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 392 | void incRenderTargetBinds() {} |
| 393 | void incShaderCompilations() {} |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 394 | void incTextureCreates() {} |
| 395 | void incTextureUploads() {} |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 396 | void incTransfersToTexture() {} |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 397 | void incStencilAttachmentCreates() {} |
joshualitt | 87a5c9f | 2015-09-08 13:42:05 -0700 | [diff] [blame] | 398 | void incNumDraws() {} |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 399 | #endif |
| 400 | }; |
| 401 | |
| 402 | Stats* stats() { return &fStats; } |
| 403 | |
bsalomon | 67d7620 | 2015-11-11 12:40:42 -0800 | [diff] [blame] | 404 | /** Creates a texture directly in the backend API without wrapping it in a GrTexture. This is |
| 405 | only to be used for testing (particularly for testing the methods that import an externally |
| 406 | created texture into Skia. Must be matched with a call to deleteTestingOnlyTexture(). */ |
jvanverth | 8895792 | 2015-07-14 11:02:52 -0700 | [diff] [blame] | 407 | virtual GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h, |
| 408 | GrPixelConfig config) const = 0; |
bsalomon | 67d7620 | 2015-11-11 12:40:42 -0800 | [diff] [blame] | 409 | /** Check a handle represents an actual texture in the backend API that has not been freed. */ |
| 410 | virtual bool isTestingOnlyBackendTexture(GrBackendObject) const = 0; |
| 411 | /** If ownership of the backend texture has been transferred pass true for abandonTexture. This |
| 412 | will do any necessary cleanup of the handle without freeing the texture in the backend |
| 413 | API. */ |
| 414 | virtual void deleteTestingOnlyBackendTexture(GrBackendObject, |
| 415 | bool abandonTexture = false) const = 0; |
jvanverth | 672bb7f | 2015-07-13 07:19:57 -0700 | [diff] [blame] | 416 | |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 417 | // width and height may be larger than rt (if underlying API allows it). |
| 418 | // Returns nullptr if compatible sb could not be created, otherwise the caller owns the ref on |
| 419 | // the GrStencilAttachment. |
| 420 | virtual GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*, |
| 421 | int width, |
| 422 | int height) = 0; |
| 423 | // clears target's entire stencil buffer to 0 |
| 424 | virtual void clearStencil(GrRenderTarget* target) = 0; |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 425 | |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 426 | // draws an outline rectangle for debugging/visualization purposes. |
| 427 | virtual void drawDebugWireRect(GrRenderTarget*, const SkIRect&, GrColor) = 0; |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 428 | |
bsalomon | e179a91 | 2016-01-20 06:18:10 -0800 | [diff] [blame^] | 429 | // Determines whether a texture will need to be rescaled in order to be used with the |
| 430 | // GrTextureParams. This variation is called when the caller will create a new texture using the |
| 431 | // texture provider from a non-texture src (cpu-backed image, ...). |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 432 | bool makeCopyForTextureParams(int width, int height, const GrTextureParams&, |
bsalomon | e179a91 | 2016-01-20 06:18:10 -0800 | [diff] [blame^] | 433 | GrTextureProducer::CopyParams*) const; |
| 434 | |
| 435 | // Like the above but this variation should be called when the caller is not creating the |
| 436 | // original texture but rather was handed the original texture. It adds additional checks |
| 437 | // relevant to original textures that were created external to Skia via |
| 438 | // GrTextureProvider::wrap methods. |
| 439 | bool makeCopyForTextureParams(GrTexture* texture, const GrTextureParams& params, |
| 440 | GrTextureProducer::CopyParams* copyParams) const { |
| 441 | if (this->makeCopyForTextureParams(texture->width(), texture->height(), params, |
| 442 | copyParams)) { |
| 443 | return true; |
| 444 | } |
| 445 | return this->onMakeCopyForTextureParams(texture, params, copyParams); |
| 446 | } |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 447 | |
jvanverth | 672bb7f | 2015-07-13 07:19:57 -0700 | [diff] [blame] | 448 | // This is only to be used in GL-specific tests. |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 449 | virtual const GrGLContext* glContextForTesting() const { return nullptr; } |
bsalomon | 993a421 | 2015-05-29 11:37:25 -0700 | [diff] [blame] | 450 | |
joshualitt | 8fd844f | 2015-12-02 13:36:47 -0800 | [diff] [blame] | 451 | // This is only to be used by testing code |
| 452 | virtual void resetShaderCacheForTesting() const {} |
| 453 | |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame] | 454 | protected: |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 455 | // Functions used to map clip-respecting stencil tests into normal |
| 456 | // stencil funcs supported by GPUs. |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 457 | static GrStencilFunc ConvertStencilFunc(bool stencilInClip, |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 458 | GrStencilFunc func); |
| 459 | static void ConvertStencilFuncAndMask(GrStencilFunc func, |
| 460 | bool clipInStencil, |
| 461 | unsigned int clipBit, |
| 462 | unsigned int userBits, |
| 463 | unsigned int* ref, |
| 464 | unsigned int* mask); |
| 465 | |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 466 | static void ElevateDrawPreference(GrGpu::DrawPreference* preference, |
| 467 | GrGpu::DrawPreference elevation) { |
| 468 | GR_STATIC_ASSERT(GrGpu::kCallerPrefersDraw_DrawPreference > GrGpu::kNoDraw_DrawPreference); |
| 469 | GR_STATIC_ASSERT(GrGpu::kGpuPrefersDraw_DrawPreference > |
| 470 | GrGpu::kCallerPrefersDraw_DrawPreference); |
| 471 | GR_STATIC_ASSERT(GrGpu::kRequireDraw_DrawPreference > |
| 472 | GrGpu::kGpuPrefersDraw_DrawPreference); |
| 473 | *preference = SkTMax(*preference, elevation); |
| 474 | } |
| 475 | |
joshualitt | 93316b9 | 2015-10-23 09:08:08 -0700 | [diff] [blame] | 476 | void handleDirtyContext() { |
| 477 | if (fResetBits) { |
| 478 | this->resetContext(); |
| 479 | } |
| 480 | } |
| 481 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 482 | Stats fStats; |
| 483 | SkAutoTDelete<GrPathRendering> fPathRendering; |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 484 | // Subclass must initialize this in its constructor. |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 485 | SkAutoTUnref<const GrCaps> fCaps; |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 486 | |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 487 | private: |
bsalomon@google.com | b635d39 | 2011-11-05 12:47:43 +0000 | [diff] [blame] | 488 | // 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] | 489 | // assumed 3D context state and dirty any state cache. |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 490 | virtual void onResetContext(uint32_t resetBits) = 0; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 491 | |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 492 | // Called before certain draws in order to guarantee coherent results from dst reads. |
| 493 | virtual void xferBarrier(GrRenderTarget*, GrXferBarrierType) = 0; |
| 494 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 495 | // overridden by backend-specific derived class to create objects. |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 496 | // Texture size and sample size will have already been validated in base class before |
| 497 | // onCreateTexture/CompressedTexture are called. |
| 498 | virtual GrTexture* onCreateTexture(const GrSurfaceDesc& desc, |
| 499 | GrGpuResource::LifeCycle lifeCycle, |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 500 | const void* srcData, size_t rowBytes) = 0; |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 501 | virtual GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, |
| 502 | GrGpuResource::LifeCycle lifeCycle, |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 503 | const void* srcData) = 0; |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 504 | virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) = 0; |
| 505 | virtual GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&, |
| 506 | GrWrapOwnership) = 0; |
robertphillips@google.com | adacc70 | 2013-10-14 21:53:24 +0000 | [diff] [blame] | 507 | virtual GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) = 0; |
| 508 | virtual GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) = 0; |
jvanverth | 73063dc | 2015-12-03 09:15:47 -0800 | [diff] [blame] | 509 | virtual GrTransferBuffer* onCreateTransferBuffer(size_t size, TransferType type) = 0; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 510 | |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 511 | // overridden by backend-specific derived class to perform the clear. |
egdaniel | 51c8d40 | 2015-08-06 10:54:13 -0700 | [diff] [blame] | 512 | virtual void onClear(GrRenderTarget*, const SkIRect& rect, GrColor color) = 0; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 513 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 514 | |
| 515 | // Overridden by backend specific classes to perform a clear of the stencil clip bits. This is |
| 516 | // ONLY used by the the clip target |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 517 | virtual void onClearStencilClip(GrRenderTarget*, const SkIRect& rect, bool insideClip) = 0; |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 518 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 519 | // overridden by backend-specific derived class to perform the draw call. |
bsalomon | e64eb57 | 2015-05-07 11:35:55 -0700 | [diff] [blame] | 520 | virtual void onDraw(const DrawArgs&, const GrNonInstancedVertices&) = 0; |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 521 | |
bsalomon | e179a91 | 2016-01-20 06:18:10 -0800 | [diff] [blame^] | 522 | virtual bool onMakeCopyForTextureParams(GrTexture* texture, const GrTextureParams&, |
| 523 | GrTextureProducer::CopyParams*) const { return false; } |
| 524 | |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 525 | virtual bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, |
| 526 | size_t rowBytes, GrPixelConfig readConfig, DrawPreference*, |
| 527 | ReadPixelTempDrawInfo*) = 0; |
| 528 | virtual bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height, size_t rowBytes, |
| 529 | GrPixelConfig srcConfig, DrawPreference*, |
| 530 | WritePixelTempDrawInfo*) = 0; |
| 531 | |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 532 | // overridden by backend-specific derived class to perform the surface read |
| 533 | virtual bool onReadPixels(GrSurface*, |
egdaniel | 6d901da | 2015-07-30 12:02:15 -0700 | [diff] [blame] | 534 | int left, int top, |
| 535 | int width, int height, |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 536 | GrPixelConfig, |
| 537 | void* buffer, |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 538 | size_t rowBytes) = 0; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 539 | |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 540 | // overridden by backend-specific derived class to perform the surface write |
| 541 | virtual bool onWritePixels(GrSurface*, |
| 542 | int left, int top, int width, int height, |
| 543 | GrPixelConfig config, const void* buffer, |
| 544 | size_t rowBytes) = 0; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 545 | |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 546 | // overridden by backend-specific derived class to perform the surface write |
| 547 | virtual bool onTransferPixels(GrSurface*, |
| 548 | int left, int top, int width, int height, |
| 549 | GrPixelConfig config, GrTransferBuffer* buffer, |
| 550 | size_t offset, size_t rowBytes) = 0; |
| 551 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 552 | // overridden by backend-specific derived class to perform the resolve |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 553 | virtual void onResolveRenderTarget(GrRenderTarget* target) = 0; |
| 554 | |
joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 555 | // overridden by backend specific derived class to perform the copy surface |
| 556 | virtual bool onCopySurface(GrSurface* dst, |
| 557 | GrSurface* src, |
| 558 | const SkIRect& srcRect, |
| 559 | const SkIPoint& dstPoint) = 0; |
| 560 | |
bsalomon@google.com | b635d39 | 2011-11-05 12:47:43 +0000 | [diff] [blame] | 561 | void resetContext() { |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 562 | this->onResetContext(fResetBits); |
| 563 | fResetBits = 0; |
bsalomon@google.com | b635d39 | 2011-11-05 12:47:43 +0000 | [diff] [blame] | 564 | ++fResetTimestamp; |
| 565 | } |
| 566 | |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 567 | ResetTimestamp fResetTimestamp; |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 568 | uint32_t fResetBits; |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 569 | // The context owns us, not vice-versa, so this ptr is not ref'ed by Gpu. |
| 570 | GrContext* fContext; |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 571 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 572 | friend class GrPathRendering; |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 573 | typedef SkRefCnt INHERITED; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 574 | }; |
| 575 | |
| 576 | #endif |