blob: d781a9c6d4e1b4b59df088563f5da872ac51ee1f [file] [log] [blame]
bsalomon6bc1b5f2015-02-23 09:06:38 -08001/*
2 * Copyright 2015 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#ifndef GrRenderTargetPriv_DEFINED
9#define GrRenderTargetPriv_DEFINED
10
11#include "GrRenderTarget.h"
cdalton28f45b92016-03-07 13:58:26 -080012#include "GrGpu.h"
13
14class GrStencilSettings;
bsalomon6bc1b5f2015-02-23 09:06:38 -080015
16/** Class that adds methods to GrRenderTarget that are only intended for use internal to Skia.
17 This class is purely a privileged window into GrRenderTarget. It should never have additional
18 data members or virtual methods. */
19class GrRenderTargetPriv {
20public:
21 /**
egdaniel8dc7c3a2015-04-16 11:22:42 -070022 * GrStencilAttachment is not part of the public API.
bsalomon6bc1b5f2015-02-23 09:06:38 -080023 */
Ben Wagner9ec70c62018-07-12 13:30:47 -040024 GrStencilAttachment* getStencilAttachment() const {
25 return fRenderTarget->fStencilAttachment.get();
26 }
bsalomon6bc1b5f2015-02-23 09:06:38 -080027
28 /**
egdanielec00d942015-09-14 12:56:10 -070029 * Attaches the GrStencilAttachment onto the render target. If stencil is a nullptr then the
30 * currently attached GrStencilAttachment will be removed if one was previously attached. This
31 * function returns false if there were any failure in attaching the GrStencilAttachment.
bsalomon6bc1b5f2015-02-23 09:06:38 -080032 */
Greg Danielcfa39352018-10-05 12:01:59 -040033 void attachStencilAttachment(sk_sp<GrStencilAttachment> stencil);
bsalomon6bc1b5f2015-02-23 09:06:38 -080034
cdalton193d9cf2016-05-12 11:52:02 -070035 int numStencilBits() const;
36
Chris Daltond7291ba2019-03-07 14:17:03 -070037 /**
38 * Returns a unique key that identifies this render target's sample pattern. (Must be
39 * multisampled.)
40 *
41 * NOTE: The pipeline argument is only required in case we need to flush draw state and actually
42 * query multisample info. The pipeline itself is not expected to affect sample locations.
43 */
44 int getSamplePatternKey(const GrPipeline&) const;
45
46 /**
47 * Retrieves the per-pixel HW sample locations for this render target, and, as a by-product, the actual
48 * number of samples in use. (This may differ from fSampleCnt.) Sample locations are returned as
49 * 0..1 offsets relative to the top-left corner of the pixel.
50 */
51 const SkTArray<SkPoint>& getSampleLocations(const GrPipeline& pipeline) const {
52 int samplePatternKey = this->getSamplePatternKey(pipeline);
53 return fRenderTarget->getGpu()->retrieveSampleLocations(samplePatternKey);
54 }
55
bsalomon6bc1b5f2015-02-23 09:06:38 -080056private:
57 explicit GrRenderTargetPriv(GrRenderTarget* renderTarget) : fRenderTarget(renderTarget) {}
58 GrRenderTargetPriv(const GrRenderTargetPriv&) {} // unimpl
59 GrRenderTargetPriv& operator=(const GrRenderTargetPriv&); // unimpl
60
61 // No taking addresses of this type.
62 const GrRenderTargetPriv* operator&() const;
63 GrRenderTargetPriv* operator&();
64
65 GrRenderTarget* fRenderTarget;
halcanary9d524f22016-03-29 09:03:52 -070066
bsalomon6bc1b5f2015-02-23 09:06:38 -080067 friend class GrRenderTarget; // to construct/copy this type.
68};
69
70inline GrRenderTargetPriv GrRenderTarget::renderTargetPriv() { return GrRenderTargetPriv(this); }
71
72inline const GrRenderTargetPriv GrRenderTarget::renderTargetPriv () const {
73 return GrRenderTargetPriv(const_cast<GrRenderTarget*>(this));
74}
75
76#endif