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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/gpu/GrContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 9 | #include "include/gpu/GrSurface.h" |
| 10 | #include "include/gpu/GrTexture.h" |
Brian Salomon | 201cdbb | 2019-08-14 17:00:30 -0400 | [diff] [blame] | 11 | #include "src/gpu/GrRenderTarget.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "src/gpu/GrResourceProvider.h" |
| 13 | #include "src/gpu/GrSurfacePriv.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 | |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 18 | size_t GrSurface::ComputeSize(GrPixelConfig config, |
| 19 | int width, |
| 20 | int height, |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 21 | int colorSamplesPerPixel, |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 22 | GrMipMapped mipMapped, |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 23 | bool binSize) { |
Jim Van Verth | 1676cb9 | 2019-01-15 13:24:45 -0500 | [diff] [blame] | 24 | size_t colorSize; |
| 25 | |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 26 | width = binSize ? GrResourceProvider::MakeApprox(width) : width; |
| 27 | height = binSize ? GrResourceProvider::MakeApprox(height) : height; |
Robert Phillips | b446088 | 2016-11-17 14:43:51 -0500 | [diff] [blame] | 28 | |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 29 | SkASSERT(kUnknown_GrPixelConfig != config); |
Jim Van Verth | 1676cb9 | 2019-01-15 13:24:45 -0500 | [diff] [blame] | 30 | if (GrPixelConfigIsCompressed(config)) { |
| 31 | colorSize = GrCompressedFormatDataSize(config, width, height); |
| 32 | } else { |
| 33 | colorSize = (size_t)width * height * GrBytesPerPixel(config); |
| 34 | } |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 35 | SkASSERT(colorSize > 0); |
| 36 | |
| 37 | size_t finalSize = colorSamplesPerPixel * colorSize; |
| 38 | |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 39 | if (GrMipMapped::kYes == mipMapped) { |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 40 | // We don't have to worry about the mipmaps being a different size than |
| 41 | // we'd expect because we never change fDesc.fWidth/fHeight. |
| 42 | finalSize += colorSize/3; |
| 43 | } |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 44 | return finalSize; |
| 45 | } |
| 46 | |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 47 | ////////////////////////////////////////////////////////////////////////////// |
| 48 | |
reed | de49988 | 2015-06-18 13:41:40 -0700 | [diff] [blame] | 49 | void GrSurface::onRelease() { |
Greg Daniel | 2d35a1c | 2019-02-01 14:48:10 -0500 | [diff] [blame] | 50 | this->invokeReleaseProc(); |
reed | de49988 | 2015-06-18 13:41:40 -0700 | [diff] [blame] | 51 | this->INHERITED::onRelease(); |
| 52 | } |
| 53 | |
| 54 | void GrSurface::onAbandon() { |
Greg Daniel | 2d35a1c | 2019-02-01 14:48:10 -0500 | [diff] [blame] | 55 | this->invokeReleaseProc(); |
reed | de49988 | 2015-06-18 13:41:40 -0700 | [diff] [blame] | 56 | this->INHERITED::onAbandon(); |
| 57 | } |