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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/include/gpu/SkGpuDevice.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,230 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2010 Google Inc.
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +
    1.12 +
    1.13 +
    1.14 +#ifndef SkGpuDevice_DEFINED
    1.15 +#define SkGpuDevice_DEFINED
    1.16 +
    1.17 +#include "SkGr.h"
    1.18 +#include "SkBitmap.h"
    1.19 +#include "SkBitmapDevice.h"
    1.20 +#include "SkPicture.h"
    1.21 +#include "SkRegion.h"
    1.22 +#include "GrContext.h"
    1.23 +
    1.24 +struct SkDrawProcs;
    1.25 +struct GrSkDrawProcs;
    1.26 +
    1.27 +class GrTextContext;
    1.28 +
    1.29 +/**
    1.30 + *  Subclass of SkBitmapDevice, which directs all drawing to the GrGpu owned by the
    1.31 + *  canvas.
    1.32 + */
    1.33 +class SK_API SkGpuDevice : public SkBitmapDevice {
    1.34 +public:
    1.35 +
    1.36 +    /**
    1.37 +     * Creates an SkGpuDevice from a GrSurface. This will fail if the surface is not a render
    1.38 +     * target. The caller owns a ref on the returned device.
    1.39 +     */
    1.40 +    static SkGpuDevice* Create(GrSurface* surface);
    1.41 +
    1.42 +    /**
    1.43 +     *  New device that will create an offscreen renderTarget based on the
    1.44 +     *  ImageInfo and sampleCount. The device's storage will not
    1.45 +     *  count against the GrContext's texture cache budget. The device's pixels
    1.46 +     *  will be uninitialized. On failure, returns NULL.
    1.47 +     */
    1.48 +    static SkGpuDevice* Create(GrContext*, const SkImageInfo&, int sampleCount);
    1.49 +
    1.50 +#ifdef SK_SUPPORT_LEGACY_COMPATIBLEDEVICE_CONFIG
    1.51 +    /**
    1.52 +     *  New device that will create an offscreen renderTarget based on the
    1.53 +     *  config, width, height, and sampleCount. The device's storage will not
    1.54 +     *  count against the GrContext's texture cache budget. The device's pixels
    1.55 +     *  will be uninitialized. TODO: This can fail, replace with a factory function.
    1.56 +     */
    1.57 +    SkGpuDevice(GrContext*, SkBitmap::Config, int width, int height, int sampleCount = 0);
    1.58 +#endif
    1.59 +
    1.60 +    /**
    1.61 +     *  DEPRECATED -- need to make this private, call Create(surface)
    1.62 +     *  New device that will render to the specified renderTarget.
    1.63 +     */
    1.64 +    SkGpuDevice(GrContext*, GrRenderTarget*);
    1.65 +
    1.66 +    /**
    1.67 +     *  DEPRECATED -- need to make this private, call Create(surface)
    1.68 +     *  New device that will render to the texture (as a rendertarget).
    1.69 +     *  The GrTexture's asRenderTarget() must be non-NULL or device will not
    1.70 +     *  function.
    1.71 +     */
    1.72 +    SkGpuDevice(GrContext*, GrTexture*);
    1.73 +
    1.74 +    virtual ~SkGpuDevice();
    1.75 +
    1.76 +    GrContext* context() const { return fContext; }
    1.77 +
    1.78 +    virtual GrRenderTarget* accessRenderTarget() SK_OVERRIDE;
    1.79 +
    1.80 +    // overrides from SkBaseDevice
    1.81 +    virtual int width() const SK_OVERRIDE {
    1.82 +        return NULL == fRenderTarget ? 0 : fRenderTarget->width();
    1.83 +    }
    1.84 +    virtual int height() const SK_OVERRIDE {
    1.85 +        return NULL == fRenderTarget ? 0 : fRenderTarget->height();
    1.86 +    }
    1.87 +    virtual bool isOpaque() const SK_OVERRIDE {
    1.88 +        return NULL == fRenderTarget ? false
    1.89 +                                     : kRGB_565_GrPixelConfig == fRenderTarget->config();
    1.90 +    }
    1.91 +    virtual SkBitmap::Config config() const SK_OVERRIDE;
    1.92 +
    1.93 +    virtual void clear(SkColor color) SK_OVERRIDE;
    1.94 +#ifdef SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG
    1.95 +    virtual void writePixels(const SkBitmap& bitmap, int x, int y,
    1.96 +                             SkCanvas::Config8888 config8888) SK_OVERRIDE;
    1.97 +#endif
    1.98 +    virtual void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE;
    1.99 +    virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count,
   1.100 +                            const SkPoint[], const SkPaint& paint) SK_OVERRIDE;
   1.101 +    virtual void drawRect(const SkDraw&, const SkRect& r,
   1.102 +                          const SkPaint& paint) SK_OVERRIDE;
   1.103 +    virtual void drawRRect(const SkDraw&, const SkRRect& r,
   1.104 +                           const SkPaint& paint) SK_OVERRIDE;
   1.105 +    virtual void drawOval(const SkDraw&, const SkRect& oval,
   1.106 +                          const SkPaint& paint) SK_OVERRIDE;
   1.107 +    virtual void drawPath(const SkDraw&, const SkPath& path,
   1.108 +                          const SkPaint& paint, const SkMatrix* prePathMatrix,
   1.109 +                          bool pathIsMutable) SK_OVERRIDE;
   1.110 +    virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
   1.111 +                            const SkMatrix&, const SkPaint&) SK_OVERRIDE;
   1.112 +    virtual void drawBitmapRect(const SkDraw&, const SkBitmap&,
   1.113 +                                const SkRect* srcOrNull, const SkRect& dst,
   1.114 +                                const SkPaint& paint,
   1.115 +                                SkCanvas::DrawBitmapRectFlags flags) SK_OVERRIDE;
   1.116 +    virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap,
   1.117 +                            int x, int y, const SkPaint& paint);
   1.118 +    virtual void drawText(const SkDraw&, const void* text, size_t len,
   1.119 +                          SkScalar x, SkScalar y, const SkPaint&) SK_OVERRIDE;
   1.120 +    virtual void drawPosText(const SkDraw&, const void* text, size_t len,
   1.121 +                             const SkScalar pos[], SkScalar constY,
   1.122 +                             int scalarsPerPos, const SkPaint&) SK_OVERRIDE;
   1.123 +    virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len,
   1.124 +                                const SkPath& path, const SkMatrix* matrix,
   1.125 +                                const SkPaint&) SK_OVERRIDE;
   1.126 +    virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCount,
   1.127 +                              const SkPoint verts[], const SkPoint texs[],
   1.128 +                              const SkColor colors[], SkXfermode* xmode,
   1.129 +                              const uint16_t indices[], int indexCount,
   1.130 +                              const SkPaint&) SK_OVERRIDE;
   1.131 +    virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y,
   1.132 +                            const SkPaint&) SK_OVERRIDE;
   1.133 +    virtual bool filterTextFlags(const SkPaint&, TextFlags*) SK_OVERRIDE;
   1.134 +
   1.135 +    virtual void flush() SK_OVERRIDE;
   1.136 +
   1.137 +    virtual void onAttachToCanvas(SkCanvas* canvas) SK_OVERRIDE;
   1.138 +    virtual void onDetachFromCanvas() SK_OVERRIDE;
   1.139 +
   1.140 +    /**
   1.141 +     * Make's this device's rendertarget current in the underlying 3D API.
   1.142 +     * Also implicitly flushes.
   1.143 +     */
   1.144 +    virtual void makeRenderTargetCurrent();
   1.145 +
   1.146 +    virtual bool canHandleImageFilter(const SkImageFilter*) SK_OVERRIDE;
   1.147 +    virtual bool filterImage(const SkImageFilter*, const SkBitmap&,
   1.148 +                             const SkImageFilter::Context&,
   1.149 +                             SkBitmap*, SkIPoint*) SK_OVERRIDE;
   1.150 +
   1.151 +    class SkAutoCachedTexture; // used internally
   1.152 +
   1.153 +
   1.154 +protected:
   1.155 +    virtual bool onReadPixels(const SkBitmap&, int x, int y, SkCanvas::Config8888) SK_OVERRIDE;
   1.156 +    virtual bool onWritePixels(const SkImageInfo&, const void*, size_t, int, int) SK_OVERRIDE;
   1.157 +
   1.158 +    /**  PRIVATE / EXPERIMENTAL -- do not call */
   1.159 +    virtual void EXPERIMENTAL_optimize(SkPicture* picture) SK_OVERRIDE;
   1.160 +    /**  PRIVATE / EXPERIMENTAL -- do not call */
   1.161 +    virtual bool EXPERIMENTAL_drawPicture(const SkPicture& picture) SK_OVERRIDE;
   1.162 +
   1.163 +private:
   1.164 +    GrContext*      fContext;
   1.165 +
   1.166 +    GrSkDrawProcs*  fDrawProcs;
   1.167 +
   1.168 +    GrClipData      fClipData;
   1.169 +
   1.170 +    GrTextContext*  fMainTextContext;
   1.171 +    GrTextContext*  fFallbackTextContext;
   1.172 +
   1.173 +    // state for our render-target
   1.174 +    GrRenderTarget*     fRenderTarget;
   1.175 +    bool                fNeedClear;
   1.176 +
   1.177 +    // called from rt and tex cons
   1.178 +    void initFromRenderTarget(GrContext*, GrRenderTarget*, bool cached);
   1.179 +
   1.180 +    // used by createCompatibleDevice
   1.181 +    SkGpuDevice(GrContext*, GrTexture* texture, bool needClear);
   1.182 +
   1.183 +    virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) SK_OVERRIDE;
   1.184 +
   1.185 +    virtual SkSurface* newSurface(const SkImageInfo&) SK_OVERRIDE;
   1.186 +
   1.187 +    // sets the render target, clip, and matrix on GrContext. Use forceIdenity to override
   1.188 +    // SkDraw's matrix and draw in device coords.
   1.189 +    void prepareDraw(const SkDraw&, bool forceIdentity);
   1.190 +
   1.191 +    /**
   1.192 +     * Implementation for both drawBitmap and drawBitmapRect.
   1.193 +     */
   1.194 +    void drawBitmapCommon(const SkDraw&,
   1.195 +                          const SkBitmap& bitmap,
   1.196 +                          const SkRect* srcRectPtr,
   1.197 +                          const SkSize* dstSizePtr,      // ignored iff srcRectPtr == NULL
   1.198 +                          const SkPaint&,
   1.199 +                          SkCanvas::DrawBitmapRectFlags flags);
   1.200 +
   1.201 +    /**
   1.202 +     * Helper functions called by drawBitmapCommon. By the time these are called the SkDraw's
   1.203 +     * matrix, clip, and the device's render target has already been set on GrContext.
   1.204 +     */
   1.205 +
   1.206 +    // The tileSize and clippedSrcRect will be valid only if true is returned.
   1.207 +    bool shouldTileBitmap(const SkBitmap& bitmap,
   1.208 +                          const GrTextureParams& sampler,
   1.209 +                          const SkRect* srcRectPtr,
   1.210 +                          int maxTileSize,
   1.211 +                          int* tileSize,
   1.212 +                          SkIRect* clippedSrcRect) const;
   1.213 +    void internalDrawBitmap(const SkBitmap&,
   1.214 +                            const SkRect&,
   1.215 +                            const GrTextureParams& params,
   1.216 +                            const SkPaint& paint,
   1.217 +                            SkCanvas::DrawBitmapRectFlags flags,
   1.218 +                            bool bicubic);
   1.219 +    void drawTiledBitmap(const SkBitmap& bitmap,
   1.220 +                         const SkRect& srcRect,
   1.221 +                         const SkIRect& clippedSrcRect,
   1.222 +                         const GrTextureParams& params,
   1.223 +                         const SkPaint& paint,
   1.224 +                         SkCanvas::DrawBitmapRectFlags flags,
   1.225 +                         int tileSize,
   1.226 +                         bool bicubic);
   1.227 +
   1.228 +    static SkPicture::AccelData::Key ComputeAccelDataKey();
   1.229 +
   1.230 +    typedef SkBitmapDevice INHERITED;
   1.231 +};
   1.232 +
   1.233 +#endif

mercurial