List items
Items from the current list are shown below.
Blog
30 Apr 2024 : Day 232 #
I spent a bit of time yesterday trying to extract colour data from the SharedSurface_EGLImage object that should, as far as I understand it, be providing the raster image to be rendered to the screen. My plan has been to override the SharedSurface::ReadPixels() method — a method that currently just returns false and does nothing more — in order to make it perform the useful task of returning colour information. Since I've already set up the code to call this, once this method is working everything else should magically fall in to place.
I tried adding code into the method body to perform the task like this:
Thankfully the Stack Overflow post has an alternative approach with methods that are all shown to already be dynamically loaded in GLContext. Consequently I've updated the code to align with the suggested approach and it now looks like this:
Although all of the EGL symbols used in the code I've added exist and are technically usable, not all of them are available because of the way visibility of them is configured in GLContext. The raw_fBindFramebuffer() and raw_fDeleteFramebuffers() methods are both marked as private. I should explain that this is because these are all the raw variants of the methods. There are non-raw versions which have public visibility, but these have additional functionality I want to avoid triggering. I really do just want to use the raw versions.
To make them accessible to SharedSurface_EGLImage outside of GLContext I've therefore hacked their visibility like so:
Having made all of these changes it's time to test things out. I've built and uploaded the code, and set the WebView app running:
But I'd like to have some proper confirmation, so tomorrow I might see if I can get a full copy of the texture written out to disk so I can see what's really happening there.
If you'd like to read any of my other gecko diary entries, they're all available on my Gecko-dev Diary page.
I tried adding code into the method body to perform the task like this:
bool SharedSurface_EGLImage::ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels) { const auto& gl = GLContextEGL::Cast(mDesc.gl); gl->fBindTexture(LOCAL_GL_TEXTURE_2D, mProdTex); gl->fGetTexImage(LOCAL_GL_TEXTURE_2D, 0, format, type, pixels); return true; }But I hit a problem when the glGetTexImage() symbol, needed for the call to fGetTexImage(), wasn't available to load dynamically from the EGL library. The error kept on coming back:
Can't find symbol 'glGetTexImage'. Crash Annotation GraphicsCriticalError: |[0][GFX1-]: Failed to create EGLConfig! (t=1.32158) [GFX1-]: Failed to create EGLConfig!As I'm sure many of you will have noted, there is in fact no support for glGetTexImage() in EGL, as is explained very succinctly on Stack Overflow. So it doesn't matter how many different permutations I was going to try, this was never going to work.
Thankfully the Stack Overflow post has an alternative approach with methods that are all shown to already be dynamically loaded in GLContext. Consequently I've updated the code to align with the suggested approach and it now looks like this:
bool SharedSurface_EGLImage::ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels) { const auto& gl = GLContextEGL::Cast(mDesc.gl); // See https://stackoverflow.com/a/53993894 GLuint fbo; gl->raw_fGenFramebuffers(1, &fbo); gl->raw_fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, fbo); gl->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_COLOR_ATTACHMENT0, LOCAL_GL_TEXTURE_2D, mProdTex, 0); gl->raw_fReadPixels(x, y, width, height, format, type, pixels); gl->raw_fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, 0); gl->raw_fDeleteFramebuffers(1, &fbo); return true; }This doesn't seem to be entirely what I want because it's really just copying the texture data back into a framebuffer and reading from there, which is very similar to what I've already done but in a slightly different place in the code. But this at least brings us one step close to the screen, which is where this all eventually is supposed to end up.
Although all of the EGL symbols used in the code I've added exist and are technically usable, not all of them are available because of the way visibility of them is configured in GLContext. The raw_fBindFramebuffer() and raw_fDeleteFramebuffers() methods are both marked as private. I should explain that this is because these are all the raw variants of the methods. There are non-raw versions which have public visibility, but these have additional functionality I want to avoid triggering. I really do just want to use the raw versions.
To make them accessible to SharedSurface_EGLImage outside of GLContext I've therefore hacked their visibility like so:
//private: public: void raw_fBindFramebuffer(GLenum target, GLuint framebuffer) { BEFORE_GL_CALL; mSymbols.fBindFramebuffer(target, framebuffer); AFTER_GL_CALL; } [...] // TODO: Make private again public: void raw_fDeleteFramebuffers(GLsizei n, const GLuint* names) { BEFORE_GL_CALL; mSymbols.fDeleteFramebuffers(n, names); AFTER_GL_CALL; } private: void raw_fDeleteRenderbuffers(GLsizei n, const GLuint* names) { BEFORE_GL_CALL; mSymbols.fDeleteRenderbuffers(n, names); AFTER_GL_CALL; } [...]This wouldn't be especially noteworthy or interesting were it not for the fact that the changes I'm making are only temporary while I debug things, so I'll want to change them back before I commit any changes to the public repository. As we've already seem before, taking a note in these diary entries of things I need to reverse is a great way for me to keep track and make sure I can reverse the changes as easily as possible.
Having made all of these changes it's time to test things out. I've built and uploaded the code, and set the WebView app running:
[JavaScript Warning: "Layout was forced before the page was fully loaded. If stylesheets are not yet loaded this may cause a flash of unstyled content." {file: "https://sailfishos.org/wp-includes/js/jquery/ jquery.min.js?ver=3.5.1" line: 2}] Colour before: (0, 0, 0, 255), 1 Colour after: (0, 0, 0, 255), 1 Colour before: (0, 0, 0, 255), 1 Colour after: (0, 0, 0, 255), 1 Colour before: (0, 0, 0, 255), 1 Colour after: (0, 0, 0, 255), 1 Colour before: (0, 0, 0, 255), 1 Colour after: (0, 0, 0, 255), 1 Colour before: (0, 0, 0, 255), 1 Colour after: (0, 0, 0, 255), 1 Colour before: (0, 0, 0, 255), 1 [...] Colour after: (107, 79, 139, 255), 1 Colour before: (137, 207, 255, 255), 1 Colour after: (137, 207, 255, 255), 1 Colour before: (135, 205, 255, 255), 1 Colour after: (135, 205, 255, 255), 1 Colour before: (132, 204, 254, 255), 1 Colour after: (132, 204, 254, 255), 1 Colour before: (0, 0, 0, 255), 1 Colour after: (0, 0, 0, 255), 1 Colour before: (10, 144, 170, 255), 1 Colour after: (10, 144, 170, 255), 1 Colour before: (0, 0, 0, 255), 1 Colour after: (0, 0, 0, 255), 1 Colour before: (59, 128, 13, 255), 1 Colour after: (59, 128, 13, 255), 1 Colour before: (108, 171, 244, 255), 1 Colour after: (108, 171, 244, 255), 1 Colour before: (185, 132, 119, 255), 1 Colour after: (185, 132, 119, 255), 1 Colour before: (0, 0, 0, 255), 1 Colour after: (0, 0, 0, 255), 1 [...]As you can see, the surface starts off fully black but gets rendered until eventually it's a mix of colours. There are still a lot of cases where the pixels are just black, which makes me a bit nervous, but the colours in general look intentional. I think this is a good sign.
But I'd like to have some proper confirmation, so tomorrow I might see if I can get a full copy of the texture written out to disk so I can see what's really happening there.
If you'd like to read any of my other gecko diary entries, they're all available on my Gecko-dev Diary page.
Comments
Uncover Disqus comments