OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/ozone/platform/dri/gbm_surface.h" | 5 #include "ui/ozone/platform/dri/gbm_surface.h" |
6 | 6 |
7 #include <gbm.h> | 7 #include <gbm.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "ui/ozone/platform/dri/dri_buffer.h" | 11 #include "ui/ozone/platform/dri/dri_buffer.h" |
12 #include "ui/ozone/platform/dri/dri_window_delegate.h" | 12 #include "ui/ozone/platform/dri/dri_window_delegate.h" |
13 #include "ui/ozone/platform/dri/gbm_buffer_base.h" | 13 #include "ui/ozone/platform/dri/gbm_buffer_base.h" |
14 #include "ui/ozone/platform/dri/gbm_wrapper.h" | 14 #include "ui/ozone/platform/dri/gbm_device.h" |
15 #include "ui/ozone/platform/dri/hardware_display_controller.h" | 15 #include "ui/ozone/platform/dri/hardware_display_controller.h" |
16 #include "ui/ozone/platform/dri/scanout_buffer.h" | 16 #include "ui/ozone/platform/dri/scanout_buffer.h" |
17 | 17 |
18 namespace ui { | 18 namespace ui { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 class GbmSurfaceBuffer : public GbmBufferBase { | 22 class GbmSurfaceBuffer : public GbmBufferBase { |
23 public: | 23 public: |
24 static scoped_refptr<GbmSurfaceBuffer> CreateBuffer( | 24 static scoped_refptr<GbmSurfaceBuffer> CreateBuffer( |
25 const scoped_refptr<DriWrapper>& dri, | 25 const scoped_refptr<DrmDevice>& drm, |
26 gbm_bo* buffer); | 26 gbm_bo* buffer); |
27 static scoped_refptr<GbmSurfaceBuffer> GetBuffer(gbm_bo* buffer); | 27 static scoped_refptr<GbmSurfaceBuffer> GetBuffer(gbm_bo* buffer); |
28 | 28 |
29 private: | 29 private: |
30 GbmSurfaceBuffer(const scoped_refptr<DriWrapper>& dri, gbm_bo* bo); | 30 GbmSurfaceBuffer(const scoped_refptr<DrmDevice>& drm, gbm_bo* bo); |
31 ~GbmSurfaceBuffer() override; | 31 ~GbmSurfaceBuffer() override; |
32 | 32 |
33 static void Destroy(gbm_bo* buffer, void* data); | 33 static void Destroy(gbm_bo* buffer, void* data); |
34 | 34 |
35 // This buffer is special and is released by GBM at any point in time (as | 35 // This buffer is special and is released by GBM at any point in time (as |
36 // long as it isn't being used). Since GBM should be the only one to | 36 // long as it isn't being used). Since GBM should be the only one to |
37 // release this buffer, keep a self-reference in order to keep this alive. | 37 // release this buffer, keep a self-reference in order to keep this alive. |
38 // When GBM calls Destroy(..) the self-reference will dissapear and this will | 38 // When GBM calls Destroy(..) the self-reference will dissapear and this will |
39 // be destroyed. | 39 // be destroyed. |
40 scoped_refptr<GbmSurfaceBuffer> self_; | 40 scoped_refptr<GbmSurfaceBuffer> self_; |
41 | 41 |
42 DISALLOW_COPY_AND_ASSIGN(GbmSurfaceBuffer); | 42 DISALLOW_COPY_AND_ASSIGN(GbmSurfaceBuffer); |
43 }; | 43 }; |
44 | 44 |
45 GbmSurfaceBuffer::GbmSurfaceBuffer(const scoped_refptr<DriWrapper>& dri, | 45 GbmSurfaceBuffer::GbmSurfaceBuffer(const scoped_refptr<DrmDevice>& drm, |
46 gbm_bo* bo) | 46 gbm_bo* bo) |
47 : GbmBufferBase(dri, bo, true) { | 47 : GbmBufferBase(drm, bo, true) { |
48 if (GetFramebufferId()) { | 48 if (GetFramebufferId()) { |
49 self_ = this; | 49 self_ = this; |
50 gbm_bo_set_user_data(bo, this, GbmSurfaceBuffer::Destroy); | 50 gbm_bo_set_user_data(bo, this, GbmSurfaceBuffer::Destroy); |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 GbmSurfaceBuffer::~GbmSurfaceBuffer() {} | 54 GbmSurfaceBuffer::~GbmSurfaceBuffer() {} |
55 | 55 |
56 // static | 56 // static |
57 scoped_refptr<GbmSurfaceBuffer> GbmSurfaceBuffer::CreateBuffer( | 57 scoped_refptr<GbmSurfaceBuffer> GbmSurfaceBuffer::CreateBuffer( |
58 const scoped_refptr<DriWrapper>& dri, | 58 const scoped_refptr<DrmDevice>& drm, |
59 gbm_bo* buffer) { | 59 gbm_bo* buffer) { |
60 scoped_refptr<GbmSurfaceBuffer> scoped_buffer(new GbmSurfaceBuffer(dri, | 60 scoped_refptr<GbmSurfaceBuffer> scoped_buffer( |
61 buffer)); | 61 new GbmSurfaceBuffer(drm, buffer)); |
62 if (!scoped_buffer->GetFramebufferId()) | 62 if (!scoped_buffer->GetFramebufferId()) |
63 return NULL; | 63 return NULL; |
64 | 64 |
65 return scoped_buffer; | 65 return scoped_buffer; |
66 } | 66 } |
67 | 67 |
68 // static | 68 // static |
69 scoped_refptr<GbmSurfaceBuffer> GbmSurfaceBuffer::GetBuffer(gbm_bo* buffer) { | 69 scoped_refptr<GbmSurfaceBuffer> GbmSurfaceBuffer::GetBuffer(gbm_bo* buffer) { |
70 return scoped_refptr<GbmSurfaceBuffer>( | 70 return scoped_refptr<GbmSurfaceBuffer>( |
71 static_cast<GbmSurfaceBuffer*>(gbm_bo_get_user_data(buffer))); | 71 static_cast<GbmSurfaceBuffer*>(gbm_bo_get_user_data(buffer))); |
72 } | 72 } |
73 | 73 |
74 // static | 74 // static |
75 void GbmSurfaceBuffer::Destroy(gbm_bo* buffer, void* data) { | 75 void GbmSurfaceBuffer::Destroy(gbm_bo* buffer, void* data) { |
76 GbmSurfaceBuffer* scoped_buffer = static_cast<GbmSurfaceBuffer*>(data); | 76 GbmSurfaceBuffer* scoped_buffer = static_cast<GbmSurfaceBuffer*>(data); |
77 scoped_buffer->self_ = NULL; | 77 scoped_buffer->self_ = NULL; |
78 } | 78 } |
79 | 79 |
80 } // namespace | 80 } // namespace |
81 | 81 |
82 GbmSurface::GbmSurface(DriWindowDelegate* window_delegate, | 82 GbmSurface::GbmSurface(DriWindowDelegate* window_delegate, |
83 const scoped_refptr<GbmWrapper>& gbm) | 83 const scoped_refptr<GbmDevice>& gbm) |
84 : GbmSurfaceless(window_delegate, NULL), | 84 : GbmSurfaceless(window_delegate, NULL), |
85 gbm_(gbm), | 85 gbm_(gbm), |
86 native_surface_(NULL), | 86 native_surface_(NULL), |
87 current_buffer_(NULL), | 87 current_buffer_(NULL), |
88 weak_factory_(this) { | 88 weak_factory_(this) { |
89 } | 89 } |
90 | 90 |
91 GbmSurface::~GbmSurface() { | 91 GbmSurface::~GbmSurface() { |
92 if (current_buffer_) | 92 if (current_buffer_) |
93 gbm_surface_release_buffer(native_surface_, current_buffer_); | 93 gbm_surface_release_buffer(native_surface_, current_buffer_); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 gbm_bo* pending_buffer) { | 166 gbm_bo* pending_buffer) { |
167 // If there was a frontbuffer, it is no longer active. Release it back to GBM. | 167 // If there was a frontbuffer, it is no longer active. Release it back to GBM. |
168 if (current_buffer_) | 168 if (current_buffer_) |
169 gbm_surface_release_buffer(native_surface_, current_buffer_); | 169 gbm_surface_release_buffer(native_surface_, current_buffer_); |
170 | 170 |
171 current_buffer_ = pending_buffer; | 171 current_buffer_ = pending_buffer; |
172 callback.Run(); | 172 callback.Run(); |
173 } | 173 } |
174 | 174 |
175 } // namespace ui | 175 } // namespace ui |
OLD | NEW |