robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 1 | /* |
| 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 Phillips | 99dead9 | 2020-01-27 16:11:57 -0500 | [diff] [blame] | 8 | #include "src/core/SkCompressedDataUtils.h" |
Greg Daniel | 01f278c | 2020-06-12 16:58:17 -0400 | [diff] [blame] | 9 | #include "src/gpu/GrBackendUtils.h" |
Brian Salomon | 201cdbb | 2019-08-14 17:00:30 -0400 | [diff] [blame] | 10 | #include "src/gpu/GrRenderTarget.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/gpu/GrResourceProvider.h" |
Greg Daniel | 456f9b5 | 2020-03-05 19:14:18 +0000 | [diff] [blame] | 12 | #include "src/gpu/GrSurface.h" |
Greg Daniel | 456f9b5 | 2020-03-05 19:14:18 +0000 | [diff] [blame] | 13 | #include "src/gpu/GrTexture.h" |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 14 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "src/core/SkMathPriv.h" |
| 16 | #include "src/gpu/SkGr.h" |
commit-bot@chromium.org | 6c5d9a1 | 2013-09-30 18:05:43 +0000 | [diff] [blame] | 17 | |
Greg Daniel | 0eca74c | 2020-10-01 13:46:00 -0400 | [diff] [blame] | 18 | size_t GrSurface::ComputeSize(const GrBackendFormat& format, |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 19 | SkISize dimensions, |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 20 | int colorSamplesPerPixel, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 21 | GrMipmapped mipMapped, |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 22 | bool binSize) { |
Greg Daniel | ada451c | 2019-11-26 09:55:20 -0500 | [diff] [blame] | 23 | // 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 Verth | 1676cb9 | 2019-01-15 13:24:45 -0500 | [diff] [blame] | 29 | size_t colorSize; |
| 30 | |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 31 | if (binSize) { |
| 32 | dimensions = GrResourceProvider::MakeApprox(dimensions); |
| 33 | } |
Robert Phillips | b446088 | 2016-11-17 14:43:51 -0500 | [diff] [blame] | 34 | |
Greg Daniel | 01f278c | 2020-06-12 16:58:17 -0400 | [diff] [blame] | 35 | SkImage::CompressionType compressionType = GrBackendFormatToCompressionType(format); |
Robert Phillips | d6df7b5 | 2019-12-13 11:17:46 -0500 | [diff] [blame] | 36 | if (compressionType != SkImage::CompressionType::kNone) { |
Robert Phillips | 99dead9 | 2020-01-27 16:11:57 -0500 | [diff] [blame] | 37 | colorSize = SkCompressedFormatDataSize(compressionType, dimensions, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 38 | mipMapped == GrMipmapped::kYes); |
Jim Van Verth | 1676cb9 | 2019-01-15 13:24:45 -0500 | [diff] [blame] | 39 | } else { |
Greg Daniel | 0eca74c | 2020-10-01 13:46:00 -0400 | [diff] [blame] | 40 | colorSize = (size_t)dimensions.width() * dimensions.height() * |
| 41 | GrBackendFormatBytesPerPixel(format); |
Jim Van Verth | 1676cb9 | 2019-01-15 13:24:45 -0500 | [diff] [blame] | 42 | } |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 43 | SkASSERT(colorSize > 0); |
| 44 | |
| 45 | size_t finalSize = colorSamplesPerPixel * colorSize; |
| 46 | |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 47 | if (GrMipmapped::kYes == mipMapped) { |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 48 | // We don't have to worry about the mipmaps being a different dimensions than |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 49 | // we'd expect because we never change fDesc.fWidth/fHeight. |
| 50 | finalSize += colorSize/3; |
| 51 | } |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 52 | return finalSize; |
| 53 | } |
| 54 | |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 55 | ////////////////////////////////////////////////////////////////////////////// |
| 56 | |
reed | de49988 | 2015-06-18 13:41:40 -0700 | [diff] [blame] | 57 | void GrSurface::onRelease() { |
Greg Daniel | 2d35a1c | 2019-02-01 14:48:10 -0500 | [diff] [blame] | 58 | this->invokeReleaseProc(); |
reed | de49988 | 2015-06-18 13:41:40 -0700 | [diff] [blame] | 59 | this->INHERITED::onRelease(); |
| 60 | } |
| 61 | |
| 62 | void GrSurface::onAbandon() { |
Greg Daniel | 2d35a1c | 2019-02-01 14:48:10 -0500 | [diff] [blame] | 63 | this->invokeReleaseProc(); |
reed | de49988 | 2015-06-18 13:41:40 -0700 | [diff] [blame] | 64 | this->INHERITED::onAbandon(); |
| 65 | } |