LCOV - code coverage report
Current view: top level - src/opengl - gpu.h (source / functions) Hit Total Coverage
Test: Code coverage Lines: 5 6 83.3 %
Date: 2025-03-29 09:04:10 Functions: 0 0 -
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 22 38 57.9 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * This file is part of libplacebo.
       3                 :            :  *
       4                 :            :  * libplacebo is free software; you can redistribute it and/or
       5                 :            :  * modify it under the terms of the GNU Lesser General Public
       6                 :            :  * License as published by the Free Software Foundation; either
       7                 :            :  * version 2.1 of the License, or (at your option) any later version.
       8                 :            :  *
       9                 :            :  * libplacebo is distributed in the hope that it will be useful,
      10                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12                 :            :  * GNU Lesser General Public License for more details.
      13                 :            :  *
      14                 :            :  * You should have received a copy of the GNU Lesser General Public
      15                 :            :  * License along with libplacebo. If not, see <http://www.gnu.org/licenses/>.
      16                 :            :  */
      17                 :            : 
      18                 :            : #pragma once
      19                 :            : 
      20                 :            : #include "../gpu.h"
      21                 :            : #include "common.h"
      22                 :            : 
      23                 :            : // Thread safety: Unsafe, same as pl_gpu_destroy
      24                 :            : pl_gpu pl_gpu_create_gl(pl_log log, pl_opengl gl, const struct pl_opengl_params *params);
      25                 :            : 
      26                 :            : // --- pl_gpu internal structs and functions
      27                 :            : 
      28                 :            : struct pl_gl {
      29                 :            :     struct pl_gpu_fns impl;
      30                 :            :     pl_opengl gl;
      31                 :            :     bool failed;
      32                 :            : 
      33                 :            :     // For import/export
      34                 :            :     EGLDisplay egl_dpy;
      35                 :            :     EGLContext egl_ctx;
      36                 :            :     bool egl_storage;
      37                 :            : #ifdef PL_HAVE_UNIX
      38                 :            :     // List of formats supported by EGL_EXT_image_dma_buf_import
      39                 :            :     PL_ARRAY(EGLint) egl_formats;
      40                 :            : #endif
      41                 :            : 
      42                 :            :     // Sync objects and associated callbacks
      43                 :            :     PL_ARRAY(struct gl_cb) callbacks;
      44                 :            : 
      45                 :            : 
      46                 :            :     // Incrementing counters to keep track of object uniqueness
      47                 :            :     int buf_id;
      48                 :            : 
      49                 :            :     // Cached capabilities
      50                 :            :     int gl_ver;
      51                 :            :     int gles_ver;
      52                 :            :     bool has_storage;
      53                 :            :     bool has_invalidate_fb;
      54                 :            :     bool has_invalidate_tex;
      55                 :            :     bool has_vao;
      56                 :            :     bool has_queries;
      57                 :            :     bool has_modifiers;
      58                 :            :     bool has_readback;
      59                 :            :     bool has_egl_storage;
      60                 :            :     bool has_egl_import;
      61                 :            :     int gather_comps;
      62                 :            : };
      63                 :            : 
      64                 :            : static inline const gl_funcs *gl_funcs_get(pl_gpu gpu)
      65                 :            : {
      66                 :      56120 :     struct pl_gl *p = PL_PRIV(gpu);
      67   [ +  +  +  +  :      49607 :     struct gl_ctx *glctx = PL_PRIV(p->gl);
          -  -  +  +  +  
          +  -  -  +  +  
                   +  - ]
      68                 :            :     return &glctx->func;
      69                 :            : }
      70                 :            : 
      71                 :            : void gl_timer_begin(pl_gpu gpu, pl_timer timer);
      72                 :            : void gl_timer_end(pl_gpu gpu, pl_timer timer);
      73                 :            : 
      74                 :            : static inline bool _make_current(pl_gpu gpu)
      75                 :            : {
      76                 :            :     struct pl_gl *p = PL_PRIV(gpu);
      77   [ +  -  +  -  :      13296 :     if (!gl_make_current(p->gl)) {
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                -  +  - ]
      78                 :          0 :         p->failed = true;
      79                 :            :         return false;
      80                 :            :     }
      81                 :            : 
      82                 :            :     return true;
      83                 :            : }
      84                 :            : 
      85                 :            : static inline void _release_current(pl_gpu gpu)
      86                 :            : {
      87                 :            :     struct pl_gl *p = PL_PRIV(gpu);
      88                 :      13296 :     gl_release_current(p->gl);
      89                 :       4855 : }
      90                 :            : 
      91                 :            : #define MAKE_CURRENT() _make_current(gpu)
      92                 :            : #define RELEASE_CURRENT() _release_current(gpu)
      93                 :            : 
      94                 :            : struct pl_tex_gl {
      95                 :            :     GLenum target;
      96                 :            :     GLuint texture;
      97                 :            :     bool wrapped_tex;
      98                 :            :     GLuint fbo; // or 0
      99                 :            :     bool wrapped_fb;
     100                 :            :     GLbitfield barrier;
     101                 :            : 
     102                 :            :     // GL format fields
     103                 :            :     GLenum format;
     104                 :            :     GLint iformat;
     105                 :            :     GLenum type;
     106                 :            : 
     107                 :            :     // For imported/exported textures
     108                 :            :     EGLImageKHR image;
     109                 :            :     int fd;
     110                 :            : };
     111                 :            : 
     112                 :            : pl_tex gl_tex_create(pl_gpu, const struct pl_tex_params *);
     113                 :            : void gl_tex_destroy(pl_gpu, pl_tex);
     114                 :            : void gl_tex_invalidate(pl_gpu, pl_tex);
     115                 :            : void gl_tex_clear_ex(pl_gpu, pl_tex, const union pl_clear_color);
     116                 :            : void gl_tex_blit(pl_gpu, const struct pl_tex_blit_params *);
     117                 :            : bool gl_tex_upload(pl_gpu, const struct pl_tex_transfer_params *);
     118                 :            : bool gl_tex_download(pl_gpu, const struct pl_tex_transfer_params *);
     119                 :            : 
     120                 :            : struct pl_buf_gl {
     121                 :            :     uint64_t id; // unique per buffer
     122                 :            :     GLuint buffer;
     123                 :            :     size_t offset;
     124                 :            :     GLsync fence;
     125                 :            :     GLbitfield barrier;
     126                 :            :     bool mapped;
     127                 :            : };
     128                 :            : 
     129                 :            : pl_buf gl_buf_create(pl_gpu, const struct pl_buf_params *);
     130                 :            : void gl_buf_destroy(pl_gpu, pl_buf);
     131                 :            : void gl_buf_write(pl_gpu, pl_buf, size_t offset, const void *src, size_t size);
     132                 :            : bool gl_buf_read(pl_gpu, pl_buf, size_t offset, void *dst, size_t size);
     133                 :            : void gl_buf_copy(pl_gpu, pl_buf dst, size_t dst_offset,
     134                 :            :                  pl_buf src, size_t src_offset, size_t size);
     135                 :            : bool gl_buf_poll(pl_gpu, pl_buf, uint64_t timeout);
     136                 :            : 
     137                 :            : struct pl_pass_gl;
     138                 :            : int gl_desc_namespace(pl_gpu, enum pl_desc_type type);
     139                 :            : pl_pass gl_pass_create(pl_gpu, const struct pl_pass_params *);
     140                 :            : void gl_pass_destroy(pl_gpu, pl_pass);
     141                 :            : void gl_pass_run(pl_gpu, const struct pl_pass_run_params *);

Generated by: LCOV version 1.16