robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | #include "GrRenderTargetProxy.h" |
| 9 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 10 | #include "GrCaps.h" |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 11 | #include "GrGpuResourcePriv.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 12 | #include "GrRenderTargetOpList.h" |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 13 | #include "GrRenderTargetPriv.h" |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 14 | #include "GrResourceProvider.h" |
Greg Daniel | 849dce1 | 2018-04-24 14:32:53 -0400 | [diff] [blame] | 15 | #include "GrSurfacePriv.h" |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 16 | #include "GrTextureRenderTargetProxy.h" |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 17 | #include "SkMathPriv.h" |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 18 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 19 | // Deferred version |
| 20 | // TODO: we can probably munge the 'desc' in both the wrapped and deferred |
| 21 | // cases to make the sampleConfig/numSamples stuff more rational. |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 22 | GrRenderTargetProxy::GrRenderTargetProxy(const GrCaps& caps, const GrBackendFormat& format, |
| 23 | const GrSurfaceDesc& desc, GrSurfaceOrigin origin, |
| 24 | SkBackingFit fit, SkBudgeted budgeted, |
| 25 | GrInternalSurfaceFlags surfaceFlags) |
| 26 | : INHERITED(format, desc, origin, fit, budgeted, surfaceFlags) |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 27 | , fSampleCnt(desc.fSampleCnt) |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 28 | , fNeedsStencil(false) |
| 29 | , fWrapsVkSecondaryCB(WrapsVkSecondaryCB::kNo) { |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 30 | // Since we know the newly created render target will be internal, we are able to precompute |
| 31 | // what the flags will ultimately end up being. |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 32 | if (caps.usesMixedSamples() && fSampleCnt > 1) { |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 33 | this->setHasMixedSamples(); |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 34 | } |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 35 | } |
| 36 | |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 37 | // Lazy-callback version |
Greg Daniel | 65fa8ca | 2018-01-10 17:06:31 -0500 | [diff] [blame] | 38 | GrRenderTargetProxy::GrRenderTargetProxy(LazyInstantiateCallback&& callback, |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 39 | LazyInstantiationType lazyType, |
| 40 | const GrBackendFormat& format, const GrSurfaceDesc& desc, |
| 41 | GrSurfaceOrigin origin, SkBackingFit fit, |
Greg Daniel | b085fa9 | 2019-03-05 16:55:12 -0500 | [diff] [blame] | 42 | SkBudgeted budgeted, GrInternalSurfaceFlags surfaceFlags, |
| 43 | WrapsVkSecondaryCB wrapsVkSecondaryCB) |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 44 | : INHERITED(std::move(callback), lazyType, format, desc, origin, fit, budgeted, |
| 45 | surfaceFlags) |
Greg Daniel | 65fa8ca | 2018-01-10 17:06:31 -0500 | [diff] [blame] | 46 | , fSampleCnt(desc.fSampleCnt) |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 47 | , fNeedsStencil(false) |
Greg Daniel | b085fa9 | 2019-03-05 16:55:12 -0500 | [diff] [blame] | 48 | , fWrapsVkSecondaryCB(wrapsVkSecondaryCB) { |
Greg Daniel | 65fa8ca | 2018-01-10 17:06:31 -0500 | [diff] [blame] | 49 | SkASSERT(SkToBool(kRenderTarget_GrSurfaceFlag & desc.fFlags)); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 50 | } |
| 51 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 52 | // Wrapped version |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 53 | GrRenderTargetProxy::GrRenderTargetProxy(sk_sp<GrSurface> surf, GrSurfaceOrigin origin, |
| 54 | WrapsVkSecondaryCB wrapsVkSecondaryCB) |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 55 | : INHERITED(std::move(surf), origin, SkBackingFit::kExact) |
| 56 | , fSampleCnt(fTarget->asRenderTarget()->numStencilSamples()) |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 57 | , fNeedsStencil(false) |
| 58 | , fWrapsVkSecondaryCB(wrapsVkSecondaryCB) { |
Robert Phillips | c4f0a82 | 2017-06-13 08:11:36 -0400 | [diff] [blame] | 59 | } |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 60 | |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 61 | int GrRenderTargetProxy::maxWindowRectangles(const GrCaps& caps) const { |
Brian Salomon | 34a2030 | 2018-12-18 12:03:07 -0500 | [diff] [blame] | 62 | return this->glRTFBOIDIs0() ? 0 : caps.maxWindowRectangles(); |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 63 | } |
| 64 | |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 65 | bool GrRenderTargetProxy::instantiate(GrResourceProvider* resourceProvider) { |
Greg Daniel | 0a375db | 2018-02-01 12:21:39 -0500 | [diff] [blame] | 66 | if (LazyState::kNot != this->lazyInstantiationState()) { |
| 67 | return false; |
| 68 | } |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 69 | static constexpr GrSurfaceDescFlags kDescFlags = kRenderTarget_GrSurfaceFlag; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 70 | |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 71 | if (!this->instantiateImpl(resourceProvider, fSampleCnt, fNeedsStencil, kDescFlags, |
Greg Daniel | d2d8e92 | 2018-02-12 12:07:39 -0500 | [diff] [blame] | 72 | GrMipMapped::kNo, nullptr)) { |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 73 | return false; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 74 | } |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 75 | SkASSERT(fTarget->asRenderTarget()); |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 76 | SkASSERT(!fTarget->asTexture()); |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 77 | return true; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 80 | sk_sp<GrSurface> GrRenderTargetProxy::createSurface(GrResourceProvider* resourceProvider) const { |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 81 | static constexpr GrSurfaceDescFlags kDescFlags = kRenderTarget_GrSurfaceFlag; |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 82 | |
Robert Phillips | 6504813 | 2017-08-10 08:44:49 -0400 | [diff] [blame] | 83 | sk_sp<GrSurface> surface = this->createSurfaceImpl(resourceProvider, fSampleCnt, fNeedsStencil, |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 84 | kDescFlags, GrMipMapped::kNo); |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 85 | if (!surface) { |
| 86 | return nullptr; |
| 87 | } |
| 88 | SkASSERT(surface->asRenderTarget()); |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 89 | SkASSERT(!surface->asTexture()); |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 90 | return surface; |
| 91 | } |
| 92 | |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 93 | size_t GrRenderTargetProxy::onUninstantiatedGpuMemorySize() const { |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 94 | int colorSamplesPerPixel = this->numColorSamples(); |
| 95 | if (colorSamplesPerPixel > 1) { |
| 96 | // Add one for the resolve buffer. |
| 97 | ++colorSamplesPerPixel; |
| 98 | } |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 99 | |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 100 | // TODO: do we have enough information to improve this worst case estimate? |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 101 | return GrSurface::ComputeSize(this->config(), this->width(), this->height(), |
| 102 | colorSamplesPerPixel, GrMipMapped::kNo, !this->priv().isExact()); |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 103 | } |
| 104 | |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 105 | bool GrRenderTargetProxy::refsWrappedObjects() const { |
| 106 | if (!fTarget) { |
| 107 | return false; |
| 108 | } |
| 109 | |
| 110 | return fTarget->resourcePriv().refsWrappedObjects(); |
| 111 | } |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 112 | |
| 113 | #ifdef SK_DEBUG |
Greg Daniel | 849dce1 | 2018-04-24 14:32:53 -0400 | [diff] [blame] | 114 | void GrRenderTargetProxy::onValidateSurface(const GrSurface* surface) { |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 115 | // We do not check that surface->asTexture returns null since, when replaying DDLs we |
| 116 | // can fulfill a renderTarget-only proxy w/ a textureRenderTarget. |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 117 | |
| 118 | // Anything that is checked here should be duplicated in GrTextureRenderTargetProxy's version |
| 119 | SkASSERT(surface->asRenderTarget()); |
| 120 | SkASSERT(surface->asRenderTarget()->numStencilSamples() == this->numStencilSamples()); |
Greg Daniel | 849dce1 | 2018-04-24 14:32:53 -0400 | [diff] [blame] | 121 | |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 122 | GrInternalSurfaceFlags proxyFlags = fSurfaceFlags; |
| 123 | GrInternalSurfaceFlags surfaceFlags = surface->surfacePriv().flags(); |
| 124 | SkASSERT((proxyFlags & GrInternalSurfaceFlags::kRenderTargetMask) == |
| 125 | (surfaceFlags & GrInternalSurfaceFlags::kRenderTargetMask)); |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 126 | } |
| 127 | #endif |