aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkBitmapDevice.h
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-01-12 22:27:57 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-01-17 21:11:46 +0000
commit98420d0c9b5934d6b08ea994844476ddedd23de0 (patch)
treea61397f482943a7293c3602ee38a4d7bd316e187 /src/core/SkBitmapDevice.h
parentad29aeeb768c048bb2f1229db8f3b7100a91ac42 (diff)
move device headers to core
CANNOT LAND until we update lots of call-sites BUG=skia: Change-Id: Ibb957dbbf5baf2a2920887e48c03709d1f6c51e1 Reviewed-on: https://skia-review.googlesource.com/6982 Commit-Queue: Mike Reed <reed@google.com> Reviewed-by: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'src/core/SkBitmapDevice.h')
-rw-r--r--src/core/SkBitmapDevice.h186
1 files changed, 186 insertions, 0 deletions
diff --git a/src/core/SkBitmapDevice.h b/src/core/SkBitmapDevice.h
new file mode 100644
index 0000000000..776b6a0dec
--- /dev/null
+++ b/src/core/SkBitmapDevice.h
@@ -0,0 +1,186 @@
+
+/*
+ * 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
+
+#include "SkBitmap.h"
+#include "SkCanvas.h"
+#include "SkColor.h"
+#include "SkDevice.h"
+#include "SkImageInfo.h"
+#include "SkPixelRef.h"
+#include "SkRect.h"
+#include "SkScalar.h"
+#include "SkSize.h"
+#include "SkSurfaceProps.h"
+#include "SkTypes.h"
+
+class SkDraw;
+class SkImageFilterCache;
+class SkMatrix;
+class SkPaint;
+class SkPath;
+class SkPixelRef;
+class SkPixmap;
+class SkRasterHandleAllocator;
+class SkRRect;
+class SkSurface;
+struct SkPoint;
+
+///////////////////////////////////////////////////////////////////////////////
+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.
+ */
+ SkBitmapDevice(const SkBitmap& bitmap);
+
+ /**
+ * 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);
+
+ /**
+ * 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.
+ */
+ SkBitmapDevice(const SkBitmap& bitmap, const SkSurfaceProps& surfaceProps,
+ void* externalHandle = nullptr);
+
+ static SkBitmapDevice* Create(const SkImageInfo&, const SkSurfaceProps&,
+ SkRasterHandleAllocator* = nullptr);
+
+protected:
+ bool onShouldDisableLCD(const SkPaint&) const override;
+ void* getRasterHandle() const override { return fRasterHandle; }
+
+ /** 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.
+ */
+ void drawPaint(const SkDraw&, const SkPaint& paint) override;
+ virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count,
+ const SkPoint[], const SkPaint& paint) override;
+ virtual void drawRect(const SkDraw&, const SkRect& r,
+ const SkPaint& paint) override;
+ virtual void drawOval(const SkDraw&, const SkRect& oval,
+ const SkPaint& paint) override;
+ virtual void drawRRect(const SkDraw&, const SkRRect& rr,
+ const SkPaint& paint) override;
+
+ /**
+ * 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,
+ bool pathIsMutable = false) override;
+ virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
+ const SkMatrix& matrix, const SkPaint& paint) override;
+ virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap,
+ int x, int y, const SkPaint& paint) override;
+
+ /**
+ * The default impl. will create a bitmap-shader from the bitmap,
+ * and call drawRect with it.
+ */
+ void drawBitmapRect(const SkDraw&, const SkBitmap&, const SkRect*, const SkRect&,
+ const SkPaint&, SkCanvas::SrcRectConstraint) override;
+
+ /**
+ * 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,
+ SkScalar x, SkScalar y, const SkPaint& paint) override;
+ virtual void drawPosText(const SkDraw&, const void* text, size_t len,
+ const SkScalar pos[], int scalarsPerPos,
+ const SkPoint& offset, const SkPaint& paint) override;
+ virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCount,
+ const SkPoint verts[], const SkPoint texs[],
+ const SkColor colors[], SkBlendMode,
+ const uint16_t indices[], int indexCount,
+ const SkPaint& paint) override;
+ virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, const SkPaint&) override;
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ void drawSpecial(const SkDraw&, SkSpecialImage*, int x, int y, const SkPaint&) override;
+ sk_sp<SkSpecialImage> makeSpecial(const SkBitmap&) override;
+ sk_sp<SkSpecialImage> makeSpecial(const SkImage*) override;
+ sk_sp<SkSpecialImage> snapSpecial() override;
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ /** 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
+ */
+#ifdef SK_SUPPORT_LEGACY_ACCESSBITMAP
+ const SkBitmap& onAccessBitmap() override;
+#else
+ const SkBitmap& onAccessBitmap();
+#endif
+
+ SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); }
+ // just for subclasses, to assign a custom pixelref
+ void setPixelRef(sk_sp<SkPixelRef> pr) { fBitmap.setPixelRef(std::move(pr), 0, 0); }
+#ifdef SK_SUPPORT_LEGACY_BITMAP_SETPIXELREF
+ SkPixelRef* setPixelRef(SkPixelRef* pr) { return fBitmap.setPixelRef(pr); }
+#endif
+
+ bool onReadPixels(const SkImageInfo&, void*, size_t, int x, int y) override;
+ bool onWritePixels(const SkImageInfo&, const void*, size_t, int, int) override;
+ bool onPeekPixels(SkPixmap*) override;
+ bool onAccessPixels(SkPixmap*) override;
+
+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.
+ void replaceBitmapBackendForRasterSurface(const SkBitmap&) override;
+
+ SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override;
+
+ sk_sp<SkSurface> makeSurface(const SkImageInfo&, const SkSurfaceProps&) override;
+
+ SkImageFilterCache* getImageFilterCache() override;
+
+ SkBitmap fBitmap;
+ void* fRasterHandle = nullptr;
+
+ void setNewSize(const SkISize&); // Used by SkCanvas for resetForNextPicture().
+
+ typedef SkBaseDevice INHERITED;
+};
+
+#endif // SkBitmapDevice_DEFINED