bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/gpu/GrGpu.h" |
Brian Salomon | 201cdbb | 2019-08-14 17:00:30 -0400 | [diff] [blame] | 12 | #include "src/gpu/GrRenderTarget.h" |
cdalton | 28f45b9 | 2016-03-07 13:58:26 -0800 | [diff] [blame] | 13 | |
| 14 | class GrStencilSettings; |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 15 | |
| 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. */ |
| 19 | class GrRenderTargetPriv { |
| 20 | public: |
| 21 | /** |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 22 | * GrStencilAttachment is not part of the public API. |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 23 | */ |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 24 | GrStencilAttachment* getStencilAttachment() const { |
| 25 | return fRenderTarget->fStencilAttachment.get(); |
| 26 | } |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 27 | |
| 28 | /** |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 29 | * 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. |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 32 | */ |
Greg Daniel | cfa3935 | 2018-10-05 12:01:59 -0400 | [diff] [blame] | 33 | void attachStencilAttachment(sk_sp<GrStencilAttachment> stencil); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 34 | |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 35 | int numStencilBits() const; |
| 36 | |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 37 | /** |
| 38 | * Returns a unique key that identifies this render target's sample pattern. (Must be |
| 39 | * multisampled.) |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 40 | */ |
Chris Dalton | 8c4cafd | 2019-04-15 19:14:36 -0600 | [diff] [blame] | 41 | int getSamplePatternKey() const; |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 42 | |
| 43 | /** |
Chris Dalton | 8c4cafd | 2019-04-15 19:14:36 -0600 | [diff] [blame] | 44 | * Retrieves the per-pixel HW sample locations for this render target, and, as a by-product, the |
| 45 | * actual number of samples in use. (This may differ from fSampleCnt.) Sample locations are |
| 46 | * returned as 0..1 offsets relative to the top-left corner of the pixel. |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 47 | */ |
Chris Dalton | 8c4cafd | 2019-04-15 19:14:36 -0600 | [diff] [blame] | 48 | const SkTArray<SkPoint>& getSampleLocations() const { |
| 49 | int samplePatternKey = this->getSamplePatternKey(); |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 50 | return fRenderTarget->getGpu()->retrieveSampleLocations(samplePatternKey); |
| 51 | } |
| 52 | |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 53 | private: |
| 54 | explicit GrRenderTargetPriv(GrRenderTarget* renderTarget) : fRenderTarget(renderTarget) {} |
| 55 | GrRenderTargetPriv(const GrRenderTargetPriv&) {} // unimpl |
| 56 | GrRenderTargetPriv& operator=(const GrRenderTargetPriv&); // unimpl |
| 57 | |
| 58 | // No taking addresses of this type. |
| 59 | const GrRenderTargetPriv* operator&() const; |
| 60 | GrRenderTargetPriv* operator&(); |
| 61 | |
| 62 | GrRenderTarget* fRenderTarget; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 63 | |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 64 | friend class GrRenderTarget; // to construct/copy this type. |
| 65 | }; |
| 66 | |
| 67 | inline GrRenderTargetPriv GrRenderTarget::renderTargetPriv() { return GrRenderTargetPriv(this); } |
| 68 | |
| 69 | inline const GrRenderTargetPriv GrRenderTarget::renderTargetPriv () const { |
| 70 | return GrRenderTargetPriv(const_cast<GrRenderTarget*>(this)); |
| 71 | } |
| 72 | |
| 73 | #endif |