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

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

Issue 2119583002: [Chromecast] Set Cast Ozone display size correctly first time (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits + fix ResizeDisplay Created 4 years, 5 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/surface_factory_cast.h ('k') | no next file » | 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 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::kCastInitialScreenWidth),
46 &width) &&
47 base::StringToInt(
48 cmd_line->GetSwitchValueASCII(switches::kCastInitialScreenHeight),
49 &height)) {
50 return gfx::Size(width, height);
51 }
52 LOG(WARNING) << "Unable to get initial screen resolution from command line,"
53 << "using default 720p";
39 return gfx::Size(1280, 720); 54 return gfx::Size(1280, 720);
40 } 55 }
41 56
42 // Hard lower bound on display resolution
43 gfx::Size GetMinDisplaySize() {
44 return gfx::Size(1280, 720);
45 }
46
47 class DummySurface : public SurfaceOzoneCanvas { 57 class DummySurface : public SurfaceOzoneCanvas {
48 public: 58 public:
49 DummySurface() {} 59 DummySurface() {}
50 ~DummySurface() override {} 60 ~DummySurface() override {}
51 61
52 // SurfaceOzoneCanvas implementation: 62 // SurfaceOzoneCanvas implementation:
53 sk_sp<SkSurface> GetSurface() override { return surface_; } 63 sk_sp<SkSurface> GetSurface() override { return surface_; }
54 64
55 void ResizeCanvas(const gfx::Size& viewport_size) override { 65 void ResizeCanvas(const gfx::Size& viewport_size) override {
56 surface_ = SkSurface::MakeRaster(SkImageInfo::MakeN32Premul( 66 surface_ = SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(
(...skipping 15 matching lines...) Expand all
72 } // namespace 82 } // namespace
73 83
74 SurfaceFactoryCast::SurfaceFactoryCast() : SurfaceFactoryCast(nullptr) {} 84 SurfaceFactoryCast::SurfaceFactoryCast() : SurfaceFactoryCast(nullptr) {}
75 85
76 SurfaceFactoryCast::SurfaceFactoryCast( 86 SurfaceFactoryCast::SurfaceFactoryCast(
77 std::unique_ptr<CastEglPlatform> egl_platform) 87 std::unique_ptr<CastEglPlatform> egl_platform)
78 : state_(kUninitialized), 88 : state_(kUninitialized),
79 display_type_(0), 89 display_type_(0),
80 have_display_type_(false), 90 have_display_type_(false),
81 window_(0), 91 window_(0),
82 display_size_(GetInitialDisplaySize()), 92 display_size_(GetDisplaySize()),
83 new_display_size_(GetInitialDisplaySize()),
84 egl_platform_(std::move(egl_platform)), 93 egl_platform_(std::move(egl_platform)),
85 overlay_count_(0), 94 overlay_count_(0),
86 previous_frame_overlay_count_(0) {} 95 previous_frame_overlay_count_(0) {}
87 96
88 SurfaceFactoryCast::~SurfaceFactoryCast() { 97 SurfaceFactoryCast::~SurfaceFactoryCast() {
89 ShutdownHardware(); 98 ShutdownHardware();
90 } 99 }
91 100
92 void SurfaceFactoryCast::InitializeHardware() { 101 void SurfaceFactoryCast::InitializeHardware() {
93 if (state_ == kInitialized) { 102 if (state_ == kInitialized) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 177
169 intptr_t SurfaceFactoryCast::GetNativeDisplay() { 178 intptr_t SurfaceFactoryCast::GetNativeDisplay() {
170 CreateDisplayTypeAndWindowIfNeeded(); 179 CreateDisplayTypeAndWindowIfNeeded();
171 return reinterpret_cast<intptr_t>(display_type_); 180 return reinterpret_cast<intptr_t>(display_type_);
172 } 181 }
173 182
174 void SurfaceFactoryCast::CreateDisplayTypeAndWindowIfNeeded() { 183 void SurfaceFactoryCast::CreateDisplayTypeAndWindowIfNeeded() {
175 if (state_ == kUninitialized) { 184 if (state_ == kUninitialized) {
176 InitializeHardware(); 185 InitializeHardware();
177 } 186 }
178 if (new_display_size_ != display_size_) {
179 DestroyDisplayTypeAndWindow();
180 display_size_ = new_display_size_;
181 }
182 DCHECK_EQ(state_, kInitialized); 187 DCHECK_EQ(state_, kInitialized);
183 if (!have_display_type_) { 188 if (!have_display_type_) {
184 chromecast::Size create_size = FromGfxSize(display_size_); 189 chromecast::Size create_size = FromGfxSize(display_size_);
185 display_type_ = egl_platform_->CreateDisplayType(create_size); 190 display_type_ = egl_platform_->CreateDisplayType(create_size);
186 have_display_type_ = true; 191 have_display_type_ = true;
187 } 192 }
188 if (!window_) { 193 if (!window_) {
189 chromecast::Size create_size = FromGfxSize(display_size_); 194 chromecast::Size create_size = FromGfxSize(display_size_);
190 window_ = egl_platform_->CreateWindow(display_type_, create_size); 195 window_ = egl_platform_->CreateWindow(display_type_, create_size);
191 if (!window_) { 196 if (!window_) {
192 DestroyDisplayTypeAndWindow(); 197 DestroyDisplayTypeAndWindow();
193 state_ = kFailed; 198 state_ = kFailed;
194 LOG(FATAL) << "Create EGLNativeWindowType(" << display_size_.ToString() 199 LOG(FATAL) << "Create EGLNativeWindowType(" << display_size_.ToString()
195 << ") failed."; 200 << ") failed.";
196 } 201 }
197 } 202 }
198 } 203 }
199 204
200 intptr_t SurfaceFactoryCast::GetNativeWindow() { 205 intptr_t SurfaceFactoryCast::GetNativeWindow() {
201 CreateDisplayTypeAndWindowIfNeeded(); 206 CreateDisplayTypeAndWindowIfNeeded();
202 return reinterpret_cast<intptr_t>(window_); 207 return reinterpret_cast<intptr_t>(window_);
203 } 208 }
204 209
205 bool SurfaceFactoryCast::ResizeDisplay(gfx::Size size) { 210 bool SurfaceFactoryCast::ResizeDisplay(gfx::Size size) {
206 // set size to at least 1280x720 even if passed 1x1 211 DCHECK_EQ(size.width(), display_size_.width());
207 size.SetToMax(GetMinDisplaySize()); 212 DCHECK_EQ(size.height(), display_size_.height());
208 if (have_display_type_ && size != display_size_) {
209 DestroyDisplayTypeAndWindow();
210 }
211 display_size_ = size;
212 return true; 213 return true;
213 } 214 }
214 215
215 void SurfaceFactoryCast::DestroyWindow() { 216 void SurfaceFactoryCast::DestroyWindow() {
216 if (window_) { 217 if (window_) {
217 egl_platform_->DestroyWindow(window_); 218 egl_platform_->DestroyWindow(window_);
218 window_ = 0; 219 window_ = 0;
219 } 220 }
220 } 221 }
221 222
222 void SurfaceFactoryCast::DestroyDisplayTypeAndWindow() { 223 void SurfaceFactoryCast::DestroyDisplayTypeAndWindow() {
223 DestroyWindow(); 224 DestroyWindow();
224 if (have_display_type_) { 225 if (have_display_type_) {
225 egl_platform_->DestroyDisplayType(display_type_); 226 egl_platform_->DestroyDisplayType(display_type_);
226 display_type_ = 0; 227 display_type_ = 0;
227 have_display_type_ = false; 228 have_display_type_ = false;
228 } 229 }
229 } 230 }
230 231
231 std::unique_ptr<SurfaceOzoneEGL> SurfaceFactoryCast::CreateEGLSurfaceForWidget( 232 std::unique_ptr<SurfaceOzoneEGL> SurfaceFactoryCast::CreateEGLSurfaceForWidget(
232 gfx::AcceleratedWidget widget) { 233 gfx::AcceleratedWidget widget) {
233 new_display_size_ = gfx::Size(widget >> 16, widget & 0xFFFF); 234 // Verify requested widget dimensions match our current display size.
234 new_display_size_.SetToMax(GetMinDisplaySize()); 235 DCHECK_EQ(widget >> 16, display_size_.width());
236 DCHECK_EQ(widget & 0xffff, display_size_.height());
235 return base::WrapUnique<SurfaceOzoneEGL>(new SurfaceOzoneEglCast(this)); 237 return base::WrapUnique<SurfaceOzoneEGL>(new SurfaceOzoneEglCast(this));
236 } 238 }
237 239
238 void SurfaceFactoryCast::ChildDestroyed() { 240 void SurfaceFactoryCast::ChildDestroyed() {
239 if (egl_platform_->MultipleSurfaceUnsupported()) 241 if (egl_platform_->MultipleSurfaceUnsupported())
240 DestroyWindow(); 242 DestroyWindow();
241 } 243 }
242 244
243 scoped_refptr<NativePixmap> SurfaceFactoryCast::CreateNativePixmap( 245 scoped_refptr<NativePixmap> SurfaceFactoryCast::CreateNativePixmap(
244 gfx::AcceleratedWidget widget, 246 gfx::AcceleratedWidget widget,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 return false; 306 return false;
305 } 307 }
306 308
307 set_gl_get_proc_address.Run(gl_proc); 309 set_gl_get_proc_address.Run(gl_proc);
308 add_gl_library.Run(lib_egl); 310 add_gl_library.Run(lib_egl);
309 add_gl_library.Run(lib_gles2); 311 add_gl_library.Run(lib_gles2);
310 return true; 312 return true;
311 } 313 }
312 314
313 } // namespace ui 315 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/cast/surface_factory_cast.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698