gfx/skia/trunk/include/gpu/GrRenderTarget.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/include/gpu/GrRenderTarget.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,171 @@
     1.4 +/*
     1.5 + * Copyright 2011 Google Inc.
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + */
    1.10 +
    1.11 +#ifndef GrRenderTarget_DEFINED
    1.12 +#define GrRenderTarget_DEFINED
    1.13 +
    1.14 +#include "GrSurface.h"
    1.15 +#include "SkRect.h"
    1.16 +
    1.17 +class GrStencilBuffer;
    1.18 +class GrTexture;
    1.19 +
    1.20 +/**
    1.21 + * GrRenderTarget represents a 2D buffer of pixels that can be rendered to.
    1.22 + * A context's render target is set by setRenderTarget(). Render targets are
    1.23 + * created by a createTexture with the kRenderTarget_TextureFlag flag.
    1.24 + * Additionally, GrContext provides methods for creating GrRenderTargets
    1.25 + * that wrap externally created render targets.
    1.26 + */
    1.27 +class GrRenderTarget : public GrSurface {
    1.28 +public:
    1.29 +    SK_DECLARE_INST_COUNT(GrRenderTarget)
    1.30 +
    1.31 +    // GrResource overrides
    1.32 +    virtual size_t sizeInBytes() const SK_OVERRIDE;
    1.33 +
    1.34 +    // GrSurface overrides
    1.35 +    /**
    1.36 +     * @return the texture associated with the render target, may be NULL.
    1.37 +     */
    1.38 +    virtual GrTexture* asTexture() SK_OVERRIDE { return fTexture; }
    1.39 +    virtual const GrTexture* asTexture() const SK_OVERRIDE { return fTexture; }
    1.40 +
    1.41 +    /**
    1.42 +     * @return this render target.
    1.43 +     */
    1.44 +    virtual GrRenderTarget* asRenderTarget() SK_OVERRIDE { return this; }
    1.45 +    virtual const GrRenderTarget* asRenderTarget() const  SK_OVERRIDE {
    1.46 +        return this;
    1.47 +    }
    1.48 +
    1.49 +    virtual bool readPixels(int left, int top, int width, int height,
    1.50 +                            GrPixelConfig config,
    1.51 +                            void* buffer,
    1.52 +                            size_t rowBytes = 0,
    1.53 +                            uint32_t pixelOpsFlags = 0) SK_OVERRIDE;
    1.54 +
    1.55 +    virtual void writePixels(int left, int top, int width, int height,
    1.56 +                             GrPixelConfig config,
    1.57 +                             const void* buffer,
    1.58 +                             size_t rowBytes = 0,
    1.59 +                             uint32_t pixelOpsFlags = 0) SK_OVERRIDE;
    1.60 +
    1.61 +    // GrRenderTarget
    1.62 +    /**
    1.63 +     * If this RT is multisampled, this is the multisample buffer
    1.64 +     * @return the 3D API's handle to this object (e.g. FBO ID in OpenGL)
    1.65 +     */
    1.66 +    virtual GrBackendObject getRenderTargetHandle() const = 0;
    1.67 +
    1.68 +    /**
    1.69 +     * If this RT is multisampled, this is the buffer it is resolved to.
    1.70 +     * Otherwise, same as getRenderTargetHandle().
    1.71 +     * (In GL a separate FBO ID is used for the MSAA and resolved buffers)
    1.72 +     * @return the 3D API's handle to this object (e.g. FBO ID in OpenGL)
    1.73 +     */
    1.74 +    virtual GrBackendObject getRenderTargetResolvedHandle() const = 0;
    1.75 +
    1.76 +    /**
    1.77 +     * @return true if the surface is multisampled, false otherwise
    1.78 +     */
    1.79 +    bool isMultisampled() const { return 0 != fDesc.fSampleCnt; }
    1.80 +
    1.81 +    /**
    1.82 +     * @return the number of samples-per-pixel or zero if non-MSAA.
    1.83 +     */
    1.84 +    int numSamples() const { return fDesc.fSampleCnt; }
    1.85 +
    1.86 +    /**
    1.87 +     * Call to indicate the multisample contents were modified such that the
    1.88 +     * render target needs to be resolved before it can be used as texture. Gr
    1.89 +     * tracks this for its own drawing and thus this only needs to be called
    1.90 +     * when the render target has been modified outside of Gr. This has no
    1.91 +     * effect on wrapped backend render targets.
    1.92 +     *
    1.93 +     * @param rect  a rect bounding the area needing resolve. NULL indicates
    1.94 +     *              the whole RT needs resolving.
    1.95 +     */
    1.96 +    void flagAsNeedingResolve(const SkIRect* rect = NULL);
    1.97 +
    1.98 +    /**
    1.99 +     * Call to override the region that needs to be resolved.
   1.100 +     */
   1.101 +    void overrideResolveRect(const SkIRect rect);
   1.102 +
   1.103 +    /**
   1.104 +     * Call to indicate that GrRenderTarget was externally resolved. This may
   1.105 +     * allow Gr to skip a redundant resolve step.
   1.106 +     */
   1.107 +    void flagAsResolved() { fResolveRect.setLargestInverted(); }
   1.108 +
   1.109 +    /**
   1.110 +     * @return true if the GrRenderTarget requires MSAA resolving
   1.111 +     */
   1.112 +    bool needsResolve() const { return !fResolveRect.isEmpty(); }
   1.113 +
   1.114 +    /**
   1.115 +     * Returns a rect bounding the region needing resolving.
   1.116 +     */
   1.117 +    const SkIRect& getResolveRect() const { return fResolveRect; }
   1.118 +
   1.119 +    /**
   1.120 +     * If the render target is multisampled this will perform a multisample
   1.121 +     * resolve. Any pending draws to the target are first flushed. This only
   1.122 +     * applies to render targets that are associated with GrTextures. After the
   1.123 +     * function returns the GrTexture will contain the resolved pixels.
   1.124 +     */
   1.125 +    void resolve();
   1.126 +
   1.127 +    // a MSAA RT may require explicit resolving , it may auto-resolve (e.g. FBO
   1.128 +    // 0 in GL), or be unresolvable because the client didn't give us the
   1.129 +    // resolve destination.
   1.130 +    enum ResolveType {
   1.131 +        kCanResolve_ResolveType,
   1.132 +        kAutoResolves_ResolveType,
   1.133 +        kCantResolve_ResolveType,
   1.134 +    };
   1.135 +    virtual ResolveType getResolveType() const = 0;
   1.136 +
   1.137 +    /**
   1.138 +     * GrStencilBuffer is not part of the public API.
   1.139 +     */
   1.140 +    GrStencilBuffer* getStencilBuffer() const { return fStencilBuffer; }
   1.141 +    void setStencilBuffer(GrStencilBuffer* stencilBuffer);
   1.142 +
   1.143 +protected:
   1.144 +    GrRenderTarget(GrGpu* gpu,
   1.145 +                   bool isWrapped,
   1.146 +                   GrTexture* texture,
   1.147 +                   const GrTextureDesc& desc)
   1.148 +        : INHERITED(gpu, isWrapped, desc)
   1.149 +        , fStencilBuffer(NULL)
   1.150 +        , fTexture(texture) {
   1.151 +        fResolveRect.setLargestInverted();
   1.152 +    }
   1.153 +
   1.154 +    // override of GrResource
   1.155 +    virtual void onAbandon() SK_OVERRIDE;
   1.156 +    virtual void onRelease() SK_OVERRIDE;
   1.157 +
   1.158 +private:
   1.159 +    friend class GrTexture;
   1.160 +    // called by ~GrTexture to remove the non-ref'ed back ptr.
   1.161 +    void owningTextureDestroyed() {
   1.162 +        SkASSERT(NULL != fTexture);
   1.163 +        fTexture = NULL;
   1.164 +    }
   1.165 +
   1.166 +    GrStencilBuffer*  fStencilBuffer;
   1.167 +    GrTexture*        fTexture; // not ref'ed
   1.168 +
   1.169 +    SkIRect           fResolveRect;
   1.170 +
   1.171 +    typedef GrSurface INHERITED;
   1.172 +};
   1.173 +
   1.174 +#endif

mercurial