blob: 4caa842b4ac9f3785fcfc4e38faba46ecd0ec0f2 [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
senorblanco@chromium.orgef5dbe12013-01-28 16:42:38 +000038 GrSurfaceOrigin origin() const {
Brian Salomond34edf32017-05-19 15:45:48 -040039 SkASSERT(kTopLeft_GrSurfaceOrigin == fOrigin || kBottomLeft_GrSurfaceOrigin == fOrigin);
40 return fOrigin;
bsalomon@google.com2d0bade2012-10-26 19:01:17 +000041 }
42
43 /**
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000044 * Retrieves the pixel config specified when the surface was created.
45 * For render targets this can be kUnknown_GrPixelConfig
46 * if client asked us to render to a target that has a pixel
47 * config that isn't equivalent with one of our configs.
48 */
Brian Salomond34edf32017-05-19 15:45:48 -040049 GrPixelConfig config() const { return fConfig; }
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000050
51 /**
Robert Phillipsc589b0b2017-04-17 07:53:07 -040052 * @return the texture associated with the surface, may be null.
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000053 */
Robert Phillipsc589b0b2017-04-17 07:53:07 -040054 virtual GrTexture* asTexture() { return nullptr; }
55 virtual const GrTexture* asTexture() const { return nullptr; }
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000056
57 /**
Robert Phillipsc589b0b2017-04-17 07:53:07 -040058 * @return the render target underlying this surface, may be null.
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000059 */
Robert Phillipsc589b0b2017-04-17 07:53:07 -040060 virtual GrRenderTarget* asRenderTarget() { return nullptr; }
61 virtual const GrRenderTarget* asRenderTarget() const { return nullptr; }
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000062
bsalomonafbf2d62014-09-30 12:18:44 -070063 /** Access methods that are only to be used within Skia code. */
64 inline GrSurfacePriv surfacePriv();
65 inline const GrSurfacePriv surfacePriv() const;
robertphillipsb06e5a22014-09-30 06:58:20 -070066
Robert Phillipsb4460882016-11-17 14:43:51 -050067 static size_t WorstCaseSize(const GrSurfaceDesc& desc, bool useNextPow2 = false);
Brian Salomonbb5711a2017-05-17 13:49:59 -040068 static size_t ComputeSize(GrPixelConfig config, int width, int height, int colorSamplesPerPixel,
Robert Phillipsb4460882016-11-17 14:43:51 -050069 bool hasMIPMaps, bool useNextPow2 = false);
Robert Phillipsd6214d42016-11-07 08:23:48 -050070
bsalomonafbf2d62014-09-30 12:18:44 -070071protected:
72 // Methods made available via GrSurfacePriv
bsalomon8d034a12014-09-22 12:21:08 -070073 bool hasPendingRead() const;
74 bool hasPendingWrite() const;
75 bool hasPendingIO() const;
76
bsalomonafbf2d62014-09-30 12:18:44 -070077 // Provides access to methods that should be public within Skia code.
78 friend class GrSurfacePriv;
79
kkinnunen2e6055b2016-04-22 01:48:29 -070080 GrSurface(GrGpu* gpu, const GrSurfaceDesc& desc)
Brian Salomond34edf32017-05-19 15:45:48 -040081 : INHERITED(gpu)
82 , fConfig(desc.fConfig)
83 , fWidth(desc.fWidth)
84 , fHeight(desc.fHeight)
85 , fOrigin(desc.fOrigin) {}
Greg Danielcef213c2017-04-21 11:52:27 -040086 ~GrSurface() override {}
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000087
bsalomon@google.com2d0bade2012-10-26 19:01:17 +000088
reed35a52612015-06-18 14:05:07 -070089 void onRelease() override;
90 void onAbandon() override;
91
92private:
Brian Salomond34edf32017-05-19 15:45:48 -040093 GrPixelConfig fConfig;
94 int fWidth;
95 int fHeight;
96 GrSurfaceOrigin fOrigin;
97
bsalomon6d3fe022014-07-25 08:35:45 -070098 typedef GrGpuResource INHERITED;
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000099};
100
bsalomonafbf2d62014-09-30 12:18:44 -0700101#endif