blob: 6a8bd3212daa0e8a4ef7a8d4578c5f9df8a3f8f4 [file] [log] [blame]
robertphillips@google.com7d501ab2012-06-21 21:09:06 +00001/*
2 * Copyright 2012 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
Robert Phillips99dead92020-01-27 16:11:57 -05008#include "src/core/SkCompressedDataUtils.h"
Greg Daniel01f278c2020-06-12 16:58:17 -04009#include "src/gpu/GrBackendUtils.h"
Brian Salomon201cdbb2019-08-14 17:00:30 -040010#include "src/gpu/GrRenderTarget.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/gpu/GrResourceProvider.h"
Greg Daniel456f9b52020-03-05 19:14:18 +000012#include "src/gpu/GrSurface.h"
Greg Daniel456f9b52020-03-05 19:14:18 +000013#include "src/gpu/GrTexture.h"
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000014
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#include "src/core/SkMathPriv.h"
16#include "src/gpu/SkGr.h"
commit-bot@chromium.org6c5d9a12013-09-30 18:05:43 +000017
Greg Daniel0eca74c2020-10-01 13:46:00 -040018size_t GrSurface::ComputeSize(const GrBackendFormat& format,
Brian Salomon9f2b86c2019-10-22 10:37:46 -040019 SkISize dimensions,
Robert Phillipsd6214d42016-11-07 08:23:48 -050020 int colorSamplesPerPixel,
Brian Salomon7e67dca2020-07-21 09:27:25 -040021 GrMipmapped mipMapped,
Robert Phillipsf9fcf7f2019-07-11 09:03:27 -040022 bool binSize) {
Greg Danielada451c2019-11-26 09:55:20 -050023 // For external formats we do not actually know the real size of the resource so we just return
24 // 0 here to indicate this.
25 if (format.textureType() == GrTextureType::kExternal) {
26 return 0;
27 }
28
Jim Van Verth1676cb92019-01-15 13:24:45 -050029 size_t colorSize;
30
Brian Salomon9f2b86c2019-10-22 10:37:46 -040031 if (binSize) {
32 dimensions = GrResourceProvider::MakeApprox(dimensions);
33 }
Robert Phillipsb4460882016-11-17 14:43:51 -050034
Greg Daniel01f278c2020-06-12 16:58:17 -040035 SkImage::CompressionType compressionType = GrBackendFormatToCompressionType(format);
Robert Phillipsd6df7b52019-12-13 11:17:46 -050036 if (compressionType != SkImage::CompressionType::kNone) {
Robert Phillips99dead92020-01-27 16:11:57 -050037 colorSize = SkCompressedFormatDataSize(compressionType, dimensions,
Brian Salomon7e67dca2020-07-21 09:27:25 -040038 mipMapped == GrMipmapped::kYes);
Jim Van Verth1676cb92019-01-15 13:24:45 -050039 } else {
Greg Daniel0eca74c2020-10-01 13:46:00 -040040 colorSize = (size_t)dimensions.width() * dimensions.height() *
41 GrBackendFormatBytesPerPixel(format);
Jim Van Verth1676cb92019-01-15 13:24:45 -050042 }
Robert Phillipsd6214d42016-11-07 08:23:48 -050043 SkASSERT(colorSize > 0);
44
45 size_t finalSize = colorSamplesPerPixel * colorSize;
46
Brian Salomon7e67dca2020-07-21 09:27:25 -040047 if (GrMipmapped::kYes == mipMapped) {
Brian Salomon9f2b86c2019-10-22 10:37:46 -040048 // We don't have to worry about the mipmaps being a different dimensions than
Robert Phillipsd6214d42016-11-07 08:23:48 -050049 // we'd expect because we never change fDesc.fWidth/fHeight.
50 finalSize += colorSize/3;
51 }
Robert Phillipsd6214d42016-11-07 08:23:48 -050052 return finalSize;
53}
54
bsalomone8d21e82015-07-16 08:23:13 -070055//////////////////////////////////////////////////////////////////////////////
56
reedde499882015-06-18 13:41:40 -070057void GrSurface::onRelease() {
Greg Daniel2d35a1c2019-02-01 14:48:10 -050058 this->invokeReleaseProc();
reedde499882015-06-18 13:41:40 -070059 this->INHERITED::onRelease();
60}
61
62void GrSurface::onAbandon() {
Greg Daniel2d35a1c2019-02-01 14:48:10 -050063 this->invokeReleaseProc();
reedde499882015-06-18 13:41:40 -070064 this->INHERITED::onAbandon();
65}