From eeedf4de06bdde741c1f0ef5eb99a41e7ba40f99 Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Sun, 30 Apr 2017 02:16:40 +0000 Subject: [PATCH] TINYGL: Deduplicate PixelFormat retrieval in zblit For some reason, loadData hardcodes a pixel format. At least avoid duplicating it in Line constructor. Likewise, avoid duplicating access to framebuffer's pixel format when constructing a Line from another. Also, avoid over-allocating Line, as its size argument is counted in pixel, not in bytes. --- graphics/tinygl/zblit.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/graphics/tinygl/zblit.cpp b/graphics/tinygl/zblit.cpp index 4e1958fd672..74088184db2 100644 --- a/graphics/tinygl/zblit.cpp +++ b/graphics/tinygl/zblit.cpp @@ -77,7 +77,7 @@ public: _binaryTransparent = false; } if (a == 0 && start >= 0) { - _lines.push_back(Line(start, y, x - start, srcBuf.getRawBuffer(start))); + _lines.push_back(Line(start, y, x - start, srcBuf.getRawBuffer(start), textureFormat)); start = -1; } else if (a != 0 && start == -1) { start = x; @@ -85,7 +85,7 @@ public: } // end of the bitmap line. if start is an actual pixel save the line. if (start >= 0) { - _lines.push_back(Line(start, y, surface.w - start, srcBuf.getRawBuffer(start))); + _lines.push_back(Line(start, y, surface.w - start, srcBuf.getRawBuffer(start), textureFormat)); } srcBuf.shiftBy(surface.w); } @@ -109,16 +109,15 @@ public: Graphics::PixelBuffer _buf; // This is needed for the conversion. Line() : _x(0), _y(0), _length(0), _pixels(nullptr) { } - Line(int x, int y, int length, byte *pixels) : _buf(TinyGL::gl_get_context()->fb->cmode, length * TinyGL::gl_get_context()->fb->cmode.bytesPerPixel, DisposeAfterUse::NO), + Line(int x, int y, int length, byte *pixels, const Graphics::PixelFormat &textureFormat) : _buf(TinyGL::gl_get_context()->fb->cmode, length, DisposeAfterUse::NO), _x(x), _y(y), _length(length) { // Performing texture to screen conversion. - const Graphics::PixelFormat textureFormat(4, 8, 8, 8, 8, 0, 8, 16, 24); Graphics::PixelBuffer srcBuf(textureFormat, pixels); _buf.copyBuffer(0, 0, length, srcBuf); _pixels = _buf.getRawBuffer(); } - Line(const Line& other) : _buf(TinyGL::gl_get_context()->fb->cmode, other._length * TinyGL::gl_get_context()->fb->cmode.bytesPerPixel, DisposeAfterUse::NO), + Line(const Line& other) : _buf(other._buf.getFormat(), other._length, DisposeAfterUse::NO), _x(other._x), _y(other._y), _length(other._length){ _buf.copyBuffer(0, 0, _length, other._buf); _pixels = _buf.getRawBuffer();