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 */ 26 int width() const { return fWidth; } 27 28 /** 29 * Retrieves the height of the surface. 30 */ 31 int height() const { return fHeight; } 32 33 /** 34 * Helper that gets the width and height of the surface as a bounding rectangle. 35 */ 36 SkRect getBoundsRect() const { return SkRect::MakeIWH(this->width(), this->height()); } 37 38 /** 39 * Retrieves the pixel config specified when the surface was created. 40 * For render targets this can be kUnknown_GrPixelConfig 41 * if client asked us to render to a target that has a pixel 42 * config that isn't equivalent with one of our configs. 43 */ 44 GrPixelConfig config() const { return fConfig; } 45 46 /** 47 * @return the texture associated with the surface, may be null. 48 */ 49 virtual GrTexture* asTexture() { return nullptr; } 50 virtual const GrTexture* asTexture() const { return nullptr; } 51 52 /** 53 * @return the render target underlying this surface, may be null. 54 */ 55 virtual GrRenderTarget* asRenderTarget() { return nullptr; } 56 virtual const GrRenderTarget* asRenderTarget() const { return nullptr; } 57 58 /** Access methods that are only to be used within Skia code. */ 59 inline GrSurfacePriv surfacePriv(); 60 inline const GrSurfacePriv surfacePriv() const; 61 62 static size_t WorstCaseSize(const GrSurfaceDesc& desc, bool useNextPow2 = false); 63 static size_t ComputeSize(GrPixelConfig config, int width, int height, int colorSamplesPerPixel, 64 GrMipMapped, bool useNextPow2 = false); 65 66 protected: 67 // Methods made available via GrSurfacePriv 68 bool hasPendingRead() const; 69 bool hasPendingWrite() const; 70 bool hasPendingIO() const; 71 72 // Provides access to methods that should be public within Skia code. 73 friend class GrSurfacePriv; 74 75 GrSurface(GrGpu* gpu, const GrSurfaceDesc& desc) 76 : INHERITED(gpu) 77 , fConfig(desc.fConfig) 78 , fWidth(desc.fWidth) 79 , fHeight(desc.fHeight) {} 80 ~GrSurface() override {} 81 82 83 void onRelease() override; 84 void onAbandon() override; 85 86 private: 87 GrPixelConfig fConfig; 88 int fWidth; 89 int fHeight; 90 91 typedef GrGpuResource INHERITED; 92 }; 93 94 #endif 95