GrGpu.h revision 1d417a8738304c115f3547ecc34dda7a7d75b97a
1/*
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.
6 */
7
8#ifndef GrGpu_DEFINED
9#define GrGpu_DEFINED
10
11#include "GrPipelineBuilder.h"
12#include "GrProgramDesc.h"
13#include "GrStencil.h"
14#include "GrSwizzle.h"
15#include "GrAllocator.h"
16#include "GrTextureParamsAdjuster.h"
17#include "GrTypes.h"
18#include "GrXferProcessor.h"
19#include "SkPath.h"
20#include "SkTArray.h"
21
22class GrBatchTracker;
23class GrContext;
24class GrGLContext;
25class GrIndexBuffer;
26class GrMesh;
27class GrNonInstancedVertices;
28class GrPath;
29class GrPathRange;
30class GrPathRenderer;
31class GrPathRendererChain;
32class GrPathRendering;
33class GrPipeline;
34class GrPrimitiveProcessor;
35class GrRenderTarget;
36class GrStencilAttachment;
37class GrSurface;
38class GrTexture;
39class GrTransferBuffer;
40class GrVertexBuffer;
41
42class GrGpu : public SkRefCnt {
43public:
44    /**
45     * Create an instance of GrGpu that matches the specified backend. If the requested backend is
46     * not supported (at compile-time or run-time) this returns nullptr. The context will not be
47     * fully constructed and should not be used by GrGpu until after this function returns.
48     */
49    static GrGpu* Create(GrBackend, GrBackendContext, const GrContextOptions&, GrContext* context);
50
51    ////////////////////////////////////////////////////////////////////////////
52
53    GrGpu(GrContext* context);
54    ~GrGpu() override;
55
56    GrContext* getContext() { return fContext; }
57    const GrContext* getContext() const { return fContext; }
58
59    /**
60     * Gets the capabilities of the draw target.
61     */
62    const GrCaps* caps() const { return fCaps.get(); }
63
64    GrPathRendering* pathRendering() { return fPathRendering.get();  }
65
66    // Called by GrContext when the underlying backend context has been destroyed.
67    // GrGpu should use this to ensure that no backend API calls will be made from
68    // here onward, including in its destructor. Subclasses should call
69    // INHERITED::contextAbandoned() if they override this.
70    virtual void contextAbandoned();
71
72    /**
73     * The GrGpu object normally assumes that no outsider is setting state
74     * within the underlying 3D API's context/device/whatever. This call informs
75     * the GrGpu that the state was modified and it shouldn't make assumptions
76     * about the state.
77     */
78    void markContextDirty(uint32_t state = kAll_GrBackendState) { fResetBits |= state; }
79
80    /**
81     * Creates a texture object. If kRenderTarget_GrSurfaceFlag the texture can
82     * be used as a render target by calling GrTexture::asRenderTarget(). Not all
83     * pixel configs can be used as render targets. Support for configs as textures
84     * or render targets can be checked using GrCaps.
85     *
86     * @param desc        describes the texture to be created.
87     * @param budgeted    does this texture count against the resource cache budget?
88     * @param texels      array of mipmap levels containing texel data to load.
89     *                    Each level begins with full-size palette data for paletted textures.
90     *                    For compressed formats the level contains the compressed pixel data.
91     *                    Otherwise, it contains width*height texels. If there is only one
92     *                    element and it contains nullptr fPixels, texture data is
93     *                    uninitialized.
94     * @return    The texture object if successful, otherwise nullptr.
95     */
96    GrTexture* createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
97                             const SkTArray<GrMipLevel>& texels);
98
99    /**
100     * Simplified createTexture() interface for when there is no initial texel data to upload.
101     */
102    GrTexture* createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted) {
103        return this->createTexture(desc, budgeted, SkTArray<GrMipLevel>());
104    }
105
106    /** Simplified createTexture() interface for when there is only a base level */
107    GrTexture* createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted, const void* level0Data,
108                             size_t rowBytes) {
109        SkASSERT(level0Data);
110        GrMipLevel level = { level0Data, rowBytes };
111        SkSTArray<1, GrMipLevel> array;
112        array.push_back() = level;
113        return this->createTexture(desc, budgeted, array);
114    }
115
116    /**
117     * Implements GrTextureProvider::wrapBackendTexture
118     */
119    GrTexture* wrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership);
120
121    /**
122     * Implements GrTextureProvider::wrapBackendRenderTarget
123     */
124    GrRenderTarget* wrapBackendRenderTarget(const GrBackendRenderTargetDesc&, GrWrapOwnership);
125
126    /**
127     * Implements GrTextureProvider::wrapBackendTextureAsRenderTarget
128     */
129    GrRenderTarget* wrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&, GrWrapOwnership);
130
131    /**
132     * Creates a vertex buffer.
133     *
134     * @param size    size in bytes of the vertex buffer
135     * @param dynamic hints whether the data will be frequently changed
136     *                by either GrVertexBuffer::map() or
137     *                GrVertexBuffer::updateData().
138     *
139     * @return    The vertex buffer if successful, otherwise nullptr.
140     */
141    GrVertexBuffer* createVertexBuffer(size_t size, bool dynamic);
142
143    /**
144     * Creates an index buffer.
145     *
146     * @param size    size in bytes of the index buffer
147     * @param dynamic hints whether the data will be frequently changed
148     *                by either GrIndexBuffer::map() or
149     *                GrIndexBuffer::updateData().
150     *
151     * @return The index buffer if successful, otherwise nullptr.
152     */
153    GrIndexBuffer* createIndexBuffer(size_t size, bool dynamic);
154
155    /**
156     * Creates a transfer buffer.
157     *
158     * @param size      size in bytes of the index buffer
159     * @param toGpu     true if used to transfer from the cpu to the gpu
160     *                  otherwise to be used to transfer from the gpu to the cpu
161     *
162     * @return The transfer buffer if successful, otherwise nullptr.
163     */
164    GrTransferBuffer* createTransferBuffer(size_t size, TransferType type);
165
166    /**
167     * Resolves MSAA.
168     */
169    void resolveRenderTarget(GrRenderTarget* target);
170
171    /** Info struct returned by getReadPixelsInfo about performing intermediate draws before
172        reading pixels for performance or correctness. */
173    struct ReadPixelTempDrawInfo {
174        /** If the GrGpu is requesting that the caller do a draw to an intermediate surface then
175            this is descriptor for the temp surface. The draw should always be a rect with
176            dst 0,0,w,h. */
177        GrSurfaceDesc   fTempSurfaceDesc;
178        /** Indicates whether there is a performance advantage to using an exact match texture
179            (in terms of width and height) for the intermediate texture instead of approximate. */
180        bool            fUseExactScratch;
181        /** Swizzle to apply during the draw. This is used to compensate for either feature or
182            performance limitations in the underlying 3D API. */
183        GrSwizzle       fSwizzle;
184        /** The config that should be used to read from the temp surface after the draw. This may be
185            different than the original read config in order to compensate for swizzling. The
186            read data will effectively be in the original read config. */
187        GrPixelConfig   fReadConfig;
188    };
189
190    /** Describes why an intermediate draw must/should be performed before readPixels. */
191    enum DrawPreference {
192        /** On input means that the caller would proceed without draw if the GrGpu doesn't request
193            one.
194            On output means that the GrGpu is not requesting a draw. */
195        kNoDraw_DrawPreference,
196        /** Means that the client would prefer a draw for performance of the readback but
197            can satisfy a straight readPixels call on the inputs without an intermediate draw.
198            getReadPixelsInfo will never set the draw preference to this value but may leave
199            it set. */
200        kCallerPrefersDraw_DrawPreference,
201        /** On output means that GrGpu would prefer a draw for performance of the readback but
202            can satisfy a straight readPixels call on the inputs without an intermediate draw. The
203            caller of getReadPixelsInfo should never specify this on intput. */
204        kGpuPrefersDraw_DrawPreference,
205        /** On input means that the caller requires a draw to do a transformation and there is no
206            CPU fallback.
207            On output means that GrGpu can only satisfy the readPixels request if the intermediate
208            draw is performed.
209          */
210        kRequireDraw_DrawPreference
211    };
212
213    /**
214     * Used to negotiate whether and how an intermediate draw should or must be performed before
215     * a readPixels call. If this returns false then GrGpu could not deduce an intermediate draw
216     * that would allow a successful readPixels call. The passed width, height, and rowBytes,
217     * must be non-zero and already reflect clipping to the src bounds.
218     */
219    bool getReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, size_t rowBytes,
220                           GrPixelConfig readConfig, DrawPreference*, ReadPixelTempDrawInfo*);
221
222    /** Info struct returned by getWritePixelsInfo about performing an intermediate draw in order
223        to write pixels to a GrSurface for either performance or correctness reasons. */
224    struct WritePixelTempDrawInfo {
225        /** If the GrGpu is requesting that the caller upload to an intermediate surface and draw
226            that to the dst then this is the descriptor for the intermediate surface. The caller
227            should upload the pixels such that the upper left pixel of the upload rect is at 0,0 in
228            the intermediate surface.*/
229        GrSurfaceDesc   fTempSurfaceDesc;
230        /** Swizzle to apply during the draw. This is used to compensate for either feature or
231            performance limitations in the underlying 3D API. */
232        GrSwizzle       fSwizzle;
233        /** The config that should be specified when uploading the *original* data to the temp
234            surface before the draw. This may be different than the original src data config in
235            order to compensate for swizzling that will occur when drawing. */
236        GrPixelConfig   fWriteConfig;
237    };
238
239    /**
240     * Used to negotiate whether and how an intermediate surface should be used to write pixels to
241     * a GrSurface. If this returns false then GrGpu could not deduce an intermediate draw
242     * that would allow a successful transfer of the src pixels to the dst. The passed width,
243     * height, and rowBytes, must be non-zero and already reflect clipping to the dst bounds.
244     */
245    bool getWritePixelsInfo(GrSurface* dstSurface, int width, int height,
246                            GrPixelConfig srcConfig, DrawPreference*, WritePixelTempDrawInfo*);
247
248    /**
249     * Reads a rectangle of pixels from a render target.
250     *
251     * @param surface       The surface to read from
252     * @param left          left edge of the rectangle to read (inclusive)
253     * @param top           top edge of the rectangle to read (inclusive)
254     * @param width         width of rectangle to read in pixels.
255     * @param height        height of rectangle to read in pixels.
256     * @param config        the pixel config of the destination buffer
257     * @param buffer        memory to read the rectangle into.
258     * @param rowBytes      the number of bytes between consecutive rows. Zero
259     *                      means rows are tightly packed.
260     * @param invertY       buffer should be populated bottom-to-top as opposed
261     *                      to top-to-bottom (skia's usual order)
262     *
263     * @return true if the read succeeded, false if not. The read can fail
264     *              because of a unsupported pixel config or because no render
265     *              target is currently set.
266     */
267    bool readPixels(GrSurface* surface,
268                    int left, int top, int width, int height,
269                    GrPixelConfig config, void* buffer, size_t rowBytes);
270
271    /**
272     * Updates the pixels in a rectangle of a surface.
273     *
274     * @param surface       The surface to write to.
275     * @param left          left edge of the rectangle to write (inclusive)
276     * @param top           top edge of the rectangle to write (inclusive)
277     * @param width         width of rectangle to write in pixels.
278     * @param height        height of rectangle to write in pixels.
279     * @param config        the pixel config of the source buffer
280     * @param texels        array of mipmap levels containing texture data
281     */
282    bool writePixels(GrSurface* surface,
283                     int left, int top, int width, int height,
284                     GrPixelConfig config,
285                     const SkTArray<GrMipLevel>& texels);
286
287    /**
288     * This function is a shim which creates a SkTArray<GrMipLevel> of size 1.
289     * It then calls writePixels with that SkTArray.
290     *
291     * @param buffer   memory to read pixels from.
292     * @param rowBytes number of bytes between consecutive rows. Zero
293     *                 means rows are tightly packed.
294     */
295    bool writePixels(GrSurface* surface,
296                     int left, int top, int width, int height,
297                     GrPixelConfig config, const void* buffer,
298                     size_t rowBytes);
299
300    /**
301     * Updates the pixels in a rectangle of a surface using a GrTransferBuffer
302     *
303     * @param surface       The surface to write to.
304     * @param left          left edge of the rectangle to write (inclusive)
305     * @param top           top edge of the rectangle to write (inclusive)
306     * @param width         width of rectangle to write in pixels.
307     * @param height        height of rectangle to write in pixels.
308     * @param config        the pixel config of the source buffer
309     * @param buffer        GrTransferBuffer to read pixels from
310     * @param offset        offset from the start of the buffer
311     * @param rowBytes      number of bytes between consecutive rows. Zero
312     *                      means rows are tightly packed.
313     */
314    bool transferPixels(GrSurface* surface,
315                        int left, int top, int width, int height,
316                        GrPixelConfig config, GrTransferBuffer* buffer,
317                        size_t offset, size_t rowBytes);
318
319    /**
320     * Clear the passed in render target. Ignores the draw state and clip.
321     */
322    void clear(const SkIRect& rect, GrColor color, GrRenderTarget* renderTarget);
323
324
325    void clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarget* renderTarget);
326
327    /**
328     * Discards the contents render target. nullptr indicates that the current render target should
329     * be discarded.
330     **/
331    virtual void discard(GrRenderTarget* = nullptr) = 0;
332
333    /**
334     * This is can be called before allocating a texture to be a dst for copySurface. It will
335     * populate the origin, config, and flags fields of the desc such that copySurface can
336     * efficiently succeed. It should only succeed if it can allow copySurface to perform a copy
337     * that would be more effecient than drawing the src to a dst render target.
338     */
339    virtual bool initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) const = 0;
340
341    // After the client interacts directly with the 3D context state the GrGpu
342    // must resync its internal state and assumptions about 3D context state.
343    // Each time this occurs the GrGpu bumps a timestamp.
344    // state of the 3D context
345    // At 10 resets / frame and 60fps a 64bit timestamp will overflow in about
346    // a billion years.
347    typedef uint64_t ResetTimestamp;
348
349    // This timestamp is always older than the current timestamp
350    static const ResetTimestamp kExpiredTimestamp = 0;
351    // Returns a timestamp based on the number of times the context was reset.
352    // This timestamp can be used to lazily detect when cached 3D context state
353    // is dirty.
354    ResetTimestamp getResetTimestamp() const { return fResetTimestamp; }
355
356    // Called to perform a surface to surface copy. Fallbacks to issuing a draw from the src to dst
357    // take place at the GrDrawTarget level and this function implement faster copy paths. The rect
358    // and point are pre-clipped. The src rect and implied dst rect are guaranteed to be within the
359    // src/dst bounds and non-empty.
360    bool copySurface(GrSurface* dst,
361                     GrSurface* src,
362                     const SkIRect& srcRect,
363                     const SkIPoint& dstPoint);
364
365    struct MultisampleSpecs {
366        // Nonzero ID that uniquely identifies these multisample specs.
367        uint8_t                            fUniqueID;
368        // The actual number of samples the GPU will run. NOTE: this value can be greater than the
369        // the render target's sample count.
370        int                                fEffectiveSampleCnt;
371        // If sample locations are supported, contains the subpixel locations at which the GPU will
372        // sample. Pixel center is at (.5, .5) and (0, 0) indicates the top left corner.
373        SkAutoTDeleteArray<const SkPoint>  fSampleLocations;
374    };
375
376    // Finds a render target's multisample specs. The stencil settings are only needed to flush the
377    // draw state prior to querying multisample information; they should not have any effect on the
378    // multisample information itself.
379    const MultisampleSpecs& getMultisampleSpecs(GrRenderTarget*, const GrStencilSettings&);
380
381    // We pass in an array of meshCount GrMesh to the draw. The backend should loop over each
382    // GrMesh object and emit a draw for it. Each draw will use the same GrPipeline and
383    // GrPrimitiveProcessor. This may fail if the draw would exceed any resource limits (e.g.
384    // number of vertex attributes is too large).
385    bool draw(const GrPipeline&,
386              const GrPrimitiveProcessor&,
387              const GrMesh*,
388              int meshCount);
389
390    // Called by drawtarget when flushing.
391    // Provides a hook for post-flush actions (e.g. PLS reset and Vulkan command buffer submits).
392    virtual void finishDrawTarget() {}
393
394    ///////////////////////////////////////////////////////////////////////////
395    // Debugging and Stats
396
397    class Stats {
398    public:
399#if GR_GPU_STATS
400        Stats() { this->reset(); }
401
402        void reset() {
403            fRenderTargetBinds = 0;
404            fShaderCompilations = 0;
405            fTextureCreates = 0;
406            fTextureUploads = 0;
407            fTransfersToTexture = 0;
408            fStencilAttachmentCreates = 0;
409            fNumDraws = 0;
410            fNumFailedDraws = 0;
411        }
412
413        int renderTargetBinds() const { return fRenderTargetBinds; }
414        void incRenderTargetBinds() { fRenderTargetBinds++; }
415        int shaderCompilations() const { return fShaderCompilations; }
416        void incShaderCompilations() { fShaderCompilations++; }
417        int textureCreates() const { return fTextureCreates; }
418        void incTextureCreates() { fTextureCreates++; }
419        int textureUploads() const { return fTextureUploads; }
420        void incTextureUploads() { fTextureUploads++; }
421        int transfersToTexture() const { return fTransfersToTexture; }
422        void incTransfersToTexture() { fTransfersToTexture++; }
423        void incStencilAttachmentCreates() { fStencilAttachmentCreates++; }
424        void incNumDraws() { fNumDraws++; }
425        void incNumFailedDraws() { ++fNumFailedDraws; }
426        void dump(SkString*);
427        void dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values);
428        int numDraws() const { return fNumDraws; }
429        int numFailedDraws() const { return fNumFailedDraws; }
430    private:
431        int fRenderTargetBinds;
432        int fShaderCompilations;
433        int fTextureCreates;
434        int fTextureUploads;
435        int fTransfersToTexture;
436        int fStencilAttachmentCreates;
437        int fNumDraws;
438        int fNumFailedDraws;
439#else
440        void dump(SkString*) {}
441        void dumpKeyValuePairs(SkTArray<SkString>*, SkTArray<double>*) {}
442        void incRenderTargetBinds() {}
443        void incShaderCompilations() {}
444        void incTextureCreates() {}
445        void incTextureUploads() {}
446        void incTransfersToTexture() {}
447        void incStencilAttachmentCreates() {}
448        void incNumDraws() {}
449        void incNumFailedDraws() {}
450#endif
451    };
452
453    Stats* stats() { return &fStats; }
454
455    /** Creates a texture directly in the backend API without wrapping it in a GrTexture. This is
456        only to be used for testing (particularly for testing the methods that import an externally
457        created texture into Skia. Must be matched with a call to deleteTestingOnlyTexture(). */
458    virtual GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h,
459                                                            GrPixelConfig config) = 0;
460    /** Check a handle represents an actual texture in the backend API that has not been freed. */
461    virtual bool isTestingOnlyBackendTexture(GrBackendObject) const = 0;
462    /** If ownership of the backend texture has been transferred pass true for abandonTexture. This
463        will do any necessary cleanup of the handle without freeing the texture in the backend
464        API. */
465    virtual void deleteTestingOnlyBackendTexture(GrBackendObject,
466                                                 bool abandonTexture = false) = 0;
467
468    // width and height may be larger than rt (if underlying API allows it).
469    // Returns nullptr if compatible sb could not be created, otherwise the caller owns the ref on
470    // the GrStencilAttachment.
471    virtual GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*,
472                                                                        int width,
473                                                                        int height) = 0;
474    // clears target's entire stencil buffer to 0
475    virtual void clearStencil(GrRenderTarget* target) = 0;
476
477    // draws an outline rectangle for debugging/visualization purposes.
478    virtual void drawDebugWireRect(GrRenderTarget*, const SkIRect&, GrColor) = 0;
479
480    // Determines whether a texture will need to be rescaled in order to be used with the
481    // GrTextureParams. This variation is called when the caller will create a new texture using the
482    // texture provider from a non-texture src (cpu-backed image, ...).
483    bool makeCopyForTextureParams(int width, int height, const GrTextureParams&,
484                                 GrTextureProducer::CopyParams*) const;
485
486    // Like the above but this variation should be called when the caller is not creating the
487    // original texture but rather was handed the original texture. It adds additional checks
488    // relevant to original textures that were created external to Skia via
489    // GrTextureProvider::wrap methods.
490    bool makeCopyForTextureParams(GrTexture* texture, const GrTextureParams& params,
491                                  GrTextureProducer::CopyParams* copyParams) const {
492        if (this->makeCopyForTextureParams(texture->width(), texture->height(), params,
493                                           copyParams)) {
494            return true;
495        }
496        return this->onMakeCopyForTextureParams(texture, params, copyParams);
497    }
498
499    // This is only to be used in GL-specific tests.
500    virtual const GrGLContext* glContextForTesting() const { return nullptr; }
501
502    // This is only to be used by testing code
503    virtual void resetShaderCacheForTesting() const {}
504
505protected:
506    // Functions used to map clip-respecting stencil tests into normal
507    // stencil funcs supported by GPUs.
508    static GrStencilFunc ConvertStencilFunc(bool stencilInClip,
509                                            GrStencilFunc func);
510    static void ConvertStencilFuncAndMask(GrStencilFunc func,
511                                          bool clipInStencil,
512                                          unsigned int clipBit,
513                                          unsigned int userBits,
514                                          unsigned int* ref,
515                                          unsigned int* mask);
516
517    static void ElevateDrawPreference(GrGpu::DrawPreference* preference,
518                                      GrGpu::DrawPreference elevation) {
519        GR_STATIC_ASSERT(GrGpu::kCallerPrefersDraw_DrawPreference > GrGpu::kNoDraw_DrawPreference);
520        GR_STATIC_ASSERT(GrGpu::kGpuPrefersDraw_DrawPreference >
521                         GrGpu::kCallerPrefersDraw_DrawPreference);
522        GR_STATIC_ASSERT(GrGpu::kRequireDraw_DrawPreference >
523                         GrGpu::kGpuPrefersDraw_DrawPreference);
524        *preference = SkTMax(*preference, elevation);
525    }
526
527    void handleDirtyContext() {
528        if (fResetBits) {
529            this->resetContext();
530        }
531    }
532
533    Stats                                   fStats;
534    SkAutoTDelete<GrPathRendering>          fPathRendering;
535    // Subclass must initialize this in its constructor.
536    SkAutoTUnref<const GrCaps>    fCaps;
537
538private:
539    // called when the 3D context state is unknown. Subclass should emit any
540    // assumed 3D context state and dirty any state cache.
541    virtual void onResetContext(uint32_t resetBits) = 0;
542
543    // Called before certain draws in order to guarantee coherent results from dst reads.
544    virtual void xferBarrier(GrRenderTarget*, GrXferBarrierType) = 0;
545
546    // overridden by backend-specific derived class to create objects.
547    // Texture size and sample size will have already been validated in base class before
548    // onCreateTexture/CompressedTexture are called.
549    virtual GrTexture* onCreateTexture(const GrSurfaceDesc& desc,
550                                       GrGpuResource::LifeCycle lifeCycle,
551                                       const SkTArray<GrMipLevel>& texels) = 0;
552    virtual GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc,
553                                                 GrGpuResource::LifeCycle lifeCycle,
554                                                 const SkTArray<GrMipLevel>& texels) = 0;
555
556    virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) = 0;
557    virtual GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&,
558                                                      GrWrapOwnership) = 0;
559    virtual GrRenderTarget* onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&,
560                                                               GrWrapOwnership) = 0;
561    virtual GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) = 0;
562    virtual GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) = 0;
563    virtual GrTransferBuffer* onCreateTransferBuffer(size_t size, TransferType type) = 0;
564
565    // overridden by backend-specific derived class to perform the clear.
566    virtual void onClear(GrRenderTarget*, const SkIRect& rect, GrColor color) = 0;
567
568    // Overridden by backend specific classes to perform a clear of the stencil clip bits.  This is
569    // ONLY used by the the clip target
570    virtual void onClearStencilClip(GrRenderTarget*, const SkIRect& rect, bool insideClip) = 0;
571
572    // overridden by backend-specific derived class to perform the draw call.
573    virtual void onDraw(const GrPipeline&,
574                        const GrPrimitiveProcessor&,
575                        const GrMesh*,
576                        int meshCount) = 0;
577
578    virtual bool onMakeCopyForTextureParams(GrTexture* texture, const GrTextureParams&,
579                                            GrTextureProducer::CopyParams*) const { return false; }
580
581    virtual bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight,
582                                     size_t rowBytes, GrPixelConfig readConfig, DrawPreference*,
583                                     ReadPixelTempDrawInfo*) = 0;
584    virtual bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height,
585                                      GrPixelConfig srcConfig, DrawPreference*,
586                                      WritePixelTempDrawInfo*) = 0;
587
588    // overridden by backend-specific derived class to perform the surface read
589    virtual bool onReadPixels(GrSurface*,
590                              int left, int top,
591                              int width, int height,
592                              GrPixelConfig,
593                              void* buffer,
594                              size_t rowBytes) = 0;
595
596    // overridden by backend-specific derived class to perform the surface write
597    virtual bool onWritePixels(GrSurface*,
598                               int left, int top, int width, int height,
599                               GrPixelConfig config,
600                               const SkTArray<GrMipLevel>& texels) = 0;
601
602    // overridden by backend-specific derived class to perform the surface write
603    virtual bool onTransferPixels(GrSurface*,
604                                  int left, int top, int width, int height,
605                                  GrPixelConfig config, GrTransferBuffer* buffer,
606                                  size_t offset, size_t rowBytes) = 0;
607
608    // overridden by backend-specific derived class to perform the resolve
609    virtual void onResolveRenderTarget(GrRenderTarget* target) = 0;
610
611    // overridden by backend specific derived class to perform the copy surface
612    virtual bool onCopySurface(GrSurface* dst,
613                               GrSurface* src,
614                               const SkIRect& srcRect,
615                               const SkIPoint& dstPoint) = 0;
616
617    // overridden by backend specific derived class to perform the multisample queries
618    virtual void onGetMultisampleSpecs(GrRenderTarget*,
619                                       const GrStencilSettings&,
620                                       int* effectiveSampleCnt,
621                                       SkAutoTDeleteArray<SkPoint>* sampleLocations) = 0;
622
623    void resetContext() {
624        this->onResetContext(fResetBits);
625        fResetBits = 0;
626        ++fResetTimestamp;
627    }
628
629    ResetTimestamp                                                      fResetTimestamp;
630    uint32_t                                                            fResetBits;
631    SkTArray<const MultisampleSpecs*, true>                             fMultisampleSpecsMap;
632    GrTAllocator<MultisampleSpecs>                                      fMultisampleSpecsAllocator;
633    // The context owns us, not vice-versa, so this ptr is not ref'ed by Gpu.
634    GrContext*                                                          fContext;
635
636    friend class GrPathRendering;
637    typedef SkRefCnt INHERITED;
638};
639
640#endif
641