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: 23 /** 24 * Retrieves the width of the surface. 25 */ width()26 int width() const { return fWidth; } 27 28 /** 29 * Retrieves the height of the surface. 30 */ height()31 int height() const { return fHeight; } 32 33 /** 34 * Helper that gets the width and height of the surface as a bounding rectangle. 35 */ getBoundsRect()36 SkRect getBoundsRect() const { return SkRect::MakeIWH(this->width(), this->height()); } 37 origin()38 GrSurfaceOrigin origin() const { 39 SkASSERT(kTopLeft_GrSurfaceOrigin == fOrigin || kBottomLeft_GrSurfaceOrigin == fOrigin); 40 return fOrigin; 41 } 42 43 /** 44 * Retrieves the pixel config specified when the surface was created. 45 * For render targets this can be kUnknown_GrPixelConfig 46 * if client asked us to render to a target that has a pixel 47 * config that isn't equivalent with one of our configs. 48 */ config()49 GrPixelConfig config() const { return fConfig; } 50 51 /** 52 * @return the texture associated with the surface, may be null. 53 */ asTexture()54 virtual GrTexture* asTexture() { return nullptr; } asTexture()55 virtual const GrTexture* asTexture() const { return nullptr; } 56 57 /** 58 * @return the render target underlying this surface, may be null. 59 */ asRenderTarget()60 virtual GrRenderTarget* asRenderTarget() { return nullptr; } asRenderTarget()61 virtual const GrRenderTarget* asRenderTarget() const { return nullptr; } 62 63 /** Access methods that are only to be used within Skia code. */ 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 GrSurface(GrGpu * gpu,const GrSurfaceDesc & desc)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) {} ~GrSurface()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 102