Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the memoryUsage() method from Texture #138

Merged
merged 1 commit into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/platform/android/VideoSurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
9 changes: 7 additions & 2 deletions src/rendering/caches/TextAtlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions src/rendering/graphics/Snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(texture->width() * texture->height() * bytesPerPixels);
}

bool Snapshot::hitTest(RenderCache* cache, float x, float y) const {
tgfx::Point local = {x, y};
if (!MapPointInverted(matrix, &local)) {
Expand Down
4 changes: 1 addition & 3 deletions src/rendering/graphics/Snapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions tgfx/include/gpu/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
12 changes: 0 additions & 12 deletions tgfx/src/gpu/opengl/GLTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -77,10 +73,6 @@ class GLAlphaTexture : public GLTexture {
sampler = std::move(textureSampler);
}

size_t memoryUsage() const override {
return static_cast<size_t>(width() * height());
}

protected:
void computeRecycleKey(BytesKey* recycleKey) const override {
ComputeRecycleKey(recycleKey, width(), height());
Expand All @@ -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());
Expand Down
9 changes: 0 additions & 9 deletions tgfx/src/gpu/opengl/GLYUVTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -63,10 +61,6 @@ class GLI420Texture : public GLYUVTexture {
return YUVPixelFormat::I420;
}

size_t memoryUsage() const override {
return static_cast<size_t>(width() * height() * I420_PIXEL_BYTES);
}

protected:
void computeRecycleKey(BytesKey* recycleKey) const override {
ComputeRecycleKey(recycleKey, width(), height());
Expand All @@ -88,9 +82,6 @@ class GLNV12Texture : public GLYUVTexture {
YUVPixelFormat pixelFormat() const override {
return YUVPixelFormat::NV12;
}
size_t memoryUsage() const override {
return static_cast<size_t>(width() * height() * NV12_PIXEL_BYTES);
}

protected:
void computeRecycleKey(BytesKey* recycleKey) const override {
Expand Down
1 change: 0 additions & 1 deletion tgfx/src/gpu/opengl/cgl/CGLHardwareTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions tgfx/src/gpu/opengl/cgl/CGLHardwareTexture.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 0 additions & 1 deletion tgfx/src/gpu/opengl/eagl/EAGLHardwareTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions tgfx/src/gpu/opengl/eagl/EAGLHardwareTexture.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 0 additions & 2 deletions tgfx/src/gpu/opengl/eagl/EAGLNV12Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ class EAGLNV12Texture : public GLYUVTexture {
return YUVPixelFormat::NV12;
}

size_t memoryUsage() const override;

protected:
void onRelease(Context* context) override;

Expand Down
5 changes: 0 additions & 5 deletions tgfx/src/gpu/opengl/eagl/EAGLNV12Texture.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions tgfx/src/gpu/opengl/egl/EGLHardwareTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ class EGLHardwareTexture : public GLTexture {
static std::shared_ptr<EGLHardwareTexture> MakeFrom(Context* context,
AHardwareBuffer* hardwareBuffer);

size_t memoryUsage() const override {
return 0;
}

private:
AHardwareBuffer* hardwareBuffer = nullptr;
EGLImageKHR eglImage = EGL_NO_IMAGE_KHR;
Expand Down