blob: 1056bdd2244d52d2a520d3af3f57fe0538d44b65 [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
8
9#ifndef GrSurface_DEFINED
10#define GrSurface_DEFINED
11
12#include "GrTypes.h"
bsalomon6d3fe022014-07-25 08:35:45 -070013#include "GrGpuResource.h"
bsalomonafbf2d62014-09-30 12:18:44 -070014#include "SkImageInfo.h"
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000015#include "SkRect.h"
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000016
robertphillipsb06e5a22014-09-30 06:58:20 -070017class GrRenderTarget;
bsalomonafbf2d62014-09-30 12:18:44 -070018class GrSurfacePriv;
19class GrTexture;
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000020
bsalomoncc97ece2015-07-08 07:53:10 -070021class SK_API GrSurface : public GrGpuResource {
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000022public:
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000023 /**
24 * Retrieves the width of the surface.
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000025 */
Brian Salomond34edf32017-05-19 15:45:48 -040026 int width() const { return fWidth; }
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000027
28 /**
29 * Retrieves the height of the surface.
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000030 */
Brian Salomond34edf32017-05-19 15:45:48 -040031 int height() const { return fHeight; }
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000032
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000033 /**
34 * Helper that gets the width and height of the surface as a bounding rectangle.
35 */
robertphillips13a7eee2016-08-31 15:06:24 -070036 SkRect getBoundsRect() const { return SkRect::MakeIWH(this->width(), this->height()); }
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000037
bsalomon@google.com2d0bade2012-10-26 19:01:17 +000038 /**
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000039 * 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 Salomond34edf32017-05-19 15:45:48 -040044 GrPixelConfig config() const { return fConfig; }
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000045
46 /**
Robert Phillipsc589b0b2017-04-17 07:53:07 -040047 * @return the texture associated with the surface, may be null.
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000048 */
Robert Phillipsc589b0b2017-04-17 07:53:07 -040049 virtual GrTexture* asTexture() { return nullptr; }
50 virtual const GrTexture* asTexture() const { return nullptr; }
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000051
52 /**
Robert Phillipsc589b0b2017-04-17 07:53:07 -040053 * @return the render target underlying this surface, may be null.
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000054 */
Robert Phillipsc589b0b2017-04-17 07:53:07 -040055 virtual GrRenderTarget* asRenderTarget() { return nullptr; }
56 virtual const GrRenderTarget* asRenderTarget() const { return nullptr; }
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000057
bsalomonafbf2d62014-09-30 12:18:44 -070058 /** Access methods that are only to be used within Skia code. */
59 inline GrSurfacePriv surfacePriv();
60 inline const GrSurfacePriv surfacePriv() const;
robertphillipsb06e5a22014-09-30 06:58:20 -070061
Robert Phillipsb4460882016-11-17 14:43:51 -050062 static size_t WorstCaseSize(const GrSurfaceDesc& desc, bool useNextPow2 = false);
Brian Salomonbb5711a2017-05-17 13:49:59 -040063 static size_t ComputeSize(GrPixelConfig config, int width, int height, int colorSamplesPerPixel,
Greg Daniele252f082017-10-23 16:05:23 -040064 GrMipMapped, bool useNextPow2 = false);
Robert Phillipsd6214d42016-11-07 08:23:48 -050065
bsalomonafbf2d62014-09-30 12:18:44 -070066protected:
67 // Methods made available via GrSurfacePriv
bsalomon8d034a12014-09-22 12:21:08 -070068 bool hasPendingRead() const;
69 bool hasPendingWrite() const;
70 bool hasPendingIO() const;
71
bsalomonafbf2d62014-09-30 12:18:44 -070072 // Provides access to methods that should be public within Skia code.
73 friend class GrSurfacePriv;
74
kkinnunen2e6055b2016-04-22 01:48:29 -070075 GrSurface(GrGpu* gpu, const GrSurfaceDesc& desc)
Brian Salomond34edf32017-05-19 15:45:48 -040076 : INHERITED(gpu)
77 , fConfig(desc.fConfig)
78 , fWidth(desc.fWidth)
Robert Phillipsb0e93a22017-08-29 08:26:54 -040079 , fHeight(desc.fHeight) {}
Greg Danielcef213c2017-04-21 11:52:27 -040080 ~GrSurface() override {}
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000081
bsalomon@google.com2d0bade2012-10-26 19:01:17 +000082
reed35a52612015-06-18 14:05:07 -070083 void onRelease() override;
84 void onAbandon() override;
85
86private:
Brian Salomond34edf32017-05-19 15:45:48 -040087 GrPixelConfig fConfig;
88 int fWidth;
89 int fHeight;
Brian Salomond34edf32017-05-19 15:45:48 -040090
bsalomon6d3fe022014-07-25 08:35:45 -070091 typedef GrGpuResource INHERITED;
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000092};
93
bsalomonafbf2d62014-09-30 12:18:44 -070094#endif