Skia
2DGraphicsLibrary
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GrSurface.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 
9 #ifndef GrSurface_DEFINED
10 #define GrSurface_DEFINED
11 
12 #include "GrTypes.h"
13 #include "GrGpuResource.h"
14 #include "SkImageInfo.h"
15 #include "SkRect.h"
16 
17 class GrRenderTarget;
18 class GrSurfacePriv;
19 class GrTexture;
20 
21 class SK_API GrSurface : public GrGpuResource {
22 public:
26  int width() const { return fWidth; }
27 
31  int height() const { return fHeight; }
32 
36  SkRect getBoundsRect() const { return SkRect::MakeIWH(this->width(), this->height()); }
37 
38  GrSurfaceOrigin origin() const {
39  SkASSERT(kTopLeft_GrSurfaceOrigin == fOrigin || kBottomLeft_GrSurfaceOrigin == fOrigin);
40  return fOrigin;
41  }
42 
49  GrPixelConfig config() const { return fConfig; }
50 
54  virtual GrTexture* asTexture() { return nullptr; }
55  virtual const GrTexture* asTexture() const { return nullptr; }
56 
60  virtual GrRenderTarget* asRenderTarget() { return nullptr; }
61  virtual const GrRenderTarget* asRenderTarget() const { return nullptr; }
62 
64  inline GrSurfacePriv surfacePriv();
65  inline const GrSurfacePriv surfacePriv() const;
66 
67  static size_t WorstCaseSize(const GrSurfaceDesc& desc, bool useNextPow2 = false);
68  static size_t ComputeSize(GrPixelConfig config, int width, int height, int colorSamplesPerPixel,
69  bool hasMIPMaps, bool useNextPow2 = false);
70 
71 protected:
72  // Methods made available via GrSurfacePriv
73  bool hasPendingRead() const;
74  bool hasPendingWrite() const;
75  bool hasPendingIO() const;
76 
77  // Provides access to methods that should be public within Skia code.
78  friend class GrSurfacePriv;
79 
80  GrSurface(GrGpu* gpu, const GrSurfaceDesc& desc)
81  : INHERITED(gpu)
82  , fConfig(desc.fConfig)
83  , fWidth(desc.fWidth)
84  , fHeight(desc.fHeight)
85  , fOrigin(desc.fOrigin) {}
86  ~GrSurface() override {}
87 
88 
89  void onRelease() override;
90  void onAbandon() override;
91 
92 private:
93  GrPixelConfig fConfig;
94  int fWidth;
95  int fHeight;
96  GrSurfaceOrigin fOrigin;
97 
98  typedef GrGpuResource INHERITED;
99 };
100 
101 #endif
Base class for objects that can be kept in the GrResourceCache.
Definition: GrGpuResource.h:144
virtual void onAbandon()
Overridden to abandon any internal handles, ptrs, etc to backend API resources.
Definition: GrGpuResource.h:273
Describes a surface to be created.
Definition: GrTypes.h:589
virtual void onRelease()
Overridden to free GPU resources in the backend API.
Definition: GrGpuResource.h:269
virtual GrRenderTarget * asRenderTarget()
Definition: GrSurface.h:60
virtual GrTexture * asTexture()
Definition: GrSurface.h:54
Definition: GrSurface.h:21
int width() const
Retrieves the width of the surface.
Definition: GrSurface.h:26
SkRect getBoundsRect() const
Helper that gets the width and height of the surface as a bounding rectangle.
Definition: GrSurface.h:36
int height() const
Retrieves the height of the surface.
Definition: GrSurface.h:31
Definition: SkRect.h:404
GrPixelConfig config() const
Retrieves the pixel config specified when the surface was created.
Definition: GrSurface.h:49
GrRenderTarget represents a 2D buffer of pixels that can be rendered to.
Definition: GrRenderTarget.h:26
Definition: GrTexture.h:19