Flutter Engine
The Flutter Engine
GrSurface.cpp
Go to the documentation of this file.
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
17
18#include "src/base/SkMathPriv.h"
19#include "src/gpu/ganesh/SkGr.h"
20
22 SkISize dimensions,
23 int colorSamplesPerPixel,
24 skgpu::Mipmapped mipmapped,
25 bool binSize) {
26 // For external formats we do not actually know the real size of the resource so we just return
27 // 0 here to indicate this.
28 if (format.textureType() == GrTextureType::kExternal) {
29 return 0;
30 }
31
32 size_t colorSize;
33
34 if (binSize) {
36 }
37
39 if (compressionType != SkTextureCompressionType::kNone) {
41 compressionType, dimensions, mipmapped == skgpu::Mipmapped::kYes);
42 } else {
43 colorSize = (size_t)dimensions.width() * dimensions.height() *
45 }
46 SkASSERT(colorSize > 0);
47
48 size_t finalSize = colorSamplesPerPixel * colorSize;
49
50 if (skgpu::Mipmapped::kYes == mipmapped) {
51 // We don't have to worry about the mipmaps being a different dimensions than
52 // we'd expect because we never change fDesc.fWidth/fHeight.
53 finalSize += colorSize/3;
54 }
55 return finalSize;
56}
57
58//////////////////////////////////////////////////////////////////////////////
59
61 SkASSERT(this->getContext());
62 fReleaseHelper.reset(new RefCntedReleaseProc(std::move(releaseHelper),
63 sk_ref_sp(this->getContext())));
64 this->onSetRelease(fReleaseHelper);
65}
66
67
69 sk_sp<GrDirectContext> directContext)
70 : fCallback(std::move(callback))
71 , fDirectContext(std::move(directContext)) {
72 SkASSERT(fCallback && fDirectContext);
73 }
74
76 fDirectContext->priv().setInsideReleaseProc(true);
77 fCallback.reset();
78 fDirectContext->priv().setInsideReleaseProc(false);
79}
80
82 this->invokeReleaseProc();
84}
85
87 this->invokeReleaseProc();
89}
size_t GrBackendFormatBytesPerPixel(const GrBackendFormat &format)
SkTextureCompressionType GrBackendFormatToCompressionType(const GrBackendFormat &format)
#define SkASSERT(cond)
Definition: SkAssert.h:116
size_t SkCompressedFormatDataSize(SkTextureCompressionType compressionType, SkISize dimensions, bool mipmapped)
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
SkTextureCompressionType
virtual void onAbandon()
const GrDirectContext * getContext() const
virtual void onRelease()
RefCntedReleaseProc(sk_sp< skgpu::RefCntedCallback > callback, sk_sp< GrDirectContext > directContext)
Definition: GrSurface.cpp:68
void setRelease(sk_sp< skgpu::RefCntedCallback > releaseHelper)
Definition: GrSurface.cpp:60
SkISize dimensions() const
Definition: GrSurface.h:27
static size_t ComputeSize(const GrBackendFormat &, SkISize dimensions, int colorSamplesPerPixel, skgpu::Mipmapped, bool binSize=false)
Definition: GrSurface.cpp:21
virtual void onSetRelease(sk_sp< RefCntedReleaseProc >)
Definition: GrSurface.h:164
void onAbandon() override
Definition: GrSurface.cpp:86
void onRelease() override
Definition: GrSurface.cpp:81
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
uint32_t uint32_t * format
SkISize GetApproxSize(SkISize size)
Mipmapped
Definition: GpuTypes.h:53
Definition: ref_ptr.h:256
Definition: SkSize.h:16
constexpr int32_t width() const
Definition: SkSize.h:36
constexpr int32_t height() const
Definition: SkSize.h:37