blob: 77a8402dbe4b75792337aa236549ca1cb1cb0be5 [file] [log] [blame]
robertphillips76948d42016-05-04 12:47:41 -07001/*
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 "GrTextureProxy.h"
9
10#include "GrTextureProvider.h"
robertphillips76948d42016-05-04 12:47:41 -070011
robertphillips8abb3702016-08-31 14:04:06 -070012GrTextureProxy::GrTextureProxy(const GrSurfaceDesc& srcDesc, SkBackingFit fit, SkBudgeted budgeted,
Robert Phillips8bc06d02016-11-01 17:28:40 -040013 const void* srcData, size_t /*rowBytes*/)
robertphillips8abb3702016-08-31 14:04:06 -070014 : INHERITED(srcDesc, fit, budgeted) {
Robert Phillips8bc06d02016-11-01 17:28:40 -040015 SkASSERT(!srcData); // currently handled in Make()
robertphillips8abb3702016-08-31 14:04:06 -070016}
17
Robert Phillips37430132016-11-09 06:50:43 -050018GrTextureProxy::GrTextureProxy(sk_sp<GrSurface> surf)
19 : INHERITED(std::move(surf), SkBackingFit::kExact) {
robertphillips76948d42016-05-04 12:47:41 -070020}
21
22GrTexture* GrTextureProxy::instantiate(GrTextureProvider* texProvider) {
Robert Phillipseaa86252016-11-08 13:49:39 +000023 GrSurface* surf = this->INHERITED::instantiate(texProvider);
24 if (!surf) {
25 return nullptr;
robertphillips76948d42016-05-04 12:47:41 -070026 }
27
Robert Phillipsc7635fa2016-10-28 13:25:24 -040028 return fTarget->asTexture();
robertphillips76948d42016-05-04 12:47:41 -070029}
30
Robert Phillips8bc06d02016-11-01 17:28:40 -040031size_t GrTextureProxy::onGpuMemorySize() const {
Robert Phillips29e52f12016-11-03 10:19:14 -040032 if (fTarget) {
33 return fTarget->gpuMemorySize();
Robert Phillips8bc06d02016-11-01 17:28:40 -040034 }
35
Robert Phillips29e52f12016-11-03 10:19:14 -040036 static const bool kHasMipMaps = true;
Robert Phillips8bc06d02016-11-01 17:28:40 -040037 // TODO: add tracking of mipmap state to improve the estimate
Robert Phillipsb4460882016-11-17 14:43:51 -050038 return GrSurface::ComputeSize(fDesc, 1, kHasMipMaps, SkBackingFit::kApprox == fFit);
Robert Phillips8bc06d02016-11-01 17:28:40 -040039}