1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_OZONE_PLATFORM_DRI_SCANOUT_SURFACE_H_
6 #define UI_OZONE_PLATFORM_DRI_SCANOUT_SURFACE_H_
16 // ScanoutSurface is an interface for a surface that can be scanned out to a
17 // monitor using the DRM/KMS API. Implementations will store the internal state
18 // associated with the drawing surface. Implementations are also required to
19 // performs all the needed operations to initialize and update the drawing
22 // The typical usage pattern is:
23 // -----------------------------------------------------------------------------
24 // HardwareDisplayController controller;
25 // // Initialize controller
27 // ScanoutSurface* surface = new ScanoutSurfaceImpl(size);
28 // surface.Initialize();
29 // controller.BindSurfaceToController(surface);
32 // DrawIntoSurface(surface);
33 // controller.SchedulePageFlip();
35 // Wait for page flip event. The DRM page flip handler will call
36 // surface.SwapBuffers();
40 // -----------------------------------------------------------------------------
41 // In the above example the wait consists of reading a DRM pageflip event from
42 // the graphics card file descriptor. This is done by calling |drmHandleEvent|,
43 // which will read and process the event. |drmHandleEvent| will call a callback
44 // registered by |SchedulePageFlip| which will update the internal state.
46 // |SchedulePageFlip| can also be used to limit drawing to the screen's vsync
47 // since page flips only happen on vsync. In a threaded environment a message
48 // loop would listen on the graphics card file descriptor for an event and
49 // |drmHandleEvent| would be called from the message loop. The event handler
50 // would also be responsible for updating the renderer's state and signal that
51 // it is OK to start drawing the next frame.
52 class ScanoutSurface
{
54 virtual ~ScanoutSurface() {}
56 // Used to allocate all necessary buffers for this surface. If the
57 // initialization succeeds, the device is ready to be used for drawing
59 // Returns true if the initialization is successful, false otherwise.
60 virtual bool Initialize() = 0;
62 // Swaps the back buffer with the front buffer.
63 virtual void SwapBuffers() = 0;
65 // Returns the ID of the current backbuffer.
66 virtual uint32_t GetFramebufferId() const = 0;
68 // Returns the handle of the current backbuffer.
69 virtual uint32_t GetHandle() const = 0;
71 // Returns the surface size.
72 virtual gfx::Size
Size() const = 0;
75 class ScanoutSurfaceGenerator
{
77 virtual ~ScanoutSurfaceGenerator() {}
79 virtual ScanoutSurface
* Create(const gfx::Size
& size
) = 0;
84 #endif // UI_OZONE_PLATFORM_DRI_SCANOUT_SURFACE_H_