OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/surface_factory_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" | 12 #include "base/callback_helpers.h" |
13 #include "base/command_line.h" | |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
16 #include "base/strings/string_number_conversions.h" | |
17 #include "chromecast/base/chromecast_switches.h" | |
15 #include "chromecast/public/cast_egl_platform.h" | 18 #include "chromecast/public/cast_egl_platform.h" |
16 #include "chromecast/public/graphics_types.h" | 19 #include "chromecast/public/graphics_types.h" |
17 #include "third_party/skia/include/core/SkSurface.h" | 20 #include "third_party/skia/include/core/SkSurface.h" |
18 #include "ui/gfx/geometry/quad_f.h" | 21 #include "ui/gfx/geometry/quad_f.h" |
19 #include "ui/gfx/vsync_provider.h" | 22 #include "ui/gfx/vsync_provider.h" |
20 #include "ui/ozone/platform/cast/surface_ozone_egl_cast.h" | 23 #include "ui/ozone/platform/cast/surface_ozone_egl_cast.h" |
21 #include "ui/ozone/public/native_pixmap.h" | 24 #include "ui/ozone/public/native_pixmap.h" |
22 #include "ui/ozone/public/surface_ozone_canvas.h" | 25 #include "ui/ozone/public/surface_ozone_canvas.h" |
23 | 26 |
24 using chromecast::CastEglPlatform; | 27 using chromecast::CastEglPlatform; |
25 | 28 |
26 namespace ui { | 29 namespace ui { |
27 | 30 |
28 namespace { | 31 namespace { |
29 | 32 |
30 typedef EGLDisplay (*EGLGetDisplayFn)(NativeDisplayType); | 33 typedef EGLDisplay (*EGLGetDisplayFn)(NativeDisplayType); |
31 typedef EGLBoolean (*EGLTerminateFn)(EGLDisplay); | 34 typedef EGLBoolean (*EGLTerminateFn)(EGLDisplay); |
32 | 35 |
33 chromecast::Size FromGfxSize(const gfx::Size& size) { | 36 chromecast::Size FromGfxSize(const gfx::Size& size) { |
34 return chromecast::Size(size.width(), size.height()); | 37 return chromecast::Size(size.width(), size.height()); |
35 } | 38 } |
36 | 39 |
37 // Initial display size to create, needed before first window is created. | 40 // Display resolution, set in browser process and passed by switches. |
38 gfx::Size GetInitialDisplaySize() { | 41 gfx::Size GetDisplaySize() { |
42 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | |
43 int width, height; | |
44 if (base::StringToInt( | |
45 cmd_line->GetSwitchValueASCII(switches::kInitialScreenWidth), | |
46 &width) && | |
47 base::StringToInt( | |
48 cmd_line->GetSwitchValueASCII(switches::kInitialScreenHeight), | |
49 &height)) { | |
50 return gfx::Size(width, height); | |
51 } | |
39 return gfx::Size(1280, 720); | 52 return gfx::Size(1280, 720); |
alokp
2016/07/06 16:58:44
LOG(WARNING)?
halliwell
2016/07/07 20:07:14
Done.
| |
40 } | 53 } |
41 | 54 |
42 // Hard lower bound on display resolution | |
43 gfx::Size GetMinDisplaySize() { | |
44 return gfx::Size(1280, 720); | |
45 } | |
46 | |
47 class DummySurface : public SurfaceOzoneCanvas { | 55 class DummySurface : public SurfaceOzoneCanvas { |
48 public: | 56 public: |
49 DummySurface() {} | 57 DummySurface() {} |
50 ~DummySurface() override {} | 58 ~DummySurface() override {} |
51 | 59 |
52 // SurfaceOzoneCanvas implementation: | 60 // SurfaceOzoneCanvas implementation: |
53 sk_sp<SkSurface> GetSurface() override { return surface_; } | 61 sk_sp<SkSurface> GetSurface() override { return surface_; } |
54 | 62 |
55 void ResizeCanvas(const gfx::Size& viewport_size) override { | 63 void ResizeCanvas(const gfx::Size& viewport_size) override { |
56 surface_ = SkSurface::MakeRaster(SkImageInfo::MakeN32Premul( | 64 surface_ = SkSurface::MakeRaster(SkImageInfo::MakeN32Premul( |
(...skipping 15 matching lines...) Expand all Loading... | |
72 } // namespace | 80 } // namespace |
73 | 81 |
74 SurfaceFactoryCast::SurfaceFactoryCast() : SurfaceFactoryCast(nullptr) {} | 82 SurfaceFactoryCast::SurfaceFactoryCast() : SurfaceFactoryCast(nullptr) {} |
75 | 83 |
76 SurfaceFactoryCast::SurfaceFactoryCast( | 84 SurfaceFactoryCast::SurfaceFactoryCast( |
77 std::unique_ptr<CastEglPlatform> egl_platform) | 85 std::unique_ptr<CastEglPlatform> egl_platform) |
78 : state_(kUninitialized), | 86 : state_(kUninitialized), |
79 display_type_(0), | 87 display_type_(0), |
80 have_display_type_(false), | 88 have_display_type_(false), |
81 window_(0), | 89 window_(0), |
82 display_size_(GetInitialDisplaySize()), | 90 display_size_(GetDisplaySize()), |
83 new_display_size_(GetInitialDisplaySize()), | |
84 egl_platform_(std::move(egl_platform)), | 91 egl_platform_(std::move(egl_platform)), |
85 overlay_count_(0), | 92 overlay_count_(0), |
86 previous_frame_overlay_count_(0) {} | 93 previous_frame_overlay_count_(0) {} |
87 | 94 |
88 SurfaceFactoryCast::~SurfaceFactoryCast() { | 95 SurfaceFactoryCast::~SurfaceFactoryCast() { |
89 ShutdownHardware(); | 96 ShutdownHardware(); |
90 } | 97 } |
91 | 98 |
92 void SurfaceFactoryCast::InitializeHardware() { | 99 void SurfaceFactoryCast::InitializeHardware() { |
93 if (state_ == kInitialized) { | 100 if (state_ == kInitialized) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
168 | 175 |
169 intptr_t SurfaceFactoryCast::GetNativeDisplay() { | 176 intptr_t SurfaceFactoryCast::GetNativeDisplay() { |
170 CreateDisplayTypeAndWindowIfNeeded(); | 177 CreateDisplayTypeAndWindowIfNeeded(); |
171 return reinterpret_cast<intptr_t>(display_type_); | 178 return reinterpret_cast<intptr_t>(display_type_); |
172 } | 179 } |
173 | 180 |
174 void SurfaceFactoryCast::CreateDisplayTypeAndWindowIfNeeded() { | 181 void SurfaceFactoryCast::CreateDisplayTypeAndWindowIfNeeded() { |
175 if (state_ == kUninitialized) { | 182 if (state_ == kUninitialized) { |
176 InitializeHardware(); | 183 InitializeHardware(); |
177 } | 184 } |
178 if (new_display_size_ != display_size_) { | |
179 DestroyDisplayTypeAndWindow(); | |
180 display_size_ = new_display_size_; | |
181 } | |
182 DCHECK_EQ(state_, kInitialized); | 185 DCHECK_EQ(state_, kInitialized); |
183 if (!have_display_type_) { | 186 if (!have_display_type_) { |
184 chromecast::Size create_size = FromGfxSize(display_size_); | 187 chromecast::Size create_size = FromGfxSize(display_size_); |
185 display_type_ = egl_platform_->CreateDisplayType(create_size); | 188 display_type_ = egl_platform_->CreateDisplayType(create_size); |
186 have_display_type_ = true; | 189 have_display_type_ = true; |
187 } | 190 } |
188 if (!window_) { | 191 if (!window_) { |
189 chromecast::Size create_size = FromGfxSize(display_size_); | 192 chromecast::Size create_size = FromGfxSize(display_size_); |
190 window_ = egl_platform_->CreateWindow(display_type_, create_size); | 193 window_ = egl_platform_->CreateWindow(display_type_, create_size); |
191 if (!window_) { | 194 if (!window_) { |
192 DestroyDisplayTypeAndWindow(); | 195 DestroyDisplayTypeAndWindow(); |
193 state_ = kFailed; | 196 state_ = kFailed; |
194 LOG(FATAL) << "Create EGLNativeWindowType(" << display_size_.ToString() | 197 LOG(FATAL) << "Create EGLNativeWindowType(" << display_size_.ToString() |
195 << ") failed."; | 198 << ") failed."; |
196 } | 199 } |
197 } | 200 } |
198 } | 201 } |
199 | 202 |
200 intptr_t SurfaceFactoryCast::GetNativeWindow() { | 203 intptr_t SurfaceFactoryCast::GetNativeWindow() { |
201 CreateDisplayTypeAndWindowIfNeeded(); | 204 CreateDisplayTypeAndWindowIfNeeded(); |
202 return reinterpret_cast<intptr_t>(window_); | 205 return reinterpret_cast<intptr_t>(window_); |
203 } | 206 } |
204 | 207 |
205 bool SurfaceFactoryCast::ResizeDisplay(gfx::Size size) { | 208 bool SurfaceFactoryCast::ResizeDisplay(gfx::Size size) { |
206 // set size to at least 1280x720 even if passed 1x1 | 209 NOTIMPLEMENTED(); |
207 size.SetToMax(GetMinDisplaySize()); | 210 return false; |
208 if (have_display_type_ && size != display_size_) { | |
209 DestroyDisplayTypeAndWindow(); | |
210 } | |
211 display_size_ = size; | |
212 return true; | |
213 } | 211 } |
214 | 212 |
215 void SurfaceFactoryCast::DestroyWindow() { | 213 void SurfaceFactoryCast::DestroyWindow() { |
216 if (window_) { | 214 if (window_) { |
217 egl_platform_->DestroyWindow(window_); | 215 egl_platform_->DestroyWindow(window_); |
218 window_ = 0; | 216 window_ = 0; |
219 } | 217 } |
220 } | 218 } |
221 | 219 |
222 void SurfaceFactoryCast::DestroyDisplayTypeAndWindow() { | 220 void SurfaceFactoryCast::DestroyDisplayTypeAndWindow() { |
223 DestroyWindow(); | 221 DestroyWindow(); |
224 if (have_display_type_) { | 222 if (have_display_type_) { |
225 egl_platform_->DestroyDisplayType(display_type_); | 223 egl_platform_->DestroyDisplayType(display_type_); |
226 display_type_ = 0; | 224 display_type_ = 0; |
227 have_display_type_ = false; | 225 have_display_type_ = false; |
228 } | 226 } |
229 } | 227 } |
230 | 228 |
231 std::unique_ptr<SurfaceOzoneEGL> SurfaceFactoryCast::CreateEGLSurfaceForWidget( | 229 std::unique_ptr<SurfaceOzoneEGL> SurfaceFactoryCast::CreateEGLSurfaceForWidget( |
232 gfx::AcceleratedWidget widget) { | 230 gfx::AcceleratedWidget widget) { |
233 new_display_size_ = gfx::Size(widget >> 16, widget & 0xFFFF); | 231 DCHECK_EQ(widget >> 16, display_size_.width()); |
alokp
2016/07/06 16:58:44
Add a comment what this DCHECK attempts to verify.
halliwell
2016/07/07 20:07:14
Done.
| |
234 new_display_size_.SetToMax(GetMinDisplaySize()); | 232 DCHECK_EQ(widget & 0xffff, display_size_.height()); |
235 return base::WrapUnique<SurfaceOzoneEGL>(new SurfaceOzoneEglCast(this)); | 233 return base::WrapUnique<SurfaceOzoneEGL>(new SurfaceOzoneEglCast(this)); |
236 } | 234 } |
237 | 235 |
238 void SurfaceFactoryCast::ChildDestroyed() { | 236 void SurfaceFactoryCast::ChildDestroyed() { |
239 if (egl_platform_->MultipleSurfaceUnsupported()) | 237 if (egl_platform_->MultipleSurfaceUnsupported()) |
240 DestroyWindow(); | 238 DestroyWindow(); |
241 } | 239 } |
242 | 240 |
243 scoped_refptr<NativePixmap> SurfaceFactoryCast::CreateNativePixmap( | 241 scoped_refptr<NativePixmap> SurfaceFactoryCast::CreateNativePixmap( |
244 gfx::AcceleratedWidget widget, | 242 gfx::AcceleratedWidget widget, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
304 return false; | 302 return false; |
305 } | 303 } |
306 | 304 |
307 set_gl_get_proc_address.Run(gl_proc); | 305 set_gl_get_proc_address.Run(gl_proc); |
308 add_gl_library.Run(lib_egl); | 306 add_gl_library.Run(lib_egl); |
309 add_gl_library.Run(lib_gles2); | 307 add_gl_library.Run(lib_gles2); |
310 return true; | 308 return true; |
311 } | 309 } |
312 | 310 |
313 } // namespace ui | 311 } // namespace ui |
OLD | NEW |