blob: 6e8dc43f75ac9c8faa19aa487468c6b545891997 [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * 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.comac10a2d2010-12-22 21:39:39 +00006 */
7
reed@google.comac10a2d2010-12-22 21:39:39 +00008#ifndef GrGpu_DEFINED
9#define GrGpu_DEFINED
10
bsalomon@google.com669fdc42011-04-05 17:08:27 +000011#include "GrDrawTarget.h"
kkinnunenccdaa042014-08-20 01:36:23 -070012#include "GrPathRendering.h"
joshualitt79f8fae2014-10-28 17:59:26 -070013#include "GrProgramDesc.h"
sugoi@google.com12b4e272012-12-06 20:13:11 +000014#include "SkPath.h"
15
bsalomon@google.com669fdc42011-04-05 17:08:27 +000016class GrContext;
bsalomone64eb572015-05-07 11:35:55 -070017class GrNonInstancedVertices;
bsalomon@google.com64aef2b2012-06-11 15:36:13 +000018class GrPath;
cdaltonb85a0aa2014-07-21 15:32:44 -070019class GrPathRange;
bsalomon@google.com30085192011-08-19 15:42:31 +000020class GrPathRenderer;
21class GrPathRendererChain;
egdaniel8dd688b2015-01-22 10:16:09 -080022class GrPipeline;
joshualitt873ad0e2015-01-20 09:08:51 -080023class GrPrimitiveProcessor;
egdaniel8dc7c3a2015-04-16 11:22:42 -070024class GrStencilAttachment;
bsalomoncb8979d2015-05-05 09:51:38 -070025class GrVertices;
reed@google.comac10a2d2010-12-22 21:39:39 +000026
joshualitt3322fa42014-11-07 08:48:51 -080027class GrGpu : public SkRefCnt {
reed@google.comac10a2d2010-12-22 21:39:39 +000028public:
29 /**
bsalomon@google.com16e3dde2012-10-25 18:43:28 +000030 * Create an instance of GrGpu that matches the specified backend. If the requested backend is
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000031 * not supported (at compile-time or run-time) this returns NULL. The context will not be
32 * fully constructed and should not be used by GrGpu until after this function returns.
reed@google.comac10a2d2010-12-22 21:39:39 +000033 */
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000034 static GrGpu* Create(GrBackend, GrBackendContext, GrContext* context);
reed@google.comac10a2d2010-12-22 21:39:39 +000035
36 ////////////////////////////////////////////////////////////////////////////
37
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000038 GrGpu(GrContext* context);
mtklein36352bf2015-03-25 18:17:31 -070039 ~GrGpu() override;
reed@google.comac10a2d2010-12-22 21:39:39 +000040
joshualitt3322fa42014-11-07 08:48:51 -080041 GrContext* getContext() { return fContext; }
42 const GrContext* getContext() const { return fContext; }
43
44 /**
45 * Gets the capabilities of the draw target.
46 */
bsalomon4b91f762015-05-19 09:29:46 -070047 const GrCaps* caps() const { return fCaps.get(); }
joshualitt3322fa42014-11-07 08:48:51 -080048
mtkleinb9eb4ac2015-02-02 18:26:03 -080049 GrPathRendering* pathRendering() { return fPathRendering.get(); }
kkinnunenccdaa042014-08-20 01:36:23 -070050
bsalomonc8dc1f72014-08-21 13:02:13 -070051 // Called by GrContext when the underlying backend context has been destroyed.
52 // GrGpu should use this to ensure that no backend API calls will be made from
53 // here onward, including in its destructor. Subclasses should call
robertphillipse3371302014-09-17 06:01:06 -070054 // INHERITED::contextAbandoned() if they override this.
55 virtual void contextAbandoned();
bsalomonc8dc1f72014-08-21 13:02:13 -070056
reed@google.comac10a2d2010-12-22 21:39:39 +000057 /**
58 * The GrGpu object normally assumes that no outsider is setting state
59 * within the underlying 3D API's context/device/whatever. This call informs
bsalomon@google.coma7f84e12011-03-10 14:13:19 +000060 * the GrGpu that the state was modified and it shouldn't make assumptions
61 * about the state.
reed@google.comac10a2d2010-12-22 21:39:39 +000062 */
mtkleinb9eb4ac2015-02-02 18:26:03 -080063 void markContextDirty(uint32_t state = kAll_GrBackendState) { fResetBits |= state; }
reed@google.comac10a2d2010-12-22 21:39:39 +000064
65 /**
bsalomon6d467ec2014-11-18 07:36:19 -080066 * Creates a texture object. If kRenderTarget_GrSurfaceFlag the texture can
67 * be used as a render target by calling GrTexture::asRenderTarget(). Not all
68 * pixel configs can be used as render targets. Support for configs as textures
bsalomon4b91f762015-05-19 09:29:46 -070069 * or render targets can be checked using GrCaps.
bsalomon@google.com1da07462011-03-10 14:51:57 +000070 *
reed@google.comac10a2d2010-12-22 21:39:39 +000071 * @param desc describes the texture to be created.
bsalomon5236cf42015-01-14 10:42:08 -080072 * @param budgeted does this texture count against the resource cache budget?
reed@google.comac10a2d2010-12-22 21:39:39 +000073 * @param srcData texel data to load texture. Begins with full-size
krajcevski9c0e6292014-06-02 07:38:14 -070074 * palette data for paletted textures. For compressed
75 * formats it contains the compressed pixel data. Otherwise,
76 * it contains width*height texels. If NULL texture data
77 * is uninitialized.
78 * @param rowBytes the number of bytes between consecutive rows. Zero
79 * means rows are tightly packed. This field is ignored
80 * for compressed formats.
reed@google.comac10a2d2010-12-22 21:39:39 +000081 *
82 * @return The texture object if successful, otherwise NULL.
83 */
bsalomon5236cf42015-01-14 10:42:08 -080084 GrTexture* createTexture(const GrSurfaceDesc& desc, bool budgeted,
85 const void* srcData, size_t rowBytes);
reed@google.comac10a2d2010-12-22 21:39:39 +000086
bsalomon@google.come269f212011-11-07 13:29:52 +000087 /**
bsalomon@google.com16e3dde2012-10-25 18:43:28 +000088 * Implements GrContext::wrapBackendTexture
bsalomon@google.come269f212011-11-07 13:29:52 +000089 */
bsalomon@google.com16e3dde2012-10-25 18:43:28 +000090 GrTexture* wrapBackendTexture(const GrBackendTextureDesc&);
bsalomon@google.come269f212011-11-07 13:29:52 +000091
92 /**
bsalomon@google.com16e3dde2012-10-25 18:43:28 +000093 * Implements GrContext::wrapBackendTexture
bsalomon@google.come269f212011-11-07 13:29:52 +000094 */
bsalomon@google.com16e3dde2012-10-25 18:43:28 +000095 GrRenderTarget* wrapBackendRenderTarget(const GrBackendRenderTargetDesc&);
bsalomon@google.come269f212011-11-07 13:29:52 +000096
97 /**
reed@google.comac10a2d2010-12-22 21:39:39 +000098 * Creates a vertex buffer.
99 *
100 * @param size size in bytes of the vertex buffer
101 * @param dynamic hints whether the data will be frequently changed
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +0000102 * by either GrVertexBuffer::map() or
103 * GrVertexBuffer::updateData().
reed@google.comac10a2d2010-12-22 21:39:39 +0000104 *
105 * @return The vertex buffer if successful, otherwise NULL.
106 */
robertphillips@google.comadacc702013-10-14 21:53:24 +0000107 GrVertexBuffer* createVertexBuffer(size_t size, bool dynamic);
reed@google.comac10a2d2010-12-22 21:39:39 +0000108
109 /**
110 * Creates an index buffer.
111 *
112 * @param size size in bytes of the index buffer
113 * @param dynamic hints whether the data will be frequently changed
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +0000114 * by either GrIndexBuffer::map() or
115 * GrIndexBuffer::updateData().
reed@google.comac10a2d2010-12-22 21:39:39 +0000116 *
117 * @return The index buffer if successful, otherwise NULL.
118 */
robertphillips@google.comadacc702013-10-14 21:53:24 +0000119 GrIndexBuffer* createIndexBuffer(size_t size, bool dynamic);
reed@google.comac10a2d2010-12-22 21:39:39 +0000120
121 /**
bsalomon@google.com75f9f252012-01-31 13:35:56 +0000122 * Resolves MSAA.
123 */
124 void resolveRenderTarget(GrRenderTarget* target);
125
126 /**
commit-bot@chromium.org5d1d79a2013-05-24 18:52:52 +0000127 * Gets a preferred 8888 config to use for writing/reading pixel data to/from a surface with
128 * config surfaceConfig. The returned config must have at least as many bits per channel as the
129 * readConfig or writeConfig param.
bsalomon@google.com0a97be22011-11-08 19:20:57 +0000130 */
commit-bot@chromium.org5d1d79a2013-05-24 18:52:52 +0000131 virtual GrPixelConfig preferredReadPixelsConfig(GrPixelConfig readConfig,
132 GrPixelConfig surfaceConfig) const {
133 return readConfig;
134 }
135 virtual GrPixelConfig preferredWritePixelsConfig(GrPixelConfig writeConfig,
136 GrPixelConfig surfaceConfig) const {
137 return writeConfig;
138 }
bsalomon@google.com0a97be22011-11-08 19:20:57 +0000139
140 /**
bsalomon@google.com9c680582013-02-06 18:17:50 +0000141 * Called before uploading writing pixels to a GrTexture when the src pixel config doesn't
142 * match the texture's config.
bsalomon@google.coma85449d2011-11-19 02:36:05 +0000143 */
bsalomon@google.com9c680582013-02-06 18:17:50 +0000144 virtual bool canWriteTexturePixels(const GrTexture*, GrPixelConfig srcConfig) const = 0;
bsalomon@google.coma85449d2011-11-19 02:36:05 +0000145
146 /**
bsalomon@google.comc4364992011-11-07 15:54:49 +0000147 * OpenGL's readPixels returns the result bottom-to-top while the skia
148 * API is top-to-bottom. Thus we have to do a y-axis flip. The obvious
149 * solution is to have the subclass do the flip using either the CPU or GPU.
150 * However, the caller (GrContext) may have transformations to apply and can
151 * simply fold in the y-flip for free. On the other hand, the subclass may
152 * be able to do it for free itself. For example, the subclass may have to
rmistry@google.comd6176b02012-08-23 18:14:13 +0000153 * do memcpys to handle rowBytes that aren't tight. It could do the y-flip
bsalomon@google.comc4364992011-11-07 15:54:49 +0000154 * concurrently.
155 *
156 * This function returns true if a y-flip is required to put the pixels in
157 * top-to-bottom order and the subclass cannot do it for free.
158 *
159 * See read pixels for the params
160 * @return true if calling readPixels with the same set of params will
161 * produce bottom-to-top data
162 */
163 virtual bool readPixelsWillPayForYFlip(GrRenderTarget* renderTarget,
164 int left, int top,
165 int width, int height,
166 GrPixelConfig config,
bsalomon@google.com56d11e02011-11-30 19:59:08 +0000167 size_t rowBytes) const = 0;
168 /**
169 * This should return true if reading a NxM rectangle of pixels from a
170 * render target is faster if the target has dimensons N and M and the read
171 * rectangle has its top-left at 0,0.
172 */
173 virtual bool fullReadPixelsIsFasterThanPartial() const { return false; };
bsalomon@google.comc4364992011-11-07 15:54:49 +0000174
175 /**
bsalomon@google.coma04e8e82012-08-27 12:53:13 +0000176 * Reads a rectangle of pixels from a render target.
bsalomon@google.comc4364992011-11-07 15:54:49 +0000177 *
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000178 * @param renderTarget the render target to read from. NULL means the
179 * current render target.
180 * @param left left edge of the rectangle to read (inclusive)
181 * @param top top edge of the rectangle to read (inclusive)
182 * @param width width of rectangle to read in pixels.
183 * @param height height of rectangle to read in pixels.
184 * @param config the pixel config of the destination buffer
185 * @param buffer memory to read the rectangle into.
bsalomon@google.comc6980972011-11-02 19:57:21 +0000186 * @param rowBytes the number of bytes between consecutive rows. Zero
187 * means rows are tightly packed.
bsalomon@google.comc4364992011-11-07 15:54:49 +0000188 * @param invertY buffer should be populated bottom-to-top as opposed
189 * to top-to-bottom (skia's usual order)
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000190 *
191 * @return true if the read succeeded, false if not. The read can fail
192 * because of a unsupported pixel config or because no render
193 * target is currently set.
194 */
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000195 bool readPixels(GrRenderTarget* renderTarget,
196 int left, int top, int width, int height,
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +0000197 GrPixelConfig config, void* buffer, size_t rowBytes);
reed@google.comac10a2d2010-12-22 21:39:39 +0000198
bsalomon@google.com6f379512011-11-16 20:36:03 +0000199 /**
200 * Updates the pixels in a rectangle of a texture.
bsalomon@google.coma85449d2011-11-19 02:36:05 +0000201 *
bsalomon@google.com6f379512011-11-16 20:36:03 +0000202 * @param left left edge of the rectangle to write (inclusive)
203 * @param top top edge of the rectangle to write (inclusive)
204 * @param width width of rectangle to write in pixels.
205 * @param height height of rectangle to write in pixels.
206 * @param config the pixel config of the source buffer
207 * @param buffer memory to read pixels from
bsalomon@google.com16e3dde2012-10-25 18:43:28 +0000208 * @param rowBytes number of bytes between consecutive rows. Zero
bsalomon@google.com6f379512011-11-16 20:36:03 +0000209 * means rows are tightly packed.
210 */
bsalomon@google.com9c680582013-02-06 18:17:50 +0000211 bool writeTexturePixels(GrTexture* texture,
bsalomon@google.com6f379512011-11-16 20:36:03 +0000212 int left, int top, int width, int height,
213 GrPixelConfig config, const void* buffer,
214 size_t rowBytes);
215
joshualitt3322fa42014-11-07 08:48:51 -0800216 /**
217 * Clear the passed in render target. Ignores the draw state and clip. Clears the whole thing if
218 * rect is NULL, otherwise just the rect. If canIgnoreRect is set then the entire render target
219 * can be optionally cleared.
220 */
bsalomon6d467ec2014-11-18 07:36:19 -0800221 void clear(const SkIRect* rect, GrColor color, bool canIgnoreRect,GrRenderTarget* renderTarget);
joshualitt3322fa42014-11-07 08:48:51 -0800222
223
bsalomon6d467ec2014-11-18 07:36:19 -0800224 void clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarget* renderTarget);
joshualitt3322fa42014-11-07 08:48:51 -0800225
226 /**
227 * Discards the contents render target. NULL indicates that the current render target should
228 * be discarded.
229 **/
230 virtual void discard(GrRenderTarget* = NULL) = 0;
231
232 /**
233 * This is can be called before allocating a texture to be a dst for copySurface. It will
bsalomonf90a02b2014-11-26 12:28:00 -0800234 * populate the origin, config, and flags fields of the desc such that copySurface can
235 * efficiently succeed. It should only succeed if it can allow copySurface to perform a copy
236 * that would be more effecient than drawing the src to a dst render target.
joshualitt3322fa42014-11-07 08:48:51 -0800237 */
bsalomonf90a02b2014-11-26 12:28:00 -0800238 virtual bool initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) = 0;
joshualitt6db519c2014-10-29 08:48:18 -0700239
bsalomon@google.com80d09b92011-11-05 21:21:13 +0000240 // After the client interacts directly with the 3D context state the GrGpu
241 // must resync its internal state and assumptions about 3D context state.
242 // Each time this occurs the GrGpu bumps a timestamp.
243 // state of the 3D context
244 // At 10 resets / frame and 60fps a 64bit timestamp will overflow in about
245 // a billion years.
246 typedef uint64_t ResetTimestamp;
247
248 // This timestamp is always older than the current timestamp
249 static const ResetTimestamp kExpiredTimestamp = 0;
250 // Returns a timestamp based on the number of times the context was reset.
251 // This timestamp can be used to lazily detect when cached 3D context state
252 // is dirty.
bsalomon6d467ec2014-11-18 07:36:19 -0800253 ResetTimestamp getResetTimestamp() const { return fResetTimestamp; }
bsalomon@google.com80d09b92011-11-05 21:21:13 +0000254
joshualitt873ad0e2015-01-20 09:08:51 -0800255 virtual void buildProgramDesc(GrProgramDesc*,
256 const GrPrimitiveProcessor&,
egdaniel8dd688b2015-01-22 10:16:09 -0800257 const GrPipeline&,
joshualitt873ad0e2015-01-20 09:08:51 -0800258 const GrBatchTracker&) const = 0;
joshualitt79f8fae2014-10-28 17:59:26 -0700259
mtklein404b3b22015-05-18 09:29:10 -0700260 // Called to determine whether a copySurface call would succeed or not. Derived
261 // classes must keep this consistent with their implementation of onCopySurface(). Fallbacks
262 // to issuing a draw from the src to dst take place at the GrDrawTarget level and this function
263 // should only return true if a faster copy path exists. The rect and point are pre-clipped. The
264 // src rect and implied dst rect are guaranteed to be within the src/dst bounds and non-empty.
265 virtual bool canCopySurface(const GrSurface* dst,
266 const GrSurface* src,
267 const SkIRect& srcRect,
268 const SkIPoint& dstPoint) = 0;
269
bsalomonf90a02b2014-11-26 12:28:00 -0800270 // 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.
joshualitt3322fa42014-11-07 08:48:51 -0800274 virtual bool copySurface(GrSurface* dst,
275 GrSurface* src,
276 const SkIRect& srcRect,
277 const SkIPoint& dstPoint) = 0;
278
cdalton9954bc32015-04-29 14:17:00 -0700279 // Called before certain draws in order to guarantee coherent results from dst reads.
cdalton231c5fd2015-05-13 12:35:36 -0700280 virtual void xferBarrier(GrRenderTarget*, GrXferBarrierType) = 0;
cdalton9954bc32015-04-29 14:17:00 -0700281
joshualitt873ad0e2015-01-20 09:08:51 -0800282 struct DrawArgs {
joshualitt873ad0e2015-01-20 09:08:51 -0800283 DrawArgs(const GrPrimitiveProcessor* primProc,
egdaniel8dd688b2015-01-22 10:16:09 -0800284 const GrPipeline* pipeline,
joshualitt873ad0e2015-01-20 09:08:51 -0800285 const GrProgramDesc* desc,
joshualitt17e73142015-01-21 11:52:36 -0800286 const GrBatchTracker* batchTracker)
joshualitt873ad0e2015-01-20 09:08:51 -0800287 : fPrimitiveProcessor(primProc)
egdaniel8dd688b2015-01-22 10:16:09 -0800288 , fPipeline(pipeline)
joshualitt873ad0e2015-01-20 09:08:51 -0800289 , fDesc(desc)
joshualitt17e73142015-01-21 11:52:36 -0800290 , fBatchTracker(batchTracker) {
egdaniel8dd688b2015-01-22 10:16:09 -0800291 SkASSERT(primProc && pipeline && desc && batchTracker);
joshualitt873ad0e2015-01-20 09:08:51 -0800292 }
293 const GrPrimitiveProcessor* fPrimitiveProcessor;
egdaniel8dd688b2015-01-22 10:16:09 -0800294 const GrPipeline* fPipeline;
joshualitt873ad0e2015-01-20 09:08:51 -0800295 const GrProgramDesc* fDesc;
296 const GrBatchTracker* fBatchTracker;
297 };
298
bsalomoncb8979d2015-05-05 09:51:38 -0700299 void draw(const DrawArgs&, const GrVertices&);
bsalomon3e791242014-12-17 13:43:13 -0800300
301 /** None of these params are optional, pointers used just to avoid making copies. */
302 struct StencilPathState {
303 bool fUseHWAA;
304 GrRenderTarget* fRenderTarget;
305 const SkMatrix* fViewMatrix;
306 const GrStencilSettings* fStencil;
307 const GrScissorState* fScissor;
308 };
309
310 void stencilPath(const GrPath*, const StencilPathState&);
311
joshualitt873ad0e2015-01-20 09:08:51 -0800312 void drawPath(const DrawArgs&, const GrPath*, const GrStencilSettings&);
313 void drawPaths(const DrawArgs&,
bsalomon830d2062014-12-15 13:12:08 -0800314 const GrPathRange*,
315 const void* indices,
316 GrDrawTarget::PathIndexType,
317 const float transformValues[],
318 GrDrawTarget::PathTransformType,
319 int count,
320 const GrStencilSettings&);
joshualitt4b68ec02014-11-07 14:11:45 -0800321
mtkleinb9eb4ac2015-02-02 18:26:03 -0800322 ///////////////////////////////////////////////////////////////////////////
323 // Debugging and Stats
324
325 class Stats {
326 public:
327#if GR_GPU_STATS
328 Stats() { this->reset(); }
329
bsalomonb12ea412015-02-02 21:19:50 -0800330 void reset() {
331 fRenderTargetBinds = 0;
332 fShaderCompilations = 0;
333 fTextureCreates = 0;
334 fTextureUploads = 0;
egdaniel8dc7c3a2015-04-16 11:22:42 -0700335 fStencilAttachmentCreates = 0;
bsalomonb12ea412015-02-02 21:19:50 -0800336 }
mtkleinb9eb4ac2015-02-02 18:26:03 -0800337
338 int renderTargetBinds() const { return fRenderTargetBinds; }
339 void incRenderTargetBinds() { fRenderTargetBinds++; }
340 int shaderCompilations() const { return fShaderCompilations; }
341 void incShaderCompilations() { fShaderCompilations++; }
bsalomonb12ea412015-02-02 21:19:50 -0800342 int textureCreates() const { return fTextureCreates; }
343 void incTextureCreates() { fTextureCreates++; }
344 int textureUploads() const { return fTextureUploads; }
345 void incTextureUploads() { fTextureUploads++; }
egdaniel8dc7c3a2015-04-16 11:22:42 -0700346 void incStencilAttachmentCreates() { fStencilAttachmentCreates++; }
mtkleinb9eb4ac2015-02-02 18:26:03 -0800347 void dump(SkString*);
348
349 private:
350 int fRenderTargetBinds;
351 int fShaderCompilations;
bsalomonb12ea412015-02-02 21:19:50 -0800352 int fTextureCreates;
353 int fTextureUploads;
egdaniel8dc7c3a2015-04-16 11:22:42 -0700354 int fStencilAttachmentCreates;
mtkleinb9eb4ac2015-02-02 18:26:03 -0800355#else
356 void dump(SkString*) {};
357 void incRenderTargetBinds() {}
358 void incShaderCompilations() {}
bsalomonb12ea412015-02-02 21:19:50 -0800359 void incTextureCreates() {}
360 void incTextureUploads() {}
egdaniel8dc7c3a2015-04-16 11:22:42 -0700361 void incStencilAttachmentCreates() {}
mtkleinb9eb4ac2015-02-02 18:26:03 -0800362#endif
363 };
364
365 Stats* stats() { return &fStats; }
366
367 /**
368 * Called at start and end of gpu trace marking
369 * GR_CREATE_GPU_TRACE_MARKER(marker_str, target) will automatically call these at the start
370 * and end of a code block respectively
371 */
372 void addGpuTraceMarker(const GrGpuTraceMarker* marker);
373 void removeGpuTraceMarker(const GrGpuTraceMarker* marker);
374
375 /**
376 * Takes the current active set of markers and stores them for later use. Any current marker
377 * in the active set is removed from the active set and the targets remove function is called.
378 * These functions do not work as a stack so you cannot call save a second time before calling
379 * restore. Also, it is assumed that when restore is called the current active set of markers
380 * is empty. When the stored markers are added back into the active set, the targets add marker
381 * is called.
382 */
383 void saveActiveTraceMarkers();
384 void restoreActiveTraceMarkers();
385
bsalomon6bc1b5f2015-02-23 09:06:38 -0800386 // Given a rt, find or create a stencil buffer and attach it
egdaniel8dc7c3a2015-04-16 11:22:42 -0700387 bool attachStencilAttachmentToRenderTarget(GrRenderTarget* target);
bsalomon6bc1b5f2015-02-23 09:06:38 -0800388
joshualittd53a8272014-11-10 16:03:14 -0800389protected:
bsalomon@google.comd302f142011-03-03 13:54:13 +0000390 // Functions used to map clip-respecting stencil tests into normal
391 // stencil funcs supported by GPUs.
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000392 static GrStencilFunc ConvertStencilFunc(bool stencilInClip,
bsalomon@google.comd302f142011-03-03 13:54:13 +0000393 GrStencilFunc func);
394 static void ConvertStencilFuncAndMask(GrStencilFunc func,
395 bool clipInStencil,
396 unsigned int clipBit,
397 unsigned int userBits,
398 unsigned int* ref,
399 unsigned int* mask);
400
mtkleinb9eb4ac2015-02-02 18:26:03 -0800401 const GrTraceMarkerSet& getActiveTraceMarkers() const { return fActiveTraceMarkers; }
joshualitt3322fa42014-11-07 08:48:51 -0800402
mtkleinb9eb4ac2015-02-02 18:26:03 -0800403 Stats fStats;
404 SkAutoTDelete<GrPathRendering> fPathRendering;
joshualitt3322fa42014-11-07 08:48:51 -0800405 // Subclass must initialize this in its constructor.
bsalomon4b91f762015-05-19 09:29:46 -0700406 SkAutoTUnref<const GrCaps> fCaps;
joshualitt3322fa42014-11-07 08:48:51 -0800407
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000408private:
bsalomon@google.comb635d392011-11-05 12:47:43 +0000409 // called when the 3D context state is unknown. Subclass should emit any
bsalomon@google.comc8f7f472012-06-18 13:44:51 +0000410 // assumed 3D context state and dirty any state cache.
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000411 virtual void onResetContext(uint32_t resetBits) = 0;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000412
bsalomon@google.com16e3dde2012-10-25 18:43:28 +0000413 // overridden by backend-specific derived class to create objects.
egdanielb0e1be22015-04-22 13:27:39 -0700414 // Texture size and sample size will have already been validated in base class before
415 // onCreateTexture/CompressedTexture are called.
416 virtual GrTexture* onCreateTexture(const GrSurfaceDesc& desc,
417 GrGpuResource::LifeCycle lifeCycle,
bsalomon5236cf42015-01-14 10:42:08 -0800418 const void* srcData, size_t rowBytes) = 0;
egdanielb0e1be22015-04-22 13:27:39 -0700419 virtual GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc,
420 GrGpuResource::LifeCycle lifeCycle,
krajcevski9c0e6292014-06-02 07:38:14 -0700421 const void* srcData) = 0;
bsalomon@google.com16e3dde2012-10-25 18:43:28 +0000422 virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&) = 0;
423 virtual GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) = 0;
robertphillips@google.comadacc702013-10-14 21:53:24 +0000424 virtual GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) = 0;
425 virtual GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) = 0;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000426
bsalomon63b21962014-11-05 07:05:34 -0800427 // overridden by backend-specific derived class to perform the clear.
joshualitt4b68ec02014-11-07 14:11:45 -0800428 virtual void onClear(GrRenderTarget*, const SkIRect* rect, GrColor color,
429 bool canIgnoreRect) = 0;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000430
joshualitt6db519c2014-10-29 08:48:18 -0700431
432 // Overridden by backend specific classes to perform a clear of the stencil clip bits. This is
433 // ONLY used by the the clip target
mtkleinb9eb4ac2015-02-02 18:26:03 -0800434 virtual void onClearStencilClip(GrRenderTarget*, const SkIRect& rect, bool insideClip) = 0;
joshualitt6db519c2014-10-29 08:48:18 -0700435
bsalomon@google.com16e3dde2012-10-25 18:43:28 +0000436 // overridden by backend-specific derived class to perform the draw call.
bsalomone64eb572015-05-07 11:35:55 -0700437 virtual void onDraw(const DrawArgs&, const GrNonInstancedVertices&) = 0;
bsalomon3e791242014-12-17 13:43:13 -0800438 virtual void onStencilPath(const GrPath*, const StencilPathState&) = 0;
439
joshualitt873ad0e2015-01-20 09:08:51 -0800440 virtual void onDrawPath(const DrawArgs&, const GrPath*, const GrStencilSettings&) = 0;
441 virtual void onDrawPaths(const DrawArgs&,
bsalomond95263c2014-12-16 13:05:12 -0800442 const GrPathRange*,
443 const void* indices,
444 GrDrawTarget::PathIndexType,
445 const float transformValues[],
446 GrDrawTarget::PathTransformType,
447 int count,
448 const GrStencilSettings&) = 0;
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000449
bsalomon@google.com16e3dde2012-10-25 18:43:28 +0000450 // overridden by backend-specific derived class to perform the read pixels.
bsalomon@google.com5877ffd2011-04-11 17:58:48 +0000451 virtual bool onReadPixels(GrRenderTarget* target,
452 int left, int top, int width, int height,
bsalomon@google.comc4364992011-11-07 15:54:49 +0000453 GrPixelConfig,
454 void* buffer,
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +0000455 size_t rowBytes) = 0;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000456
bsalomon@google.com16e3dde2012-10-25 18:43:28 +0000457 // overridden by backend-specific derived class to perform the texture update
bsalomon@google.com9c680582013-02-06 18:17:50 +0000458 virtual bool onWriteTexturePixels(GrTexture* texture,
bsalomon@google.com6f379512011-11-16 20:36:03 +0000459 int left, int top, int width, int height,
460 GrPixelConfig config, const void* buffer,
461 size_t rowBytes) = 0;
462
bsalomon@google.com16e3dde2012-10-25 18:43:28 +0000463 // overridden by backend-specific derived class to perform the resolve
bsalomon@google.com75f9f252012-01-31 13:35:56 +0000464 virtual void onResolveRenderTarget(GrRenderTarget* target) = 0;
465
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000466 // width and height may be larger than rt (if underlying API allows it).
467 // Should attach the SB to the RT. Returns false if compatible sb could
468 // not be created.
egdaniel8dc7c3a2015-04-16 11:22:42 -0700469 virtual bool createStencilAttachmentForRenderTarget(GrRenderTarget*, int width, int height) = 0;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000470
471 // attaches an existing SB to an existing RT.
egdaniel8dc7c3a2015-04-16 11:22:42 -0700472 virtual bool attachStencilAttachmentToRenderTarget(GrStencilAttachment*, GrRenderTarget*) = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000473
bsalomonb0bd4f62014-09-03 07:19:50 -0700474 // clears target's entire stencil buffer to 0
475 virtual void clearStencil(GrRenderTarget* target) = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000476
joshualitt3322fa42014-11-07 08:48:51 -0800477 virtual void didAddGpuTraceMarker() = 0;
478 virtual void didRemoveGpuTraceMarker() = 0;
479
bsalomon@google.comb635d392011-11-05 12:47:43 +0000480 void resetContext() {
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000481 this->onResetContext(fResetBits);
482 fResetBits = 0;
bsalomon@google.comb635d392011-11-05 12:47:43 +0000483 ++fResetTimestamp;
484 }
485
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000486 void handleDirtyContext() {
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000487 if (fResetBits) {
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000488 this->resetContext();
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000489 }
490 }
491
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000492 ResetTimestamp fResetTimestamp;
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000493 uint32_t fResetBits;
joshualitt3322fa42014-11-07 08:48:51 -0800494 // To keep track that we always have at least as many debug marker adds as removes
495 int fGpuTraceMarkerCount;
496 GrTraceMarkerSet fActiveTraceMarkers;
497 GrTraceMarkerSet fStoredTraceMarkers;
498 // The context owns us, not vice-versa, so this ptr is not ref'ed by Gpu.
499 GrContext* fContext;
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000500
joshualitt3322fa42014-11-07 08:48:51 -0800501 typedef SkRefCnt INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +0000502};
503
504#endif