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