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
18size_t GrSurface::ComputeSize(const GrCaps& caps,
19 const GrBackendFormat& format,
20 SkISize dimensions,
21 int colorSamplesPerPixel,
22 GrMipmapped mipMapped,
23 bool binSize) {
24 // For external formats we do not actually know the real size of the resource so we just return
25 // 0 here to indicate this.
26 if (format.textureType() == GrTextureType::kExternal) {
27 return 0;
28 }
29
30 size_t colorSize;
31
32 if (binSize) {
33 dimensions = GrResourceProvider::MakeApprox(dimensions);
34 }
35
36 SkImage::CompressionType compressionType = GrBackendFormatToCompressionType(format);
37 if (compressionType != SkImage::CompressionType::kNone) {
38 colorSize = SkCompressedFormatDataSize(compressionType, dimensions,
39 mipMapped == GrMipmapped::kYes);
40 } else {
41 colorSize = (size_t)dimensions.width() * dimensions.height() * caps.bytesPerPixel(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
57void GrSurface::onRelease() {
58 this->invokeReleaseProc();
59 this->INHERITED::onRelease();
60}
61
62void GrSurface::onAbandon() {
63 this->invokeReleaseProc();
64 this->INHERITED::onAbandon();
65}
66