xpra icon
Bug tracker and wiki

Ticket #1765: gl-yuva.patch

File gl-yuva.patch, 7.6 KB (added by Antoine Martin, 6 months ago)

stub implementation for opengl

  • xpra/client/gl/gl_window_backing_base.py

     
    11# This file is part of Xpra.
    22# Copyright (C) 2013 Serviware (Arthur Huillet, <ahuillet@serviware.com>)
    3 # Copyright (C) 2012-2019 Antoine Martin <antoine@xpra.org>
     3# Copyright (C) 2012-2020 Antoine Martin <antoine@xpra.org>
    44# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
    55# later version. See the file COPYING for details.
    66
     
    1515    GL_UNPACK_ROW_LENGTH, GL_UNPACK_ALIGNMENT,
    1616    GL_TEXTURE_MAG_FILTER, GL_TEXTURE_MIN_FILTER, GL_NEAREST,
    1717    GL_UNSIGNED_BYTE, GL_LUMINANCE, GL_LINEAR,
    18     GL_TEXTURE0, GL_TEXTURE1, GL_TEXTURE2, GL_QUADS, GL_LINE_LOOP, GL_LINES, GL_COLOR_BUFFER_BIT,
     18    GL_TEXTURE0, GL_TEXTURE1, GL_TEXTURE2, GL_TEXTURE3,
     19    GL_QUADS, GL_LINE_LOOP, GL_LINES, GL_COLOR_BUFFER_BIT,
    1920    GL_TEXTURE_WRAP_S, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER,
    2021    GL_DONT_CARE, GL_TRUE, GL_DEPTH_TEST, GL_SCISSOR_TEST, GL_LIGHTING, GL_DITHER,
    2122    GL_RGB, GL_RGBA, GL_BGR, GL_BGRA, GL_RGBA8, GL_RGB8, GL_RGB10_A2, GL_RGB565, GL_RGB5_A1, GL_RGBA4,
     
    6364    WEBP_PILLOW, SCROLL_ENCODING,
    6465    )
    6566from xpra.client.gl.gl_check import GL_ALPHA_SUPPORTED, is_pyopengl_memoryview_safe, get_max_texture_size
    66 from xpra.client.gl.gl_colorspace_conversions import YUV2RGB_shader, YUV2RGB_FULL_shader, RGBP2RGB_shader
     67from xpra.client.gl.gl_colorspace_conversions import (
     68    YUV2RGB_shader, YUV2RGB_FULL_shader, RGBP2RGB_shader, YUVA2RGBA_shader,
     69    )
    6770from xpra.client.gl.gl_spinner import draw_spinner
    6871from xpra.log import Logger
    6972
     
    200203TEX_Y = 0
    201204TEX_U = 1
    202205TEX_V = 2
    203 TEX_RGB = 3
    204 TEX_FBO = 4         #FBO texture (guaranteed up-to-date window contents)
    205 TEX_TMP_FBO = 5
    206 TEX_CURSOR = 6
    207 N_TEXTURES = 7
     206TEX_A = 3
     207TEX_RGB = 4
     208TEX_FBO = 5         #FBO texture (guaranteed up-to-date window contents)
     209TEX_TMP_FBO = 6
     210TEX_CURSOR = 7
     211N_TEXTURES = 8
    208212
    209213# Shader number assignment
    210214YUV2RGB_SHADER = 0
    211215RGBP2RGB_SHADER = 1
    212216YUV2RGB_FULL_SHADER = 2
     217YUVA2RGBA_SHADER = 3
    213218
     219SHADER_STR = {
     220    YUV2RGB_SHADER      : "YUV2RGB",
     221    RGBP2RGB_SHADER     : "RGBP2RGB",
     222    YUV2RGB_FULL_SHADER : "YUV2RGB_FULL",
     223    YUVA2RGBA_SHADER    : "YUVA2RGBA",
     224    }
    214225
    215226"""
    216227The logic is as follows:
     
    450461        for name, progid, progstr in (
    451462            ("YUV2RGB",     YUV2RGB_SHADER,         YUV2RGB_shader),
    452463            ("YUV2RGBFULL", YUV2RGB_FULL_SHADER,    YUV2RGB_FULL_shader),
     464            ("YUVA2RGBA",   YUVA2RGBA_SHADER,       YUVA2RGBA_shader),
    453465            ("RGBP2RGB",    RGBP2RGB_SHADER,        RGBP2RGB_shader),
    454466            ):
    455467            glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, self.shaders[progid])
     
    10071019    def paint_webp(self, img_data, x : int, y : int, width : int, height : int, options, callbacks):
    10081020        subsampling = options.strget("subsampling")
    10091021        has_alpha = options.boolget("has_alpha")
    1010         if subsampling=="YUV420P" and WEBP_YUV and self.webp_decoder and not WEBP_PILLOW and not has_alpha and width>=2 and height>=2:
     1022        if subsampling=="YUV420P" and WEBP_YUV and self.webp_decoder and not WEBP_PILLOW and width>=2 and height>=2:
    10111023            img = self.webp_decoder.decompress_yuv(img_data)
    10121024            flush = options.intget("flush", 0)
    10131025            w = img.get_width()
    10141026            h = img.get_height()
    1015             self.idle_add(self.gl_paint_planar, YUV2RGB_SHADER, flush, "webp", img,
     1027            if has_alpha:
     1028                shader = YUVA2RGBA_SHADER
     1029            else:
     1030                shader = YUV2RGB_SHADER
     1031            self.idle_add(self.gl_paint_planar, shader, flush, "webp", img,
    10161032                          x, y, w, h, width, height, options, callbacks)
    10171033            return
    10181034        super().paint_webp(img_data, x, y, width, height, options, callbacks)
     
    11121128                        x : int, y : int, enc_width : int, enc_height : int, width : int, height : int,
    11131129                        options, callbacks):
    11141130        #this function runs in the UI thread, no video_decoder lock held
    1115         log("gl_paint_planar%s", (flush, encoding, img, x, y, enc_width, enc_height, width, height, options, callbacks))
     1131        log("gl_paint_planar%s", (SHADER_STR.get(shader, shader), flush, encoding, img,
     1132                                  x, y, enc_width, enc_height, width, height,
     1133                                  options, callbacks))
    11161134        x, y = self.gravity_adjust(x, y, options)
    11171135        try:
    11181136            pixel_format = img.get_pixel_format()
    1119             assert pixel_format in ("YUV420P", "YUV422P", "YUV444P", "GBRP"), \
     1137            assert pixel_format in ("YUV420P", "YUV422P", "YUV444P", "GBRP", "YUVA"), \
    11201138                "sorry the GL backing does not handle pixel format '%s' yet!" % (pixel_format)
    11211139
    11221140            context = self.gl_context()
     
    11641182            self.pixel_format = pixel_format
    11651183            self.texture_size = (width, height)
    11661184            # Create textures of the same size as the window's
    1167             for texture, index in ((GL_TEXTURE0, TEX_Y), (GL_TEXTURE1, TEX_U), (GL_TEXTURE2, TEX_V)):
    1168                 (div_w, div_h) = divs[index]
     1185            for texture, index in (
     1186                (GL_TEXTURE0, TEX_Y),
     1187                (GL_TEXTURE1, TEX_U),
     1188                (GL_TEXTURE2, TEX_V),
     1189                (GL_TEXTURE3, TEX_A),
     1190                ):
     1191                div_w, div_h = divs[index]
    11691192                glActiveTexture(texture)
    11701193                target = GL_TEXTURE_RECTANGLE_ARB
    11711194                glBindTexture(target, self.textures[index])
  • xpra/client/gl/gl_colorspace_conversions.py

     
    4343# 10 instructions, 2 R-regs
    4444"""
    4545
     46YUVA2RGBA_shader = b"""!!ARBfp1.0
     47# cgc version 3.1.0010, build date Feb 10 2012
     48# command line args: -profile arbfp1
     49# source file: yuv.cg
     50#vendor NVIDIA Corporation
     51#version 3.1.0.10
     52#profile arbfp1
     53#program main
     54#semantic main.IN
     55#var float2 IN.texcoord1 : $vin.TEXCOORD0 : TEX0 : 0 : 1
     56#var float2 IN.texcoord2 : $vin.TEXCOORD1 : TEX1 : 0 : 1
     57#var float2 IN.texcoord3 : $vin.TEXCOORD2 : TEX2 : 0 : 1
     58#var float2 IN.texcoord4 : $vin.TEXCOORD2 : TEX3 : 0 : 1
     59#var samplerRECT IN.texture1 : TEXUNIT0 : texunit 0 : 0 : 1
     60#var samplerRECT IN.texture2 : TEXUNIT1 : texunit 1 : 0 : 1
     61#var samplerRECT IN.texture3 : TEXUNIT2 : texunit 2 : 0 : 1
     62#var samplerRECT IN.texture4 : TEXUNIT3 : texunit 3 : 0 : 1
     63#var float4 IN.color : $vin.COLOR0 : COL0 : 0 : 1
     64#var float4 main.color : $vout.COLOR0 : COL : -1 : 1
     65#const c[0] = 1.1643835 2.017231 0 0.5
     66#const c[1] = 0.0625 1.1643835 -0.3917616 -0.81296802
     67#const c[2] = 1.1643835 0 1.5960271
     68    PARAM c[3] = { { 1.1643835, 2.017231, 0, 0.5 },
     69            { 0.0625, 1.1643835, -0.3917616, -0.81296802 },
     70            { 1.1643835, 0, 1.5960271 } };
     71    TEMP R0;
     72    TEMP R1;
     73    TEX R0.x, fragment.texcoord[2], texture[2], RECT;
     74    ADD R1.z, R0.x, -c[0].w;
     75    TEX R1.x, fragment.texcoord[0], texture[0], RECT;
     76    TEX R0.x, fragment.texcoord[1], texture[1], RECT;
     77    ADD R1.x, R1, -c[1];
     78    ADD R1.y, R0.x, -c[0].w;
     79    DP3 result.color.z, R1, c[0];
     80    DP3 result.color.y, R1, c[1].yzww;
     81    DP3 result.color.x, R1, c[2];
     82    MOV result.color.w, fragment.texcoord[3];
     83    END
     84# 10 instructions, 2 R-regs
     85"""
     86
    4687YUV2RGB_FULL_shader = b"""!!ARBfp1.0
    4788# cgc version 3.0.0016, build date Feb 13 2011
    4889# command line args: -profile arbfp1