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 | |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 8 | #ifndef GrSurface_DEFINED |
| 9 | #define GrSurface_DEFINED |
| 10 | |
| 11 | #include "GrTypes.h" |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 12 | #include "GrBackendSurface.h" |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 13 | #include "GrGpuResource.h" |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 14 | #include "SkImageInfo.h" |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 15 | #include "SkRect.h" |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 16 | |
robertphillips | b06e5a2 | 2014-09-30 06:58:20 -0700 | [diff] [blame] | 17 | class GrRenderTarget; |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 18 | class GrSurfacePriv; |
| 19 | class GrTexture; |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 20 | |
bsalomon | cc97ece | 2015-07-08 07:53:10 -0700 | [diff] [blame] | 21 | class SK_API GrSurface : public GrGpuResource { |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 22 | public: |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 23 | /** |
| 24 | * Retrieves the width of the surface. |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 25 | */ |
Brian Salomon | d34edf3 | 2017-05-19 15:45:48 -0400 | [diff] [blame] | 26 | int width() const { return fWidth; } |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Retrieves the height of the surface. |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 30 | */ |
Brian Salomon | d34edf3 | 2017-05-19 15:45:48 -0400 | [diff] [blame] | 31 | int height() const { return fHeight; } |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 32 | |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 33 | /** |
| 34 | * Helper that gets the width and height of the surface as a bounding rectangle. |
| 35 | */ |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 36 | SkRect getBoundsRect() const { return SkRect::MakeIWH(this->width(), this->height()); } |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 37 | |
bsalomon@google.com | 2d0bade | 2012-10-26 19:01:17 +0000 | [diff] [blame] | 38 | /** |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 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 | */ |
Brian Salomon | d34edf3 | 2017-05-19 15:45:48 -0400 | [diff] [blame] | 44 | GrPixelConfig config() const { return fConfig; } |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 45 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 46 | virtual GrBackendFormat backendFormat() const = 0; |
| 47 | |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 48 | /** |
Robert Phillips | c589b0b | 2017-04-17 07:53:07 -0400 | [diff] [blame] | 49 | * @return the texture associated with the surface, may be null. |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 50 | */ |
Robert Phillips | c589b0b | 2017-04-17 07:53:07 -0400 | [diff] [blame] | 51 | virtual GrTexture* asTexture() { return nullptr; } |
| 52 | virtual const GrTexture* asTexture() const { return nullptr; } |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 53 | |
| 54 | /** |
Robert Phillips | c589b0b | 2017-04-17 07:53:07 -0400 | [diff] [blame] | 55 | * @return the render target underlying this surface, may be null. |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 56 | */ |
Robert Phillips | c589b0b | 2017-04-17 07:53:07 -0400 | [diff] [blame] | 57 | virtual GrRenderTarget* asRenderTarget() { return nullptr; } |
| 58 | virtual const GrRenderTarget* asRenderTarget() const { return nullptr; } |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 59 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 60 | /** Access methods that are only to be used within Skia code. */ |
| 61 | inline GrSurfacePriv surfacePriv(); |
| 62 | inline const GrSurfacePriv surfacePriv() const; |
robertphillips | b06e5a2 | 2014-09-30 06:58:20 -0700 | [diff] [blame] | 63 | |
Robert Phillips | b446088 | 2016-11-17 14:43:51 -0500 | [diff] [blame] | 64 | static size_t WorstCaseSize(const GrSurfaceDesc& desc, bool useNextPow2 = false); |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 65 | static size_t ComputeSize(GrPixelConfig config, int width, int height, int colorSamplesPerPixel, |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 66 | GrMipMapped, bool useNextPow2 = false); |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 67 | |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 68 | /** |
| 69 | * The pixel values of this surface cannot be modified (e.g. doesn't support write pixels or |
| 70 | * MIP map level regen). |
| 71 | */ |
| 72 | bool readOnly() const { return fSurfaceFlags & GrInternalSurfaceFlags::kReadOnly; } |
| 73 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 74 | protected: |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 75 | void setHasMixedSamples() { |
| 76 | SkASSERT(this->asRenderTarget()); |
| 77 | fSurfaceFlags |= GrInternalSurfaceFlags::kMixedSampled; |
| 78 | } |
| 79 | bool hasMixedSamples() const { return fSurfaceFlags & GrInternalSurfaceFlags::kMixedSampled; } |
| 80 | |
| 81 | void setSupportsWindowRects() { |
| 82 | SkASSERT(this->asRenderTarget()); |
| 83 | fSurfaceFlags |= GrInternalSurfaceFlags::kWindowRectsSupport; |
| 84 | } |
| 85 | bool supportsWindowRects() const { |
| 86 | return fSurfaceFlags & GrInternalSurfaceFlags::kWindowRectsSupport; |
| 87 | } |
| 88 | |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 89 | void setGLRTFBOIDIs0() { |
| 90 | SkASSERT(this->asRenderTarget()); |
| 91 | fSurfaceFlags |= GrInternalSurfaceFlags::kGLRTFBOIDIs0; |
| 92 | } |
| 93 | bool glRTFBOIDis0() const { |
| 94 | return fSurfaceFlags & GrInternalSurfaceFlags::kGLRTFBOIDIs0; |
| 95 | } |
| 96 | |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 97 | void setReadOnly() { |
| 98 | SkASSERT(!this->asRenderTarget()); |
| 99 | fSurfaceFlags |= GrInternalSurfaceFlags::kReadOnly; |
| 100 | } |
| 101 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 102 | // Methods made available via GrSurfacePriv |
bsalomon | 8d034a1 | 2014-09-22 12:21:08 -0700 | [diff] [blame] | 103 | bool hasPendingRead() const; |
| 104 | bool hasPendingWrite() const; |
| 105 | bool hasPendingIO() const; |
| 106 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 107 | // Provides access to methods that should be public within Skia code. |
| 108 | friend class GrSurfacePriv; |
| 109 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 110 | GrSurface(GrGpu* gpu, const GrSurfaceDesc& desc) |
Brian Salomon | d34edf3 | 2017-05-19 15:45:48 -0400 | [diff] [blame] | 111 | : INHERITED(gpu) |
| 112 | , fConfig(desc.fConfig) |
| 113 | , fWidth(desc.fWidth) |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 114 | , fHeight(desc.fHeight) |
Brian Salomon | 9f7d9a2 | 2018-12-11 19:01:32 +0000 | [diff] [blame^] | 115 | , fSurfaceFlags(GrInternalSurfaceFlags::kNone) { |
| 116 | } |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 117 | |
Greg Daniel | cef213c | 2017-04-21 11:52:27 -0400 | [diff] [blame] | 118 | ~GrSurface() override {} |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 119 | |
reed | 35a5261 | 2015-06-18 14:05:07 -0700 | [diff] [blame] | 120 | void onRelease() override; |
| 121 | void onAbandon() override; |
| 122 | |
| 123 | private: |
Derek Sollenberger | cf6da8c | 2018-03-29 13:40:02 -0400 | [diff] [blame] | 124 | const char* getResourceType() const override { return "Surface"; } |
| 125 | |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 126 | GrPixelConfig fConfig; |
| 127 | int fWidth; |
| 128 | int fHeight; |
| 129 | GrInternalSurfaceFlags fSurfaceFlags; |
Brian Salomon | d34edf3 | 2017-05-19 15:45:48 -0400 | [diff] [blame] | 130 | |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 131 | typedef GrGpuResource INHERITED; |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 132 | }; |
| 133 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 134 | #endif |