Rendercontext & Double-Bufgering By Jan Holesovsky @JHolesovsky - - PowerPoint PPT Presentation

rendercontext double bufgering
SMART_READER_LITE
LIVE PREVIEW

Rendercontext & Double-Bufgering By Jan Holesovsky @JHolesovsky - - PowerPoint PPT Presentation

Rendercontext & Double-Bufgering By Jan Holesovsky @JHolesovsky <kendy@collabora.com> @CollaboraOffjce www.CollaboraOffjce.com VCL changes... VCL (Visual Class Library) LibreOffjce's graphics toolkit ~20 year history


slide-1
SLIDE 1

Rendercontext & Double-Bufgering

By Jan Holesovsky

@JHolesovsky <kendy@collabora.com> @CollaboraOffjce www.CollaboraOffjce.com

slide-2
SLIDE 2

2 / 14 LibreOffice Conference 2015, Aarhus | Jan Holesovsky

VCL changes...

  • VCL (Visual Class Library)
  • LibreOffjce's graphics toolkit
  • ~20 year history
  • Undergoing a major upgrade to allow

modern features like OpenGL support

  • Attend the Michael's VCL talk
  • The rendercontext is just part of the entire

picture

slide-3
SLIDE 3

3 / 14 LibreOffice Conference 2015, Aarhus | Jan Holesovsky

When do we draw?

  • Before the RenderContext rework

started, Paint() methods were called just at any time

  • When painting (that's OK of course)
  • But also in event handlers (key press,

mouse over efgect, …)

  • T

riggered by timer

  • Any other random time (eg. in Writer – the

debug rectangle at the top left when layout fjnishes)

slide-4
SLIDE 4

4 / 14 LibreOffice Conference 2015, Aarhus | Jan Holesovsky

Ideal state

  • Painting triggered in a controlled way
  • Only the Paint() methods paint
  • Only VCL triggers the paint

– Consequently it can control the conditions of

the paint – various setups / tear downs etc.

  • Everything else only invalidates the area

– And VCL decides when to paint, and what

  • Painting de-coupled from vcl::Window
  • vcl::Window becomes more abstract
slide-5
SLIDE 5

5 / 14 LibreOffice Conference 2015, Aarhus | Jan Holesovsky

RenderContext – what's that?

  • RenderContext: class that implements the

drawing

  • At the moment, vcl::Window inherits from

OutputDevice which allows all the painting at random points of time

– That's what we want to avoid

  • Instead, RenderContext is an

implementation of the OutputDevice

  • And is passed as a param of the Paint() method
  • vcl::Window paints only in Paint()
slide-6
SLIDE 6

6 / 14 LibreOffice Conference 2015, Aarhus | Jan Holesovsky

Problems with direct paints

  • Direct paints are problematic, because

the render context is not available

  • The code that previously called Paint()

directly now has to use Invalidate()

  • Invalidate()s are fast now – thanks to the

Idle work

  • Rework to use Invalidate() has to be

done carefully though

  • Danger of Invalidate() loops
slide-7
SLIDE 7

7 / 14 LibreOffice Conference 2015, Aarhus | Jan Holesovsky

Double-bufgering

  • Easy once RenderContext is used

everywhere

  • vcl/source/window/paint.cxx responsible

for the rendering in the right order

  • For double-bufgering, additionally:

– Bufger set up before calling paint

(VirtualDevice)

– Then call the Paint()s (as before) – Copy the bufger to the screen when done

slide-8
SLIDE 8

8 / 14 LibreOffice Conference 2015, Aarhus | Jan Holesovsky

Rendercontext rework

  • Easy parts
  • Adding the RenderContext parameter (via

clang plugin)

  • Hard parts
  • Everything else :-)
  • Implemented by T
  • maž Vajngerl and

Miklos Vajna

  • Laszlo Nemeth and others nailed down

many bugs – thank you!

slide-9
SLIDE 9

9 / 14 LibreOffice Conference 2015, Aarhus | Jan Holesovsky

Hard parts of the work

  • Direct paints stateful in many cases
  • Background set once in a constructor, instead of

the Paint method

  • OutputDevice cached
  • Many places just try to remember the

OutputDevice, and paint to it later

  • Blinking cursor
  • Currently it just inverts what is on the screen
  • Size of the window vs. size of the

rendercontext confusion

slide-10
SLIDE 10

10 / 14 LibreOffice Conference 2015, Aarhus | Jan Holesovsky

Current status

  • Currently
  • Most of the classes modifjed to paint only

in the Paint() methods

  • StartCenter completely double-bufgered
  • Writer mostly double-bufgered

– Except text cursor – needs inverting still – and

some deep pieces

  • Try yourself:
  • export VCL_DOUBLEBUFFERING_FORCE_ENABLE=1
slide-11
SLIDE 11

DEMO

slide-12
SLIDE 12

12 / 14 LibreOffice Conference 2015, Aarhus | Jan Holesovsky

TODO

  • T

ext cursor

  • Inverting not convenient; should we have it

as a fmat rectangle? [as in Firefox etc.]

  • Switch it on for StartCenter and Writer
  • Cleanup
  • Get rid of the code paths that are not

needed for double-bufgering

  • Implement it for Calc, Impress and Base
slide-13
SLIDE 13

13 / 14 LibreOffice Conference 2015, Aarhus | Jan Holesovsky

And further...

  • Switch all the drawing to tiled rendering
  • Paint methods would not paint the entire

screen, but only 256x256 'tiles'

  • Currently used on Android & LibreOffjce

On-Line

  • Adding Desktop would make it one code

path again

  • Would allow extremely fast OpenGL

scrolling / panning / zoom

slide-14
SLIDE 14

14 / 14 LibreOffice Conference 2015, Aarhus | Jan Holesovsky

Questions?

Thanks for listening!