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