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" |
| 14 | #include "GrTraceMarker.h" |
| 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; |
bsalomon | 993a421 | 2015-05-29 11:37:25 -0700 | [diff] [blame] | 20 | struct GrGLInterface; |
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; |
| 34 | class GrVertexBuffer; |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 35 | class GrVertices; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 36 | |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 37 | class GrGpu : public SkRefCnt { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 38 | public: |
| 39 | /** |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 40 | * 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] | 41 | * not supported (at compile-time or run-time) this returns NULL. The context will not be |
| 42 | * 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] | 43 | */ |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 44 | static GrGpu* Create(GrBackend, GrBackendContext, const GrContextOptions&, GrContext* context); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 45 | |
| 46 | //////////////////////////////////////////////////////////////////////////// |
| 47 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 48 | GrGpu(GrContext* context); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 49 | ~GrGpu() override; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 50 | |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 51 | GrContext* getContext() { return fContext; } |
| 52 | const GrContext* getContext() const { return fContext; } |
| 53 | |
| 54 | /** |
| 55 | * Gets the capabilities of the draw target. |
| 56 | */ |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 57 | const GrCaps* caps() const { return fCaps.get(); } |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 58 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 59 | GrPathRendering* pathRendering() { return fPathRendering.get(); } |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 60 | |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 61 | // Called by GrContext when the underlying backend context has been destroyed. |
| 62 | // GrGpu should use this to ensure that no backend API calls will be made from |
| 63 | // here onward, including in its destructor. Subclasses should call |
robertphillips | e337130 | 2014-09-17 06:01:06 -0700 | [diff] [blame] | 64 | // INHERITED::contextAbandoned() if they override this. |
| 65 | virtual void contextAbandoned(); |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 66 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 67 | /** |
| 68 | * The GrGpu object normally assumes that no outsider is setting state |
| 69 | * 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] | 70 | * the GrGpu that the state was modified and it shouldn't make assumptions |
| 71 | * about the state. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 72 | */ |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 73 | void markContextDirty(uint32_t state = kAll_GrBackendState) { fResetBits |= state; } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 74 | |
| 75 | /** |
bsalomon | 6d467ec | 2014-11-18 07:36:19 -0800 | [diff] [blame] | 76 | * Creates a texture object. If kRenderTarget_GrSurfaceFlag the texture can |
| 77 | * be used as a render target by calling GrTexture::asRenderTarget(). Not all |
| 78 | * pixel configs can be used as render targets. Support for configs as textures |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 79 | * or render targets can be checked using GrCaps. |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 80 | * |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 81 | * @param desc describes the texture to be created. |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 82 | * @param budgeted does this texture count against the resource cache budget? |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 83 | * @param srcData texel data to load texture. Begins with full-size |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 84 | * palette data for paletted textures. For compressed |
| 85 | * formats it contains the compressed pixel data. Otherwise, |
| 86 | * it contains width*height texels. If NULL texture data |
| 87 | * is uninitialized. |
| 88 | * @param rowBytes the number of bytes between consecutive rows. Zero |
| 89 | * means rows are tightly packed. This field is ignored |
| 90 | * for compressed formats. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 91 | * |
| 92 | * @return The texture object if successful, otherwise NULL. |
| 93 | */ |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 94 | GrTexture* createTexture(const GrSurfaceDesc& desc, bool budgeted, |
| 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 | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 100 | GrTexture* wrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership); |
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 | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 105 | GrRenderTarget* wrapBackendRenderTarget(const GrBackendRenderTargetDesc&, GrWrapOwnership); |
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 |
commit-bot@chromium.org | 8341eb7 | 2014-05-07 20:51:05 +0000 | [diff] [blame] | 112 | * by either GrVertexBuffer::map() or |
| 113 | * GrVertexBuffer::updateData(). |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 114 | * |
| 115 | * @return The vertex buffer if successful, otherwise NULL. |
| 116 | */ |
robertphillips@google.com | adacc70 | 2013-10-14 21:53:24 +0000 | [diff] [blame] | 117 | GrVertexBuffer* createVertexBuffer(size_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 |
commit-bot@chromium.org | 8341eb7 | 2014-05-07 20:51:05 +0000 | [diff] [blame] | 124 | * by either GrIndexBuffer::map() or |
| 125 | * GrIndexBuffer::updateData(). |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 126 | * |
| 127 | * @return The index buffer if successful, otherwise NULL. |
| 128 | */ |
robertphillips@google.com | adacc70 | 2013-10-14 21:53:24 +0000 | [diff] [blame] | 129 | GrIndexBuffer* createIndexBuffer(size_t size, bool dynamic); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 130 | |
| 131 | /** |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 132 | * Resolves MSAA. |
| 133 | */ |
| 134 | void resolveRenderTarget(GrRenderTarget* target); |
| 135 | |
| 136 | /** |
commit-bot@chromium.org | 5d1d79a | 2013-05-24 18:52:52 +0000 | [diff] [blame] | 137 | * Gets a preferred 8888 config to use for writing/reading pixel data to/from a surface with |
| 138 | * config surfaceConfig. The returned config must have at least as many bits per channel as the |
| 139 | * readConfig or writeConfig param. |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 140 | */ |
commit-bot@chromium.org | 5d1d79a | 2013-05-24 18:52:52 +0000 | [diff] [blame] | 141 | virtual GrPixelConfig preferredReadPixelsConfig(GrPixelConfig readConfig, |
| 142 | GrPixelConfig surfaceConfig) const { |
| 143 | return readConfig; |
| 144 | } |
| 145 | virtual GrPixelConfig preferredWritePixelsConfig(GrPixelConfig writeConfig, |
| 146 | GrPixelConfig surfaceConfig) const { |
| 147 | return writeConfig; |
| 148 | } |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 149 | |
| 150 | /** |
bsalomon | 47c1ccb | 2015-06-24 15:04:13 -0700 | [diff] [blame^] | 151 | * Called before uploading writing pixels to a GrTexture when the src pixel config doesn't |
| 152 | * match the texture's config. |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 153 | */ |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 154 | virtual bool canWriteTexturePixels(const GrTexture*, GrPixelConfig srcConfig) const = 0; |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 155 | |
| 156 | /** |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 157 | * OpenGL's readPixels returns the result bottom-to-top while the skia |
| 158 | * API is top-to-bottom. Thus we have to do a y-axis flip. The obvious |
| 159 | * solution is to have the subclass do the flip using either the CPU or GPU. |
| 160 | * However, the caller (GrContext) may have transformations to apply and can |
| 161 | * simply fold in the y-flip for free. On the other hand, the subclass may |
| 162 | * 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] | 163 | * 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] | 164 | * concurrently. |
| 165 | * |
| 166 | * This function returns true if a y-flip is required to put the pixels in |
| 167 | * top-to-bottom order and the subclass cannot do it for free. |
| 168 | * |
| 169 | * See read pixels for the params |
| 170 | * @return true if calling readPixels with the same set of params will |
| 171 | * produce bottom-to-top data |
| 172 | */ |
| 173 | virtual bool readPixelsWillPayForYFlip(GrRenderTarget* renderTarget, |
| 174 | int left, int top, |
| 175 | int width, int height, |
| 176 | GrPixelConfig config, |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 177 | size_t rowBytes) const = 0; |
| 178 | /** |
| 179 | * This should return true if reading a NxM rectangle of pixels from a |
| 180 | * render target is faster if the target has dimensons N and M and the read |
| 181 | * rectangle has its top-left at 0,0. |
| 182 | */ |
| 183 | virtual bool fullReadPixelsIsFasterThanPartial() const { return false; }; |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 184 | |
| 185 | /** |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 186 | * Reads a rectangle of pixels from a render target. |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 187 | * |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 188 | * @param renderTarget the render target to read from. NULL means the |
| 189 | * current render target. |
| 190 | * @param left left edge of the rectangle to read (inclusive) |
| 191 | * @param top top edge of the rectangle to read (inclusive) |
| 192 | * @param width width of rectangle to read in pixels. |
| 193 | * @param height height of rectangle to read in pixels. |
| 194 | * @param config the pixel config of the destination buffer |
| 195 | * @param buffer memory to read the rectangle into. |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 196 | * @param rowBytes the number of bytes between consecutive rows. Zero |
| 197 | * means rows are tightly packed. |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 198 | * @param invertY buffer should be populated bottom-to-top as opposed |
| 199 | * to top-to-bottom (skia's usual order) |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 200 | * |
| 201 | * @return true if the read succeeded, false if not. The read can fail |
| 202 | * because of a unsupported pixel config or because no render |
| 203 | * target is currently set. |
| 204 | */ |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 205 | bool readPixels(GrRenderTarget* renderTarget, |
| 206 | int left, int top, int width, int height, |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 207 | GrPixelConfig config, void* buffer, size_t rowBytes); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 208 | |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 209 | /** |
| 210 | * Updates the pixels in a rectangle of a texture. |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 211 | * |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 212 | * @param left left edge of the rectangle to write (inclusive) |
| 213 | * @param top top edge of the rectangle to write (inclusive) |
| 214 | * @param width width of rectangle to write in pixels. |
| 215 | * @param height height of rectangle to write in pixels. |
| 216 | * @param config the pixel config of the source buffer |
| 217 | * @param buffer memory to read pixels from |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 218 | * @param rowBytes number of bytes between consecutive rows. Zero |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 219 | * means rows are tightly packed. |
| 220 | */ |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 221 | bool writeTexturePixels(GrTexture* texture, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 222 | int left, int top, int width, int height, |
| 223 | GrPixelConfig config, const void* buffer, |
| 224 | size_t rowBytes); |
| 225 | |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 226 | /** |
| 227 | * Clear the passed in render target. Ignores the draw state and clip. Clears the whole thing if |
| 228 | * rect is NULL, otherwise just the rect. If canIgnoreRect is set then the entire render target |
| 229 | * can be optionally cleared. |
| 230 | */ |
bsalomon | 6d467ec | 2014-11-18 07:36:19 -0800 | [diff] [blame] | 231 | void clear(const SkIRect* rect, GrColor color, bool canIgnoreRect,GrRenderTarget* renderTarget); |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 232 | |
| 233 | |
bsalomon | 6d467ec | 2014-11-18 07:36:19 -0800 | [diff] [blame] | 234 | void clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarget* renderTarget); |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 235 | |
| 236 | /** |
| 237 | * Discards the contents render target. NULL indicates that the current render target should |
| 238 | * be discarded. |
| 239 | **/ |
| 240 | virtual void discard(GrRenderTarget* = NULL) = 0; |
| 241 | |
| 242 | /** |
| 243 | * 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] | 244 | * populate the origin, config, and flags fields of the desc such that copySurface can |
| 245 | * efficiently succeed. It should only succeed if it can allow copySurface to perform a copy |
| 246 | * 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] | 247 | */ |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 248 | virtual bool initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) = 0; |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 249 | |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 250 | // After the client interacts directly with the 3D context state the GrGpu |
| 251 | // must resync its internal state and assumptions about 3D context state. |
| 252 | // Each time this occurs the GrGpu bumps a timestamp. |
| 253 | // state of the 3D context |
| 254 | // At 10 resets / frame and 60fps a 64bit timestamp will overflow in about |
| 255 | // a billion years. |
| 256 | typedef uint64_t ResetTimestamp; |
| 257 | |
| 258 | // This timestamp is always older than the current timestamp |
| 259 | static const ResetTimestamp kExpiredTimestamp = 0; |
| 260 | // Returns a timestamp based on the number of times the context was reset. |
| 261 | // This timestamp can be used to lazily detect when cached 3D context state |
| 262 | // is dirty. |
bsalomon | 6d467ec | 2014-11-18 07:36:19 -0800 | [diff] [blame] | 263 | ResetTimestamp getResetTimestamp() const { return fResetTimestamp; } |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 264 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 265 | virtual void buildProgramDesc(GrProgramDesc*, |
| 266 | const GrPrimitiveProcessor&, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 267 | const GrPipeline&, |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 268 | const GrBatchTracker&) const = 0; |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 269 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 270 | // Called to perform a surface to surface copy. Fallbacks to issuing a draw from the src to dst |
| 271 | // take place at the GrDrawTarget level and this function implement faster copy paths. The rect |
| 272 | // and point are pre-clipped. The src rect and implied dst rect are guaranteed to be within the |
| 273 | // src/dst bounds and non-empty. |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 274 | virtual bool copySurface(GrSurface* dst, |
| 275 | GrSurface* src, |
| 276 | const SkIRect& srcRect, |
| 277 | const SkIPoint& dstPoint) = 0; |
| 278 | |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 279 | // Called before certain draws in order to guarantee coherent results from dst reads. |
cdalton | 231c5fd | 2015-05-13 12:35:36 -0700 | [diff] [blame] | 280 | virtual void xferBarrier(GrRenderTarget*, GrXferBarrierType) = 0; |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 281 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 282 | struct DrawArgs { |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 283 | DrawArgs(const GrPrimitiveProcessor* primProc, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 284 | const GrPipeline* pipeline, |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 285 | const GrProgramDesc* desc, |
joshualitt | 17e7314 | 2015-01-21 11:52:36 -0800 | [diff] [blame] | 286 | const GrBatchTracker* batchTracker) |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 287 | : fPrimitiveProcessor(primProc) |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 288 | , fPipeline(pipeline) |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 289 | , fDesc(desc) |
joshualitt | 17e7314 | 2015-01-21 11:52:36 -0800 | [diff] [blame] | 290 | , fBatchTracker(batchTracker) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 291 | SkASSERT(primProc && pipeline && desc && batchTracker); |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 292 | } |
| 293 | const GrPrimitiveProcessor* fPrimitiveProcessor; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 294 | const GrPipeline* fPipeline; |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 295 | const GrProgramDesc* fDesc; |
| 296 | const GrBatchTracker* fBatchTracker; |
| 297 | }; |
| 298 | |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 299 | void draw(const DrawArgs&, const GrVertices&); |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 300 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 301 | /////////////////////////////////////////////////////////////////////////// |
| 302 | // Debugging and Stats |
| 303 | |
| 304 | class Stats { |
| 305 | public: |
| 306 | #if GR_GPU_STATS |
| 307 | Stats() { this->reset(); } |
| 308 | |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 309 | void reset() { |
| 310 | fRenderTargetBinds = 0; |
| 311 | fShaderCompilations = 0; |
| 312 | fTextureCreates = 0; |
| 313 | fTextureUploads = 0; |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 314 | fStencilAttachmentCreates = 0; |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 315 | } |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 316 | |
| 317 | int renderTargetBinds() const { return fRenderTargetBinds; } |
| 318 | void incRenderTargetBinds() { fRenderTargetBinds++; } |
| 319 | int shaderCompilations() const { return fShaderCompilations; } |
| 320 | void incShaderCompilations() { fShaderCompilations++; } |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 321 | int textureCreates() const { return fTextureCreates; } |
| 322 | void incTextureCreates() { fTextureCreates++; } |
| 323 | int textureUploads() const { return fTextureUploads; } |
| 324 | void incTextureUploads() { fTextureUploads++; } |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 325 | void incStencilAttachmentCreates() { fStencilAttachmentCreates++; } |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 326 | void dump(SkString*); |
| 327 | |
| 328 | private: |
| 329 | int fRenderTargetBinds; |
| 330 | int fShaderCompilations; |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 331 | int fTextureCreates; |
| 332 | int fTextureUploads; |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 333 | int fStencilAttachmentCreates; |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 334 | #else |
| 335 | void dump(SkString*) {}; |
| 336 | void incRenderTargetBinds() {} |
| 337 | void incShaderCompilations() {} |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 338 | void incTextureCreates() {} |
| 339 | void incTextureUploads() {} |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 340 | void incStencilAttachmentCreates() {} |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 341 | #endif |
| 342 | }; |
| 343 | |
| 344 | Stats* stats() { return &fStats; } |
| 345 | |
| 346 | /** |
| 347 | * Called at start and end of gpu trace marking |
| 348 | * GR_CREATE_GPU_TRACE_MARKER(marker_str, target) will automatically call these at the start |
| 349 | * and end of a code block respectively |
| 350 | */ |
| 351 | void addGpuTraceMarker(const GrGpuTraceMarker* marker); |
| 352 | void removeGpuTraceMarker(const GrGpuTraceMarker* marker); |
| 353 | |
| 354 | /** |
| 355 | * Takes the current active set of markers and stores them for later use. Any current marker |
| 356 | * in the active set is removed from the active set and the targets remove function is called. |
| 357 | * These functions do not work as a stack so you cannot call save a second time before calling |
| 358 | * restore. Also, it is assumed that when restore is called the current active set of markers |
| 359 | * is empty. When the stored markers are added back into the active set, the targets add marker |
| 360 | * is called. |
| 361 | */ |
| 362 | void saveActiveTraceMarkers(); |
| 363 | void restoreActiveTraceMarkers(); |
| 364 | |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 365 | // Given a rt, find or create a stencil buffer and attach it |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 366 | bool attachStencilAttachmentToRenderTarget(GrRenderTarget* target); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 367 | |
bsalomon | 993a421 | 2015-05-29 11:37:25 -0700 | [diff] [blame] | 368 | // This is only to be used in tests. |
| 369 | virtual const GrGLInterface* glInterfaceForTesting() const { return NULL; } |
| 370 | |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame] | 371 | protected: |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 372 | // Functions used to map clip-respecting stencil tests into normal |
| 373 | // stencil funcs supported by GPUs. |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 374 | static GrStencilFunc ConvertStencilFunc(bool stencilInClip, |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 375 | GrStencilFunc func); |
| 376 | static void ConvertStencilFuncAndMask(GrStencilFunc func, |
| 377 | bool clipInStencil, |
| 378 | unsigned int clipBit, |
| 379 | unsigned int userBits, |
| 380 | unsigned int* ref, |
| 381 | unsigned int* mask); |
| 382 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 383 | const GrTraceMarkerSet& getActiveTraceMarkers() const { return fActiveTraceMarkers; } |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 384 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 385 | Stats fStats; |
| 386 | SkAutoTDelete<GrPathRendering> fPathRendering; |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 387 | // Subclass must initialize this in its constructor. |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 388 | SkAutoTUnref<const GrCaps> fCaps; |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 389 | |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 390 | private: |
bsalomon@google.com | b635d39 | 2011-11-05 12:47:43 +0000 | [diff] [blame] | 391 | // 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] | 392 | // assumed 3D context state and dirty any state cache. |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 393 | virtual void onResetContext(uint32_t resetBits) = 0; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 394 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 395 | // overridden by backend-specific derived class to create objects. |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 396 | // Texture size and sample size will have already been validated in base class before |
| 397 | // onCreateTexture/CompressedTexture are called. |
| 398 | virtual GrTexture* onCreateTexture(const GrSurfaceDesc& desc, |
| 399 | GrGpuResource::LifeCycle lifeCycle, |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 400 | const void* srcData, size_t rowBytes) = 0; |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 401 | virtual GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, |
| 402 | GrGpuResource::LifeCycle lifeCycle, |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 403 | const void* srcData) = 0; |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 404 | virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) = 0; |
| 405 | virtual GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&, |
| 406 | GrWrapOwnership) = 0; |
robertphillips@google.com | adacc70 | 2013-10-14 21:53:24 +0000 | [diff] [blame] | 407 | virtual GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) = 0; |
| 408 | virtual GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) = 0; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 409 | |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 410 | // overridden by backend-specific derived class to perform the clear. |
joshualitt | 4b68ec0 | 2014-11-07 14:11:45 -0800 | [diff] [blame] | 411 | virtual void onClear(GrRenderTarget*, const SkIRect* rect, GrColor color, |
| 412 | bool canIgnoreRect) = 0; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 413 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 414 | |
| 415 | // Overridden by backend specific classes to perform a clear of the stencil clip bits. This is |
| 416 | // ONLY used by the the clip target |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 417 | virtual void onClearStencilClip(GrRenderTarget*, const SkIRect& rect, bool insideClip) = 0; |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 418 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 419 | // overridden by backend-specific derived class to perform the draw call. |
bsalomon | e64eb57 | 2015-05-07 11:35:55 -0700 | [diff] [blame] | 420 | virtual void onDraw(const DrawArgs&, const GrNonInstancedVertices&) = 0; |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 421 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 422 | virtual bool onReadPixels(GrRenderTarget* target, |
| 423 | int left, int top, int width, int height, |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 424 | GrPixelConfig, |
| 425 | void* buffer, |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 426 | size_t rowBytes) = 0; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 427 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 428 | // overridden by backend-specific derived class to perform the texture update |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 429 | virtual bool onWriteTexturePixels(GrTexture* texture, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 430 | int left, int top, int width, int height, |
| 431 | GrPixelConfig config, const void* buffer, |
| 432 | size_t rowBytes) = 0; |
| 433 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 434 | // overridden by backend-specific derived class to perform the resolve |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 435 | virtual void onResolveRenderTarget(GrRenderTarget* target) = 0; |
| 436 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 437 | // width and height may be larger than rt (if underlying API allows it). |
| 438 | // Should attach the SB to the RT. Returns false if compatible sb could |
| 439 | // not be created. |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 440 | virtual bool createStencilAttachmentForRenderTarget(GrRenderTarget*, int width, int height) = 0; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 441 | |
| 442 | // attaches an existing SB to an existing RT. |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 443 | virtual bool attachStencilAttachmentToRenderTarget(GrStencilAttachment*, GrRenderTarget*) = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 444 | |
bsalomon | b0bd4f6 | 2014-09-03 07:19:50 -0700 | [diff] [blame] | 445 | // clears target's entire stencil buffer to 0 |
| 446 | virtual void clearStencil(GrRenderTarget* target) = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 447 | |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 448 | virtual void didAddGpuTraceMarker() = 0; |
| 449 | virtual void didRemoveGpuTraceMarker() = 0; |
| 450 | |
bsalomon@google.com | b635d39 | 2011-11-05 12:47:43 +0000 | [diff] [blame] | 451 | void resetContext() { |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 452 | this->onResetContext(fResetBits); |
| 453 | fResetBits = 0; |
bsalomon@google.com | b635d39 | 2011-11-05 12:47:43 +0000 | [diff] [blame] | 454 | ++fResetTimestamp; |
| 455 | } |
| 456 | |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 457 | void handleDirtyContext() { |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 458 | if (fResetBits) { |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 459 | this->resetContext(); |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 460 | } |
| 461 | } |
| 462 | |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 463 | ResetTimestamp fResetTimestamp; |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 464 | uint32_t fResetBits; |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 465 | // To keep track that we always have at least as many debug marker adds as removes |
| 466 | int fGpuTraceMarkerCount; |
| 467 | GrTraceMarkerSet fActiveTraceMarkers; |
| 468 | GrTraceMarkerSet fStoredTraceMarkers; |
| 469 | // The context owns us, not vice-versa, so this ptr is not ref'ed by Gpu. |
| 470 | GrContext* fContext; |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 471 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 472 | friend class GrPathRendering; |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 473 | typedef SkRefCnt INHERITED; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 474 | }; |
| 475 | |
| 476 | #endif |