robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 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 "GrResource.h" |
| 14 | |
| 15 | class GrTexture; |
| 16 | class GrRenderTarget; |
| 17 | |
| 18 | class GrSurface : public GrResource { |
| 19 | public: |
| 20 | SK_DECLARE_INST_COUNT(GrSurface); |
| 21 | |
| 22 | /** |
| 23 | * Retrieves the width of the surface. |
| 24 | * |
| 25 | * @return the width in texels |
| 26 | */ |
| 27 | int width() const { return fDesc.fWidth; } |
| 28 | |
| 29 | /** |
| 30 | * Retrieves the height of the surface. |
| 31 | * |
| 32 | * @return the height in texels |
| 33 | */ |
| 34 | int height() const { return fDesc.fHeight; } |
| 35 | |
| 36 | /** |
| 37 | * Retrieves the pixel config specified when the surface was created. |
| 38 | * For render targets this can be kUnknown_GrPixelConfig |
| 39 | * if client asked us to render to a target that has a pixel |
| 40 | * config that isn't equivalent with one of our configs. |
| 41 | */ |
| 42 | GrPixelConfig config() const { return fDesc.fConfig; } |
| 43 | |
| 44 | /** |
| 45 | * Return the descriptor describing the surface |
| 46 | */ |
| 47 | const GrTextureDesc& desc() const { return fDesc; } |
| 48 | |
| 49 | /** |
| 50 | * @return the texture associated with the surface, may be NULL. |
| 51 | */ |
| 52 | virtual GrTexture* asTexture() = 0; |
| 53 | virtual const GrTexture* asTexture() const = 0; |
| 54 | |
| 55 | /** |
| 56 | * @return the render target underlying this surface, may be NULL. |
| 57 | */ |
| 58 | virtual GrRenderTarget* asRenderTarget() = 0; |
| 59 | virtual const GrRenderTarget* asRenderTarget() const = 0; |
| 60 | |
| 61 | /** |
| 62 | * Reads a rectangle of pixels from the surface. |
| 63 | * @param left left edge of the rectangle to read (inclusive) |
| 64 | * @param top top edge of the rectangle to read (inclusive) |
| 65 | * @param width width of rectangle to read in pixels. |
| 66 | * @param height height of rectangle to read in pixels. |
| 67 | * @param config the pixel config of the destination buffer |
| 68 | * @param buffer memory to read the rectangle into. |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 69 | * @param rowBytes number of bytes bewtween consecutive rows. Zero means rows are tightly |
| 70 | * packed. |
| 71 | * @param pixelOpsFlags See the GrContext::PixelOpsFlags enum. |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 72 | * |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 73 | * @return true if the read succeeded, false if not. The read can fail because of an unsupported |
| 74 | * pixel config. |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 75 | */ |
| 76 | virtual bool readPixels(int left, int top, int width, int height, |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 77 | GrPixelConfig config, |
| 78 | void* buffer, |
| 79 | size_t rowBytes = 0, |
| 80 | uint32_t pixelOpsFlags = 0) = 0; |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 81 | |
| 82 | /** |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 83 | * Copy the src pixels [buffer, rowbytes, pixelconfig] into the surface at the specified |
| 84 | * rectangle. |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 85 | * @param left left edge of the rectangle to write (inclusive) |
| 86 | * @param top top edge of the rectangle to write (inclusive) |
| 87 | * @param width width of rectangle to write in pixels. |
| 88 | * @param height height of rectangle to write in pixels. |
| 89 | * @param config the pixel config of the source buffer |
| 90 | * @param buffer memory to read the rectangle from. |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 91 | * @param rowBytes number of bytes bewtween consecutive rows. Zero means rows are tightly |
| 92 | * packed. |
| 93 | * @param pixelOpsFlags See the GrContext::PixelOpsFlags enum. |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 94 | */ |
| 95 | virtual void writePixels(int left, int top, int width, int height, |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 96 | GrPixelConfig config, |
| 97 | const void* buffer, |
| 98 | size_t rowBytes = 0, |
| 99 | uint32_t pixelOpsFlags = 0) = 0; |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 100 | |
| 101 | protected: |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 102 | GrTextureDesc fDesc; |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 103 | |
| 104 | GrSurface(GrGpu* gpu, const GrTextureDesc& desc) |
| 105 | : INHERITED(gpu) |
| 106 | , fDesc(desc) { |
| 107 | } |
| 108 | |
| 109 | private: |
| 110 | typedef GrResource INHERITED; |
| 111 | }; |
| 112 | |
| 113 | #endif // GrSurface_DEFINED |