Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: ui/ozone/platform/cast/gl_ozone_egl_cast.cc

Issue 2723583003: Convert Ozone cast to use GLOzone API. (Closed)
Patch Set: . Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/ozone/platform/cast/gl_ozone_egl_cast.h ('k') | ui/ozone/platform/cast/gl_surface_cast.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/cast/surface_factory_cast.h" 5 #include "ui/ozone/platform/cast/gl_ozone_egl_cast.h"
6 6
7 #include <EGL/egl.h> 7 #include <EGL/egl.h>
8 #include <dlfcn.h> 8 #include <dlfcn.h>
9 9
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/callback_helpers.h"
13 #include "base/command_line.h" 12 #include "base/command_line.h"
14 #include "base/macros.h" 13 #include "base/macros.h"
15 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
16 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
17 #include "chromecast/base/chromecast_switches.h" 16 #include "chromecast/base/chromecast_switches.h"
18 #include "chromecast/public/cast_egl_platform.h" 17 #include "chromecast/public/cast_egl_platform.h"
19 #include "chromecast/public/graphics_types.h" 18 #include "chromecast/public/graphics_types.h"
20 #include "third_party/skia/include/core/SkSurface.h"
21 #include "ui/gfx/geometry/quad_f.h"
22 #include "ui/gfx/vsync_provider.h" 19 #include "ui/gfx/vsync_provider.h"
23 #include "ui/ozone/platform/cast/gl_surface_cast.h" 20 #include "ui/ozone/platform/cast/gl_surface_cast.h"
24 #include "ui/ozone/public/native_pixmap.h"
25 #include "ui/ozone/public/surface_ozone_canvas.h"
26 21
27 using chromecast::CastEglPlatform; 22 using chromecast::CastEglPlatform;
28 23
29 namespace ui { 24 namespace ui {
30 25
31 namespace { 26 namespace {
32 27
33 typedef EGLDisplay (*EGLGetDisplayFn)(NativeDisplayType); 28 typedef EGLDisplay (*EGLGetDisplayFn)(NativeDisplayType);
34 typedef EGLBoolean (*EGLTerminateFn)(EGLDisplay); 29 typedef EGLBoolean (*EGLTerminateFn)(EGLDisplay);
35 30
(...skipping 11 matching lines...) Expand all
47 base::StringToInt( 42 base::StringToInt(
48 cmd_line->GetSwitchValueASCII(switches::kCastInitialScreenHeight), 43 cmd_line->GetSwitchValueASCII(switches::kCastInitialScreenHeight),
49 &height)) { 44 &height)) {
50 return gfx::Size(width, height); 45 return gfx::Size(width, height);
51 } 46 }
52 LOG(WARNING) << "Unable to get initial screen resolution from command line," 47 LOG(WARNING) << "Unable to get initial screen resolution from command line,"
53 << "using default 720p"; 48 << "using default 720p";
54 return gfx::Size(1280, 720); 49 return gfx::Size(1280, 720);
55 } 50 }
56 51
57 class DummySurface : public SurfaceOzoneCanvas {
58 public:
59 DummySurface() {}
60 ~DummySurface() override {}
61
62 // SurfaceOzoneCanvas implementation:
63 sk_sp<SkSurface> GetSurface() override { return surface_; }
64
65 void ResizeCanvas(const gfx::Size& viewport_size) override {
66 surface_ = SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(
67 viewport_size.width(), viewport_size.height()));
68 }
69
70 void PresentCanvas(const gfx::Rect& damage) override {}
71
72 std::unique_ptr<gfx::VSyncProvider> CreateVSyncProvider() override {
73 return nullptr;
74 }
75
76 private:
77 sk_sp<SkSurface> surface_;
78
79 DISALLOW_COPY_AND_ASSIGN(DummySurface);
80 };
81
82 } // namespace 52 } // namespace
83 53
84 SurfaceFactoryCast::SurfaceFactoryCast() : SurfaceFactoryCast(nullptr) {} 54 GLOzoneEglCast::GLOzoneEglCast(std::unique_ptr<CastEglPlatform> egl_platform)
55 : display_size_(GetDisplaySize()), egl_platform_(std::move(egl_platform)) {}
85 56
86 SurfaceFactoryCast::SurfaceFactoryCast( 57 GLOzoneEglCast::~GLOzoneEglCast() {
87 std::unique_ptr<CastEglPlatform> egl_platform)
88 : state_(kUninitialized),
89 display_type_(0),
90 have_display_type_(false),
91 window_(0),
92 display_size_(GetDisplaySize()),
93 egl_platform_(std::move(egl_platform)),
94 overlay_count_(0),
95 previous_frame_overlay_count_(0) {}
96
97 SurfaceFactoryCast::~SurfaceFactoryCast() {
98 // eglTerminate must be called first on display before releasing resources 58 // eglTerminate must be called first on display before releasing resources
99 // and shutting down hardware 59 // and shutting down hardware
100 TerminateDisplay(); 60 TerminateDisplay();
101 ShutdownHardware(); 61 ShutdownHardware();
102 } 62 }
103 63
104 void SurfaceFactoryCast::InitializeHardware() { 64 void GLOzoneEglCast::InitializeHardware() {
105 if (state_ == kInitialized) { 65 if (state_ == kInitialized) {
106 return; 66 return;
107 } 67 }
108 CHECK_EQ(state_, kUninitialized); 68 CHECK_EQ(state_, kUninitialized);
109 69
110 if (egl_platform_->InitializeHardware()) { 70 if (egl_platform_->InitializeHardware()) {
111 state_ = kInitialized; 71 state_ = kInitialized;
112 } else { 72 } else {
113 ShutdownHardware(); 73 ShutdownHardware();
114 state_ = kFailed; 74 state_ = kFailed;
115 } 75 }
116 } 76 }
117 77
118 void SurfaceFactoryCast::TerminateDisplay() { 78 void GLOzoneEglCast::TerminateDisplay() {
119 void* egl_lib_handle = egl_platform_->GetEglLibrary(); 79 void* egl_lib_handle = egl_platform_->GetEglLibrary();
120 if (!egl_lib_handle) 80 if (!egl_lib_handle)
121 return; 81 return;
122 82
123 EGLGetDisplayFn get_display = 83 EGLGetDisplayFn get_display =
124 reinterpret_cast<EGLGetDisplayFn>(dlsym(egl_lib_handle, "eglGetDisplay")); 84 reinterpret_cast<EGLGetDisplayFn>(dlsym(egl_lib_handle, "eglGetDisplay"));
125 EGLTerminateFn terminate = 85 EGLTerminateFn terminate =
126 reinterpret_cast<EGLTerminateFn>(dlsym(egl_lib_handle, "eglTerminate")); 86 reinterpret_cast<EGLTerminateFn>(dlsym(egl_lib_handle, "eglTerminate"));
127 DCHECK(get_display); 87 DCHECK(get_display);
128 DCHECK(terminate); 88 DCHECK(terminate);
129 89
130 EGLDisplay display = get_display(GetNativeDisplay()); 90 EGLDisplay display = get_display(GetNativeDisplay());
131 DCHECK_NE(display, EGL_NO_DISPLAY); 91 DCHECK_NE(display, EGL_NO_DISPLAY);
132 92
133 EGLBoolean terminate_result = terminate(display); 93 EGLBoolean terminate_result = terminate(display);
134 DCHECK_EQ(terminate_result, static_cast<EGLBoolean>(EGL_TRUE)); 94 DCHECK_EQ(terminate_result, static_cast<EGLBoolean>(EGL_TRUE));
135 } 95 }
136 96
137 void SurfaceFactoryCast::ShutdownHardware() { 97 void GLOzoneEglCast::ShutdownHardware() {
138 if (state_ != kInitialized) 98 if (state_ != kInitialized)
139 return; 99 return;
140 100
141 DestroyDisplayTypeAndWindow(); 101 DestroyDisplayTypeAndWindow();
142 102
143 egl_platform_->ShutdownHardware(); 103 egl_platform_->ShutdownHardware();
144 104
145 state_ = kUninitialized; 105 state_ = kUninitialized;
146 } 106 }
147 107
148 void SurfaceFactoryCast::OnSwapBuffers() { 108 void GLOzoneEglCast::OnSwapBuffers() {
149 DCHECK(overlay_count_ == 0 || overlay_count_ == 1); 109 DCHECK(overlay_count_ == 0 || overlay_count_ == 1);
150 110
151 // Logging for overlays to help diagnose bugs when nothing is visible on 111 // Logging for overlays to help diagnose bugs when nothing is visible on
152 // screen. Logging this every frame would be overwhelming, so we just 112 // screen. Logging this every frame would be overwhelming, so we just
153 // log on the transitions from 0 overlays -> 1 overlay and vice versa. 113 // log on the transitions from 0 overlays -> 1 overlay and vice versa.
154 if (overlay_count_ == 0 && previous_frame_overlay_count_ != 0) { 114 if (overlay_count_ == 0 && previous_frame_overlay_count_ != 0) {
155 LOG(INFO) << "Overlays deactivated"; 115 LOG(INFO) << "Overlays deactivated";
156 } else if (overlay_count_ != 0 && previous_frame_overlay_count_ == 0) { 116 } else if (overlay_count_ != 0 && previous_frame_overlay_count_ == 0) {
157 LOG(INFO) << "Overlays activated: " << overlay_bounds_.ToString(); 117 LOG(INFO) << "Overlays activated: " << overlay_bounds_.ToString();
158 } else if (overlay_count_ == previous_frame_overlay_count_ && 118 } else if (overlay_count_ == previous_frame_overlay_count_ &&
159 overlay_bounds_ != previous_frame_overlay_bounds_) { 119 overlay_bounds_ != previous_frame_overlay_bounds_) {
160 LOG(INFO) << "Overlay geometry changed to " << overlay_bounds_.ToString(); 120 LOG(INFO) << "Overlay geometry changed to " << overlay_bounds_.ToString();
161 } 121 }
162 122
163 previous_frame_overlay_count_ = overlay_count_; 123 previous_frame_overlay_count_ = overlay_count_;
164 previous_frame_overlay_bounds_ = overlay_bounds_; 124 previous_frame_overlay_bounds_ = overlay_bounds_;
165 overlay_count_ = 0; 125 overlay_count_ = 0;
166 } 126 }
167 127
168 void SurfaceFactoryCast::OnOverlayScheduled(const gfx::Rect& display_bounds) { 128 void GLOzoneEglCast::OnOverlayScheduled(const gfx::Rect& display_bounds) {
169 ++overlay_count_; 129 ++overlay_count_;
170 overlay_bounds_ = display_bounds; 130 overlay_bounds_ = display_bounds;
171 } 131 }
172 132
173 scoped_refptr<gl::GLSurface> SurfaceFactoryCast::CreateViewGLSurface( 133 scoped_refptr<gl::GLSurface> GLOzoneEglCast::CreateViewGLSurface(
174 gl::GLImplementation implementation,
175 gfx::AcceleratedWidget widget) { 134 gfx::AcceleratedWidget widget) {
176 if (implementation != gl::kGLImplementationEGLGLES2) {
177 NOTREACHED();
178 return nullptr;
179 }
180
181 // Verify requested widget dimensions match our current display size. 135 // Verify requested widget dimensions match our current display size.
182 DCHECK_EQ(widget >> 16, display_size_.width()); 136 DCHECK_EQ(widget >> 16, display_size_.width());
183 DCHECK_EQ(widget & 0xffff, display_size_.height()); 137 DCHECK_EQ(widget & 0xffff, display_size_.height());
184 138
185 return gl::InitializeGLSurface(new GLSurfaceCast(widget, this)); 139 return gl::InitializeGLSurface(new GLSurfaceCast(widget, this));
186 } 140 }
187 141
188 scoped_refptr<gl::GLSurface> SurfaceFactoryCast::CreateOffscreenGLSurface( 142 scoped_refptr<gl::GLSurface> GLOzoneEglCast::CreateOffscreenGLSurface(
189 gl::GLImplementation implementation,
190 const gfx::Size& size) { 143 const gfx::Size& size) {
191 if (implementation != gl::kGLImplementationEGLGLES2) {
192 NOTREACHED();
193 return nullptr;
194 }
195
196 return gl::InitializeGLSurface(new gl::PbufferGLSurfaceEGL(size)); 144 return gl::InitializeGLSurface(new gl::PbufferGLSurfaceEGL(size));
197 } 145 }
198 146
199 std::unique_ptr<SurfaceOzoneCanvas> SurfaceFactoryCast::CreateCanvasForWidget( 147 intptr_t GLOzoneEglCast::GetNativeDisplay() {
200 gfx::AcceleratedWidget widget) {
201 // Software canvas support only in headless mode
202 if (egl_platform_)
203 return nullptr;
204 return base::WrapUnique<SurfaceOzoneCanvas>(new DummySurface());
205 }
206
207 intptr_t SurfaceFactoryCast::GetNativeDisplay() {
208 CreateDisplayTypeAndWindowIfNeeded(); 148 CreateDisplayTypeAndWindowIfNeeded();
209 return reinterpret_cast<intptr_t>(display_type_); 149 return reinterpret_cast<intptr_t>(display_type_);
210 } 150 }
211 151
212 void SurfaceFactoryCast::CreateDisplayTypeAndWindowIfNeeded() { 152 void GLOzoneEglCast::CreateDisplayTypeAndWindowIfNeeded() {
213 if (state_ == kUninitialized) { 153 if (state_ == kUninitialized) {
214 InitializeHardware(); 154 InitializeHardware();
215 } 155 }
216 DCHECK_EQ(state_, kInitialized); 156 DCHECK_EQ(state_, kInitialized);
217 if (!have_display_type_) { 157 if (!have_display_type_) {
218 chromecast::Size create_size = FromGfxSize(display_size_); 158 chromecast::Size create_size = FromGfxSize(display_size_);
219 display_type_ = egl_platform_->CreateDisplayType(create_size); 159 display_type_ = egl_platform_->CreateDisplayType(create_size);
220 have_display_type_ = true; 160 have_display_type_ = true;
221 } 161 }
222 if (!window_) { 162 if (!window_) {
223 chromecast::Size create_size = FromGfxSize(display_size_); 163 chromecast::Size create_size = FromGfxSize(display_size_);
224 window_ = egl_platform_->CreateWindow(display_type_, create_size); 164 window_ = egl_platform_->CreateWindow(display_type_, create_size);
225 if (!window_) { 165 if (!window_) {
226 DestroyDisplayTypeAndWindow(); 166 DestroyDisplayTypeAndWindow();
227 state_ = kFailed; 167 state_ = kFailed;
228 LOG(FATAL) << "Create EGLNativeWindowType(" << display_size_.ToString() 168 LOG(FATAL) << "Create EGLNativeWindowType(" << display_size_.ToString()
229 << ") failed."; 169 << ") failed.";
230 } 170 }
231 } 171 }
232 } 172 }
233 173
234 intptr_t SurfaceFactoryCast::GetNativeWindow() { 174 intptr_t GLOzoneEglCast::GetNativeWindow() {
235 CreateDisplayTypeAndWindowIfNeeded(); 175 CreateDisplayTypeAndWindowIfNeeded();
236 return reinterpret_cast<intptr_t>(window_); 176 return reinterpret_cast<intptr_t>(window_);
237 } 177 }
238 178
239 bool SurfaceFactoryCast::ResizeDisplay(gfx::Size size) { 179 bool GLOzoneEglCast::ResizeDisplay(gfx::Size size) {
240 DCHECK_EQ(size.width(), display_size_.width()); 180 DCHECK_EQ(size.width(), display_size_.width());
241 DCHECK_EQ(size.height(), display_size_.height()); 181 DCHECK_EQ(size.height(), display_size_.height());
242 return true; 182 return true;
243 } 183 }
244 184
245 void SurfaceFactoryCast::DestroyWindow() { 185 void GLOzoneEglCast::DestroyWindow() {
246 if (window_) { 186 if (window_) {
247 egl_platform_->DestroyWindow(window_); 187 egl_platform_->DestroyWindow(window_);
248 window_ = 0; 188 window_ = 0;
249 } 189 }
250 } 190 }
251 191
252 void SurfaceFactoryCast::DestroyDisplayTypeAndWindow() { 192 void GLOzoneEglCast::DestroyDisplayTypeAndWindow() {
253 DestroyWindow(); 193 DestroyWindow();
254 if (have_display_type_) { 194 if (have_display_type_) {
255 egl_platform_->DestroyDisplayType(display_type_); 195 egl_platform_->DestroyDisplayType(display_type_);
256 display_type_ = 0; 196 display_type_ = 0;
257 have_display_type_ = false; 197 have_display_type_ = false;
258 } 198 }
259 } 199 }
260 200
261 void SurfaceFactoryCast::ChildDestroyed() { 201 void GLOzoneEglCast::ChildDestroyed() {
262 if (egl_platform_->MultipleSurfaceUnsupported()) 202 if (egl_platform_->MultipleSurfaceUnsupported())
263 DestroyWindow(); 203 DestroyWindow();
264 } 204 }
265 205
266 scoped_refptr<NativePixmap> SurfaceFactoryCast::CreateNativePixmap( 206 bool GLOzoneEglCast::LoadGLES2Bindings() {
267 gfx::AcceleratedWidget widget,
268 gfx::Size size,
269 gfx::BufferFormat format,
270 gfx::BufferUsage usage) {
271 class CastPixmap : public NativePixmap {
272 public:
273 explicit CastPixmap(SurfaceFactoryCast* parent) : parent_(parent) {}
274
275 void* GetEGLClientBuffer() const override {
276 // TODO(halliwell): try to implement this through CastEglPlatform.
277 return nullptr;
278 }
279 bool AreDmaBufFdsValid() const override { return false; }
280 size_t GetDmaBufFdCount() const override { return 0; }
281 int GetDmaBufFd(size_t plane) const override { return -1; }
282 int GetDmaBufPitch(size_t plane) const override { return 0; }
283 int GetDmaBufOffset(size_t plane) const override { return 0; }
284 uint64_t GetDmaBufModifier(size_t plane) const override { return 0; }
285 gfx::BufferFormat GetBufferFormat() const override {
286 return gfx::BufferFormat::BGRA_8888;
287 }
288 gfx::Size GetBufferSize() const override { return gfx::Size(); }
289
290 bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
291 int plane_z_order,
292 gfx::OverlayTransform plane_transform,
293 const gfx::Rect& display_bounds,
294 const gfx::RectF& crop_rect) override {
295 parent_->OnOverlayScheduled(display_bounds);
296 return true;
297 }
298 void SetProcessingCallback(
299 const ProcessingCallback& processing_callback) override {}
300 gfx::NativePixmapHandle ExportHandle() override {
301 return gfx::NativePixmapHandle();
302 }
303
304 private:
305 ~CastPixmap() override {}
306
307 SurfaceFactoryCast* parent_;
308
309 DISALLOW_COPY_AND_ASSIGN(CastPixmap);
310 };
311 return make_scoped_refptr(new CastPixmap(this));
312 }
313
314 bool SurfaceFactoryCast::LoadEGLGLES2Bindings() {
315 if (state_ != kInitialized) { 207 if (state_ != kInitialized) {
316 InitializeHardware(); 208 InitializeHardware();
317 if (state_ != kInitialized) { 209 if (state_ != kInitialized) {
318 return false; 210 return false;
319 } 211 }
320 } 212 }
321 213
322 void* lib_egl = egl_platform_->GetEglLibrary(); 214 void* lib_egl = egl_platform_->GetEglLibrary();
323 void* lib_gles2 = egl_platform_->GetGles2Library(); 215 void* lib_gles2 = egl_platform_->GetGles2Library();
324 gl::GLGetProcAddressProc gl_proc = reinterpret_cast<gl::GLGetProcAddressProc>( 216 gl::GLGetProcAddressProc gl_proc = reinterpret_cast<gl::GLGetProcAddressProc>(
325 egl_platform_->GetGLProcAddressProc()); 217 egl_platform_->GetGLProcAddressProc());
326 if (!lib_egl || !lib_gles2 || !gl_proc) { 218 if (!lib_egl || !lib_gles2 || !gl_proc) {
327 return false; 219 return false;
328 } 220 }
329 221
330 gl::SetGLGetProcAddressProc(gl_proc); 222 gl::SetGLGetProcAddressProc(gl_proc);
331 gl::AddGLNativeLibrary(lib_egl); 223 gl::AddGLNativeLibrary(lib_egl);
332 gl::AddGLNativeLibrary(lib_gles2); 224 gl::AddGLNativeLibrary(lib_gles2);
333 return true; 225 return true;
334 } 226 }
335 227
336 } // namespace ui 228 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/cast/gl_ozone_egl_cast.h ('k') | ui/ozone/platform/cast/gl_surface_cast.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698