2008-12-17 15:59:43 +00:00
|
|
|
/*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Copyright 2010 The Android Open Source Project
|
2008-12-17 15:59:43 +00:00
|
|
|
*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkDevice_DEFINED
|
|
|
|
#define SkDevice_DEFINED
|
|
|
|
|
|
|
|
#include "SkRefCnt.h"
|
|
|
|
#include "SkBitmap.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkColor.h"
|
2014-03-14 15:44:01 +00:00
|
|
|
#include "SkImageFilter.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2011-02-22 20:56:26 +00:00
|
|
|
class SkClipStack;
|
2008-12-17 15:59:43 +00:00
|
|
|
class SkDraw;
|
2015-03-04 03:08:17 +00:00
|
|
|
class SkDrawFilter;
|
2008-12-17 15:59:43 +00:00
|
|
|
struct SkIRect;
|
|
|
|
class SkMatrix;
|
2011-03-30 21:23:07 +00:00
|
|
|
class SkMetaData;
|
2008-12-17 15:59:43 +00:00
|
|
|
class SkRegion;
|
2014-09-17 17:49:38 +00:00
|
|
|
struct SkDeviceProperties;
|
2013-06-26 19:18:23 +00:00
|
|
|
class GrRenderTarget;
|
2011-07-18 15:25:04 +00:00
|
|
|
|
2013-08-29 11:54:56 +00:00
|
|
|
class SK_API SkBaseDevice : public SkRefCnt {
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
2013-08-29 11:54:56 +00:00
|
|
|
SK_DECLARE_INST_COUNT(SkBaseDevice)
|
2012-06-21 20:25:03 +00:00
|
|
|
|
2011-06-16 19:10:39 +00:00
|
|
|
/**
|
2013-08-29 11:54:56 +00:00
|
|
|
* Construct a new device.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2013-08-29 11:54:56 +00:00
|
|
|
SkBaseDevice();
|
2014-11-13 20:41:02 +00:00
|
|
|
explicit SkBaseDevice(const SkDeviceProperties&);
|
2013-08-29 11:54:56 +00:00
|
|
|
virtual ~SkBaseDevice();
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2011-08-08 19:41:56 +00:00
|
|
|
SkMetaData& getMetaData();
|
|
|
|
|
2014-02-13 17:14:46 +00:00
|
|
|
/**
|
|
|
|
* Return ImageInfo for this device. If the canvas is not backed by pixels
|
|
|
|
* (cpu or gpu), then the info's ColorType will be kUnknown_SkColorType.
|
|
|
|
*/
|
|
|
|
virtual SkImageInfo imageInfo() const;
|
|
|
|
|
2011-08-30 15:56:11 +00:00
|
|
|
/**
|
|
|
|
* Return the bounds of the device in the coordinate space of the root
|
|
|
|
* canvas. The root device will have its top-left at 0,0, but other devices
|
|
|
|
* such as those associated with saveLayer may have a non-zero origin.
|
|
|
|
*/
|
2013-11-13 16:02:18 +00:00
|
|
|
void getGlobalBounds(SkIRect* bounds) const {
|
|
|
|
SkASSERT(bounds);
|
|
|
|
const SkIPoint& origin = this->getOrigin();
|
|
|
|
bounds->setXYWH(origin.x(), origin.y(), this->width(), this->height());
|
|
|
|
}
|
2013-11-14 07:02:31 +00:00
|
|
|
|
2014-11-19 16:04:34 +00:00
|
|
|
SkIRect getGlobalBounds() const {
|
|
|
|
SkIRect bounds;
|
|
|
|
this->getGlobalBounds(&bounds);
|
|
|
|
return bounds;
|
|
|
|
}
|
|
|
|
|
2014-06-14 11:24:56 +00:00
|
|
|
int width() const {
|
|
|
|
return this->imageInfo().width();
|
|
|
|
}
|
2014-07-07 20:51:48 +00:00
|
|
|
|
2014-06-14 11:24:56 +00:00
|
|
|
int height() const {
|
|
|
|
return this->imageInfo().height();
|
|
|
|
}
|
2014-07-07 20:51:48 +00:00
|
|
|
|
2014-06-14 11:24:56 +00:00
|
|
|
bool isOpaque() const {
|
|
|
|
return this->imageInfo().isOpaque();
|
|
|
|
}
|
2013-08-30 07:01:34 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Return the bitmap associated with this device. Call this each time you need
|
|
|
|
to access the bitmap, as it notifies the subclass to perform any flushing
|
|
|
|
etc. before you examine the pixels.
|
|
|
|
@param changePixels set to true if the caller plans to change the pixels
|
|
|
|
@return the device's bitmap
|
|
|
|
*/
|
|
|
|
const SkBitmap& accessBitmap(bool changePixels);
|
|
|
|
|
2014-03-17 17:03:18 +00:00
|
|
|
bool writePixels(const SkImageInfo&, const void*, size_t rowBytes, int x, int y);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2015-06-05 21:11:32 +00:00
|
|
|
/**
|
|
|
|
* Try to get write-access to the pixels behind the device. If successful, this returns true
|
|
|
|
* and fills-out the pixmap parameter. On success it also bumps the genID of the underlying
|
|
|
|
* bitmap.
|
|
|
|
*
|
|
|
|
* On failure, returns false and ignores the pixmap parameter.
|
|
|
|
*/
|
2015-05-26 18:31:54 +00:00
|
|
|
bool accessPixels(SkPixmap* pmap);
|
2014-03-12 18:28:35 +00:00
|
|
|
|
2015-06-05 21:11:32 +00:00
|
|
|
/**
|
|
|
|
* Try to get read-only-access to the pixels behind the device. If successful, this returns
|
|
|
|
* true and fills-out the pixmap parameter.
|
|
|
|
*
|
|
|
|
* On failure, returns false and ignores the pixmap parameter.
|
|
|
|
*/
|
|
|
|
bool peekPixels(SkPixmap*);
|
|
|
|
|
2011-07-18 15:25:04 +00:00
|
|
|
/**
|
|
|
|
* Return the device's associated gpu render target, or NULL.
|
2010-12-20 18:26:13 +00:00
|
|
|
*/
|
2014-06-27 18:34:19 +00:00
|
|
|
virtual GrRenderTarget* accessRenderTarget() { return NULL; }
|
2010-12-20 18:26:13 +00:00
|
|
|
|
2011-08-08 19:41:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the device's origin: its offset in device coordinates from
|
|
|
|
* the default origin in its canvas' matrix/clip
|
|
|
|
*/
|
|
|
|
const SkIPoint& getOrigin() const { return fOrigin; }
|
|
|
|
|
2012-08-23 18:09:54 +00:00
|
|
|
/**
|
2012-07-13 15:36:15 +00:00
|
|
|
* onAttachToCanvas is invoked whenever a device is installed in a canvas
|
|
|
|
* (i.e., setDevice, saveLayer (for the new device created by the save),
|
2013-08-29 11:54:56 +00:00
|
|
|
* and SkCanvas' SkBaseDevice & SkBitmap -taking ctors). It allows the
|
2012-07-13 15:36:15 +00:00
|
|
|
* devices to prepare for drawing (e.g., locking their pixels, etc.)
|
|
|
|
*/
|
2013-03-11 18:50:03 +00:00
|
|
|
virtual void onAttachToCanvas(SkCanvas*) {
|
2012-08-29 21:26:13 +00:00
|
|
|
SkASSERT(!fAttachedToCanvas);
|
2012-07-13 15:36:15 +00:00
|
|
|
#ifdef SK_DEBUG
|
|
|
|
fAttachedToCanvas = true;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* onDetachFromCanvas notifies a device that it will no longer be drawn to.
|
|
|
|
* It gives the device a chance to clean up (e.g., unlock its pixels). It
|
2012-08-23 18:09:54 +00:00
|
|
|
* is invoked from setDevice (for the displaced device), restore and
|
2012-07-13 15:36:15 +00:00
|
|
|
* possibly from SkCanvas' dtor.
|
|
|
|
*/
|
|
|
|
virtual void onDetachFromCanvas() {
|
2012-08-29 21:26:13 +00:00
|
|
|
SkASSERT(fAttachedToCanvas);
|
2012-07-13 15:36:15 +00:00
|
|
|
#ifdef SK_DEBUG
|
|
|
|
fAttachedToCanvas = false;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2012-01-05 17:05:05 +00:00
|
|
|
protected:
|
2015-03-14 17:54:31 +00:00
|
|
|
enum TileUsage {
|
|
|
|
kPossible_TileUsage, //!< the created device may be drawn tiled
|
|
|
|
kNever_TileUsage, //!< the created device will never be drawn tiled
|
2012-01-05 17:05:05 +00:00
|
|
|
};
|
|
|
|
|
2011-08-08 19:41:56 +00:00
|
|
|
struct TextFlags {
|
2014-09-16 19:27:55 +00:00
|
|
|
uint32_t fFlags; // SkPaint::getFlags()
|
2011-08-08 19:41:56 +00:00
|
|
|
};
|
|
|
|
|
2014-11-13 22:05:58 +00:00
|
|
|
/**
|
|
|
|
* Returns the text-related flags, possibly modified based on the state of the
|
|
|
|
* device (e.g. support for LCD).
|
|
|
|
*/
|
|
|
|
uint32_t filterTextFlags(const SkPaint&) const;
|
|
|
|
|
2014-11-13 20:41:02 +00:00
|
|
|
virtual bool onShouldDisableLCD(const SkPaint&) const { return false; }
|
2011-08-08 19:41:56 +00:00
|
|
|
|
2012-10-09 22:30:18 +00:00
|
|
|
/**
|
2012-10-10 15:25:50 +00:00
|
|
|
*
|
|
|
|
* DEPRECATED: This will be removed in a future change. Device subclasses
|
|
|
|
* should use the matrix and clip from the SkDraw passed to draw functions.
|
|
|
|
*
|
2012-10-09 22:30:18 +00:00
|
|
|
* Called with the correct matrix and clip before this device is drawn
|
|
|
|
* to using those settings. If your subclass overrides this, be sure to
|
|
|
|
* call through to the base class as well.
|
|
|
|
*
|
|
|
|
* The clipstack is another view of the clip. It records the actual
|
|
|
|
* geometry that went into building the region. It is present for devices
|
|
|
|
* that want to parse it, but is not required: the region is a complete
|
|
|
|
* picture of the current clip. (i.e. if you regionize all of the geometry
|
|
|
|
* in the clipstack, you will arrive at an equivalent region to the one
|
|
|
|
* passed in).
|
2012-10-10 15:25:50 +00:00
|
|
|
*/
|
|
|
|
virtual void setMatrixClip(const SkMatrix&, const SkRegion&,
|
2013-08-29 11:54:56 +00:00
|
|
|
const SkClipStack&) {};
|
2012-10-09 22:30:18 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** These are called inside the per-device-layer loop for each draw call.
|
|
|
|
When these are called, we have already applied any saveLayer operations,
|
|
|
|
and are handling any looping from the paint, and any effects from the
|
|
|
|
DrawFilter.
|
|
|
|
*/
|
2013-08-29 11:54:56 +00:00
|
|
|
virtual void drawPaint(const SkDraw&, const SkPaint& paint) = 0;
|
2008-12-17 15:59:43 +00:00
|
|
|
virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count,
|
2013-08-29 11:54:56 +00:00
|
|
|
const SkPoint[], const SkPaint& paint) = 0;
|
2008-12-17 15:59:43 +00:00
|
|
|
virtual void drawRect(const SkDraw&, const SkRect& r,
|
2013-08-29 11:54:56 +00:00
|
|
|
const SkPaint& paint) = 0;
|
2013-01-22 13:34:01 +00:00
|
|
|
virtual void drawOval(const SkDraw&, const SkRect& oval,
|
2013-08-29 11:54:56 +00:00
|
|
|
const SkPaint& paint) = 0;
|
2013-04-25 15:27:00 +00:00
|
|
|
virtual void drawRRect(const SkDraw&, const SkRRect& rr,
|
2013-08-29 11:54:56 +00:00
|
|
|
const SkPaint& paint) = 0;
|
2013-04-25 15:27:00 +00:00
|
|
|
|
2014-02-21 02:32:36 +00:00
|
|
|
// Default impl calls drawPath()
|
|
|
|
virtual void drawDRRect(const SkDraw&, const SkRRect& outer,
|
|
|
|
const SkRRect& inner, const SkPaint&);
|
|
|
|
|
2011-03-25 15:08:16 +00:00
|
|
|
/**
|
|
|
|
* If pathIsMutable, then the implementation is allowed to cast path to a
|
|
|
|
* non-const pointer and modify it in place (as an optimization). Canvas
|
|
|
|
* may do this to implement helpers such as drawOval, by placing a temp
|
|
|
|
* path on the stack to hold the representation of the oval.
|
|
|
|
*
|
|
|
|
* If prePathMatrix is not null, it should logically be applied before any
|
|
|
|
* stroking or other effects. If there are no effects on the paint that
|
|
|
|
* affect the geometry/rasterization, then the pre matrix can just be
|
|
|
|
* pre-concated with the current matrix.
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
virtual void drawPath(const SkDraw&, const SkPath& path,
|
2010-12-20 18:26:13 +00:00
|
|
|
const SkPaint& paint,
|
|
|
|
const SkMatrix* prePathMatrix = NULL,
|
2013-08-29 11:54:56 +00:00
|
|
|
bool pathIsMutable = false) = 0;
|
2008-12-17 15:59:43 +00:00
|
|
|
virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
|
2013-08-29 11:54:56 +00:00
|
|
|
const SkMatrix& matrix, const SkPaint& paint) = 0;
|
2008-12-17 15:59:43 +00:00
|
|
|
virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap,
|
2013-08-29 11:54:56 +00:00
|
|
|
int x, int y, const SkPaint& paint) = 0;
|
2012-09-25 15:37:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The default impl. will create a bitmap-shader from the bitmap,
|
|
|
|
* and call drawRect with it.
|
|
|
|
*/
|
|
|
|
virtual void drawBitmapRect(const SkDraw&, const SkBitmap&,
|
|
|
|
const SkRect* srcOrNull, const SkRect& dst,
|
2013-08-16 10:24:37 +00:00
|
|
|
const SkPaint& paint,
|
2013-08-29 11:54:56 +00:00
|
|
|
SkCanvas::DrawBitmapRectFlags flags) = 0;
|
2012-09-25 15:37:50 +00:00
|
|
|
|
2015-05-06 19:56:48 +00:00
|
|
|
virtual void drawImage(const SkDraw&, const SkImage*, SkScalar x, SkScalar y, const SkPaint&);
|
|
|
|
virtual void drawImageRect(const SkDraw&, const SkImage*, const SkRect* src, const SkRect& dst,
|
|
|
|
const SkPaint&);
|
|
|
|
|
2011-08-22 21:30:43 +00:00
|
|
|
/**
|
|
|
|
* Does not handle text decoration.
|
|
|
|
* Decorations (underline and stike-thru) will be handled by SkCanvas.
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
virtual void drawText(const SkDraw&, const void* text, size_t len,
|
2013-08-29 11:54:56 +00:00
|
|
|
SkScalar x, SkScalar y, const SkPaint& paint) = 0;
|
2008-12-17 15:59:43 +00:00
|
|
|
virtual void drawPosText(const SkDraw&, const void* text, size_t len,
|
Revert of Revert of Fix SkTextBlob offset semantics. (patchset #1 id:1 of https://codereview.chromium.org/609223003/)
Reason for revert:
Re-landing: Chromium-side fix to be landed with the roll (https://codereview.chromium.org/607853003/)
Original issue's description:
> Revert of Fix SkTextBlob offset semantics. (patchset #2 id:20001 of https://codereview.chromium.org/605533002/)
>
> Reason for revert:
> Breaking the Chrome builds with the error:
>
> [14:54:14.317833] ../../skia/ext/pixel_ref_utils.cc:221:16: error: 'drawPosText' marked 'override' but does not override any member functions
> [14:54:14.318022] virtual void drawPosText(const SkDraw& draw,
> [14:54:14.318082] ^
>
> Original issue's description:
> > Fix SkTextBlob offset semantics.
> >
> > Implement proper x/y drawTextBlob() handling by plumbing a
> > drawPosText() offset parameter (to act as an additional glyph pos
> > translation) throughout the device layer.
> >
> > The new offset superceeds the existing constY, with a minor semantic
> > tweak: whereas previous implementations were ignoring constY in 2D
> > positioning mode (scalarsPerGlyph == 2), now the offset is always
> > observed, in all positioning modes. We can do this because existing
> > drawPosText() clients always pass constY == 0 for full positioning mode.
> >
> > R=reed@google.com, jvanverth@google.com, robertphillips@google.com
> >
> > Committed: https://skia.googlesource.com/skia/+/c13bc571d3e61a43b87eb97f0719abd304cafaf2
>
> TBR=jvanverth@google.com,reed@google.com,bsalomon@google.com,fmalita@chromium.org
> NOTREECHECKS=true
> NOTRY=true
>
> Committed: https://skia.googlesource.com/skia/+/d46b8d2bab7cfba8458432248e1568ac377429e9
R=jvanverth@google.com, reed@google.com, bsalomon@google.com, robertphillips@google.com
TBR=bsalomon@google.com, jvanverth@google.com, reed@google.com, robertphillips@google.com
NOTREECHECKS=true
NOTRY=true
Author: fmalita@chromium.org
Review URL: https://codereview.chromium.org/607413003
2014-09-29 13:29:53 +00:00
|
|
|
const SkScalar pos[], int scalarsPerPos,
|
|
|
|
const SkPoint& offset, const SkPaint& paint) = 0;
|
2008-12-17 15:59:43 +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,
|
2013-08-29 11:54:56 +00:00
|
|
|
const SkPaint& paint) = 0;
|
2014-08-28 21:32:24 +00:00
|
|
|
// default implementation unrolls the blob runs.
|
|
|
|
virtual void drawTextBlob(const SkDraw&, const SkTextBlob*, SkScalar x, SkScalar y,
|
2015-03-04 03:08:17 +00:00
|
|
|
const SkPaint& paint, SkDrawFilter* drawFilter);
|
2014-08-04 17:02:00 +00:00
|
|
|
// default implementation calls drawVertices
|
2014-08-12 15:34:29 +00:00
|
|
|
virtual void drawPatch(const SkDraw&, const SkPoint cubics[12], const SkColor colors[4],
|
|
|
|
const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint);
|
2013-08-20 20:06:40 +00:00
|
|
|
/** The SkDevice passed will be an SkDevice which was returned by a call to
|
2015-03-14 17:54:31 +00:00
|
|
|
onCreateDevice on this device with kNeverTile_TileExpectation.
|
2011-08-08 19:41:56 +00:00
|
|
|
*/
|
2013-08-29 11:54:56 +00:00
|
|
|
virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y,
|
|
|
|
const SkPaint&) = 0;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2015-02-17 18:33:54 +00:00
|
|
|
virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, const SkPath&,
|
|
|
|
const SkMatrix*, const SkPaint&);
|
2015-05-26 18:31:54 +00:00
|
|
|
|
2014-03-17 21:31:26 +00:00
|
|
|
bool readPixels(const SkImageInfo&, void* dst, size_t rowBytes, int x, int y);
|
2011-11-03 20:29:47 +00:00
|
|
|
|
2011-01-25 23:50:57 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-02-07 16:27:57 +00:00
|
|
|
/** Update as needed the pixel value in the bitmap, so that the caller can
|
2013-08-30 07:01:34 +00:00
|
|
|
access the pixels directly.
|
2013-08-29 11:54:56 +00:00
|
|
|
@return The device contents as a bitmap
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2013-08-29 11:54:56 +00:00
|
|
|
virtual const SkBitmap& onAccessBitmap() = 0;
|
2012-01-28 01:45:11 +00:00
|
|
|
|
2012-01-05 21:15:07 +00:00
|
|
|
/**
|
2012-03-23 15:36:36 +00:00
|
|
|
* Override and return true for filters that the device can handle
|
|
|
|
* intrinsically. Doing so means that SkCanvas will pass-through this
|
|
|
|
* filter to drawSprite and drawDevice (and potentially filterImage).
|
|
|
|
* Returning false means the SkCanvas will have apply the filter itself,
|
|
|
|
* and just pass the resulting image to the device.
|
2012-01-05 21:15:07 +00:00
|
|
|
*/
|
2014-06-27 18:34:19 +00:00
|
|
|
virtual bool canHandleImageFilter(const SkImageFilter*) { return false; }
|
2012-03-23 15:36:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Related (but not required) to canHandleImageFilter, this method returns
|
|
|
|
* true if the device could apply the filter to the src bitmap and return
|
|
|
|
* the result (and updates offset as needed).
|
|
|
|
* If the device does not recognize or support this filter,
|
|
|
|
* it just returns false and leaves result and offset unchanged.
|
|
|
|
*/
|
2014-03-14 15:44:01 +00:00
|
|
|
virtual bool filterImage(const SkImageFilter*, const SkBitmap&,
|
2014-11-14 19:11:46 +00:00
|
|
|
const SkImageFilter::Context&,
|
|
|
|
SkBitmap* /*result*/, SkIPoint* /*offset*/) {
|
2014-06-27 18:34:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-01-05 21:15:07 +00:00
|
|
|
|
2013-12-19 16:12:25 +00:00
|
|
|
protected:
|
2015-05-26 18:31:54 +00:00
|
|
|
virtual SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) { return NULL; }
|
|
|
|
virtual bool onPeekPixels(SkPixmap*) { return false; }
|
2014-02-14 03:02:05 +00:00
|
|
|
|
2014-03-17 21:31:26 +00:00
|
|
|
/**
|
|
|
|
* The caller is responsible for "pre-clipping" the dst. The impl can assume that the dst
|
|
|
|
* image at the specified x,y offset will fit within the device's bounds.
|
|
|
|
*
|
|
|
|
* This is explicitly asserted in readPixels(), the public way to call this.
|
|
|
|
*/
|
|
|
|
virtual bool onReadPixels(const SkImageInfo&, void*, size_t, int x, int y);
|
2014-03-12 03:04:08 +00:00
|
|
|
|
2014-03-07 03:25:16 +00:00
|
|
|
/**
|
|
|
|
* The caller is responsible for "pre-clipping" the src. The impl can assume that the src
|
|
|
|
* image at the specified x,y offset will fit within the device's bounds.
|
|
|
|
*
|
|
|
|
* This is explicitly asserted in writePixelsDirect(), the public way to call this.
|
|
|
|
*/
|
|
|
|
virtual bool onWritePixels(const SkImageInfo&, const void*, size_t, int x, int y);
|
|
|
|
|
2015-05-26 18:31:54 +00:00
|
|
|
virtual bool onAccessPixels(SkPixmap*) { return false; }
|
2014-03-12 18:28:35 +00:00
|
|
|
|
2013-12-19 16:12:25 +00:00
|
|
|
/**
|
|
|
|
* Leaky properties are those which the device should be applying but it isn't.
|
|
|
|
* These properties will be applied by the draw, when and as it can.
|
|
|
|
* If the device does handle a property, that property should be set to the identity value
|
|
|
|
* for that property, effectively making it non-leaky.
|
|
|
|
*/
|
2014-09-17 17:49:38 +00:00
|
|
|
const SkDeviceProperties& getLeakyProperties() const {
|
|
|
|
return *fLeakyProperties;
|
|
|
|
}
|
2013-12-19 16:12:25 +00:00
|
|
|
|
2014-03-16 19:46:36 +00:00
|
|
|
/**
|
|
|
|
* PRIVATE / EXPERIMENTAL -- do not call
|
|
|
|
* This entry point gives the backend an opportunity to take over the rendering
|
|
|
|
* of 'picture'. If optimization data is available (due to an earlier
|
|
|
|
* 'optimize' call) this entry point should make use of it and return true
|
|
|
|
* if all rendering has been done. If false is returned, SkCanvas will
|
2014-03-17 03:02:17 +00:00
|
|
|
* perform its own rendering pass. It is acceptable for the backend
|
2014-03-16 19:46:36 +00:00
|
|
|
* to perform some device-specific warm up tasks and then let SkCanvas
|
|
|
|
* perform the main rendering loop (by return false from here).
|
|
|
|
*/
|
2014-08-09 18:08:05 +00:00
|
|
|
virtual bool EXPERIMENTAL_drawPicture(SkCanvas*, const SkPicture*, const SkMatrix*,
|
|
|
|
const SkPaint*);
|
2014-03-16 19:46:36 +00:00
|
|
|
|
2014-11-13 16:33:37 +00:00
|
|
|
struct CreateInfo {
|
2015-03-14 17:54:31 +00:00
|
|
|
static SkPixelGeometry AdjustGeometry(const SkImageInfo&, TileUsage, SkPixelGeometry);
|
2014-11-13 20:41:02 +00:00
|
|
|
|
2015-03-14 17:54:31 +00:00
|
|
|
// The constructor may change the pixel geometry based on other parameters.
|
2015-04-15 20:05:18 +00:00
|
|
|
CreateInfo(const SkImageInfo& info,
|
|
|
|
TileUsage tileUsage,
|
|
|
|
SkPixelGeometry geo,
|
|
|
|
bool forImageFilter = false)
|
2014-11-13 20:41:02 +00:00
|
|
|
: fInfo(info)
|
2015-03-14 17:54:31 +00:00
|
|
|
, fTileUsage(tileUsage)
|
|
|
|
, fPixelGeometry(AdjustGeometry(info, tileUsage, geo))
|
2015-04-15 20:05:18 +00:00
|
|
|
, fForImageFilter(forImageFilter) {}
|
2014-11-13 20:41:02 +00:00
|
|
|
|
2015-03-14 17:54:31 +00:00
|
|
|
const SkImageInfo fInfo;
|
|
|
|
const TileUsage fTileUsage;
|
|
|
|
const SkPixelGeometry fPixelGeometry;
|
2015-04-15 20:05:18 +00:00
|
|
|
const bool fForImageFilter;
|
2014-11-13 16:33:37 +00:00
|
|
|
};
|
2014-11-13 20:41:02 +00:00
|
|
|
|
2015-03-14 17:54:31 +00:00
|
|
|
/**
|
|
|
|
* Create a new device based on CreateInfo. If the paint is not null, then it represents a
|
|
|
|
* preview of how the new device will be composed with its creator device (this).
|
2015-04-29 15:34:00 +00:00
|
|
|
*
|
|
|
|
* The subclass may be handed this device in drawDevice(), so it must always return
|
|
|
|
* a device that it knows how to draw, and that it knows how to identify if it is not of the
|
|
|
|
* same subclass (since drawDevice is passed a SkBaseDevice*). If the subclass cannot fulfill
|
|
|
|
* that contract (e.g. PDF cannot support some settings on the paint) it should return NULL,
|
|
|
|
* and the caller may then decide to explicitly create a bitmapdevice, knowing that later
|
|
|
|
* it could not call drawDevice with it (but it could call drawSprite or drawBitmap).
|
2015-03-14 17:54:31 +00:00
|
|
|
*/
|
2015-03-14 11:30:21 +00:00
|
|
|
virtual SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-11-13 20:41:02 +00:00
|
|
|
virtual void initForRootLayer(SkPixelGeometry geo);
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
private:
|
2011-03-04 22:27:10 +00:00
|
|
|
friend class SkCanvas;
|
2012-10-09 22:30:18 +00:00
|
|
|
friend struct DeviceCM; //for setMatrixClip
|
2011-08-08 19:41:56 +00:00
|
|
|
friend class SkDraw;
|
|
|
|
friend class SkDrawIter;
|
|
|
|
friend class SkDeviceFilteredPaint;
|
2012-09-27 21:57:45 +00:00
|
|
|
friend class SkDeviceImageFilterProxy;
|
2014-03-12 18:28:35 +00:00
|
|
|
friend class SkDeferredDevice; // for newSurface
|
2014-11-19 16:04:34 +00:00
|
|
|
friend class SkNoPixelsBitmapDevice;
|
2011-08-08 19:41:56 +00:00
|
|
|
|
2012-08-28 12:19:02 +00:00
|
|
|
friend class SkSurface_Raster;
|
2013-08-29 11:54:56 +00:00
|
|
|
|
2012-08-28 12:19:02 +00:00
|
|
|
// used to change the backend's pixels (and possibly config/rowbytes)
|
|
|
|
// but cannot change the width/height, so there should be no change to
|
|
|
|
// any clip information.
|
2013-11-13 16:02:18 +00:00
|
|
|
// TODO: move to SkBitmapDevice
|
2014-06-27 18:34:19 +00:00
|
|
|
virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) {}
|
2012-08-28 12:19:02 +00:00
|
|
|
|
Revert of Revert of allow canvas to force conservative clips (for speed) (patchset #1 id:1 of https://codereview.chromium.org/554033003/)
Reason for revert:
May just rebaseline, plus want to see the results of the chrome tests, so re-trying this CL.
Original issue's description:
> Revert of allow canvas to force conservative clips (for speed) (patchset #7 id:120001 of https://codereview.chromium.org/541593005/)
>
> Reason for revert:
> multipicturedraw failed on nvprmsaa -- don't know why yet
>
> Original issue's description:
> > Allow SkCanvas to be initialized to force conservative rasterclips. This has the following effects:
> >
> > 1. Queries to the current clip will be conservatively large. This can mean the quickReject may return false more often.
> >
> > 2. The conservative clips mean less work is done.
> >
> > 3. Enabled by default for Gpu, Record, and NoSaveLayer canvases.
> >
> > 4. API is private for now.
> >
> > Committed: https://skia.googlesource.com/skia/+/27a5e656c3d6ef22f9cb34de18e1b960da3aa241
>
> TBR=robertphillips@google.com,bsalomon@google.com,mtklein@google.com,junov@google.com
> NOTREECHECKS=true
> NOTRY=true
>
> Committed: https://skia.googlesource.com/skia/+/6f09709519b79a1159f3826645f1c5fbc101ee11
R=robertphillips@google.com, bsalomon@google.com, mtklein@google.com, junov@google.com, reed@google.com
TBR=bsalomon@google.com, junov@google.com, mtklein@google.com, reed@google.com, robertphillips@google.com
NOTREECHECKS=true
NOTRY=true
Author: reed@chromium.org
Review URL: https://codereview.chromium.org/560713002
2014-09-10 01:46:22 +00:00
|
|
|
virtual bool forceConservativeRasterClip() const { return false; }
|
|
|
|
|
2011-10-03 19:03:48 +00:00
|
|
|
// just called by SkCanvas when built as a layer
|
|
|
|
void setOrigin(int x, int y) { fOrigin.set(x, y); }
|
2011-03-04 22:27:10 +00:00
|
|
|
|
2011-08-08 19:41:56 +00:00
|
|
|
/** Causes any deferred drawing to the device to be completed.
|
|
|
|
*/
|
2014-06-27 18:34:19 +00:00
|
|
|
virtual void flush() {}
|
2011-08-08 19:41:56 +00:00
|
|
|
|
2014-08-08 14:14:35 +00:00
|
|
|
virtual SkImageFilter::Cache* getImageFilterCache() { return NULL; }
|
2014-07-30 18:26:46 +00:00
|
|
|
|
2011-03-04 22:27:10 +00:00
|
|
|
SkIPoint fOrigin;
|
2011-03-30 21:23:07 +00:00
|
|
|
SkMetaData* fMetaData;
|
2014-09-17 17:49:38 +00:00
|
|
|
SkDeviceProperties* fLeakyProperties; // will always exist.
|
2012-06-21 20:25:03 +00:00
|
|
|
|
2012-07-13 15:36:15 +00:00
|
|
|
#ifdef SK_DEBUG
|
|
|
|
bool fAttachedToCanvas;
|
|
|
|
#endif
|
|
|
|
|
2012-06-21 20:25:03 +00:00
|
|
|
typedef SkRefCnt INHERITED;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|