| 1 |
/* |
| 2 |
* Copyright 2013 Google Inc. |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#ifndef SkBitmapDevice_DEFINED |
| 9 |
#define SkBitmapDevice_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkBitmap.h" |
| 12 |
#include "include/core/SkCanvas.h" |
| 13 |
#include "include/core/SkColor.h" |
| 14 |
#include "include/core/SkRect.h" |
| 15 |
#include "include/core/SkRefCnt.h" |
| 16 |
#include "include/core/SkSamplingOptions.h" |
| 17 |
#include "include/core/SkSpan.h" |
| 18 |
#include "src/core/SkCPURecorderImpl.h" |
| 19 |
#include "src/core/SkDevice.h" |
| 20 |
#include "src/core/SkGlyphRunPainter.h" |
| 21 |
#include "src/core/SkRasterClipStack.h" |
| 22 |
|
| 23 |
class SkBlender; |
| 24 |
class SkImage; |
| 25 |
class SkMatrix; |
| 26 |
class SkMesh; |
| 27 |
class SkMipmap; |
| 28 |
class SkPaint; |
| 29 |
class SkPath; |
| 30 |
class SkPixmap; |
| 31 |
class SkRRect; |
| 32 |
class SkRasterHandleAllocator; |
| 33 |
class SkRecorder; |
| 34 |
class SkRegion; |
| 35 |
class SkShader; |
| 36 |
class SkSpecialImage; |
| 37 |
class SkSurface; |
| 38 |
class SkSurfaceProps; |
| 39 |
class SkVertices; |
| 40 |
enum class SkClipOp; |
| 41 |
struct SkImageInfo; |
| 42 |
struct SkPoint; |
| 43 |
struct SkRSXform; |
| 44 |
namespace sktext { class GlyphRunList; } |
| 45 |
|
| 46 |
/////////////////////////////////////////////////////////////////////////////// |
| 47 |
class SkBitmapDevice final : public SkDevice { |
| 48 |
public: |
| 49 |
/** |
| 50 |
* Construct a new device with the specified bitmap as its backend. It is |
| 51 |
* valid for the bitmap to have no pixels associated with it. In that case, |
| 52 |
* any drawing to this device will have no effect. |
| 53 |
*/ |
| 54 |
explicit SkBitmapDevice(const SkBitmap& bitmap); |
| 55 |
|
| 56 |
/** |
| 57 |
* Construct a new device with the specified bitmap as its backend. It is |
| 58 |
* valid for the bitmap to have no pixels associated with it. In that case, |
| 59 |
* any drawing to this device will have no effect. |
| 60 |
*/ |
| 61 |
SkBitmapDevice(const SkBitmap& bitmap, const SkSurfaceProps& surfaceProps, |
| 62 |
void* externalHandle = nullptr); |
| 63 |
|
| 64 |
SkBitmapDevice(skcpu::RecorderImpl*, const SkBitmap& bitmap); |
| 65 |
SkBitmapDevice(skcpu::RecorderImpl*, |
| 66 |
const SkBitmap& bitmap, |
| 67 |
const SkSurfaceProps& surfaceProps, |
| 68 |
void* externalHandle = nullptr); |
| 69 |
|
| 70 |
static sk_sp<SkBitmapDevice> Create(const SkImageInfo&, const SkSurfaceProps&, |
| 71 |
SkRasterHandleAllocator* = nullptr); |
| 72 |
|
| 73 |
void drawPaint(const SkPaint& paint) override; |
| 74 |
void drawPoints(SkCanvas::PointMode, SkSpan<const SkPoint>, const SkPaint&) override; |
| 75 |
void drawRect(const SkRect& r, const SkPaint& paint) override; |
| 76 |
void drawOval(const SkRect& oval, const SkPaint& paint) override; |
| 77 |
void drawRRect(const SkRRect& rr, const SkPaint& paint) override; |
| 78 |
|
| 79 |
void drawPath(const SkPath&, const SkPaint&) override; |
| 80 |
|
| 81 |
void drawImageRect(const SkImage*, const SkRect* src, const SkRect& dst, |
| 82 |
const SkSamplingOptions&, const SkPaint&, |
| 83 |
SkCanvas::SrcRectConstraint) override; |
| 84 |
|
| 85 |
void drawVertices(const SkVertices*, sk_sp<SkBlender>, const SkPaint&, bool) override; |
| 86 |
// Implemented in src/sksl/SkBitmapDevice_mesh.cpp |
| 87 |
void drawMesh(const SkMesh&, sk_sp<SkBlender>, const SkPaint&) override; |
| 88 |
|
| 89 |
void drawAtlas(SkSpan<const SkRSXform>, SkSpan<const SkRect>, SkSpan<const SkColor>, |
| 90 |
sk_sp<SkBlender>, const SkPaint&) override; |
| 91 |
|
| 92 |
/////////////////////////////////////////////////////////////////////////// |
| 93 |
|
| 94 |
void pushClipStack() override; |
| 95 |
void popClipStack() override; |
| 96 |
void clipRect(const SkRect& rect, SkClipOp, bool aa) override; |
| 97 |
void clipRRect(const SkRRect& rrect, SkClipOp, bool aa) override; |
| 98 |
void clipPath(const SkPath& path, SkClipOp, bool aa) override; |
| 99 |
void clipRegion(const SkRegion& deviceRgn, SkClipOp) override; |
| 100 |
void replaceClip(const SkIRect& rect) override; |
| 101 |
bool isClipAntiAliased() const override; |
| 102 |
bool isClipEmpty() const override; |
| 103 |
bool isClipRect() const override; |
| 104 |
bool isClipWideOpen() const override; |
| 105 |
void android_utils_clipAsRgn(SkRegion*) const override; |
| 106 |
SkIRect devClipBounds() const override; |
| 107 |
|
| 108 |
/////////////////////////////////////////////////////////////////////////// |
| 109 |
|
| 110 |
void drawSpecial(SkSpecialImage*, const SkMatrix&, const SkSamplingOptions&, |
| 111 |
const SkPaint&, SkCanvas::SrcRectConstraint) override; |
| 112 |
|
| 113 |
void drawCoverageMask(const SkSpecialImage*, const SkMatrix&, const SkSamplingOptions&, |
| 114 |
const SkPaint&) override; |
| 115 |
|
| 116 |
bool drawBlurredRRect(const SkRRect&, const SkPaint&, float) override; |
| 117 |
|
| 118 |
sk_sp<SkSpecialImage> snapSpecial(const SkIRect&, bool forceCopy = false) override; |
| 119 |
|
| 120 |
sk_sp<SkDevice> createDevice(const CreateInfo&, const SkPaint*) override; |
| 121 |
|
| 122 |
sk_sp<SkSurface> makeSurface(const SkImageInfo&, const SkSurfaceProps&) override; |
| 123 |
|
| 124 |
void setImmutable() override { fBitmap.setImmutable(); } |
| 125 |
|
| 126 |
void* getRasterHandle() const override { return fRasterHandle; } |
| 127 |
|
| 128 |
SkRecorder* baseRecorder() const override { return fRecorder; } |
| 129 |
|
| 130 |
private: |
| 131 |
friend class SkDrawTiler; |
| 132 |
friend class SkSurface_Raster; |
| 133 |
|
| 134 |
class BDDraw; |
| 135 |
|
| 136 |
// Used to change the backend's pixels (and possibly config/rowbytes) but cannot change the |
| 137 |
// width/height, so there should be no change to any clip information. |
| 138 |
void replaceBitmapBackendForRasterSurface(const SkBitmap&); |
| 139 |
|
| 140 |
void onClipShader(sk_sp<SkShader>) override; |
| 141 |
|
| 142 |
void onDrawGlyphRunList(SkCanvas*, const sktext::GlyphRunList&, const SkPaint& paint) override; |
| 143 |
|
| 144 |
bool onReadPixels(const SkPixmap&, int x, int y) override; |
| 145 |
bool onWritePixels(const SkPixmap&, int, int) override; |
| 146 |
bool onPeekPixels(SkPixmap*) override; |
| 147 |
bool onAccessPixels(SkPixmap*) override; |
| 148 |
|
| 149 |
void drawBitmap(const SkBitmap&, |
| 150 |
const SkMatrix&, |
| 151 |
const SkRect* dstOrNull, |
| 152 |
const SkSamplingOptions&, |
| 153 |
const SkPaint&, |
| 154 |
sk_sp<SkMipmap>); |
| 155 |
|
| 156 |
void* fRasterHandle = nullptr; |
| 157 |
skcpu::RecorderImpl* fRecorder = nullptr; |
| 158 |
SkBitmap fBitmap; |
| 159 |
SkRasterClipStack fRCStack; |
| 160 |
skcpu::GlyphRunListPainter fGlyphPainter; |
| 161 |
}; |
| 162 |
|
| 163 |
#endif // SkBitmapDevice_DEFINED |