1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/ozone/platform/drm/gpu/gbm_surface_factory.h"
#include <gbm.h>
#include "base/files/file_path.h"
#include "build/build_config.h"
#include "third_party/khronos/EGL/egl.h"
#include "ui/ozone/common/egl_util.h"
#include "ui/ozone/platform/drm/common/drm_util.h"
#include "ui/ozone/platform/drm/gpu/drm_thread_proxy.h"
#include "ui/ozone/platform/drm/gpu/drm_window_proxy.h"
#include "ui/ozone/platform/drm/gpu/gbm_buffer.h"
#include "ui/ozone/platform/drm/gpu/gbm_surfaceless.h"
#include "ui/ozone/platform/drm/gpu/proxy_helpers.h"
#include "ui/ozone/platform/drm/gpu/screen_manager.h"
#include "ui/ozone/public/native_pixmap.h"
#include "ui/ozone/public/surface_ozone_canvas.h"
#include "ui/ozone/public/surface_ozone_egl.h"
namespace ui {
GbmSurfaceFactory::GbmSurfaceFactory(DrmThreadProxy* drm_thread)
: drm_thread_(drm_thread) {}
GbmSurfaceFactory::~GbmSurfaceFactory() {
DCHECK(thread_checker_.CalledOnValidThread());
}
void GbmSurfaceFactory::RegisterSurface(gfx::AcceleratedWidget widget,
GbmSurfaceless* surface) {
DCHECK(thread_checker_.CalledOnValidThread());
widget_to_surface_map_.insert(std::make_pair(widget, surface));
}
void GbmSurfaceFactory::UnregisterSurface(gfx::AcceleratedWidget widget) {
DCHECK(thread_checker_.CalledOnValidThread());
widget_to_surface_map_.erase(widget);
}
GbmSurfaceless* GbmSurfaceFactory::GetSurface(
gfx::AcceleratedWidget widget) const {
DCHECK(thread_checker_.CalledOnValidThread());
auto it = widget_to_surface_map_.find(widget);
DCHECK(it != widget_to_surface_map_.end());
return it->second;
}
intptr_t GbmSurfaceFactory::GetNativeDisplay() {
DCHECK(thread_checker_.CalledOnValidThread());
return EGL_DEFAULT_DISPLAY;
}
bool GbmSurfaceFactory::LoadEGLGLES2Bindings(
AddGLLibraryCallback add_gl_library,
SetGLGetProcAddressProcCallback set_gl_get_proc_address) {
DCHECK(thread_checker_.CalledOnValidThread());
return LoadDefaultEGLGLES2Bindings(add_gl_library, set_gl_get_proc_address);
}
scoped_ptr<SurfaceOzoneCanvas> GbmSurfaceFactory::CreateCanvasForWidget(
gfx::AcceleratedWidget widget) {
DCHECK(thread_checker_.CalledOnValidThread());
LOG(ERROR) << "Software rendering mode is not supported with GBM platform";
return nullptr;
}
scoped_ptr<SurfaceOzoneEGL> GbmSurfaceFactory::CreateEGLSurfaceForWidget(
gfx::AcceleratedWidget widget) {
NOTREACHED();
return nullptr;
}
scoped_ptr<SurfaceOzoneEGL>
GbmSurfaceFactory::CreateSurfacelessEGLSurfaceForWidget(
gfx::AcceleratedWidget widget) {
DCHECK(thread_checker_.CalledOnValidThread());
return make_scoped_ptr(
new GbmSurfaceless(drm_thread_->CreateDrmWindowProxy(widget), this));
}
std::vector<gfx::BufferFormat> GbmSurfaceFactory::GetScanoutFormats(
gfx::AcceleratedWidget widget) {
std::vector<gfx::BufferFormat> scanout_formats;
drm_thread_->GetScanoutFormats(widget, &scanout_formats);
return scanout_formats;
}
scoped_refptr<ui::NativePixmap> GbmSurfaceFactory::CreateNativePixmap(
gfx::AcceleratedWidget widget,
gfx::Size size,
gfx::BufferFormat format,
gfx::BufferUsage usage) {
#if !defined(OS_CHROMEOS)
// Support for memory mapping accelerated buffers requires some
// CrOS-specific patches (using vgem).
DCHECK(gfx::BufferUsage::SCANOUT == usage);
#endif
scoped_refptr<GbmBuffer> buffer =
drm_thread_->CreateBuffer(widget, size, format, usage);
if (!buffer.get())
return nullptr;
return make_scoped_refptr(new GbmPixmap(this, buffer));
}
scoped_refptr<ui::NativePixmap> GbmSurfaceFactory::CreateNativePixmapFromHandle(
gfx::Size size,
gfx::BufferFormat format,
const gfx::NativePixmapHandle& handle) {
scoped_refptr<GbmBuffer> buffer = drm_thread_->CreateBufferFromFD(
size, format, base::ScopedFD(handle.fd.fd), handle.stride);
if (!buffer)
return nullptr;
return make_scoped_refptr(new GbmPixmap(this, buffer));
}
} // namespace ui
|