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" |
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 | */ |
| 26 | int width() const { return fDesc.fWidth; } |
| 27 | |
| 28 | /** |
| 29 | * Retrieves the height of the surface. |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 30 | */ |
| 31 | int height() const { return fDesc.fHeight; } |
| 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 | |
senorblanco@chromium.org | ef5dbe1 | 2013-01-28 16:42:38 +0000 | [diff] [blame] | 38 | GrSurfaceOrigin origin() const { |
Robert Phillips | c589b0b | 2017-04-17 07:53:07 -0400 | [diff] [blame^] | 39 | SkASSERT(kTopLeft_GrSurfaceOrigin == fDesc.fOrigin || |
| 40 | kBottomLeft_GrSurfaceOrigin == fDesc.fOrigin); |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 41 | return fDesc.fOrigin; |
bsalomon@google.com | 2d0bade | 2012-10-26 19:01:17 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | /** |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 45 | * Retrieves the pixel config specified when the surface was created. |
| 46 | * For render targets this can be kUnknown_GrPixelConfig |
| 47 | * if client asked us to render to a target that has a pixel |
| 48 | * config that isn't equivalent with one of our configs. |
| 49 | */ |
| 50 | GrPixelConfig config() const { return fDesc.fConfig; } |
| 51 | |
| 52 | /** |
| 53 | * Return the descriptor describing the surface |
| 54 | */ |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 55 | const GrSurfaceDesc& desc() const { return fDesc; } |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 56 | |
| 57 | /** |
Robert Phillips | c589b0b | 2017-04-17 07:53:07 -0400 | [diff] [blame^] | 58 | * @return the texture associated with the surface, may be null. |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 59 | */ |
Robert Phillips | c589b0b | 2017-04-17 07:53:07 -0400 | [diff] [blame^] | 60 | virtual GrTexture* asTexture() { return nullptr; } |
| 61 | virtual const GrTexture* asTexture() const { return nullptr; } |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 62 | |
| 63 | /** |
Robert Phillips | c589b0b | 2017-04-17 07:53:07 -0400 | [diff] [blame^] | 64 | * @return the render target underlying this surface, may be null. |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 65 | */ |
Robert Phillips | c589b0b | 2017-04-17 07:53:07 -0400 | [diff] [blame^] | 66 | virtual GrRenderTarget* asRenderTarget() { return nullptr; } |
| 67 | virtual const GrRenderTarget* asRenderTarget() const { return nullptr; } |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 68 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 69 | /** Access methods that are only to be used within Skia code. */ |
| 70 | inline GrSurfacePriv surfacePriv(); |
| 71 | inline const GrSurfacePriv surfacePriv() const; |
robertphillips | b06e5a2 | 2014-09-30 06:58:20 -0700 | [diff] [blame] | 72 | |
reed | de49988 | 2015-06-18 13:41:40 -0700 | [diff] [blame] | 73 | typedef void* ReleaseCtx; |
| 74 | typedef void (*ReleaseProc)(ReleaseCtx); |
mtklein | 2766c00 | 2015-06-26 11:45:03 -0700 | [diff] [blame] | 75 | |
reed | de49988 | 2015-06-18 13:41:40 -0700 | [diff] [blame] | 76 | void setRelease(ReleaseProc proc, ReleaseCtx ctx) { |
| 77 | fReleaseProc = proc; |
| 78 | fReleaseCtx = ctx; |
| 79 | } |
| 80 | |
Robert Phillips | b446088 | 2016-11-17 14:43:51 -0500 | [diff] [blame] | 81 | static size_t WorstCaseSize(const GrSurfaceDesc& desc, bool useNextPow2 = false); |
| 82 | static size_t ComputeSize(const GrSurfaceDesc& desc, int colorSamplesPerPixel, |
| 83 | bool hasMIPMaps, bool useNextPow2 = false); |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 84 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 85 | protected: |
| 86 | // Methods made available via GrSurfacePriv |
bsalomon | 8d034a1 | 2014-09-22 12:21:08 -0700 | [diff] [blame] | 87 | bool hasPendingRead() const; |
| 88 | bool hasPendingWrite() const; |
| 89 | bool hasPendingIO() const; |
| 90 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 91 | // Provides access to methods that should be public within Skia code. |
| 92 | friend class GrSurfacePriv; |
| 93 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 94 | GrSurface(GrGpu* gpu, const GrSurfaceDesc& desc) |
| 95 | : INHERITED(gpu) |
reed | de49988 | 2015-06-18 13:41:40 -0700 | [diff] [blame] | 96 | , fDesc(desc) |
Robert Phillips | c589b0b | 2017-04-17 07:53:07 -0400 | [diff] [blame^] | 97 | , fReleaseProc(nullptr) |
| 98 | , fReleaseCtx(nullptr) { |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 99 | } |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 100 | ~GrSurface() override; |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 101 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 102 | GrSurfaceDesc fDesc; |
bsalomon@google.com | 2d0bade | 2012-10-26 19:01:17 +0000 | [diff] [blame] | 103 | |
reed | 35a5261 | 2015-06-18 14:05:07 -0700 | [diff] [blame] | 104 | void onRelease() override; |
| 105 | void onAbandon() override; |
| 106 | |
| 107 | private: |
reed | de49988 | 2015-06-18 13:41:40 -0700 | [diff] [blame] | 108 | void invokeReleaseProc() { |
| 109 | if (fReleaseProc) { |
| 110 | fReleaseProc(fReleaseCtx); |
Robert Phillips | c589b0b | 2017-04-17 07:53:07 -0400 | [diff] [blame^] | 111 | fReleaseProc = nullptr; |
reed | de49988 | 2015-06-18 13:41:40 -0700 | [diff] [blame] | 112 | } |
| 113 | } |
mtklein | 2766c00 | 2015-06-26 11:45:03 -0700 | [diff] [blame] | 114 | |
reed | de49988 | 2015-06-18 13:41:40 -0700 | [diff] [blame] | 115 | ReleaseProc fReleaseProc; |
| 116 | ReleaseCtx fReleaseCtx; |
| 117 | |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 118 | typedef GrGpuResource INHERITED; |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 119 | }; |
| 120 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 121 | #endif |