aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkSpecialSurface.h
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2016-02-04 10:52:42 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-02-04 10:52:42 -0800
commitb6c65e99956b867e24bd5bd68ae37673a9fd4b27 (patch)
treecb320967a3e8253a1100881942b540594f33315d /src/core/SkSpecialSurface.h
parent7471c780d48afd4dc02ed45c60a2fd2efa9e5a84 (diff)
Add SkSpecialImage & SkSpecialSurface classes
Diffstat (limited to 'src/core/SkSpecialSurface.h')
-rw-r--r--src/core/SkSpecialSurface.h93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/core/SkSpecialSurface.h b/src/core/SkSpecialSurface.h
new file mode 100644
index 0000000000..2751c4a794
--- /dev/null
+++ b/src/core/SkSpecialSurface.h
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file
+ */
+
+#ifndef SkSpecialSurface_DEFINED
+#define SkSpecialSurface_DEFINED
+
+#include "SkRefCnt.h"
+#include "SkSurfaceProps.h"
+
+class GrContext;
+struct GrSurfaceDesc;
+class SkCanvas;
+struct SkImageInfo;
+class SkSpecialImage;
+
+/**
+ * SkSpecialSurface is a restricted form of SkSurface solely for internal use. It differs
+ * from SkSurface in that:
+ * - it can be backed by GrTextures larger than [ fWidth, fHeight ]
+ * - it can't be used for tiling
+ * - it becomes inactive once a snapshot of it is taken (i.e., no copy-on-write)
+ * - it has no generation ID
+ */
+class SkSpecialSurface : public SkRefCnt {
+public:
+ const SkSurfaceProps& props() const { return fProps; }
+
+ int width() const { return fSubset.width(); }
+ int height() const { return fSubset.height(); }
+
+ /**
+ * Return a canvas that will draw into this surface. This will always
+ * return the same canvas for a given surface, and is managed/owned by the
+ * surface.
+ *
+ * The canvas will be invalid after 'newImageSnapshot' is called.
+ */
+ SkCanvas* getCanvas();
+
+ /**
+ * Returns an image of the current state of the surface pixels up to this
+ * point. The canvas returned by 'getCanvas' becomes invalidated by this
+ * call and no more drawing to this surface is allowed.
+ */
+ SkSpecialImage* newImageSnapshot();
+
+ /**
+ * Use an existing (renderTarget-capable) GrTexture as the backing store.
+ */
+ static SkSpecialSurface* NewFromTexture(const SkIRect& subset, GrTexture*,
+ const SkSurfaceProps* = nullptr);
+
+ /**
+ * Allocate a new GPU-backed SkSpecialSurface. If the requested surface cannot
+ * be created, nullptr will be returned.
+ */
+ static SkSpecialSurface* NewRenderTarget(GrContext*, const GrSurfaceDesc&,
+ const SkSurfaceProps* = nullptr);
+
+ /**
+ * Use and existing SkBitmap as the backing store.
+ */
+ static SkSpecialSurface* NewFromBitmap(const SkIRect& subset, SkBitmap& bm,
+ const SkSurfaceProps* = nullptr);
+
+ /**
+ * Return a new CPU-backed surface, with the memory for the pixels automatically
+ * allocated.
+ *
+ * If the requested surface cannot be created, or the request is not a
+ * supported configuration, nullptr will be returned.
+ */
+ static SkSpecialSurface* NewRaster(const SkImageInfo&, const SkSurfaceProps* = nullptr);
+
+protected:
+ SkSpecialSurface(const SkIRect& subset, const SkSurfaceProps*);
+
+ // For testing only
+ friend class TestingSpecialSurfaceAccess;
+ const SkIRect& subset() const { return fSubset; }
+
+private:
+ const SkSurfaceProps fProps;
+ const SkIRect fSubset;
+
+ typedef SkRefCnt INHERITED;
+};
+
+#endif