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 | |
8 | #include "include/gpu/GrContext.h" |
9 | #include "src/core/SkCompressedDataUtils.h" |
10 | #include "src/gpu/GrRenderTarget.h" |
11 | #include "src/gpu/GrResourceProvider.h" |
12 | #include "src/gpu/GrSurface.h" |
13 | #include "src/gpu/GrSurfacePriv.h" |
14 | #include "src/gpu/GrTexture.h" |
15 | |
16 | #include "src/core/SkMathPriv.h" |
17 | #include "src/gpu/SkGr.h" |
18 | |
19 | size_t GrSurface::ComputeSize(const GrCaps& caps, |
20 | const GrBackendFormat& format, |
21 | SkISize dimensions, |
22 | int colorSamplesPerPixel, |
23 | GrMipMapped mipMapped, |
24 | bool binSize) { |
25 | // For external formats we do not actually know the real size of the resource so we just return |
26 | // 0 here to indicate this. |
27 | if (format.textureType() == GrTextureType::kExternal) { |
28 | return 0; |
29 | } |
30 | |
31 | size_t colorSize; |
32 | |
33 | if (binSize) { |
34 | dimensions = GrResourceProvider::MakeApprox(dimensions); |
35 | } |
36 | |
37 | SkImage::CompressionType compressionType = caps.compressionType(format); |
38 | if (compressionType != SkImage::CompressionType::kNone) { |
39 | colorSize = SkCompressedFormatDataSize(compressionType, dimensions, |
40 | mipMapped == GrMipMapped::kYes); |
41 | } else { |
42 | colorSize = (size_t)dimensions.width() * dimensions.height() * caps.bytesPerPixel(format); |
43 | } |
44 | SkASSERT(colorSize > 0); |
45 | |
46 | size_t finalSize = colorSamplesPerPixel * colorSize; |
47 | |
48 | if (GrMipMapped::kYes == mipMapped) { |
49 | // We don't have to worry about the mipmaps being a different dimensions than |
50 | // we'd expect because we never change fDesc.fWidth/fHeight. |
51 | finalSize += colorSize/3; |
52 | } |
53 | return finalSize; |
54 | } |
55 | |
56 | ////////////////////////////////////////////////////////////////////////////// |
57 | |
58 | void GrSurface::onRelease() { |
59 | this->invokeReleaseProc(); |
60 | this->INHERITED::onRelease(); |
61 | } |
62 | |
63 | void GrSurface::onAbandon() { |
64 | this->invokeReleaseProc(); |
65 | this->INHERITED::onAbandon(); |
66 | } |
67 |