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"
|
2013-08-29 11:54:56 +00:00
|
|
|
#include "SkBitmapDevice.h"
|
2014-03-16 19:46:36 +00:00
|
|
|
#include "SkPicture.h"
|
2010-12-22 21:39:39 +00:00
|
|
|
#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;
|
|
|
|
|
2014-01-30 22:05:47 +00:00
|
|
|
class GrTextContext;
|
2014-01-30 16:41:23 +00:00
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
/**
|
2013-08-29 11:54:56 +00:00
|
|
|
* Subclass of SkBitmapDevice, which directs all drawing to the GrGpu owned by the
|
2010-12-22 21:39:39 +00:00
|
|
|
* canvas.
|
|
|
|
*/
|
2013-08-29 11:54:56 +00:00
|
|
|
class SK_API SkGpuDevice : public SkBitmapDevice {
|
2010-12-22 21:39:39 +00:00
|
|
|
public:
|
2013-03-28 19:18:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an SkGpuDevice from a GrSurface. This will fail if the surface is not a render
|
|
|
|
* target. The caller owns a ref on the returned device.
|
|
|
|
*/
|
|
|
|
static SkGpuDevice* Create(GrSurface* surface);
|
|
|
|
|
2014-02-16 00:59:25 +00:00
|
|
|
/**
|
|
|
|
* New device that will create an offscreen renderTarget based on the
|
|
|
|
* ImageInfo and sampleCount. The device's storage will not
|
|
|
|
* count against the GrContext's texture cache budget. The device's pixels
|
|
|
|
* will be uninitialized. On failure, returns NULL.
|
|
|
|
*/
|
|
|
|
static SkGpuDevice* Create(GrContext*, const SkImageInfo&, int sampleCount);
|
|
|
|
|
|
|
|
#ifdef SK_SUPPORT_LEGACY_COMPATIBLEDEVICE_CONFIG
|
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
|
2013-03-28 19:18:12 +00:00
|
|
|
* will be uninitialized. TODO: This can fail, replace with a factory function.
|
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);
|
2014-02-16 00:59:25 +00:00
|
|
|
#endif
|
2011-06-16 19:10:39 +00:00
|
|
|
|
|
|
|
/**
|
2013-10-31 17:28:30 +00:00
|
|
|
* DEPRECATED -- need to make this private, call Create(surface)
|
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
|
|
|
/**
|
2013-10-31 17:28:30 +00:00
|
|
|
* DEPRECATED -- need to make this private, call Create(surface)
|
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; }
|
|
|
|
|
2013-06-26 19:18:23 +00:00
|
|
|
virtual GrRenderTarget* accessRenderTarget() SK_OVERRIDE;
|
2010-12-22 21:39:39 +00:00
|
|
|
|
2013-08-29 11:54:56 +00:00
|
|
|
// overrides from SkBaseDevice
|
2013-09-17 12:26:23 +00:00
|
|
|
virtual int width() const SK_OVERRIDE {
|
|
|
|
return NULL == fRenderTarget ? 0 : fRenderTarget->width();
|
|
|
|
}
|
|
|
|
virtual int height() const SK_OVERRIDE {
|
|
|
|
return NULL == fRenderTarget ? 0 : fRenderTarget->height();
|
|
|
|
}
|
2013-09-18 07:01:33 +00:00
|
|
|
virtual bool isOpaque() const SK_OVERRIDE {
|
|
|
|
return NULL == fRenderTarget ? false
|
|
|
|
: kRGB_565_GrPixelConfig == fRenderTarget->config();
|
2013-09-17 12:26:23 +00:00
|
|
|
}
|
|
|
|
virtual SkBitmap::Config config() const SK_OVERRIDE;
|
2010-12-22 21:39:39 +00:00
|
|
|
|
2011-12-07 15:07:23 +00:00
|
|
|
virtual void clear(SkColor color) SK_OVERRIDE;
|
|
|
|
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-04-25 15:27:00 +00:00
|
|
|
virtual void drawRRect(const SkDraw&, const SkRRect& r,
|
|
|
|
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,
|
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,
|
2013-08-16 10:24:37 +00:00
|
|
|
const SkPaint& paint,
|
|
|
|
SkCanvas::DrawBitmapRectFlags flags) 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;
|
2013-08-29 11:54:56 +00:00
|
|
|
virtual void drawDevice(const SkDraw&, SkBaseDevice*, 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
|
|
|
|
2013-08-29 11:54:56 +00:00
|
|
|
virtual void flush() SK_OVERRIDE;
|
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();
|
|
|
|
|
2014-02-05 22:32:02 +00:00
|
|
|
virtual bool canHandleImageFilter(const SkImageFilter*) SK_OVERRIDE;
|
2014-03-14 15:44:01 +00:00
|
|
|
virtual bool filterImage(const SkImageFilter*, const SkBitmap&,
|
|
|
|
const SkImageFilter::Context&,
|
2012-03-23 15:36:36 +00:00
|
|
|
SkBitmap*, SkIPoint*) SK_OVERRIDE;
|
2012-01-28 01:45:11 +00:00
|
|
|
|
2012-03-05 19:57:21 +00:00
|
|
|
class SkAutoCachedTexture; // used internally
|
|
|
|
|
2014-03-16 19:46:36 +00:00
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
protected:
|
2014-03-07 03:25:16 +00:00
|
|
|
virtual bool onReadPixels(const SkBitmap&, int x, int y, SkCanvas::Config8888) SK_OVERRIDE;
|
|
|
|
virtual bool onWritePixels(const SkImageInfo&, const void*, size_t, int, int) SK_OVERRIDE;
|
2011-11-02 19:57:21 +00:00
|
|
|
|
2014-03-16 19:46:36 +00:00
|
|
|
/** PRIVATE / EXPERIMENTAL -- do not call */
|
|
|
|
virtual void EXPERIMENTAL_optimize(SkPicture* picture) SK_OVERRIDE;
|
|
|
|
/** PRIVATE / EXPERIMENTAL -- do not call */
|
|
|
|
virtual bool EXPERIMENTAL_drawPicture(const SkPicture& picture) SK_OVERRIDE;
|
|
|
|
|
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
|
|
|
|
2014-01-30 22:05:47 +00:00
|
|
|
GrTextContext* fMainTextContext;
|
|
|
|
GrTextContext* fFallbackTextContext;
|
2014-01-24 14:38:27 +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
|
|
|
|
2014-02-16 00:59:25 +00:00
|
|
|
virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) SK_OVERRIDE;
|
2011-06-17 13:10:25 +00:00
|
|
|
|
2014-02-05 15:32:21 +00:00
|
|
|
virtual SkSurface* newSurface(const SkImageInfo&) SK_OVERRIDE;
|
|
|
|
|
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,
|
2014-01-13 14:47:00 +00:00
|
|
|
const SkSize* dstSizePtr, // ignored iff srcRectPtr == NULL
|
2013-08-16 10:24:37 +00:00
|
|
|
const SkPaint&,
|
|
|
|
SkCanvas::DrawBitmapRectFlags flags);
|
2012-10-11 19:39:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper functions called by drawBitmapCommon. By the time these are called the SkDraw's
|
2013-10-25 14:58:12 +00:00
|
|
|
* matrix, clip, and the device's render target has already been set on GrContext.
|
2012-10-11 19:39:09 +00:00
|
|
|
*/
|
2013-10-25 14:58:12 +00:00
|
|
|
|
|
|
|
// The tileSize and clippedSrcRect will be valid only if true is returned.
|
2011-11-30 14:13:48 +00:00
|
|
|
bool shouldTileBitmap(const SkBitmap& bitmap,
|
2012-07-25 21:27:09 +00:00
|
|
|
const GrTextureParams& sampler,
|
2013-10-24 17:52:07 +00:00
|
|
|
const SkRect* srcRectPtr,
|
|
|
|
int maxTileSize,
|
2013-10-25 14:58:12 +00:00
|
|
|
int* tileSize,
|
|
|
|
SkIRect* clippedSrcRect) 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 GrTextureParams& params,
|
2013-08-16 10:24:37 +00:00
|
|
|
const SkPaint& paint,
|
2013-12-02 22:22:35 +00:00
|
|
|
SkCanvas::DrawBitmapRectFlags flags,
|
|
|
|
bool bicubic);
|
2012-10-11 19:39:09 +00:00
|
|
|
void drawTiledBitmap(const SkBitmap& bitmap,
|
2012-09-28 18:06:49 +00:00
|
|
|
const SkRect& srcRect,
|
2013-10-25 14:58:12 +00:00
|
|
|
const SkIRect& clippedSrcRect,
|
2012-09-28 18:06:49 +00:00
|
|
|
const GrTextureParams& params,
|
2013-08-16 10:24:37 +00:00
|
|
|
const SkPaint& paint,
|
2013-10-24 17:52:07 +00:00
|
|
|
SkCanvas::DrawBitmapRectFlags flags,
|
2013-12-02 22:22:35 +00:00
|
|
|
int tileSize,
|
|
|
|
bool bicubic);
|
2010-12-22 21:39:39 +00:00
|
|
|
|
2014-03-16 19:46:36 +00:00
|
|
|
static SkPicture::AccelData::Key ComputeAccelDataKey();
|
|
|
|
|
2013-08-29 11:54:56 +00:00
|
|
|
typedef SkBitmapDevice INHERITED;
|
2010-12-22 21:39:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|