• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "src/core/SkCompressedDataUtils.h"
9 #include "src/gpu/GrBackendUtils.h"
10 #include "src/gpu/GrRenderTarget.h"
11 #include "src/gpu/GrResourceProvider.h"
12 #include "src/gpu/GrSurface.h"
13 #include "src/gpu/GrTexture.h"
14 
15 #include "src/core/SkMathPriv.h"
16 #include "src/gpu/SkGr.h"
17 
ComputeSize(const GrBackendFormat & format,SkISize dimensions,int colorSamplesPerPixel,GrMipmapped mipMapped,bool binSize)18 size_t GrSurface::ComputeSize(const GrBackendFormat& format,
19                               SkISize dimensions,
20                               int colorSamplesPerPixel,
21                               GrMipmapped mipMapped,
22                               bool binSize) {
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 
29     size_t colorSize;
30 
31     if (binSize) {
32         dimensions = GrResourceProvider::MakeApprox(dimensions);
33     }
34 
35     SkImage::CompressionType compressionType = GrBackendFormatToCompressionType(format);
36     if (compressionType != SkImage::CompressionType::kNone) {
37         colorSize = SkCompressedFormatDataSize(compressionType, dimensions,
38                                                mipMapped == GrMipmapped::kYes);
39     } else {
40         colorSize = (size_t)dimensions.width() * dimensions.height() *
41                     GrBackendFormatBytesPerPixel(format);
42     }
43     SkASSERT(colorSize > 0);
44 
45     size_t finalSize = colorSamplesPerPixel * colorSize;
46 
47     if (GrMipmapped::kYes == mipMapped) {
48         // We don't have to worry about the mipmaps being a different dimensions than
49         // we'd expect because we never change fDesc.fWidth/fHeight.
50         finalSize += colorSize/3;
51     }
52     return finalSize;
53 }
54 
55 //////////////////////////////////////////////////////////////////////////////
56 
onRelease()57 void GrSurface::onRelease() {
58     this->invokeReleaseProc();
59     this->INHERITED::onRelease();
60 }
61 
onAbandon()62 void GrSurface::onAbandon() {
63     this->invokeReleaseProc();
64     this->INHERITED::onAbandon();
65 }
66