xpra icon
Bug tracker and wiki

Ticket #478: gl-resize.patch

File gl-resize.patch, 4.7 KB (added by Antoine Martin, 2 years ago)

try to use blitframebuffer and the tmpfbo to preserve the contents - no workee

  • xpra/client/gl/gl_window_backing_base.py

     
    276276    def init(self, ww, wh, bw, bh):
    277277        #re-init gl projection with new dimensions
    278278        #(see gl_init)
     279        self.render_size = ww, wh
    279280        if self.size!=(bw, bh):
    280             self.gl_setup = False
    281             self.size = bw, bh
    282         self.render_size = ww, wh
     281            if self.gl_setup:
     282                self.resize(bw, bh)
     283            else:
     284                self.size = bw, bh
    283285
    284286    def gl_marker(self, *msg):
    285287        log(*msg)
     
    459461            b.destroy()
    460462        self.glconfig = None
    461463
     464    def resize(self, bw, bh):
     465        ow, oh = self.size
     466        self.size = bw, bh
     467        log("resize%s", (bw, bh))
     468        context = self.gl_context()
     469        if not context:
     470            log.warn("Warning: cannot resize, no OpenGL context!")
     471            return
     472        with context:
     473            bw, bh = self.size
     474            self.set_rgb_paint_state()
     475
     476            glViewport(0, 0, bw, bh)
     477            glMatrixMode(GL_PROJECTION)
     478            glLoadIdentity()
     479            glOrtho(0.0, bw, bh, 0.0, -1.0, 1.0)
     480            glMatrixMode(GL_MODELVIEW)
     481
     482            # Define new empty tmp FBO using the new size:
     483            glBindTexture(GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_TMP_FBO])
     484            glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_BASE_LEVEL, 0)
     485            glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAX_LEVEL, 0)
     486            glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, self.texture_pixel_format, bw, bh, 0, self.texture_pixel_format, GL_UNSIGNED_BYTE, None)
     487            glBindFramebuffer(GL_FRAMEBUFFER, self.tmp_fbo)
     488            glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_TMP_FBO], 0)
     489            glClear(GL_COLOR_BUFFER_BIT)
     490
     491            glBindFramebuffer(GL_READ_FRAMEBUFFER, self.offscreen_fbo)
     492            glBindTexture(GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_FBO])
     493            glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_FBO], 0)
     494            glReadBuffer(GL_COLOR_ATTACHMENT0)
     495
     496            glBindFramebuffer(GL_DRAW_FRAMEBUFFER, self.tmp_fbo)
     497            glBindTexture(GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_TMP_FBO])
     498            glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_TMP_FBO], 0)
     499            glDrawBuffer(GL_COLOR_ATTACHMENT1)
     500
     501            w = min(ow, bw)
     502            h = min(oh, bh)
     503            shrinkh = oh-h
     504            growh = bh-h
     505            #copy current fbo:
     506            glBlitFramebuffer(0, h, w, 0,
     507                              0, h, w, 0,
     508                              GL_COLOR_BUFFER_BIT, GL_NEAREST)
     509            log.info("glBlitFramebuffer%s", (0, oh, w, shrinkh,
     510                              0, bh, w, growh))
     511
     512            #now swap references to tmp and offscreen so tmp becomes the new offscreen:
     513            tmp = self.offscreen_fbo
     514            self.offscreen_fbo = self.tmp_fbo
     515            self.tmp_fbo = tmp
     516            tmp = self.textures[TEX_FBO]
     517            self.textures[TEX_FBO] = self.textures[TEX_TMP_FBO]
     518            self.textures[TEX_TMP_FBO] = tmp
     519
     520            #and again, new empty fbo:
     521            glBindTexture(GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_TMP_FBO])
     522            glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_BASE_LEVEL, 0)
     523            glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAX_LEVEL, 0)
     524            glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, self.texture_pixel_format, bw, bh, 0, self.texture_pixel_format, GL_UNSIGNED_BYTE, None)
     525            glBindFramebuffer(GL_FRAMEBUFFER, self.tmp_fbo)
     526            glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_TMP_FBO], 0)
     527            glClear(GL_COLOR_BUFFER_BIT)
     528
     529            #restore normal paint state:
     530            glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_FBO], 0)
     531            glBindFramebuffer(GL_READ_FRAMEBUFFER, self.offscreen_fbo)
     532            glBindFramebuffer(GL_DRAW_FRAMEBUFFER, self.offscreen_fbo)
     533            glBindFramebuffer(GL_FRAMEBUFFER, self.offscreen_fbo)
     534
     535            self.unset_rgb_paint_state()
     536            self.paint_box("scroll", True, 0, bw, w, growh)
     537            self.present_fbo(0, 0, bw, bh)
     538
    462539    def paint_scroll(self, x, y, w, h, scroll_data, options, callbacks):
    463540        flush = options.intget("flush", 0)
    464541        self.idle_add(self.do_scroll_paints, scroll_data, flush)