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 | /** |
bsalomon@google.com | 2d0bade | 2012-10-26 19:01:17 +0000 | [diff] [blame^] | 37 | * Some surfaces will be stored such that the upper and left edges of the content meet at the |
| 38 | * the origin (in texture coord space) and for other surfaces the lower and left edges meet at |
| 39 | * the origin. Render-targets are always consistent with the convention of the underlying |
| 40 | * backend API to make it easier to mix native backend rendering with Skia rendering. Wrapped |
| 41 | * backend surfaces always use the backend's convention as well. |
| 42 | */ |
| 43 | enum Origin { |
| 44 | kTopLeft_Origin, |
| 45 | kBottomLeft_Origin, |
| 46 | }; |
| 47 | Origin origin() const { |
| 48 | GrAssert(kTopLeft_Origin == fOrigin || kBottomLeft_Origin == fOrigin); |
| 49 | return fOrigin; |
| 50 | } |
| 51 | |
| 52 | /** |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 53 | * Retrieves the pixel config specified when the surface was created. |
| 54 | * For render targets this can be kUnknown_GrPixelConfig |
| 55 | * if client asked us to render to a target that has a pixel |
| 56 | * config that isn't equivalent with one of our configs. |
| 57 | */ |
| 58 | GrPixelConfig config() const { return fDesc.fConfig; } |
| 59 | |
| 60 | /** |
| 61 | * Return the descriptor describing the surface |
| 62 | */ |
| 63 | const GrTextureDesc& desc() const { return fDesc; } |
| 64 | |
| 65 | /** |
| 66 | * @return the texture associated with the surface, may be NULL. |
| 67 | */ |
| 68 | virtual GrTexture* asTexture() = 0; |
| 69 | virtual const GrTexture* asTexture() const = 0; |
| 70 | |
| 71 | /** |
| 72 | * @return the render target underlying this surface, may be NULL. |
| 73 | */ |
| 74 | virtual GrRenderTarget* asRenderTarget() = 0; |
| 75 | virtual const GrRenderTarget* asRenderTarget() const = 0; |
| 76 | |
| 77 | /** |
| 78 | * Reads a rectangle of pixels from the surface. |
| 79 | * @param left left edge of the rectangle to read (inclusive) |
| 80 | * @param top top edge of the rectangle to read (inclusive) |
| 81 | * @param width width of rectangle to read in pixels. |
| 82 | * @param height height of rectangle to read in pixels. |
| 83 | * @param config the pixel config of the destination buffer |
| 84 | * @param buffer memory to read the rectangle into. |
bsalomon@google.com | 2d0bade | 2012-10-26 19:01:17 +0000 | [diff] [blame^] | 85 | * @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] | 86 | * packed. |
| 87 | * @param pixelOpsFlags See the GrContext::PixelOpsFlags enum. |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 88 | * |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 89 | * @return true if the read succeeded, false if not. The read can fail because of an unsupported |
| 90 | * pixel config. |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 91 | */ |
| 92 | virtual bool readPixels(int left, int top, int width, int height, |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 93 | GrPixelConfig config, |
| 94 | void* buffer, |
| 95 | size_t rowBytes = 0, |
| 96 | uint32_t pixelOpsFlags = 0) = 0; |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 97 | |
| 98 | /** |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 99 | * Copy the src pixels [buffer, rowbytes, pixelconfig] into the surface at the specified |
| 100 | * rectangle. |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 101 | * @param left left edge of the rectangle to write (inclusive) |
| 102 | * @param top top edge of the rectangle to write (inclusive) |
| 103 | * @param width width of rectangle to write in pixels. |
| 104 | * @param height height of rectangle to write in pixels. |
| 105 | * @param config the pixel config of the source buffer |
| 106 | * @param buffer memory to read the rectangle from. |
bsalomon@google.com | 2d0bade | 2012-10-26 19:01:17 +0000 | [diff] [blame^] | 107 | * @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] | 108 | * packed. |
| 109 | * @param pixelOpsFlags See the GrContext::PixelOpsFlags enum. |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 110 | */ |
| 111 | virtual void writePixels(int left, int top, int width, int height, |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 112 | GrPixelConfig config, |
| 113 | const void* buffer, |
| 114 | size_t rowBytes = 0, |
| 115 | uint32_t pixelOpsFlags = 0) = 0; |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 116 | |
| 117 | protected: |
bsalomon@google.com | 2d0bade | 2012-10-26 19:01:17 +0000 | [diff] [blame^] | 118 | GrSurface(GrGpu* gpu, const GrTextureDesc& desc, Origin origin) |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 119 | : INHERITED(gpu) |
bsalomon@google.com | 2d0bade | 2012-10-26 19:01:17 +0000 | [diff] [blame^] | 120 | , fDesc(desc) |
| 121 | , fOrigin(origin) { |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 122 | } |
| 123 | |
bsalomon@google.com | 2d0bade | 2012-10-26 19:01:17 +0000 | [diff] [blame^] | 124 | GrTextureDesc fDesc; |
| 125 | |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 126 | private: |
bsalomon@google.com | 2d0bade | 2012-10-26 19:01:17 +0000 | [diff] [blame^] | 127 | Origin fOrigin; |
| 128 | |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 129 | typedef GrResource INHERITED; |
| 130 | }; |
| 131 | |
| 132 | #endif // GrSurface_DEFINED |