Robert Phillips | 1e3121a | 2021-06-02 09:34:57 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021 Google LLC |
| 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 | |
Robert Phillips | cc44feb | 2021-07-06 12:21:37 -0400 | [diff] [blame] | 8 | #include "src/gpu/BaseDevice.h" |
Robert Phillips | 1e3121a | 2021-06-02 09:34:57 -0400 | [diff] [blame] | 9 | |
| 10 | #include "include/gpu/GrRecordingContext.h" |
| 11 | #include "src/gpu/GrProxyProvider.h" |
| 12 | #include "src/gpu/GrRecordingContextPriv.h" |
Robert Phillips | cc44feb | 2021-07-06 12:21:37 -0400 | [diff] [blame] | 13 | #include "src/gpu/GrSurfaceProxyView.h" |
Robert Phillips | 1e3121a | 2021-06-02 09:34:57 -0400 | [diff] [blame] | 14 | |
| 15 | #define ASSERT_SINGLE_OWNER GR_ASSERT_SINGLE_OWNER(fContext->priv().singleOwner()) |
| 16 | |
Robert Phillips | cc44feb | 2021-07-06 12:21:37 -0400 | [diff] [blame] | 17 | namespace skgpu { |
| 18 | |
| 19 | GrRenderTargetProxy* BaseDevice::targetProxy() { |
| 20 | return this->readSurfaceView().asRenderTargetProxy(); |
| 21 | } |
| 22 | |
| 23 | bool BaseDevice::replaceBackingProxy(SkSurface::ContentChangeMode mode) { |
Robert Phillips | 1e3121a | 2021-06-02 09:34:57 -0400 | [diff] [blame] | 24 | ASSERT_SINGLE_OWNER |
| 25 | |
| 26 | const SkImageInfo& ii = this->imageInfo(); |
| 27 | GrRenderTargetProxy* oldRTP = this->targetProxy(); |
| 28 | GrSurfaceProxyView oldView = this->readSurfaceView(); |
| 29 | |
| 30 | auto grColorType = SkColorTypeToGrColorType(ii.colorType()); |
| 31 | auto format = fContext->priv().caps()->getDefaultBackendFormat(grColorType, GrRenderable::kYes); |
| 32 | if (!format.isValid()) { |
| 33 | return false; |
| 34 | } |
| 35 | |
| 36 | GrProxyProvider* proxyProvider = fContext->priv().proxyProvider(); |
| 37 | // This entry point is used by SkSurface_Gpu::onCopyOnWrite so it must create a |
| 38 | // kExact-backed render target proxy |
| 39 | sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(format, |
| 40 | ii.dimensions(), |
| 41 | GrRenderable::kYes, |
| 42 | oldRTP->numSamples(), |
| 43 | oldView.mipmapped(), |
| 44 | SkBackingFit::kExact, |
| 45 | oldRTP->isBudgeted(), |
| 46 | GrProtected::kNo); |
| 47 | if (!proxy) { |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | return this->replaceBackingProxy(mode, sk_ref_sp(proxy->asRenderTargetProxy()), |
| 52 | grColorType, ii.refColorSpace(), oldView.origin(), |
| 53 | this->surfaceProps()); |
| 54 | } |
Robert Phillips | cc44feb | 2021-07-06 12:21:37 -0400 | [diff] [blame] | 55 | |
| 56 | } // namespace skgpu |