blob: 4da8e99534b91c19ee1288a92ca460a5c0dea263 [file] [log] [blame]
Robert Phillips1e3121a2021-06-02 09:34:57 -04001/*
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 Phillipscc44feb2021-07-06 12:21:37 -04008#include "src/gpu/BaseDevice.h"
Robert Phillips1e3121a2021-06-02 09:34:57 -04009
10#include "include/gpu/GrRecordingContext.h"
11#include "src/gpu/GrProxyProvider.h"
12#include "src/gpu/GrRecordingContextPriv.h"
Robert Phillipscc44feb2021-07-06 12:21:37 -040013#include "src/gpu/GrSurfaceProxyView.h"
Robert Phillips1e3121a2021-06-02 09:34:57 -040014
15#define ASSERT_SINGLE_OWNER GR_ASSERT_SINGLE_OWNER(fContext->priv().singleOwner())
16
Robert Phillipscc44feb2021-07-06 12:21:37 -040017namespace skgpu {
18
19GrRenderTargetProxy* BaseDevice::targetProxy() {
20 return this->readSurfaceView().asRenderTargetProxy();
21}
22
23bool BaseDevice::replaceBackingProxy(SkSurface::ContentChangeMode mode) {
Robert Phillips1e3121a2021-06-02 09:34:57 -040024 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 Phillipscc44feb2021-07-06 12:21:37 -040055
56} // namespace skgpu