2010-12-22 21:39:39 +00:00
|
|
|
|
2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2010 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2010-12-22 21:39:39 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2011-07-28 14:26:00 +00:00
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
#ifndef SkGpuDevice_DEFINED
|
|
|
|
#define SkGpuDevice_DEFINED
|
|
|
|
|
|
|
|
#include "SkGr.h"
|
2011-06-16 19:10:39 +00:00
|
|
|
#include "SkBitmap.h"
|
2010-12-22 21:39:39 +00:00
|
|
|
#include "SkDevice.h"
|
|
|
|
#include "SkRegion.h"
|
2011-07-26 20:45:30 +00:00
|
|
|
#include "GrContext.h"
|
2010-12-22 21:39:39 +00:00
|
|
|
|
|
|
|
struct SkDrawProcs;
|
|
|
|
struct GrSkDrawProcs;
|
|
|
|
class GrTextContext;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Subclass of SkDevice, which directs all drawing to the GrGpu owned by the
|
|
|
|
* canvas.
|
|
|
|
*/
|
2011-03-21 19:51:57 +00:00
|
|
|
class SK_API SkGpuDevice : public SkDevice {
|
2010-12-22 21:39:39 +00:00
|
|
|
public:
|
2011-01-18 20:57:22 +00:00
|
|
|
/**
|
2011-06-16 19:10:39 +00:00
|
|
|
* New device that will create an offscreen renderTarget based on the
|
2012-11-01 02:01:27 +00:00
|
|
|
* config, width, height, and sampleCount. The device's storage will not
|
|
|
|
* count against the GrContext's texture cache budget. The device's pixels
|
2012-10-31 13:56:35 +00:00
|
|
|
* will be uninitialized.
|
2011-01-18 20:57:22 +00:00
|
|
|
*/
|
2012-10-31 13:56:35 +00:00
|
|
|
SkGpuDevice(GrContext*, SkBitmap::Config, int width, int height, int sampleCount = 0);
|
2011-06-16 19:10:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* New device that will render to the specified renderTarget.
|
|
|
|
*/
|
|
|
|
SkGpuDevice(GrContext*, GrRenderTarget*);
|
2011-01-18 20:57:22 +00:00
|
|
|
|
2011-06-17 15:10:21 +00:00
|
|
|
/**
|
|
|
|
* New device that will render to the texture (as a rendertarget).
|
|
|
|
* The GrTexture's asRenderTarget() must be non-NULL or device will not
|
|
|
|
* function.
|
|
|
|
*/
|
|
|
|
SkGpuDevice(GrContext*, GrTexture*);
|
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
virtual ~SkGpuDevice();
|
2011-01-11 18:59:23 +00:00
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
GrContext* context() const { return fContext; }
|
|
|
|
|
2011-12-07 15:07:23 +00:00
|
|
|
virtual SkGpuRenderTarget* accessRenderTarget() SK_OVERRIDE;
|
2010-12-22 21:39:39 +00:00
|
|
|
|
|
|
|
// overrides from SkDevice
|
|
|
|
|
2011-12-07 15:07:23 +00:00
|
|
|
virtual void clear(SkColor color) SK_OVERRIDE;
|
2011-11-10 20:57:43 +00:00
|
|
|
virtual void writePixels(const SkBitmap& bitmap, int x, int y,
|
|
|
|
SkCanvas::Config8888 config8888) SK_OVERRIDE;
|
2011-01-11 18:59:23 +00:00
|
|
|
|
2011-12-07 15:07:23 +00:00
|
|
|
virtual void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE;
|
2010-12-22 21:39:39 +00:00
|
|
|
virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count,
|
2011-12-07 15:07:23 +00:00
|
|
|
const SkPoint[], const SkPaint& paint) SK_OVERRIDE;
|
2010-12-22 21:39:39 +00:00
|
|
|
virtual void drawRect(const SkDraw&, const SkRect& r,
|
2011-12-07 15:07:23 +00:00
|
|
|
const SkPaint& paint) SK_OVERRIDE;
|
2013-01-22 13:34:01 +00:00
|
|
|
virtual void drawOval(const SkDraw&, const SkRect& oval,
|
|
|
|
const SkPaint& paint) SK_OVERRIDE;
|
2010-12-22 21:39:39 +00:00
|
|
|
virtual void drawPath(const SkDraw&, const SkPath& path,
|
|
|
|
const SkPaint& paint, const SkMatrix* prePathMatrix,
|
2011-12-07 15:07:23 +00:00
|
|
|
bool pathIsMutable) SK_OVERRIDE;
|
2010-12-22 21:39:39 +00:00
|
|
|
virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
|
|
|
|
const SkIRect* srcRectOrNull,
|
2011-12-07 15:07:23 +00:00
|
|
|
const SkMatrix&, const SkPaint&) SK_OVERRIDE;
|
2012-09-25 15:37:50 +00:00
|
|
|
virtual void drawBitmapRect(const SkDraw&, const SkBitmap&,
|
|
|
|
const SkRect* srcOrNull, const SkRect& dst,
|
|
|
|
const SkPaint& paint) SK_OVERRIDE;
|
2010-12-22 21:39:39 +00:00
|
|
|
virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap,
|
|
|
|
int x, int y, const SkPaint& paint);
|
|
|
|
virtual void drawText(const SkDraw&, const void* text, size_t len,
|
2011-12-07 15:07:23 +00:00
|
|
|
SkScalar x, SkScalar y, const SkPaint&) SK_OVERRIDE;
|
2010-12-22 21:39:39 +00:00
|
|
|
virtual void drawPosText(const SkDraw&, const void* text, size_t len,
|
|
|
|
const SkScalar pos[], SkScalar constY,
|
2011-12-07 15:07:23 +00:00
|
|
|
int scalarsPerPos, const SkPaint&) SK_OVERRIDE;
|
2010-12-22 21:39:39 +00:00
|
|
|
virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len,
|
|
|
|
const SkPath& path, const SkMatrix* matrix,
|
2011-12-07 15:07:23 +00:00
|
|
|
const SkPaint&) SK_OVERRIDE;
|
2010-12-22 21:39:39 +00:00
|
|
|
virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCount,
|
|
|
|
const SkPoint verts[], const SkPoint texs[],
|
|
|
|
const SkColor colors[], SkXfermode* xmode,
|
|
|
|
const uint16_t indices[], int indexCount,
|
2011-12-07 15:07:23 +00:00
|
|
|
const SkPaint&) SK_OVERRIDE;
|
2010-12-22 21:39:39 +00:00
|
|
|
virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y,
|
2011-12-07 15:07:23 +00:00
|
|
|
const SkPaint&) SK_OVERRIDE;
|
|
|
|
virtual bool filterTextFlags(const SkPaint&, TextFlags*) SK_OVERRIDE;
|
2011-01-11 18:59:23 +00:00
|
|
|
|
2012-01-28 01:45:11 +00:00
|
|
|
virtual void flush();
|
2011-01-11 18:59:23 +00:00
|
|
|
|
2012-07-13 15:36:15 +00:00
|
|
|
virtual void onAttachToCanvas(SkCanvas* canvas) SK_OVERRIDE;
|
|
|
|
virtual void onDetachFromCanvas() SK_OVERRIDE;
|
|
|
|
|
2011-01-11 18:59:23 +00:00
|
|
|
/**
|
2010-12-22 21:39:39 +00:00
|
|
|
* Make's this device's rendertarget current in the underlying 3D API.
|
|
|
|
* Also implicitly flushes.
|
|
|
|
*/
|
|
|
|
virtual void makeRenderTargetCurrent();
|
|
|
|
|
2012-03-23 15:36:36 +00:00
|
|
|
virtual bool canHandleImageFilter(SkImageFilter*) SK_OVERRIDE;
|
|
|
|
virtual bool filterImage(SkImageFilter*, const SkBitmap&, const SkMatrix&,
|
|
|
|
SkBitmap*, SkIPoint*) SK_OVERRIDE;
|
2012-01-28 01:45:11 +00:00
|
|
|
|
2012-03-05 19:57:21 +00:00
|
|
|
class SkAutoCachedTexture; // used internally
|
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
protected:
|
2011-11-02 19:57:21 +00:00
|
|
|
// overrides from SkDevice
|
2011-11-02 20:06:25 +00:00
|
|
|
virtual bool onReadPixels(const SkBitmap& bitmap,
|
2011-11-03 20:29:47 +00:00
|
|
|
int x, int y,
|
|
|
|
SkCanvas::Config8888 config8888) SK_OVERRIDE;
|
2011-11-02 19:57:21 +00:00
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
private:
|
|
|
|
GrContext* fContext;
|
2011-01-21 21:03:59 +00:00
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
GrSkDrawProcs* fDrawProcs;
|
|
|
|
|
2012-07-31 19:15:58 +00:00
|
|
|
GrClipData fClipData;
|
2012-07-13 15:36:15 +00:00
|
|
|
|
2012-10-10 15:25:50 +00:00
|
|
|
// state for our render-target
|
2011-07-26 20:45:30 +00:00
|
|
|
GrRenderTarget* fRenderTarget;
|
|
|
|
bool fNeedClear;
|
2011-01-11 18:59:23 +00:00
|
|
|
|
2011-06-17 15:10:21 +00:00
|
|
|
// called from rt and tex cons
|
2012-08-28 15:07:11 +00:00
|
|
|
void initFromRenderTarget(GrContext*, GrRenderTarget*, bool cached);
|
2011-06-17 15:10:21 +00:00
|
|
|
|
2012-03-30 18:45:35 +00:00
|
|
|
// used by createCompatibleDevice
|
2012-08-16 14:49:16 +00:00
|
|
|
SkGpuDevice(GrContext*, GrTexture* texture, bool needClear);
|
2012-03-30 18:45:35 +00:00
|
|
|
|
2012-07-03 19:12:29 +00:00
|
|
|
// override from SkDevice
|
2012-01-28 01:45:11 +00:00
|
|
|
virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config config,
|
|
|
|
int width, int height,
|
2011-06-17 13:10:25 +00:00
|
|
|
bool isOpaque,
|
2012-05-23 11:44:08 +00:00
|
|
|
Usage usage) SK_OVERRIDE;
|
2011-06-17 13:10:25 +00:00
|
|
|
|
2011-01-21 21:03:59 +00:00
|
|
|
SkDrawProcs* initDrawForText(GrTextContext*);
|
2011-02-17 16:43:10 +00:00
|
|
|
bool bindDeviceAsTexture(GrPaint* paint);
|
2010-12-22 21:39:39 +00:00
|
|
|
|
2012-10-12 15:01:38 +00:00
|
|
|
// sets the render target, clip, and matrix on GrContext. Use forceIdenity to override
|
|
|
|
// SkDraw's matrix and draw in device coords.
|
|
|
|
void prepareDraw(const SkDraw&, bool forceIdentity);
|
2012-10-11 19:39:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation for both drawBitmap and drawBitmapRect.
|
|
|
|
*/
|
|
|
|
void drawBitmapCommon(const SkDraw&,
|
|
|
|
const SkBitmap& bitmap,
|
|
|
|
const SkRect* srcRectPtr,
|
|
|
|
const SkMatrix&,
|
|
|
|
const SkPaint&);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper functions called by drawBitmapCommon. By the time these are called the SkDraw's
|
|
|
|
* matrix has already been set on GrContext
|
|
|
|
*/
|
2011-11-30 14:13:48 +00:00
|
|
|
bool shouldTileBitmap(const SkBitmap& bitmap,
|
2012-07-25 21:27:09 +00:00
|
|
|
const GrTextureParams& sampler,
|
2012-09-28 18:06:49 +00:00
|
|
|
const SkRect* srcRectPtr) const;
|
2012-10-11 19:39:09 +00:00
|
|
|
void internalDrawBitmap(const SkBitmap&,
|
2012-09-28 18:06:49 +00:00
|
|
|
const SkRect&,
|
2012-09-18 14:14:49 +00:00
|
|
|
const SkMatrix&,
|
|
|
|
const GrTextureParams& params,
|
|
|
|
GrPaint* grPaint);
|
2012-10-11 19:39:09 +00:00
|
|
|
void drawTiledBitmap(const SkBitmap& bitmap,
|
2012-09-28 18:06:49 +00:00
|
|
|
const SkRect& srcRect,
|
|
|
|
const SkMatrix& m,
|
|
|
|
const GrTextureParams& params,
|
|
|
|
GrPaint* grPaint);
|
2010-12-22 21:39:39 +00:00
|
|
|
|
2012-03-16 14:02:46 +00:00
|
|
|
/**
|
|
|
|
* Returns non-initialized instance.
|
|
|
|
*/
|
|
|
|
GrTextContext* getTextContext();
|
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
typedef SkDevice INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|