blob: 90f75a82cb01e626f967120015b03d1af2bcf0fe [file] [log] [blame]
robertphillips@google.com7d501ab2012-06-21 21:09:06 +00001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/gpu/GrContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -05009#include "include/gpu/GrSurface.h"
10#include "include/gpu/GrTexture.h"
Brian Salomon201cdbb2019-08-14 17:00:30 -040011#include "src/gpu/GrRenderTarget.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "src/gpu/GrResourceProvider.h"
13#include "src/gpu/GrSurfacePriv.h"
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000014
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#include "src/core/SkMathPriv.h"
16#include "src/gpu/SkGr.h"
commit-bot@chromium.org6c5d9a12013-09-30 18:05:43 +000017
Greg Daniela00bcad2019-10-11 13:21:48 -040018size_t GrSurface::ComputeSize(const GrCaps& caps,
Greg Daniel7fd7a8a2019-10-10 16:10:31 -040019 const GrBackendFormat& format,
Brian Salomonbb5711a2017-05-17 13:49:59 -040020 int width,
21 int height,
Robert Phillipsd6214d42016-11-07 08:23:48 -050022 int colorSamplesPerPixel,
Greg Daniele252f082017-10-23 16:05:23 -040023 GrMipMapped mipMapped,
Robert Phillipsf9fcf7f2019-07-11 09:03:27 -040024 bool binSize) {
Jim Van Verth1676cb92019-01-15 13:24:45 -050025 size_t colorSize;
26
Robert Phillipsf9fcf7f2019-07-11 09:03:27 -040027 width = binSize ? GrResourceProvider::MakeApprox(width) : width;
28 height = binSize ? GrResourceProvider::MakeApprox(height) : height;
Robert Phillipsb4460882016-11-17 14:43:51 -050029
Greg Daniela00bcad2019-10-11 13:21:48 -040030 // Just setting a defualt value here to appease warnings on uninitialized object.
31 SkImage::CompressionType compressionType = SkImage::kETC1_CompressionType;
32 if (caps.isFormatCompressed(format, &compressionType)) {
33 colorSize = GrCompressedFormatDataSize(compressionType, width, height);
Jim Van Verth1676cb92019-01-15 13:24:45 -050034 } else {
Greg Daniel7fd7a8a2019-10-10 16:10:31 -040035 colorSize = (size_t)width * height * caps.bytesPerPixel(format);
Jim Van Verth1676cb92019-01-15 13:24:45 -050036 }
Robert Phillipsd6214d42016-11-07 08:23:48 -050037 SkASSERT(colorSize > 0);
38
39 size_t finalSize = colorSamplesPerPixel * colorSize;
40
Greg Daniele252f082017-10-23 16:05:23 -040041 if (GrMipMapped::kYes == mipMapped) {
Robert Phillipsd6214d42016-11-07 08:23:48 -050042 // We don't have to worry about the mipmaps being a different size than
43 // we'd expect because we never change fDesc.fWidth/fHeight.
44 finalSize += colorSize/3;
45 }
Robert Phillipsd6214d42016-11-07 08:23:48 -050046 return finalSize;
47}
48
bsalomone8d21e82015-07-16 08:23:13 -070049//////////////////////////////////////////////////////////////////////////////
50
reedde499882015-06-18 13:41:40 -070051void GrSurface::onRelease() {
Greg Daniel2d35a1c2019-02-01 14:48:10 -050052 this->invokeReleaseProc();
reedde499882015-06-18 13:41:40 -070053 this->INHERITED::onRelease();
54}
55
56void GrSurface::onAbandon() {
Greg Daniel2d35a1c2019-02-01 14:48:10 -050057 this->invokeReleaseProc();
reedde499882015-06-18 13:41:40 -070058 this->INHERITED::onAbandon();
59}