blob: 7d4040e3f150a637c7138956b6ad3036bf8eb4c9 [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
Brian Salomonbb5711a2017-05-17 13:49:59 -040039 // TODO: add tracking of mipmap state to improve the estimate. We track whether we are created
40 // with mip maps but not whether a texture read from the proxy will lazily generate mip maps.
Robert Phillips84a81202016-11-04 11:59:10 -040041
42 // TODO: do we have enough information to improve this worst case estimate?
Greg Daniele252f082017-10-23 16:05:23 -040043 return GrSurface::ComputeSize(fConfig, fWidth, fHeight, colorSamplesPerPixel, GrMipMapped::kYes,
Brian Salomonbb5711a2017-05-17 13:49:59 -040044 SkBackingFit::kApprox == fFit);
Robert Phillips84a81202016-11-04 11:59:10 -040045}
46
Robert Phillipseee4d6e2017-06-05 09:26:07 -040047bool GrTextureRenderTargetProxy::instantiate(GrResourceProvider* resourceProvider) {
Brian Salomonbb5711a2017-05-17 13:49:59 -040048 static constexpr GrSurfaceFlags kFlags = kRenderTarget_GrSurfaceFlag;
49
Robert Phillipsae7d3f32017-09-21 08:26:08 -040050 const GrUniqueKey& key = this->getUniqueKey();
51
Robert Phillips65048132017-08-10 08:44:49 -040052 if (!this->instantiateImpl(resourceProvider, this->numStencilSamples(), this->needsStencil(),
Greg Daniele252f082017-10-23 16:05:23 -040053 kFlags, this->mipMapped(), this->mipColorMode(),
Robert Phillipsae7d3f32017-09-21 08:26:08 -040054 key.isValid() ? &key : nullptr)) {
Robert Phillipseee4d6e2017-06-05 09:26:07 -040055 return false;
Brian Salomonbb5711a2017-05-17 13:49:59 -040056 }
Robert Phillipsae7d3f32017-09-21 08:26:08 -040057 if (key.isValid()) {
58 SkASSERT(key == this->getUniqueKey());
59 }
60
Robert Phillipseee4d6e2017-06-05 09:26:07 -040061 SkASSERT(fTarget->asRenderTarget());
62 SkASSERT(fTarget->asTexture());
Brian Salomonbb5711a2017-05-17 13:49:59 -040063
Robert Phillipseee4d6e2017-06-05 09:26:07 -040064 return true;
Brian Salomonbb5711a2017-05-17 13:49:59 -040065}
Robert Phillips5af44de2017-07-18 14:49:38 -040066
67sk_sp<GrSurface> GrTextureRenderTargetProxy::createSurface(
68 GrResourceProvider* resourceProvider) const {
69 static constexpr GrSurfaceFlags kFlags = kRenderTarget_GrSurfaceFlag;
70
71 sk_sp<GrSurface> surface = this->createSurfaceImpl(resourceProvider, this->numStencilSamples(),
Robert Phillips65048132017-08-10 08:44:49 -040072 this->needsStencil(), kFlags,
Greg Daniele252f082017-10-23 16:05:23 -040073 this->mipMapped(), this->mipColorMode());
Robert Phillips5af44de2017-07-18 14:49:38 -040074 if (!surface) {
75 return nullptr;
76 }
77 SkASSERT(surface->asRenderTarget());
78 SkASSERT(surface->asTexture());
79
80 return surface;
81}
82