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-03-30 18:45:35 +00:00
|
|
|
* config, width, height. The device's storage will not count against
|
|
|
|
* the GrContext's texture cache budget. The device's pixels will be
|
|
|
|
* uninitialized.
|
2011-01-18 20:57:22 +00:00
|
|
|
*/
|
2012-03-30 18:45:35 +00:00
|
|
|
SkGpuDevice(GrContext*, SkBitmap::Config, int width, int height);
|
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; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Override from SkGpuDevice, so we can set our FBO to be the render target
|
|
|
|
* The canvas parameter must be a SkGpuCanvas
|
|
|
|
*/
|
2011-03-03 13:54:13 +00:00
|
|
|
virtual void gainFocus(SkCanvas*, const SkMatrix&, const SkRegion&,
|
2011-12-07 15:07:23 +00:00
|
|
|
const SkClipStack& clipStack) SK_OVERRIDE;
|
2010-12-22 21:39:39 +00:00
|
|
|
|
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-09-13 14:41:06 +00:00
|
|
|
virtual void setMatrixClip(const SkMatrix& matrix, const SkRegion& clip,
|
2011-12-07 15:07:23 +00:00
|
|
|
const SkClipStack&) SK_OVERRIDE;
|
2010-12-22 21:39:39 +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;
|
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;
|
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
|
|
|
|
|
|
|
/**
|
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-07-26 20:45:30 +00:00
|
|
|
typedef GrContext::TextureCacheEntry TexCache;
|
|
|
|
TexCache lockCachedTexture(const SkBitmap& bitmap,
|
2012-03-30 18:45:35 +00:00
|
|
|
const GrSamplerState* sampler);
|
2011-11-30 14:13:48 +00:00
|
|
|
bool isBitmapInTextureCache(const SkBitmap& bitmap,
|
|
|
|
const GrSamplerState& sampler) const;
|
2011-07-26 20:45:30 +00:00
|
|
|
void unlockCachedTexture(TexCache);
|
2010-12-22 21:39:39 +00:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
// state for our offscreen render-target
|
2011-07-26 20:45:30 +00:00
|
|
|
TexCache fCache;
|
|
|
|
GrTexture* fTexture;
|
|
|
|
GrRenderTarget* fRenderTarget;
|
|
|
|
bool fNeedClear;
|
|
|
|
bool fNeedPrepareRenderTarget;
|
2011-01-11 18:59:23 +00:00
|
|
|
|
2011-06-17 15:10:21 +00:00
|
|
|
// called from rt and tex cons
|
|
|
|
void initFromRenderTarget(GrContext*, GrRenderTarget*);
|
|
|
|
|
2012-03-30 18:45:35 +00:00
|
|
|
// used by createCompatibleDevice
|
|
|
|
SkGpuDevice(GrContext*, GrTexture* texture, TexCache, bool needClear);
|
|
|
|
|
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
|
|
|
|
2011-01-21 21:03:59 +00:00
|
|
|
void prepareRenderTarget(const SkDraw&);
|
2011-11-30 14:13:48 +00:00
|
|
|
bool shouldTileBitmap(const SkBitmap& bitmap,
|
|
|
|
const GrSamplerState& sampler,
|
|
|
|
const SkIRect* srcRectPtr,
|
|
|
|
int* tileSize) const;
|
2011-01-21 21:03:59 +00:00
|
|
|
void internalDrawBitmap(const SkDraw&, const SkBitmap&,
|
|
|
|
const SkIRect&, const SkMatrix&, 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
|
|
|
|
|