Skia
2DGraphicsLibrary
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkSurface.h
1 /*
2  * Copyright 2012 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 SkSurface_DEFINED
9 #define SkSurface_DEFINED
10 
11 #include "SkRefCnt.h"
12 #include "SkImage.h"
13 #include "SkSurfaceProps.h"
14 
15 class SkCanvas;
16 class SkPaint;
18 class GrBackendSemaphore;
19 class GrContext;
20 class GrRenderTarget;
21 
32 class SK_API SkSurface : public SkRefCnt {
33 public:
43  static sk_sp<SkSurface> MakeRasterDirect(const SkImageInfo&, void* pixels, size_t rowBytes,
44  const SkSurfaceProps* = nullptr);
45 
50  static sk_sp<SkSurface> MakeRasterDirectReleaseProc(const SkImageInfo&, void* pixels, size_t rowBytes,
51  void (*releaseProc)(void* pixels, void* context),
52  void* context, const SkSurfaceProps* = nullptr);
53 
63  static sk_sp<SkSurface> MakeRaster(const SkImageInfo&, size_t rowBytes, const SkSurfaceProps*);
64 
69  const SkSurfaceProps* props = nullptr) {
70  return MakeRaster(info, 0, props);
71  }
72 
78  static sk_sp<SkSurface> MakeRasterN32Premul(int width, int height,
79  const SkSurfaceProps* props = nullptr) {
80  return MakeRaster(SkImageInfo::MakeN32Premul(width, height), props);
81  }
82 
89  static sk_sp<SkSurface> MakeFromBackendTexture(GrContext*, const GrBackendTextureDesc&,
91 
98  static sk_sp<SkSurface> MakeFromBackendTexture(GrContext*, const GrBackendTexture&,
99  GrSurfaceOrigin origin, int sampleCnt,
101 
107  static sk_sp<SkSurface> MakeFromBackendRenderTarget(GrContext*,
110  const SkSurfaceProps*);
111 
112  static sk_sp<SkSurface> MakeFromBackendRenderTarget(GrContext*,
113  const GrBackendRenderTarget&,
114  GrSurfaceOrigin origin,
116  const SkSurfaceProps*);
117 
126  static sk_sp<SkSurface> MakeFromBackendTextureAsRenderTarget(
128 
129  static sk_sp<SkSurface> MakeFromBackendTextureAsRenderTarget(GrContext*,
130  const GrBackendTexture&,
131  GrSurfaceOrigin origin,
132  int sampleCnt,
134  const SkSurfaceProps*);
135 
141  const SkSurfaceProps* props) {
142  return MakeFromBackendTexture(ctx, desc, nullptr, props);
143  }
144 
145  static sk_sp<SkSurface> MakeFromBackendRenderTarget(GrContext* ctx,
146  const GrBackendRenderTargetDesc& desc,
147  const SkSurfaceProps* props) {
148  return MakeFromBackendRenderTarget(ctx, desc, nullptr, props);
149  }
150 
151  static sk_sp<SkSurface> MakeFromBackendTextureAsRenderTarget(
152  GrContext* ctx, const GrBackendTextureDesc& desc, const SkSurfaceProps* props) {
153  return MakeFromBackendTextureAsRenderTarget(ctx, desc, nullptr, props);
154  }
155 
156 
161  static sk_sp<SkSurface> MakeRenderTarget(GrContext*, SkBudgeted, const SkImageInfo&,
162  int sampleCount, GrSurfaceOrigin,
163  const SkSurfaceProps*);
164 
165  static sk_sp<SkSurface> MakeRenderTarget(GrContext* context, SkBudgeted budgeted,
166  const SkImageInfo& info, int sampleCount,
167  const SkSurfaceProps* props) {
168  return MakeRenderTarget(context, budgeted, info, sampleCount,
169  kBottomLeft_GrSurfaceOrigin, props);
170  }
171 
172  static sk_sp<SkSurface> MakeRenderTarget(GrContext* gr, SkBudgeted b, const SkImageInfo& info) {
173  if (!info.width() || !info.height()) {
174  return nullptr;
175  }
176  return MakeRenderTarget(gr, b, info, 0, kBottomLeft_GrSurfaceOrigin, nullptr);
177  }
178 
179  int width() const { return fWidth; }
180  int height() const { return fHeight; }
181 
191  uint32_t generationID();
192 
207  };
208 
215  void notifyContentWillChange(ContentChangeMode mode);
216 
221  };
222 
223  /*
224  * These are legacy aliases which will be removed soon
225  */
226  static const BackendHandleAccess kFlushRead_TextureHandleAccess =
227  kFlushRead_BackendHandleAccess;
228  static const BackendHandleAccess kFlushWrite_TextureHandleAccess =
229  kFlushWrite_BackendHandleAccess;
230  static const BackendHandleAccess kDiscardWrite_TextureHandleAccess =
231  kDiscardWrite_BackendHandleAccess;
232 
233 
241  GrBackendObject getTextureHandle(BackendHandleAccess);
242 
249  bool getRenderTargetHandle(GrBackendObject*, BackendHandleAccess);
250 
257  SkCanvas* getCanvas();
258 
272  sk_sp<SkSurface> makeSurface(const SkImageInfo&);
273 
280  sk_sp<SkImage> makeImageSnapshot();
281 
289  void draw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*);
290 
300  bool peekPixels(SkPixmap*);
301 
320  bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
321  int srcX, int srcY);
322 
323  const SkSurfaceProps& props() const { return fProps; }
324 
331  void prepareForExternalIO();
332 
336  void flush();
337 
349  bool flushAndSignalSemaphores(int numSemaphores, GrBackendSemaphore* signalSemaphores);
350 
359  bool wait(int numSemaphores, const GrBackendSemaphore* waitSemaphores);
360 
361 protected:
362  SkSurface(int width, int height, const SkSurfaceProps*);
363  SkSurface(const SkImageInfo&, const SkSurfaceProps*);
364 
365  // called by subclass if their contents have changed
366  void dirtyGenerationID() {
367  fGenerationID = 0;
368  }
369 
370 private:
371  const SkSurfaceProps fProps;
372  const int fWidth;
373  const int fHeight;
374  uint32_t fGenerationID;
375 
376  typedef SkRefCnt INHERITED;
377 };
378 
379 #endif
A Canvas encapsulates all of the state about drawing into a device (bitmap).
Definition: SkCanvas.h:59
Definition: GrTypes.h:679
Definition: GrBackendSurface.h:67
Describe an image's dimensions and pixel type.
Definition: SkImageInfo.h:181
Describes properties and constraints of a given SkSurface.
Definition: SkSurfaceProps.h:51
Pairs SkImageInfo with actual pixels and rowbytes.
Definition: SkPixmap.h:23
SkSurface is responsible for managing the pixels that a canvas draws into.
Definition: SkSurface.h:32
static sk_sp< SkSurface > MakeRaster(const SkImageInfo &info, const SkSurfaceProps *props=nullptr)
Allocate a new surface, automatically computing the rowBytes.
Definition: SkSurface.h:68
Definition: SkRefCnt.h:125
Gr can wrap an existing render target created by the client in the 3D API with a GrRenderTarget objec...
Definition: GrTypes.h:711
The SkPaint class holds the style and color information about how to draw geometries, text and bitmaps.
Definition: SkPaint.h:45
Definition: GrBackendSurface.h:18
caller must over-write the entire backend object
Definition: SkSurface.h:220
Wrapper class for passing into and receiving data from Ganesh about a backend semaphore object...
Definition: GrBackendSemaphore.h:22
static SkImageInfo MakeN32Premul(int width, int height, sk_sp< SkColorSpace > cs=nullptr)
Sets colortype to the native ARGB32 type, and the alphatype to premul.
Definition: SkImageInfo.h:212
static sk_sp< SkSurface > MakeFromBackendTexture(GrContext *ctx, const GrBackendTextureDesc &desc, const SkSurfaceProps *props)
Legacy versions of the above factories, without color space support.
Definition: SkSurface.h:140
static sk_sp< SkSurface > MakeRasterN32Premul(int width, int height, const SkSurfaceProps *props=nullptr)
Helper version of NewRaster.
Definition: SkSurface.h:78
Shared pointer class to wrap classes that support a ref()/unref() interface.
Definition: SkRefCnt.h:246
ContentChangeMode
Modes that can be passed to notifyContentWillChange.
Definition: SkSurface.h:196
Definition: GrContext.h:47
Use this mode if prior surface contents need to be preserved or if in doubt.
Definition: SkSurface.h:206
caller may read from the backend object
Definition: SkSurface.h:218
Use this mode if it is known that the upcoming content changes will clear or overwrite prior contents...
Definition: SkSurface.h:201
GrRenderTarget represents a 2D buffer of pixels that can be rendered to.
Definition: GrRenderTarget.h:26
caller may write to the backend object
Definition: SkSurface.h:219
BackendHandleAccess
Definition: SkSurface.h:217