blob: 0ce6bea4e63ea813db3ae41c7e2d0054d92e19c1 [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
kkinnunencabe20c2015-06-01 01:37:26 -070011#include "GrPipelineBuilder.h"
joshualitt79f8fae2014-10-28 17:59:26 -070012#include "GrProgramDesc.h"
kkinnunencabe20c2015-06-01 01:37:26 -070013#include "GrStencil.h"
14#include "GrTraceMarker.h"
15#include "GrXferProcessor.h"
sugoi@google.com12b4e272012-12-06 20:13:11 +000016#include "SkPath.h"
17
kkinnunencabe20c2015-06-01 01:37:26 -070018class GrBatchTracker;
bsalomon@google.com669fdc42011-04-05 17:08:27 +000019class GrContext;
reedf9ad5582015-06-25 21:29:25 -070020class GrGLContext;
kkinnunencabe20c2015-06-01 01:37:26 -070021class GrIndexBuffer;
bsalomone64eb572015-05-07 11:35:55 -070022class GrNonInstancedVertices;
bsalomon@google.com64aef2b2012-06-11 15:36:13 +000023class GrPath;
cdaltonb85a0aa2014-07-21 15:32:44 -070024class GrPathRange;
bsalomon@google.com30085192011-08-19 15:42:31 +000025class GrPathRenderer;
26class GrPathRendererChain;
kkinnunencabe20c2015-06-01 01:37:26 -070027class GrPathRendering;
egdaniel8dd688b2015-01-22 10:16:09 -080028class GrPipeline;
joshualitt873ad0e2015-01-20 09:08:51 -080029class GrPrimitiveProcessor;
kkinnunencabe20c2015-06-01 01:37:26 -070030class GrRenderTarget;
egdaniel8dc7c3a2015-04-16 11:22:42 -070031class GrStencilAttachment;
kkinnunencabe20c2015-06-01 01:37:26 -070032class GrSurface;
33class GrTexture;
34class GrVertexBuffer;
bsalomoncb8979d2015-05-05 09:51:38 -070035class GrVertices;
reed@google.comac10a2d2010-12-22 21:39:39 +000036
joshualitt3322fa42014-11-07 08:48:51 -080037class GrGpu : public SkRefCnt {
reed@google.comac10a2d2010-12-22 21:39:39 +000038public:
39 /**
bsalomon@google.com16e3dde2012-10-25 18:43:28 +000040 * Create an instance of GrGpu that matches the specified backend. If the requested backend is
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000041 * 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.comac10a2d2010-12-22 21:39:39 +000043 */
bsalomon682c2692015-05-22 14:01:46 -070044 static GrGpu* Create(GrBackend, GrBackendContext, const GrContextOptions&, GrContext* context);
reed@google.comac10a2d2010-12-22 21:39:39 +000045
46 ////////////////////////////////////////////////////////////////////////////
47
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000048 GrGpu(GrContext* context);
mtklein36352bf2015-03-25 18:17:31 -070049 ~GrGpu() override;
reed@google.comac10a2d2010-12-22 21:39:39 +000050
joshualitt3322fa42014-11-07 08:48:51 -080051 GrContext* getContext() { return fContext; }
52 const GrContext* getContext() const { return fContext; }
53
54 /**
55 * Gets the capabilities of the draw target.
56 */
bsalomon4b91f762015-05-19 09:29:46 -070057 const GrCaps* caps() const { return fCaps.get(); }
joshualitt3322fa42014-11-07 08:48:51 -080058
kkinnunencabe20c2015-06-01 01:37:26 -070059 GrPathRendering* pathRendering() { return fPathRendering.get(); }
kkinnunenccdaa042014-08-20 01:36:23 -070060
bsalomonc8dc1f72014-08-21 13:02:13 -070061 // 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
robertphillipse3371302014-09-17 06:01:06 -070064 // INHERITED::contextAbandoned() if they override this.
65 virtual void contextAbandoned();
bsalomonc8dc1f72014-08-21 13:02:13 -070066
reed@google.comac10a2d2010-12-22 21:39:39 +000067 /**
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.coma7f84e12011-03-10 14:13:19 +000070 * the GrGpu that the state was modified and it shouldn't make assumptions
71 * about the state.
reed@google.comac10a2d2010-12-22 21:39:39 +000072 */
mtkleinb9eb4ac2015-02-02 18:26:03 -080073 void markContextDirty(uint32_t state = kAll_GrBackendState) { fResetBits |= state; }
reed@google.comac10a2d2010-12-22 21:39:39 +000074
75 /**
bsalomon6d467ec2014-11-18 07:36:19 -080076 * 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
bsalomon4b91f762015-05-19 09:29:46 -070079 * or render targets can be checked using GrCaps.
bsalomon@google.com1da07462011-03-10 14:51:57 +000080 *
reed@google.comac10a2d2010-12-22 21:39:39 +000081 * @param desc describes the texture to be created.
bsalomon5236cf42015-01-14 10:42:08 -080082 * @param budgeted does this texture count against the resource cache budget?
reed@google.comac10a2d2010-12-22 21:39:39 +000083 * @param srcData texel data to load texture. Begins with full-size
krajcevski9c0e6292014-06-02 07:38:14 -070084 * 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.comac10a2d2010-12-22 21:39:39 +000091 *
92 * @return The texture object if successful, otherwise NULL.
93 */
bsalomon5236cf42015-01-14 10:42:08 -080094 GrTexture* createTexture(const GrSurfaceDesc& desc, bool budgeted,
95 const void* srcData, size_t rowBytes);
reed@google.comac10a2d2010-12-22 21:39:39 +000096
bsalomon@google.come269f212011-11-07 13:29:52 +000097 /**
bsalomon@google.com16e3dde2012-10-25 18:43:28 +000098 * Implements GrContext::wrapBackendTexture
bsalomon@google.come269f212011-11-07 13:29:52 +000099 */
bsalomon6dc6f5f2015-06-18 09:12:16 -0700100 GrTexture* wrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership);
bsalomon@google.come269f212011-11-07 13:29:52 +0000101
102 /**
bsalomon@google.com16e3dde2012-10-25 18:43:28 +0000103 * Implements GrContext::wrapBackendTexture
bsalomon@google.come269f212011-11-07 13:29:52 +0000104 */
bsalomon6dc6f5f2015-06-18 09:12:16 -0700105 GrRenderTarget* wrapBackendRenderTarget(const GrBackendRenderTargetDesc&, GrWrapOwnership);
bsalomon@google.come269f212011-11-07 13:29:52 +0000106
107 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000108 * 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.org8341eb72014-05-07 20:51:05 +0000112 * by either GrVertexBuffer::map() or
113 * GrVertexBuffer::updateData().
reed@google.comac10a2d2010-12-22 21:39:39 +0000114 *
115 * @return The vertex buffer if successful, otherwise NULL.
116 */
robertphillips@google.comadacc702013-10-14 21:53:24 +0000117 GrVertexBuffer* createVertexBuffer(size_t size, bool dynamic);
reed@google.comac10a2d2010-12-22 21:39:39 +0000118
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.org8341eb72014-05-07 20:51:05 +0000124 * by either GrIndexBuffer::map() or
125 * GrIndexBuffer::updateData().
reed@google.comac10a2d2010-12-22 21:39:39 +0000126 *
127 * @return The index buffer if successful, otherwise NULL.
128 */
robertphillips@google.comadacc702013-10-14 21:53:24 +0000129 GrIndexBuffer* createIndexBuffer(size_t size, bool dynamic);
reed@google.comac10a2d2010-12-22 21:39:39 +0000130
131 /**
bsalomon@google.com75f9f252012-01-31 13:35:56 +0000132 * Resolves MSAA.
133 */
134 void resolveRenderTarget(GrRenderTarget* target);
135
136 /**
commit-bot@chromium.org5d1d79a2013-05-24 18:52:52 +0000137 * 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.com0a97be22011-11-08 19:20:57 +0000140 */
commit-bot@chromium.org5d1d79a2013-05-24 18:52:52 +0000141 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.com0a97be22011-11-08 19:20:57 +0000149
150 /**
bsalomon47c1ccb2015-06-24 15:04:13 -0700151 * Called before uploading writing pixels to a GrTexture when the src pixel config doesn't
152 * match the texture's config.
bsalomon@google.coma85449d2011-11-19 02:36:05 +0000153 */
bsalomon@google.com9c680582013-02-06 18:17:50 +0000154 virtual bool canWriteTexturePixels(const GrTexture*, GrPixelConfig srcConfig) const = 0;
bsalomon@google.coma85449d2011-11-19 02:36:05 +0000155
156 /**
bsalomon@google.comc4364992011-11-07 15:54:49 +0000157 * 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.comd6176b02012-08-23 18:14:13 +0000163 * do memcpys to handle rowBytes that aren't tight. It could do the y-flip
bsalomon@google.comc4364992011-11-07 15:54:49 +0000164 * 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.com56d11e02011-11-30 19:59:08 +0000177 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.comc4364992011-11-07 15:54:49 +0000184
185 /**
bsalomon@google.coma04e8e82012-08-27 12:53:13 +0000186 * Reads a rectangle of pixels from a render target.
bsalomon@google.comc4364992011-11-07 15:54:49 +0000187 *
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000188 * @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.comc6980972011-11-02 19:57:21 +0000196 * @param rowBytes the number of bytes between consecutive rows. Zero
197 * means rows are tightly packed.
bsalomon@google.comc4364992011-11-07 15:54:49 +0000198 * @param invertY buffer should be populated bottom-to-top as opposed
199 * to top-to-bottom (skia's usual order)
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000200 *
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.com669fdc42011-04-05 17:08:27 +0000205 bool readPixels(GrRenderTarget* renderTarget,
206 int left, int top, int width, int height,
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +0000207 GrPixelConfig config, void* buffer, size_t rowBytes);
reed@google.comac10a2d2010-12-22 21:39:39 +0000208
bsalomon@google.com6f379512011-11-16 20:36:03 +0000209 /**
210 * Updates the pixels in a rectangle of a texture.
bsalomon@google.coma85449d2011-11-19 02:36:05 +0000211 *
bsalomon@google.com6f379512011-11-16 20:36:03 +0000212 * @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.com16e3dde2012-10-25 18:43:28 +0000218 * @param rowBytes number of bytes between consecutive rows. Zero
bsalomon@google.com6f379512011-11-16 20:36:03 +0000219 * means rows are tightly packed.
220 */
bsalomon@google.com9c680582013-02-06 18:17:50 +0000221 bool writeTexturePixels(GrTexture* texture,
bsalomon@google.com6f379512011-11-16 20:36:03 +0000222 int left, int top, int width, int height,
223 GrPixelConfig config, const void* buffer,
224 size_t rowBytes);
225
joshualitt3322fa42014-11-07 08:48:51 -0800226 /**
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 */
bsalomon6d467ec2014-11-18 07:36:19 -0800231 void clear(const SkIRect* rect, GrColor color, bool canIgnoreRect,GrRenderTarget* renderTarget);
joshualitt3322fa42014-11-07 08:48:51 -0800232
233
bsalomon6d467ec2014-11-18 07:36:19 -0800234 void clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarget* renderTarget);
joshualitt3322fa42014-11-07 08:48:51 -0800235
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
bsalomonf90a02b2014-11-26 12:28:00 -0800244 * 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.
joshualitt3322fa42014-11-07 08:48:51 -0800247 */
bsalomonf90a02b2014-11-26 12:28:00 -0800248 virtual bool initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) = 0;
joshualitt6db519c2014-10-29 08:48:18 -0700249
bsalomon@google.com80d09b92011-11-05 21:21:13 +0000250 // 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.
bsalomon6d467ec2014-11-18 07:36:19 -0800263 ResetTimestamp getResetTimestamp() const { return fResetTimestamp; }
bsalomon@google.com80d09b92011-11-05 21:21:13 +0000264
joshualitt873ad0e2015-01-20 09:08:51 -0800265 virtual void buildProgramDesc(GrProgramDesc*,
266 const GrPrimitiveProcessor&,
egdaniel8dd688b2015-01-22 10:16:09 -0800267 const GrPipeline&,
joshualitt873ad0e2015-01-20 09:08:51 -0800268 const GrBatchTracker&) const = 0;
joshualitt79f8fae2014-10-28 17:59:26 -0700269
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
mtkleinb9eb4ac2015-02-02 18:26:03 -0800301 ///////////////////////////////////////////////////////////////////////////
302 // Debugging and Stats
303
304 class Stats {
305 public:
306#if GR_GPU_STATS
307 Stats() { this->reset(); }
308
bsalomonb12ea412015-02-02 21:19:50 -0800309 void reset() {
310 fRenderTargetBinds = 0;
311 fShaderCompilations = 0;
312 fTextureCreates = 0;
313 fTextureUploads = 0;
egdaniel8dc7c3a2015-04-16 11:22:42 -0700314 fStencilAttachmentCreates = 0;
bsalomonb12ea412015-02-02 21:19:50 -0800315 }
mtkleinb9eb4ac2015-02-02 18:26:03 -0800316
317 int renderTargetBinds() const { return fRenderTargetBinds; }
318 void incRenderTargetBinds() { fRenderTargetBinds++; }
319 int shaderCompilations() const { return fShaderCompilations; }
320 void incShaderCompilations() { fShaderCompilations++; }
bsalomonb12ea412015-02-02 21:19:50 -0800321 int textureCreates() const { return fTextureCreates; }
322 void incTextureCreates() { fTextureCreates++; }
323 int textureUploads() const { return fTextureUploads; }
324 void incTextureUploads() { fTextureUploads++; }
egdaniel8dc7c3a2015-04-16 11:22:42 -0700325 void incStencilAttachmentCreates() { fStencilAttachmentCreates++; }
mtkleinb9eb4ac2015-02-02 18:26:03 -0800326 void dump(SkString*);
327
328 private:
329 int fRenderTargetBinds;
330 int fShaderCompilations;
bsalomonb12ea412015-02-02 21:19:50 -0800331 int fTextureCreates;
332 int fTextureUploads;
egdaniel8dc7c3a2015-04-16 11:22:42 -0700333 int fStencilAttachmentCreates;
mtkleinb9eb4ac2015-02-02 18:26:03 -0800334#else
335 void dump(SkString*) {};
336 void incRenderTargetBinds() {}
337 void incShaderCompilations() {}
bsalomonb12ea412015-02-02 21:19:50 -0800338 void incTextureCreates() {}
339 void incTextureUploads() {}
egdaniel8dc7c3a2015-04-16 11:22:42 -0700340 void incStencilAttachmentCreates() {}
mtkleinb9eb4ac2015-02-02 18:26:03 -0800341#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
jvanverth672bb7f2015-07-13 07:19:57 -0700365 // creation and deletion of raw texture for testing
366 virtual GrBackendObject createBackendTexture(void* pixels, int w, int h,
367 GrPixelConfig config) const = 0;
368 virtual bool isBackendTexture(GrBackendObject id) const = 0;
369 virtual void deleteBackendTexture(GrBackendObject id) const = 0;
370
bsalomon6bc1b5f2015-02-23 09:06:38 -0800371 // Given a rt, find or create a stencil buffer and attach it
egdaniel8dc7c3a2015-04-16 11:22:42 -0700372 bool attachStencilAttachmentToRenderTarget(GrRenderTarget* target);
bsalomon6bc1b5f2015-02-23 09:06:38 -0800373
jvanverth672bb7f2015-07-13 07:19:57 -0700374 // This is only to be used in GL-specific tests.
reedf9ad5582015-06-25 21:29:25 -0700375 virtual const GrGLContext* glContextForTesting() const { return NULL; }
bsalomon993a4212015-05-29 11:37:25 -0700376
joshualittd53a8272014-11-10 16:03:14 -0800377protected:
bsalomon@google.comd302f142011-03-03 13:54:13 +0000378 // Functions used to map clip-respecting stencil tests into normal
379 // stencil funcs supported by GPUs.
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000380 static GrStencilFunc ConvertStencilFunc(bool stencilInClip,
bsalomon@google.comd302f142011-03-03 13:54:13 +0000381 GrStencilFunc func);
382 static void ConvertStencilFuncAndMask(GrStencilFunc func,
383 bool clipInStencil,
384 unsigned int clipBit,
385 unsigned int userBits,
386 unsigned int* ref,
387 unsigned int* mask);
388
mtkleinb9eb4ac2015-02-02 18:26:03 -0800389 const GrTraceMarkerSet& getActiveTraceMarkers() const { return fActiveTraceMarkers; }
joshualitt3322fa42014-11-07 08:48:51 -0800390
mtkleinb9eb4ac2015-02-02 18:26:03 -0800391 Stats fStats;
392 SkAutoTDelete<GrPathRendering> fPathRendering;
joshualitt3322fa42014-11-07 08:48:51 -0800393 // Subclass must initialize this in its constructor.
bsalomon4b91f762015-05-19 09:29:46 -0700394 SkAutoTUnref<const GrCaps> fCaps;
joshualitt3322fa42014-11-07 08:48:51 -0800395
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000396private:
bsalomon@google.comb635d392011-11-05 12:47:43 +0000397 // called when the 3D context state is unknown. Subclass should emit any
bsalomon@google.comc8f7f472012-06-18 13:44:51 +0000398 // assumed 3D context state and dirty any state cache.
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000399 virtual void onResetContext(uint32_t resetBits) = 0;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000400
bsalomon@google.com16e3dde2012-10-25 18:43:28 +0000401 // overridden by backend-specific derived class to create objects.
egdanielb0e1be22015-04-22 13:27:39 -0700402 // Texture size and sample size will have already been validated in base class before
403 // onCreateTexture/CompressedTexture are called.
404 virtual GrTexture* onCreateTexture(const GrSurfaceDesc& desc,
405 GrGpuResource::LifeCycle lifeCycle,
bsalomon5236cf42015-01-14 10:42:08 -0800406 const void* srcData, size_t rowBytes) = 0;
egdanielb0e1be22015-04-22 13:27:39 -0700407 virtual GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc,
408 GrGpuResource::LifeCycle lifeCycle,
krajcevski9c0e6292014-06-02 07:38:14 -0700409 const void* srcData) = 0;
bsalomon6dc6f5f2015-06-18 09:12:16 -0700410 virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) = 0;
411 virtual GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&,
412 GrWrapOwnership) = 0;
robertphillips@google.comadacc702013-10-14 21:53:24 +0000413 virtual GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) = 0;
414 virtual GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) = 0;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000415
bsalomon63b21962014-11-05 07:05:34 -0800416 // overridden by backend-specific derived class to perform the clear.
joshualitt4b68ec02014-11-07 14:11:45 -0800417 virtual void onClear(GrRenderTarget*, const SkIRect* rect, GrColor color,
418 bool canIgnoreRect) = 0;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000419
joshualitt6db519c2014-10-29 08:48:18 -0700420
421 // Overridden by backend specific classes to perform a clear of the stencil clip bits. This is
422 // ONLY used by the the clip target
mtkleinb9eb4ac2015-02-02 18:26:03 -0800423 virtual void onClearStencilClip(GrRenderTarget*, const SkIRect& rect, bool insideClip) = 0;
joshualitt6db519c2014-10-29 08:48:18 -0700424
bsalomon@google.com16e3dde2012-10-25 18:43:28 +0000425 // overridden by backend-specific derived class to perform the draw call.
bsalomone64eb572015-05-07 11:35:55 -0700426 virtual void onDraw(const DrawArgs&, const GrNonInstancedVertices&) = 0;
bsalomon3e791242014-12-17 13:43:13 -0800427
bsalomon@google.com5877ffd2011-04-11 17:58:48 +0000428 virtual bool onReadPixels(GrRenderTarget* target,
429 int left, int top, int width, int height,
bsalomon@google.comc4364992011-11-07 15:54:49 +0000430 GrPixelConfig,
431 void* buffer,
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +0000432 size_t rowBytes) = 0;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000433
bsalomon@google.com16e3dde2012-10-25 18:43:28 +0000434 // overridden by backend-specific derived class to perform the texture update
bsalomon@google.com9c680582013-02-06 18:17:50 +0000435 virtual bool onWriteTexturePixels(GrTexture* texture,
bsalomon@google.com6f379512011-11-16 20:36:03 +0000436 int left, int top, int width, int height,
437 GrPixelConfig config, const void* buffer,
438 size_t rowBytes) = 0;
439
bsalomon@google.com16e3dde2012-10-25 18:43:28 +0000440 // overridden by backend-specific derived class to perform the resolve
bsalomon@google.com75f9f252012-01-31 13:35:56 +0000441 virtual void onResolveRenderTarget(GrRenderTarget* target) = 0;
442
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000443 // width and height may be larger than rt (if underlying API allows it).
444 // Should attach the SB to the RT. Returns false if compatible sb could
445 // not be created.
egdaniel8dc7c3a2015-04-16 11:22:42 -0700446 virtual bool createStencilAttachmentForRenderTarget(GrRenderTarget*, int width, int height) = 0;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000447
448 // attaches an existing SB to an existing RT.
egdaniel8dc7c3a2015-04-16 11:22:42 -0700449 virtual bool attachStencilAttachmentToRenderTarget(GrStencilAttachment*, GrRenderTarget*) = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000450
bsalomonb0bd4f62014-09-03 07:19:50 -0700451 // clears target's entire stencil buffer to 0
452 virtual void clearStencil(GrRenderTarget* target) = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000453
joshualitt3322fa42014-11-07 08:48:51 -0800454 virtual void didAddGpuTraceMarker() = 0;
455 virtual void didRemoveGpuTraceMarker() = 0;
456
bsalomon@google.comb635d392011-11-05 12:47:43 +0000457 void resetContext() {
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000458 this->onResetContext(fResetBits);
459 fResetBits = 0;
bsalomon@google.comb635d392011-11-05 12:47:43 +0000460 ++fResetTimestamp;
461 }
462
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000463 void handleDirtyContext() {
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000464 if (fResetBits) {
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000465 this->resetContext();
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000466 }
467 }
468
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000469 ResetTimestamp fResetTimestamp;
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000470 uint32_t fResetBits;
joshualitt3322fa42014-11-07 08:48:51 -0800471 // To keep track that we always have at least as many debug marker adds as removes
472 int fGpuTraceMarkerCount;
473 GrTraceMarkerSet fActiveTraceMarkers;
474 GrTraceMarkerSet fStoredTraceMarkers;
475 // The context owns us, not vice-versa, so this ptr is not ref'ed by Gpu.
476 GrContext* fContext;
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000477
kkinnunencabe20c2015-06-01 01:37:26 -0700478 friend class GrPathRendering;
joshualitt3322fa42014-11-07 08:48:51 -0800479 typedef SkRefCnt INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +0000480};
481
482#endif