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_factory.h" | 5 #include "ui/ozone/platform/dri/gbm_surface_factory.h" |
6 | 6 |
7 #include <gbm.h> | 7 #include <gbm.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "third_party/khronos/EGL/egl.h" | 11 #include "third_party/khronos/EGL/egl.h" |
12 #include "ui/ozone/common/egl_util.h" | 12 #include "ui/ozone/common/egl_util.h" |
13 #include "ui/ozone/platform/dri/dri_window_delegate_impl.h" | 13 #include "ui/ozone/platform/dri/dri_window_delegate_impl.h" |
14 #include "ui/ozone/platform/dri/dri_window_delegate_manager.h" | 14 #include "ui/ozone/platform/dri/dri_window_delegate_manager.h" |
15 #include "ui/ozone/platform/dri/dri_wrapper.h" | |
16 #include "ui/ozone/platform/dri/gbm_buffer.h" | 15 #include "ui/ozone/platform/dri/gbm_buffer.h" |
17 #include "ui/ozone/platform/dri/gbm_surface.h" | 16 #include "ui/ozone/platform/dri/gbm_surface.h" |
18 #include "ui/ozone/platform/dri/gbm_surfaceless.h" | 17 #include "ui/ozone/platform/dri/gbm_surfaceless.h" |
| 18 #include "ui/ozone/platform/dri/gbm_wrapper.h" |
19 #include "ui/ozone/platform/dri/screen_manager.h" | 19 #include "ui/ozone/platform/dri/screen_manager.h" |
20 #include "ui/ozone/public/native_pixmap.h" | 20 #include "ui/ozone/public/native_pixmap.h" |
21 #include "ui/ozone/public/overlay_candidates_ozone.h" | 21 #include "ui/ozone/public/overlay_candidates_ozone.h" |
22 #include "ui/ozone/public/ozone_switches.h" | 22 #include "ui/ozone/public/ozone_switches.h" |
23 #include "ui/ozone/public/surface_ozone_egl.h" | 23 #include "ui/ozone/public/surface_ozone_egl.h" |
24 | 24 |
25 namespace ui { | 25 namespace ui { |
26 namespace { | 26 namespace { |
27 | 27 |
28 class SingleOverlay : public OverlayCandidatesOzone { | 28 class SingleOverlay : public OverlayCandidatesOzone { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 } | 62 } |
63 } | 63 } |
64 | 64 |
65 DISALLOW_COPY_AND_ASSIGN(SingleOverlay); | 65 DISALLOW_COPY_AND_ASSIGN(SingleOverlay); |
66 }; | 66 }; |
67 | 67 |
68 } // namespace | 68 } // namespace |
69 | 69 |
70 GbmSurfaceFactory::GbmSurfaceFactory(bool allow_surfaceless) | 70 GbmSurfaceFactory::GbmSurfaceFactory(bool allow_surfaceless) |
71 : DriSurfaceFactory(NULL, NULL), | 71 : DriSurfaceFactory(NULL, NULL), |
72 device_(NULL), | |
73 allow_surfaceless_(allow_surfaceless) { | 72 allow_surfaceless_(allow_surfaceless) { |
74 } | 73 } |
75 | 74 |
76 GbmSurfaceFactory::~GbmSurfaceFactory() {} | 75 GbmSurfaceFactory::~GbmSurfaceFactory() {} |
77 | 76 |
78 void GbmSurfaceFactory::InitializeGpu( | 77 void GbmSurfaceFactory::InitializeGpu( |
79 DriWrapper* dri, | 78 GbmWrapper* gbm, |
80 gbm_device* device, | |
81 ScreenManager* screen_manager, | 79 ScreenManager* screen_manager, |
82 DriWindowDelegateManager* window_manager) { | 80 DriWindowDelegateManager* window_manager) { |
83 drm_ = dri; | 81 gbm_ = gbm; |
84 device_ = device; | |
85 screen_manager_ = screen_manager; | 82 screen_manager_ = screen_manager; |
86 window_manager_ = window_manager; | 83 window_manager_ = window_manager; |
87 } | 84 } |
88 | 85 |
89 intptr_t GbmSurfaceFactory::GetNativeDisplay() { | 86 intptr_t GbmSurfaceFactory::GetNativeDisplay() { |
90 return reinterpret_cast<intptr_t>(device_); | 87 DCHECK(gbm_); |
| 88 return reinterpret_cast<intptr_t>(gbm_->device()); |
91 } | 89 } |
92 | 90 |
93 int GbmSurfaceFactory::GetDrmFd() { | 91 int GbmSurfaceFactory::GetDrmFd() { |
94 DCHECK(drm_); | 92 DCHECK(gbm_); |
95 return drm_->get_fd(); | 93 return gbm_->get_fd(); |
96 } | 94 } |
97 | 95 |
98 const int32* GbmSurfaceFactory::GetEGLSurfaceProperties( | 96 const int32* GbmSurfaceFactory::GetEGLSurfaceProperties( |
99 const int32* desired_list) { | 97 const int32* desired_list) { |
100 static const int32 kConfigAttribs[] = { | 98 static const int32 kConfigAttribs[] = { |
101 EGL_BUFFER_SIZE, 32, | 99 EGL_BUFFER_SIZE, 32, |
102 EGL_ALPHA_SIZE, 8, | 100 EGL_ALPHA_SIZE, 8, |
103 EGL_BLUE_SIZE, 8, | 101 EGL_BLUE_SIZE, 8, |
104 EGL_GREEN_SIZE, 8, | 102 EGL_GREEN_SIZE, 8, |
105 EGL_RED_SIZE, 8, | 103 EGL_RED_SIZE, 8, |
106 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, | 104 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
107 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, | 105 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
108 EGL_NONE | 106 EGL_NONE |
109 }; | 107 }; |
110 | 108 |
111 return kConfigAttribs; | 109 return kConfigAttribs; |
112 } | 110 } |
113 | 111 |
114 bool GbmSurfaceFactory::LoadEGLGLES2Bindings( | 112 bool GbmSurfaceFactory::LoadEGLGLES2Bindings( |
115 AddGLLibraryCallback add_gl_library, | 113 AddGLLibraryCallback add_gl_library, |
116 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { | 114 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { |
117 return LoadDefaultEGLGLES2Bindings(add_gl_library, set_gl_get_proc_address); | 115 return LoadDefaultEGLGLES2Bindings(add_gl_library, set_gl_get_proc_address); |
118 } | 116 } |
119 | 117 |
120 scoped_ptr<SurfaceOzoneEGL> GbmSurfaceFactory::CreateEGLSurfaceForWidget( | 118 scoped_ptr<SurfaceOzoneEGL> GbmSurfaceFactory::CreateEGLSurfaceForWidget( |
121 gfx::AcceleratedWidget widget) { | 119 gfx::AcceleratedWidget widget) { |
122 DriWindowDelegate* delegate = GetOrCreateWindowDelegate(widget); | 120 DriWindowDelegate* delegate = GetOrCreateWindowDelegate(widget); |
123 | 121 |
124 scoped_ptr<GbmSurface> surface(new GbmSurface(delegate, device_, drm_)); | 122 scoped_ptr<GbmSurface> surface(new GbmSurface(delegate, gbm_)); |
125 if (!surface->Initialize()) | 123 if (!surface->Initialize()) |
126 return nullptr; | 124 return nullptr; |
127 | 125 |
128 return surface.Pass(); | 126 return surface.Pass(); |
129 } | 127 } |
130 | 128 |
131 scoped_ptr<SurfaceOzoneEGL> | 129 scoped_ptr<SurfaceOzoneEGL> |
132 GbmSurfaceFactory::CreateSurfacelessEGLSurfaceForWidget( | 130 GbmSurfaceFactory::CreateSurfacelessEGLSurfaceForWidget( |
133 gfx::AcceleratedWidget widget) { | 131 gfx::AcceleratedWidget widget) { |
134 if (!allow_surfaceless_) | 132 if (!allow_surfaceless_) |
135 return scoped_ptr<SurfaceOzoneEGL>(); | 133 return scoped_ptr<SurfaceOzoneEGL>(); |
136 | 134 |
137 DriWindowDelegate* delegate = GetOrCreateWindowDelegate(widget); | 135 DriWindowDelegate* delegate = GetOrCreateWindowDelegate(widget); |
138 return scoped_ptr<SurfaceOzoneEGL>(new GbmSurfaceless(delegate)); | 136 return scoped_ptr<SurfaceOzoneEGL>(new GbmSurfaceless(delegate)); |
139 } | 137 } |
140 | 138 |
141 scoped_refptr<ui::NativePixmap> GbmSurfaceFactory::CreateNativePixmap( | 139 scoped_refptr<ui::NativePixmap> GbmSurfaceFactory::CreateNativePixmap( |
142 gfx::AcceleratedWidget widget, | 140 gfx::AcceleratedWidget widget, |
143 gfx::Size size, | 141 gfx::Size size, |
144 BufferFormat format, | 142 BufferFormat format, |
145 BufferUsage usage) { | 143 BufferUsage usage) { |
146 if (usage == MAP) | 144 if (usage == MAP) |
147 return NULL; | 145 return NULL; |
148 | 146 |
149 scoped_refptr<GbmBuffer> buffer = | 147 scoped_refptr<GbmBuffer> buffer = |
150 GbmBuffer::CreateBuffer(drm_, device_, format, size, true); | 148 GbmBuffer::CreateBuffer(gbm_, format, size, true); |
151 if (!buffer.get()) | 149 if (!buffer.get()) |
152 return NULL; | 150 return NULL; |
153 | 151 |
154 scoped_refptr<GbmPixmap> pixmap(new GbmPixmap(buffer)); | 152 scoped_refptr<GbmPixmap> pixmap(new GbmPixmap(buffer)); |
155 if (!pixmap->Initialize(drm_)) | 153 if (!pixmap->Initialize(gbm_)) |
156 return NULL; | 154 return NULL; |
157 | 155 |
158 return pixmap; | 156 return pixmap; |
159 } | 157 } |
160 | 158 |
161 OverlayCandidatesOzone* GbmSurfaceFactory::GetOverlayCandidates( | 159 OverlayCandidatesOzone* GbmSurfaceFactory::GetOverlayCandidates( |
162 gfx::AcceleratedWidget w) { | 160 gfx::AcceleratedWidget w) { |
163 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 161 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
164 switches::kOzoneTestSingleOverlaySupport)) | 162 switches::kOzoneTestSingleOverlaySupport)) |
165 return new SingleOverlay(); | 163 return new SingleOverlay(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 return true; | 201 return true; |
204 } | 202 } |
205 NOTREACHED(); | 203 NOTREACHED(); |
206 return false; | 204 return false; |
207 } | 205 } |
208 | 206 |
209 DriWindowDelegate* GbmSurfaceFactory::GetOrCreateWindowDelegate( | 207 DriWindowDelegate* GbmSurfaceFactory::GetOrCreateWindowDelegate( |
210 gfx::AcceleratedWidget widget) { | 208 gfx::AcceleratedWidget widget) { |
211 if (!window_manager_->HasWindowDelegate(widget)) { | 209 if (!window_manager_->HasWindowDelegate(widget)) { |
212 scoped_ptr<DriWindowDelegate> delegate(new DriWindowDelegateImpl( | 210 scoped_ptr<DriWindowDelegate> delegate(new DriWindowDelegateImpl( |
213 widget, drm_, window_manager_, screen_manager_)); | 211 widget, gbm_, window_manager_, screen_manager_)); |
214 delegate->Initialize(); | 212 delegate->Initialize(); |
215 window_manager_->AddWindowDelegate(widget, delegate.Pass()); | 213 window_manager_->AddWindowDelegate(widget, delegate.Pass()); |
216 } | 214 } |
217 | 215 |
218 return window_manager_->GetWindowDelegate(widget); | 216 return window_manager_->GetWindowDelegate(widget); |
219 } | 217 } |
220 | 218 |
221 } // namespace ui | 219 } // namespace ui |
OLD | NEW |