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_GBM_SURFACE_H_
6 #define UI_OZONE_PLATFORM_DRI_GBM_SURFACE_H_
8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "ui/gfx/geometry/size.h"
11 #include "ui/ozone/platform/dri/scanout_surface.h"
22 // Implement the ScanoutSurface interface on top of GBM (Generic Buffer
23 // Manager). GBM provides generic access to hardware accelerated surfaces which
24 // can be used in association with EGL to provide accelerated drawing.
25 class GbmSurface : public ScanoutSurface {
27 GbmSurface(gbm_device* device, DriWrapper* dri, const gfx::Size& size);
28 virtual ~GbmSurface();
31 virtual bool Initialize() OVERRIDE;
32 virtual uint32_t GetFramebufferId() const OVERRIDE;
33 virtual uint32_t GetHandle() const OVERRIDE;
34 virtual gfx::Size Size() const OVERRIDE;
35 virtual void SwapBuffers() OVERRIDE;
37 // Before scheduling the backbuffer to be scanned out we need to "lock" it.
38 // When we lock it, GBM will give a pointer to a buffer representing the
39 // backbuffer. It will also update its information on which buffers can not be
40 // used for drawing. The buffer will be released when the page flip event
41 // occurs (see SwapBuffers). This is called from GbmSurfaceFactory before
42 // scheduling a page flip.
43 void LockCurrentDrawable();
45 gbm_surface* native_surface() { return native_surface_; };
48 gbm_device* gbm_device_;
54 // The native GBM surface. In EGL this represents the EGLNativeWindowType.
55 gbm_surface* native_surface_;
57 // Backing GBM buffers. One is the current front buffer. The other is the
58 // current backbuffer that is pending scan out.
61 // Index to the front buffer.
64 // We can't lock (and get) an accelerated buffer from the GBM surface until
65 // after something draws into it. But modesetting needs to happen earlier,
66 // before an actual window is created and draws. So, we create a dumb buffer
68 scoped_ptr<DriBuffer> dumb_buffer_;
70 DISALLOW_COPY_AND_ASSIGN(GbmSurface);
75 #endif // UI_OZONE_PLATFORM_DRI_GBM_SURFACE_H_