blob: 46d3945de44eb383e741e1bf3f45be92404a0866 [file] [log] [blame]
robertphillips@google.com7d501ab2012-06-21 21:09:06 +00001/*
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.com7d501ab2012-06-21 21:09:06 +00008#ifndef GrSurface_DEFINED
9#define GrSurface_DEFINED
10
11#include "GrTypes.h"
bsalomon6d3fe022014-07-25 08:35:45 -070012#include "GrGpuResource.h"
bsalomonafbf2d62014-09-30 12:18:44 -070013#include "SkImageInfo.h"
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000014#include "SkRect.h"
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000015
robertphillipsb06e5a22014-09-30 06:58:20 -070016class GrRenderTarget;
bsalomonafbf2d62014-09-30 12:18:44 -070017class GrSurfacePriv;
18class GrTexture;
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000019
bsalomoncc97ece2015-07-08 07:53:10 -070020class SK_API GrSurface : public GrGpuResource {
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000021public:
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000022 /**
23 * Retrieves the width of the surface.
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000024 */
Brian Salomond34edf32017-05-19 15:45:48 -040025 int width() const { return fWidth; }
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000026
27 /**
28 * Retrieves the height of the surface.
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000029 */
Brian Salomond34edf32017-05-19 15:45:48 -040030 int height() const { return fHeight; }
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000031
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000032 /**
33 * Helper that gets the width and height of the surface as a bounding rectangle.
34 */
robertphillips13a7eee2016-08-31 15:06:24 -070035 SkRect getBoundsRect() const { return SkRect::MakeIWH(this->width(), this->height()); }
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000036
bsalomon@google.com2d0bade2012-10-26 19:01:17 +000037 /**
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000038 * Retrieves the pixel config specified when the surface was created.
39 * For render targets this can be kUnknown_GrPixelConfig
40 * if client asked us to render to a target that has a pixel
41 * config that isn't equivalent with one of our configs.
42 */
Brian Salomond34edf32017-05-19 15:45:48 -040043 GrPixelConfig config() const { return fConfig; }
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000044
45 /**
Robert Phillipsc589b0b2017-04-17 07:53:07 -040046 * @return the texture associated with the surface, may be null.
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000047 */
Robert Phillipsc589b0b2017-04-17 07:53:07 -040048 virtual GrTexture* asTexture() { return nullptr; }
49 virtual const GrTexture* asTexture() const { return nullptr; }
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000050
51 /**
Robert Phillipsc589b0b2017-04-17 07:53:07 -040052 * @return the render target underlying this surface, may be null.
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000053 */
Robert Phillipsc589b0b2017-04-17 07:53:07 -040054 virtual GrRenderTarget* asRenderTarget() { return nullptr; }
55 virtual const GrRenderTarget* asRenderTarget() const { return nullptr; }
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000056
bsalomonafbf2d62014-09-30 12:18:44 -070057 /** Access methods that are only to be used within Skia code. */
58 inline GrSurfacePriv surfacePriv();
59 inline const GrSurfacePriv surfacePriv() const;
robertphillipsb06e5a22014-09-30 06:58:20 -070060
Robert Phillipsb4460882016-11-17 14:43:51 -050061 static size_t WorstCaseSize(const GrSurfaceDesc& desc, bool useNextPow2 = false);
Brian Salomonbb5711a2017-05-17 13:49:59 -040062 static size_t ComputeSize(GrPixelConfig config, int width, int height, int colorSamplesPerPixel,
Greg Daniele252f082017-10-23 16:05:23 -040063 GrMipMapped, bool useNextPow2 = false);
Robert Phillipsd6214d42016-11-07 08:23:48 -050064
bsalomonafbf2d62014-09-30 12:18:44 -070065protected:
Robert Phillipsabf7b762018-03-21 12:13:37 -040066 void setDoesNotSupportMipMaps() {
67 SkASSERT(this->asTexture());
68 fSurfaceFlags |= GrInternalSurfaceFlags::kDoesNotSupportMipMaps;
69 }
70 bool doesNotSupportMipMaps() const {
71 return fSurfaceFlags & GrInternalSurfaceFlags::kDoesNotSupportMipMaps;
72 }
73
74 void setIsClampOnly() {
75 SkASSERT(this->asTexture());
76 fSurfaceFlags |= GrInternalSurfaceFlags::kIsClampOnly;
77 }
78 bool isClampOnly() const { return fSurfaceFlags & GrInternalSurfaceFlags::kIsClampOnly; }
79
Robert Phillipsfe0253f2018-03-16 16:47:25 -040080 void setHasMixedSamples() {
81 SkASSERT(this->asRenderTarget());
82 fSurfaceFlags |= GrInternalSurfaceFlags::kMixedSampled;
83 }
84 bool hasMixedSamples() const { return fSurfaceFlags & GrInternalSurfaceFlags::kMixedSampled; }
85
86 void setSupportsWindowRects() {
87 SkASSERT(this->asRenderTarget());
88 fSurfaceFlags |= GrInternalSurfaceFlags::kWindowRectsSupport;
89 }
90 bool supportsWindowRects() const {
91 return fSurfaceFlags & GrInternalSurfaceFlags::kWindowRectsSupport;
92 }
93
bsalomonafbf2d62014-09-30 12:18:44 -070094 // Methods made available via GrSurfacePriv
bsalomon8d034a12014-09-22 12:21:08 -070095 bool hasPendingRead() const;
96 bool hasPendingWrite() const;
97 bool hasPendingIO() const;
98
bsalomonafbf2d62014-09-30 12:18:44 -070099 // Provides access to methods that should be public within Skia code.
100 friend class GrSurfacePriv;
101
kkinnunen2e6055b2016-04-22 01:48:29 -0700102 GrSurface(GrGpu* gpu, const GrSurfaceDesc& desc)
Brian Salomond34edf32017-05-19 15:45:48 -0400103 : INHERITED(gpu)
104 , fConfig(desc.fConfig)
105 , fWidth(desc.fWidth)
Robert Phillipsfe0253f2018-03-16 16:47:25 -0400106 , fHeight(desc.fHeight)
107 , fSurfaceFlags(GrInternalSurfaceFlags::kNone) {
108 }
109
Greg Danielcef213c2017-04-21 11:52:27 -0400110 ~GrSurface() override {}
robertphillips@google.com7d501ab2012-06-21 21:09:06 +0000111
bsalomon@google.com2d0bade2012-10-26 19:01:17 +0000112
reed35a52612015-06-18 14:05:07 -0700113 void onRelease() override;
114 void onAbandon() override;
115
116private:
Derek Sollenbergercf6da8c2018-03-29 13:40:02 -0400117 const char* getResourceType() const override { return "Surface"; }
118
Robert Phillipsfe0253f2018-03-16 16:47:25 -0400119 GrPixelConfig fConfig;
120 int fWidth;
121 int fHeight;
122 GrInternalSurfaceFlags fSurfaceFlags;
Brian Salomond34edf32017-05-19 15:45:48 -0400123
bsalomon6d3fe022014-07-25 08:35:45 -0700124 typedef GrGpuResource INHERITED;
robertphillips@google.com7d501ab2012-06-21 21:09:06 +0000125};
126
bsalomonafbf2d62014-09-30 12:18:44 -0700127#endif