blob: dd79bfefff055184fa31eb06008d4d469b273aa1 [file] [log] [blame]
Robert Phillips84a81202016-11-04 11:59:10 -04001/*
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 "GrTextureRenderTargetProxy.h"
9
10// Deferred version
Robert Phillipsc787e492017-02-28 11:26:32 -050011// This class is virtually derived from GrSurfaceProxy (via both GrTextureProxy and
Robert Phillips84a81202016-11-04 11:59:10 -040012// GrRenderTargetProxy) so its constructor must be explicitly called.
13GrTextureRenderTargetProxy::GrTextureRenderTargetProxy(const GrCaps& caps,
14 const GrSurfaceDesc& desc,
15 SkBackingFit fit,
Robert Phillipsc787e492017-02-28 11:26:32 -050016 SkBudgeted budgeted,
17 uint32_t flags)
18 : GrSurfaceProxy(desc, fit, budgeted, flags)
19 // for now textures w/ data are always wrapped
Robert Phillipsc4f0a822017-06-13 08:11:36 -040020 , GrTextureProxy(desc, fit, budgeted, nullptr, 0, flags)
Robert Phillipsc787e492017-02-28 11:26:32 -050021 , GrRenderTargetProxy(caps, desc, fit, budgeted, flags) {
Robert Phillips84a81202016-11-04 11:59:10 -040022}
23
24// Wrapped version
Robert Phillipsc787e492017-02-28 11:26:32 -050025// This class is virtually derived from GrSurfaceProxy (via both GrTextureProxy and
Robert Phillips84a81202016-11-04 11:59:10 -040026// GrRenderTargetProxy) so its constructor must be explicitly called.
Robert Phillips066f0202017-07-25 10:16:35 -040027GrTextureRenderTargetProxy::GrTextureRenderTargetProxy(sk_sp<GrSurface> surf,
28 GrSurfaceOrigin origin)
29 : GrSurfaceProxy(surf, origin, SkBackingFit::kExact)
30 , GrTextureProxy(surf, origin)
31 , GrRenderTargetProxy(surf, origin) {
Robert Phillips37430132016-11-09 06:50:43 -050032 SkASSERT(surf->asTexture());
33 SkASSERT(surf->asRenderTarget());
Robert Phillips84a81202016-11-04 11:59:10 -040034}
35
Brian Salomonbb5711a2017-05-17 13:49:59 -040036size_t GrTextureRenderTargetProxy::onUninstantiatedGpuMemorySize() const {
37 int colorSamplesPerPixel = this->numColorSamples() + 1;
38
Robert Phillips84a81202016-11-04 11:59:10 -040039 // TODO: do we have enough information to improve this worst case estimate?
Greg Daniel027815f2017-10-24 09:17:00 -040040 return GrSurface::ComputeSize(fConfig, fWidth, fHeight, colorSamplesPerPixel, this->mipMapped(),
Brian Salomonbb5711a2017-05-17 13:49:59 -040041 SkBackingFit::kApprox == fFit);
Robert Phillips84a81202016-11-04 11:59:10 -040042}
43
Robert Phillipseee4d6e2017-06-05 09:26:07 -040044bool GrTextureRenderTargetProxy::instantiate(GrResourceProvider* resourceProvider) {
Brian Salomonbb5711a2017-05-17 13:49:59 -040045 static constexpr GrSurfaceFlags kFlags = kRenderTarget_GrSurfaceFlag;
46
Robert Phillipsae7d3f32017-09-21 08:26:08 -040047 const GrUniqueKey& key = this->getUniqueKey();
48
Robert Phillips65048132017-08-10 08:44:49 -040049 if (!this->instantiateImpl(resourceProvider, this->numStencilSamples(), this->needsStencil(),
Greg Daniele252f082017-10-23 16:05:23 -040050 kFlags, this->mipMapped(), this->mipColorMode(),
Robert Phillipsae7d3f32017-09-21 08:26:08 -040051 key.isValid() ? &key : nullptr)) {
Robert Phillipseee4d6e2017-06-05 09:26:07 -040052 return false;
Brian Salomonbb5711a2017-05-17 13:49:59 -040053 }
Robert Phillipsae7d3f32017-09-21 08:26:08 -040054 if (key.isValid()) {
55 SkASSERT(key == this->getUniqueKey());
56 }
57
Robert Phillipseee4d6e2017-06-05 09:26:07 -040058 SkASSERT(fTarget->asRenderTarget());
59 SkASSERT(fTarget->asTexture());
Brian Salomonbb5711a2017-05-17 13:49:59 -040060
Robert Phillipseee4d6e2017-06-05 09:26:07 -040061 return true;
Brian Salomonbb5711a2017-05-17 13:49:59 -040062}
Robert Phillips5af44de2017-07-18 14:49:38 -040063
64sk_sp<GrSurface> GrTextureRenderTargetProxy::createSurface(
65 GrResourceProvider* resourceProvider) const {
66 static constexpr GrSurfaceFlags kFlags = kRenderTarget_GrSurfaceFlag;
67
68 sk_sp<GrSurface> surface = this->createSurfaceImpl(resourceProvider, this->numStencilSamples(),
Robert Phillips65048132017-08-10 08:44:49 -040069 this->needsStencil(), kFlags,
Greg Daniele252f082017-10-23 16:05:23 -040070 this->mipMapped(), this->mipColorMode());
Robert Phillips5af44de2017-07-18 14:49:38 -040071 if (!surface) {
72 return nullptr;
73 }
74 SkASSERT(surface->asRenderTarget());
75 SkASSERT(surface->asTexture());
76
77 return surface;
78}
79