diff --git a/src/platform/android/VideoSurface.h b/src/platform/android/VideoSurface.h index ba57c88795..d52995acd7 100644 --- a/src/platform/android/VideoSurface.h +++ b/src/platform/android/VideoSurface.h @@ -28,10 +28,6 @@ class OESTexture : public tgfx::GLTexture { tgfx::Point getTextureCoord(float x, float y) const override; - size_t memoryUsage() const override { - return 0; - } - protected: void onRelease(tgfx::Context* context) override; diff --git a/src/rendering/caches/TextAtlas.cpp b/src/rendering/caches/TextAtlas.cpp index bae2bcf117..4703225277 100644 --- a/src/rendering/caches/TextAtlas.cpp +++ b/src/rendering/caches/TextAtlas.cpp @@ -21,6 +21,7 @@ #include "core/Mask.h" #include "gpu/Canvas.h" #include "gpu/Surface.h" +#include "gpu/opengl/GLTexture.h" namespace pag { class Atlas { @@ -103,11 +104,15 @@ class RectanglePack { }; size_t Atlas::memoryUsage() const { + if (textures.empty()) { + return 0; + } size_t usage = 0; for (auto& texture : textures) { - usage += texture->memoryUsage(); + usage += texture->width() * texture->height(); } - return usage; + auto bytesPerPixels = textures[0]->getSampler()->format == tgfx::PixelFormat::ALPHA_8 ? 1 : 4; + return usage * bytesPerPixels; } static tgfx::PaintStyle ToTGFX(TextStyle style) { diff --git a/src/rendering/graphics/Snapshot.cpp b/src/rendering/graphics/Snapshot.cpp index a4144a21bc..98154d0764 100644 --- a/src/rendering/graphics/Snapshot.cpp +++ b/src/rendering/graphics/Snapshot.cpp @@ -22,6 +22,17 @@ #include "rendering/caches/RenderCache.h" namespace pag { + +size_t Snapshot::memoryUsage() const { + float bytesPerPixels; + if (texture->isYUV()) { + bytesPerPixels = 1.5f; + } else { + bytesPerPixels = texture->getSampler()->format == tgfx::PixelFormat::ALPHA_8 ? 1 : 4; + } + return static_cast(texture->width() * texture->height() * bytesPerPixels); +} + bool Snapshot::hitTest(RenderCache* cache, float x, float y) const { tgfx::Point local = {x, y}; if (!MapPointInverted(matrix, &local)) { diff --git a/src/rendering/graphics/Snapshot.h b/src/rendering/graphics/Snapshot.h index 01e571663f..3be1e17572 100644 --- a/src/rendering/graphics/Snapshot.h +++ b/src/rendering/graphics/Snapshot.h @@ -56,9 +56,7 @@ class Snapshot { /** * Returns memory usage information for this Snapshot. */ - size_t memoryUsage() const { - return texture->memoryUsage(); - } + size_t memoryUsage() const; /** * Evaluates the Snapshot to see if it overlaps or intersects with the specified point. The point diff --git a/tgfx/include/gpu/Texture.h b/tgfx/include/gpu/Texture.h index 0d61117a7b..04aafeee02 100644 --- a/tgfx/include/gpu/Texture.h +++ b/tgfx/include/gpu/Texture.h @@ -102,11 +102,6 @@ class Texture : public Resource { */ virtual Point getTextureCoord(float x, float y) const = 0; - /** - * Returns memory usage information for this Texture. - */ - virtual size_t memoryUsage() const = 0; - /** * Returns the default texture sampler. */ diff --git a/tgfx/src/gpu/opengl/GLTexture.cpp b/tgfx/src/gpu/opengl/GLTexture.cpp index ac78b2d914..e5c3a3b874 100644 --- a/tgfx/src/gpu/opengl/GLTexture.cpp +++ b/tgfx/src/gpu/opengl/GLTexture.cpp @@ -29,10 +29,6 @@ class GLBackendTexture : public GLTexture { sampler = std::move(textureSampler); } - size_t memoryUsage() const override { - return 0; - } - protected: void onRelease(Context* context) override { if (adopted) { @@ -77,10 +73,6 @@ class GLAlphaTexture : public GLTexture { sampler = std::move(textureSampler); } - size_t memoryUsage() const override { - return static_cast(width() * height()); - } - protected: void computeRecycleKey(BytesKey* recycleKey) const override { ComputeRecycleKey(recycleKey, width(), height()); @@ -107,10 +99,6 @@ class GLRGBATexture : public GLTexture { sampler = std::move(textureSampler); } - size_t memoryUsage() const override { - return width() * height() * 4; - } - protected: void computeRecycleKey(BytesKey* recycleKey) const override { ComputeRecycleKey(recycleKey, width(), height()); diff --git a/tgfx/src/gpu/opengl/GLYUVTexture.cpp b/tgfx/src/gpu/opengl/GLYUVTexture.cpp index d0dfb784f3..0a649b9e60 100644 --- a/tgfx/src/gpu/opengl/GLYUVTexture.cpp +++ b/tgfx/src/gpu/opengl/GLYUVTexture.cpp @@ -23,8 +23,6 @@ namespace tgfx { #define I420_PLANE_COUNT 3 #define NV12_PLANE_COUNT 2 -#define I420_PIXEL_BYTES 1.5 -#define NV12_PIXEL_BYTES 1.5 struct YUVConfig { YUVConfig(YUVColorSpace colorSpace, YUVColorRange colorRange, int width, int height, @@ -63,10 +61,6 @@ class GLI420Texture : public GLYUVTexture { return YUVPixelFormat::I420; } - size_t memoryUsage() const override { - return static_cast(width() * height() * I420_PIXEL_BYTES); - } - protected: void computeRecycleKey(BytesKey* recycleKey) const override { ComputeRecycleKey(recycleKey, width(), height()); @@ -88,9 +82,6 @@ class GLNV12Texture : public GLYUVTexture { YUVPixelFormat pixelFormat() const override { return YUVPixelFormat::NV12; } - size_t memoryUsage() const override { - return static_cast(width() * height() * NV12_PIXEL_BYTES); - } protected: void computeRecycleKey(BytesKey* recycleKey) const override { diff --git a/tgfx/src/gpu/opengl/cgl/CGLHardwareTexture.h b/tgfx/src/gpu/opengl/cgl/CGLHardwareTexture.h index 0fa33545d5..0765c87415 100644 --- a/tgfx/src/gpu/opengl/cgl/CGLHardwareTexture.h +++ b/tgfx/src/gpu/opengl/cgl/CGLHardwareTexture.h @@ -31,7 +31,6 @@ class CGLHardwareTexture : public GLTexture { ~CGLHardwareTexture() override; Point getTextureCoord(float x, float y) const override; - size_t memoryUsage() const override; protected: void computeRecycleKey(BytesKey* recycleKey) const override; diff --git a/tgfx/src/gpu/opengl/cgl/CGLHardwareTexture.mm b/tgfx/src/gpu/opengl/cgl/CGLHardwareTexture.mm index 9c82becd20..834c896ec5 100644 --- a/tgfx/src/gpu/opengl/cgl/CGLHardwareTexture.mm +++ b/tgfx/src/gpu/opengl/cgl/CGLHardwareTexture.mm @@ -88,11 +88,6 @@ return GLTexture::getTextureCoord(x, y); } -size_t CGLHardwareTexture::memoryUsage() const { - // 显存来自 CVPixelBuffer,这里不做重复统计。 - return 0; -} - void CGLHardwareTexture::computeRecycleKey(BytesKey* recycleKey) const { ComputeRecycleKey(recycleKey, pixelBuffer); } diff --git a/tgfx/src/gpu/opengl/eagl/EAGLHardwareTexture.h b/tgfx/src/gpu/opengl/eagl/EAGLHardwareTexture.h index d71e7a1046..4b64205f32 100644 --- a/tgfx/src/gpu/opengl/eagl/EAGLHardwareTexture.h +++ b/tgfx/src/gpu/opengl/eagl/EAGLHardwareTexture.h @@ -30,7 +30,6 @@ class EAGLHardwareTexture : public GLTexture { explicit EAGLHardwareTexture(CVPixelBufferRef pixelBuffer); ~EAGLHardwareTexture() override; - size_t memoryUsage() const override; protected: void computeRecycleKey(BytesKey* recycleKey) const override; diff --git a/tgfx/src/gpu/opengl/eagl/EAGLHardwareTexture.mm b/tgfx/src/gpu/opengl/eagl/EAGLHardwareTexture.mm index 91f51f7576..feb324b490 100644 --- a/tgfx/src/gpu/opengl/eagl/EAGLHardwareTexture.mm +++ b/tgfx/src/gpu/opengl/eagl/EAGLHardwareTexture.mm @@ -109,11 +109,6 @@ static CVOpenGLESTextureRef GetTextureRef(Context* context, CVPixelBufferRef pix } } -size_t EAGLHardwareTexture::memoryUsage() const { - // 显存来自 CVPixelBuffer,这里不做重复统计。 - return 0; -} - void EAGLHardwareTexture::computeRecycleKey(BytesKey* recycleKey) const { ComputeRecycleKey(recycleKey, pixelBuffer); } diff --git a/tgfx/src/gpu/opengl/eagl/EAGLNV12Texture.h b/tgfx/src/gpu/opengl/eagl/EAGLNV12Texture.h index b723b66cdd..e88acd86be 100644 --- a/tgfx/src/gpu/opengl/eagl/EAGLNV12Texture.h +++ b/tgfx/src/gpu/opengl/eagl/EAGLNV12Texture.h @@ -36,8 +36,6 @@ class EAGLNV12Texture : public GLYUVTexture { return YUVPixelFormat::NV12; } - size_t memoryUsage() const override; - protected: void onRelease(Context* context) override; diff --git a/tgfx/src/gpu/opengl/eagl/EAGLNV12Texture.mm b/tgfx/src/gpu/opengl/eagl/EAGLNV12Texture.mm index a1e782b784..76356e5681 100644 --- a/tgfx/src/gpu/opengl/eagl/EAGLNV12Texture.mm +++ b/tgfx/src/gpu/opengl/eagl/EAGLNV12Texture.mm @@ -89,11 +89,6 @@ static GLSampler ToGLSampler(CVOpenGLESTextureRef texture, PixelFormat format) { } } -size_t EAGLNV12Texture::memoryUsage() const { - // 显存来自 CVPixelBuffer,这里不做重复统计。 - return 0; -} - void EAGLNV12Texture::onRelease(Context*) { if (lumaTexture == nil || chromaTexture == nil) { return; diff --git a/tgfx/src/gpu/opengl/egl/EGLHardwareTexture.h b/tgfx/src/gpu/opengl/egl/EGLHardwareTexture.h index 1d4d7ef372..e721c9f8ab 100644 --- a/tgfx/src/gpu/opengl/egl/EGLHardwareTexture.h +++ b/tgfx/src/gpu/opengl/egl/EGLHardwareTexture.h @@ -31,10 +31,6 @@ class EGLHardwareTexture : public GLTexture { static std::shared_ptr MakeFrom(Context* context, AHardwareBuffer* hardwareBuffer); - size_t memoryUsage() const override { - return 0; - } - private: AHardwareBuffer* hardwareBuffer = nullptr; EGLImageKHR eglImage = EGL_NO_IMAGE_KHR;