| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 | 8 |
| 9 #ifndef GrSurface_DEFINED | 9 #ifndef GrSurface_DEFINED |
| 10 #define GrSurface_DEFINED | 10 #define GrSurface_DEFINED |
| 11 | 11 |
| 12 #include "GrTypes.h" | 12 #include "GrTypes.h" |
| 13 #include "GrGpuResource.h" | 13 #include "GrGpuResource.h" |
| 14 #include "SkImageInfo.h" | |
| 15 #include "SkRect.h" | 14 #include "SkRect.h" |
| 16 | 15 |
| 16 class GrTexture; |
| 17 class GrRenderTarget; | 17 class GrRenderTarget; |
| 18 class GrSurfacePriv; | 18 struct SkImageInfo; |
| 19 class GrTexture; | |
| 20 | 19 |
| 21 class GrSurface : public GrGpuResource { | 20 class GrSurface : public GrGpuResource { |
| 22 public: | 21 public: |
| 23 SK_DECLARE_INST_COUNT(GrSurface); | 22 SK_DECLARE_INST_COUNT(GrSurface); |
| 24 | 23 |
| 25 /** | 24 /** |
| 26 * Retrieves the width of the surface. | 25 * Retrieves the width of the surface. |
| 27 * | 26 * |
| 28 * @return the width in texels | 27 * @return the width in texels |
| 29 */ | 28 */ |
| (...skipping 23 matching lines...) Expand all Loading... |
| 53 * if client asked us to render to a target that has a pixel | 52 * if client asked us to render to a target that has a pixel |
| 54 * config that isn't equivalent with one of our configs. | 53 * config that isn't equivalent with one of our configs. |
| 55 */ | 54 */ |
| 56 GrPixelConfig config() const { return fDesc.fConfig; } | 55 GrPixelConfig config() const { return fDesc.fConfig; } |
| 57 | 56 |
| 58 /** | 57 /** |
| 59 * Return the descriptor describing the surface | 58 * Return the descriptor describing the surface |
| 60 */ | 59 */ |
| 61 const GrTextureDesc& desc() const { return fDesc; } | 60 const GrTextureDesc& desc() const { return fDesc; } |
| 62 | 61 |
| 62 SkImageInfo info() const; |
| 63 |
| 63 /** | 64 /** |
| 64 * @return the texture associated with the surface, may be NULL. | 65 * @return the texture associated with the surface, may be NULL. |
| 65 */ | 66 */ |
| 66 virtual GrTexture* asTexture() = 0; | 67 virtual GrTexture* asTexture() = 0; |
| 67 virtual const GrTexture* asTexture() const = 0; | 68 virtual const GrTexture* asTexture() const = 0; |
| 68 | 69 |
| 69 /** | 70 /** |
| 70 * @return the render target underlying this surface, may be NULL. | 71 * @return the render target underlying this surface, may be NULL. |
| 71 */ | 72 */ |
| 72 virtual GrRenderTarget* asRenderTarget() = 0; | 73 virtual GrRenderTarget* asRenderTarget() = 0; |
| 73 virtual const GrRenderTarget* asRenderTarget() const = 0; | 74 virtual const GrRenderTarget* asRenderTarget() const = 0; |
| 74 | 75 |
| 75 /** | 76 /** |
| 77 * Checks whether this GrSurface refers to the same GPU object as other. Thi
s |
| 78 * catches the case where a GrTexture and GrRenderTarget refer to the same |
| 79 * GPU memory. |
| 80 */ |
| 81 bool isSameAs(const GrSurface* other) const { |
| 82 const GrRenderTarget* thisRT = this->asRenderTarget(); |
| 83 if (thisRT) { |
| 84 return thisRT == other->asRenderTarget(); |
| 85 } else { |
| 86 const GrTexture* thisTex = this->asTexture(); |
| 87 SkASSERT(thisTex); // We must be one or the other |
| 88 return thisTex == other->asTexture(); |
| 89 } |
| 90 } |
| 91 |
| 92 /** |
| 76 * Reads a rectangle of pixels from the surface. | 93 * Reads a rectangle of pixels from the surface. |
| 77 * @param left left edge of the rectangle to read (inclusive) | 94 * @param left left edge of the rectangle to read (inclusive) |
| 78 * @param top top edge of the rectangle to read (inclusive) | 95 * @param top top edge of the rectangle to read (inclusive) |
| 79 * @param width width of rectangle to read in pixels. | 96 * @param width width of rectangle to read in pixels. |
| 80 * @param height height of rectangle to read in pixels. | 97 * @param height height of rectangle to read in pixels. |
| 81 * @param config the pixel config of the destination buffer | 98 * @param config the pixel config of the destination buffer |
| 82 * @param buffer memory to read the rectangle into. | 99 * @param buffer memory to read the rectangle into. |
| 83 * @param rowBytes number of bytes between consecutive rows. Zero means
rows are tightly | 100 * @param rowBytes number of bytes between consecutive rows. Zero means
rows are tightly |
| 84 * packed. | 101 * packed. |
| 85 * @param pixelOpsFlags See the GrContext::PixelOpsFlags enum. | 102 * @param pixelOpsFlags See the GrContext::PixelOpsFlags enum. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 105 * @param rowBytes number of bytes between consecutive rows. Zero means
rows are tightly | 122 * @param rowBytes number of bytes between consecutive rows. Zero means
rows are tightly |
| 106 * packed. | 123 * packed. |
| 107 * @param pixelOpsFlags See the GrContext::PixelOpsFlags enum. | 124 * @param pixelOpsFlags See the GrContext::PixelOpsFlags enum. |
| 108 */ | 125 */ |
| 109 virtual void writePixels(int left, int top, int width, int height, | 126 virtual void writePixels(int left, int top, int width, int height, |
| 110 GrPixelConfig config, | 127 GrPixelConfig config, |
| 111 const void* buffer, | 128 const void* buffer, |
| 112 size_t rowBytes = 0, | 129 size_t rowBytes = 0, |
| 113 uint32_t pixelOpsFlags = 0) = 0; | 130 uint32_t pixelOpsFlags = 0) = 0; |
| 114 | 131 |
| 115 /** Access methods that are only to be used within Skia code. */ | 132 /** |
| 116 inline GrSurfacePriv surfacePriv(); | 133 * Write the contents of the surface to a PNG. Returns true if successful. |
| 117 inline const GrSurfacePriv surfacePriv() const; | 134 * @param filename Full path to desired file |
| 135 */ |
| 136 bool savePixels(const char* filename); |
| 118 | 137 |
| 119 protected: | |
| 120 // Methods made available via GrSurfacePriv | |
| 121 SkImageInfo info() const; | |
| 122 bool savePixels(const char* filename); | |
| 123 bool hasPendingRead() const; | 138 bool hasPendingRead() const; |
| 124 bool hasPendingWrite() const; | 139 bool hasPendingWrite() const; |
| 125 bool hasPendingIO() const; | 140 bool hasPendingIO() const; |
| 126 bool isSameAs(const GrSurface* other) const; | |
| 127 | 141 |
| 128 // Provides access to methods that should be public within Skia code. | 142 protected: |
| 129 friend class GrSurfacePriv; | |
| 130 | |
| 131 GrSurface(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc) | 143 GrSurface(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc) |
| 132 : INHERITED(gpu, isWrapped) | 144 : INHERITED(gpu, isWrapped) |
| 133 , fDesc(desc) { | 145 , fDesc(desc) { |
| 134 } | 146 } |
| 135 | 147 |
| 136 GrTextureDesc fDesc; | 148 GrTextureDesc fDesc; |
| 137 | 149 |
| 138 private: | 150 private: |
| 139 typedef GrGpuResource INHERITED; | 151 typedef GrGpuResource INHERITED; |
| 140 }; | 152 }; |
| 141 | 153 |
| 142 #endif | 154 #endif // GrSurface_DEFINED |
| OLD | NEW |