2013-08-21 13:54:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkBitmapDevice_DEFINED
|
|
|
|
#define SkBitmapDevice_DEFINED
|
|
|
|
|
2015-08-05 20:57:49 +00:00
|
|
|
#include "SkBitmap.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkColor.h"
|
2013-08-21 13:54:44 +00:00
|
|
|
#include "SkDevice.h"
|
2015-08-05 20:57:49 +00:00
|
|
|
#include "SkImageFilter.h"
|
|
|
|
#include "SkImageInfo.h"
|
|
|
|
#include "SkRect.h"
|
|
|
|
#include "SkScalar.h"
|
|
|
|
#include "SkSize.h"
|
|
|
|
#include "SkSurfaceProps.h"
|
|
|
|
#include "SkTypes.h"
|
|
|
|
|
|
|
|
class SkDraw;
|
|
|
|
class SkMatrix;
|
|
|
|
class SkPaint;
|
|
|
|
class SkPath;
|
|
|
|
class SkPixelRef;
|
|
|
|
class SkPixmap;
|
|
|
|
class SkRRect;
|
|
|
|
class SkSurface;
|
|
|
|
class SkXfermode;
|
|
|
|
struct SkPoint;
|
2013-08-21 13:54:44 +00:00
|
|
|
|
2013-08-29 11:54:56 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
class SK_API SkBitmapDevice : public SkBaseDevice {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Construct a new device with the specified bitmap as its backend. It is
|
|
|
|
* valid for the bitmap to have no pixels associated with it. In that case,
|
|
|
|
* any drawing to this device will have no effect.
|
2015-06-22 16:46:59 +00:00
|
|
|
*/
|
2013-08-29 11:54:56 +00:00
|
|
|
SkBitmapDevice(const SkBitmap& bitmap);
|
2015-06-22 16:46:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new device along with its requisite pixel memory using
|
|
|
|
* default SkSurfaceProps (i.e., kLegacyFontHost_InitType-style).
|
|
|
|
* Note: this entry point is slated for removal - no one should call it.
|
|
|
|
*/
|
|
|
|
static SkBitmapDevice* Create(const SkImageInfo& info);
|
|
|
|
|
2013-08-29 11:54:56 +00:00
|
|
|
/**
|
|
|
|
* Construct a new device with the specified bitmap as its backend. It is
|
|
|
|
* valid for the bitmap to have no pixels associated with it. In that case,
|
|
|
|
* any drawing to this device will have no effect.
|
2015-06-22 16:46:59 +00:00
|
|
|
*/
|
2015-06-19 18:49:52 +00:00
|
|
|
SkBitmapDevice(const SkBitmap& bitmap, const SkSurfaceProps& surfaceProps);
|
2015-06-22 16:46:59 +00:00
|
|
|
|
|
|
|
static SkBitmapDevice* Create(const SkImageInfo&, const SkSurfaceProps&);
|
2013-08-29 11:54:56 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkImageInfo imageInfo() const override;
|
2014-02-13 17:14:46 +00:00
|
|
|
|
2013-08-29 11:54:56 +00:00
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
bool onShouldDisableLCD(const SkPaint&) const override;
|
2013-08-29 11:54:56 +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.
|
|
|
|
*/
|
2015-03-26 01:17:31 +00:00
|
|
|
void drawPaint(const SkDraw&, const SkPaint& paint) override;
|
2013-08-29 11:54:56 +00:00
|
|
|
virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count,
|
2015-03-26 01:17:31 +00:00
|
|
|
const SkPoint[], const SkPaint& paint) override;
|
2013-08-29 11:54:56 +00:00
|
|
|
virtual void drawRect(const SkDraw&, const SkRect& r,
|
2015-03-26 01:17:31 +00:00
|
|
|
const SkPaint& paint) override;
|
2013-08-29 11:54:56 +00:00
|
|
|
virtual void drawOval(const SkDraw&, const SkRect& oval,
|
2015-03-26 01:17:31 +00:00
|
|
|
const SkPaint& paint) override;
|
2013-08-29 11:54:56 +00:00
|
|
|
virtual void drawRRect(const SkDraw&, const SkRRect& rr,
|
2015-03-26 01:17:31 +00:00
|
|
|
const SkPaint& paint) override;
|
2013-08-29 11:54:56 +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.
|
|
|
|
*/
|
|
|
|
virtual void drawPath(const SkDraw&, const SkPath& path,
|
|
|
|
const SkPaint& paint,
|
|
|
|
const SkMatrix* prePathMatrix = NULL,
|
2015-03-26 01:17:31 +00:00
|
|
|
bool pathIsMutable = false) override;
|
2013-08-29 11:54:56 +00:00
|
|
|
virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
|
2015-03-26 01:17:31 +00:00
|
|
|
const SkMatrix& matrix, const SkPaint& paint) override;
|
2013-08-29 11:54:56 +00:00
|
|
|
virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap,
|
2015-03-26 01:17:31 +00:00
|
|
|
int x, int y, const SkPaint& paint) override;
|
2013-08-29 11:54:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The default impl. will create a bitmap-shader from the bitmap,
|
|
|
|
* and call drawRect with it.
|
|
|
|
*/
|
2015-07-14 17:54:12 +00:00
|
|
|
void drawBitmapRect(const SkDraw&, const SkBitmap&, const SkRect*, const SkRect&,
|
2015-07-28 14:35:14 +00:00
|
|
|
const SkPaint&, SkCanvas::SrcRectConstraint) override;
|
2013-08-29 11:54:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Does not handle text decoration.
|
|
|
|
* Decorations (underline and stike-thru) will be handled by SkCanvas.
|
|
|
|
*/
|
|
|
|
virtual void drawText(const SkDraw&, const void* text, size_t len,
|
2015-03-26 01:17:31 +00:00
|
|
|
SkScalar x, SkScalar y, const SkPaint& paint) override;
|
2013-08-29 11:54:56 +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,
|
2015-03-26 01:17:31 +00:00
|
|
|
const SkPoint& offset, const SkPaint& paint) override;
|
2013-08-29 11:54:56 +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,
|
2015-03-26 01:17:31 +00:00
|
|
|
const SkPaint& paint) override;
|
|
|
|
virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, const SkPaint&) override;
|
2013-08-29 11:54:56 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/** Update as needed the pixel value in the bitmap, so that the caller can
|
|
|
|
access the pixels directly. Note: only the pixels field should be
|
|
|
|
altered. The config/width/height/rowbytes must remain unchanged.
|
|
|
|
@return the device contents as a bitmap
|
|
|
|
*/
|
2015-03-26 01:17:31 +00:00
|
|
|
const SkBitmap& onAccessBitmap() override;
|
2013-08-29 11:54:56 +00:00
|
|
|
|
|
|
|
SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); }
|
|
|
|
// just for subclasses, to assign a custom pixelref
|
2014-01-08 15:42:01 +00:00
|
|
|
SkPixelRef* setPixelRef(SkPixelRef* pr) {
|
|
|
|
fBitmap.setPixelRef(pr);
|
2013-08-29 11:54:56 +00:00
|
|
|
return pr;
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool onReadPixels(const SkImageInfo&, void*, size_t, int x, int y) override;
|
|
|
|
bool onWritePixels(const SkImageInfo&, const void*, size_t, int, int) override;
|
2015-05-26 18:31:54 +00:00
|
|
|
bool onPeekPixels(SkPixmap*) override;
|
|
|
|
bool onAccessPixels(SkPixmap*) override;
|
2015-05-26 04:21:27 +00:00
|
|
|
void onAttachToCanvas(SkCanvas*) override;
|
|
|
|
void onDetachFromCanvas() override;
|
2013-08-29 11:54:56 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class SkCanvas;
|
|
|
|
friend struct DeviceCM; //for setMatrixClip
|
|
|
|
friend class SkDraw;
|
|
|
|
friend class SkDrawIter;
|
|
|
|
friend class SkDeviceFilteredPaint;
|
|
|
|
|
|
|
|
friend class SkSurface_Raster;
|
|
|
|
|
|
|
|
// 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.
|
2015-03-26 01:17:31 +00:00
|
|
|
void replaceBitmapBackendForRasterSurface(const SkBitmap&) override;
|
2013-08-29 11:54:56 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override;
|
2013-08-29 11:54:56 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) override;
|
2014-02-05 15:32:21 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkImageFilter::Cache* getImageFilterCache() override;
|
2014-07-30 18:26:46 +00:00
|
|
|
|
2013-08-29 11:54:56 +00:00
|
|
|
SkBitmap fBitmap;
|
|
|
|
|
2015-04-08 18:25:48 +00:00
|
|
|
void setNewSize(const SkISize&); // Used by SkCanvas for resetForNextPicture().
|
|
|
|
|
2013-08-29 11:54:56 +00:00
|
|
|
typedef SkBaseDevice INHERITED;
|
|
|
|
};
|
2013-08-21 13:54:44 +00:00
|
|
|
|
|
|
|
#endif // SkBitmapDevice_DEFINED
|