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