Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 #include "chromecast/ozone/surface_factory_chromecast.h" | |
|
lcwu1
2015/03/27 00:51:43
Add a vertical space above.
halliwell
2015/03/27 01:45:03
Done.
| |
| 5 | |
| 6 #include "base/callback_helpers.h" | |
| 7 #include "chromecast/ozone/chromecast_egl_platform.h" | |
| 8 #include "chromecast/ozone/surface_ozone_egl_chromecast.h" | |
| 9 | |
| 10 namespace chromecast { | |
| 11 namespace ozone { | |
| 12 | |
| 13 SurfaceFactoryChromecast::SurfaceFactoryChromecast( | |
| 14 scoped_ptr<ChromecastEglPlatform> egl_platform) | |
| 15 : state_(UNINITIALIZED), | |
| 16 destroy_window_pending_state_(kNoDestroyPending), | |
| 17 display_type_(0), | |
| 18 window_(0), | |
| 19 default_display_size_(egl_platform->GetDefaultDisplaySize()), | |
| 20 display_size_(default_display_size_), | |
| 21 new_display_size_(default_display_size_), | |
| 22 egl_platform_(egl_platform.Pass()) { | |
| 23 } | |
| 24 | |
| 25 SurfaceFactoryChromecast::~SurfaceFactoryChromecast() { | |
| 26 DestroyDisplayTypeAndWindow(); | |
| 27 } | |
| 28 | |
| 29 void SurfaceFactoryChromecast::InitializeHardware() { | |
| 30 if (state_ == INITIALIZED) { | |
| 31 return; | |
| 32 } | |
| 33 CHECK_EQ(state_, UNINITIALIZED); | |
| 34 | |
| 35 if (egl_platform_->InitializeHardware()) { | |
| 36 state_ = INITIALIZED; | |
| 37 } else { | |
| 38 ShutdownHardware(); | |
| 39 state_ = FAILED; | |
| 40 } | |
| 41 } | |
| 42 | |
| 43 void SurfaceFactoryChromecast::ShutdownHardware() { | |
| 44 DestroyDisplayTypeAndWindow(); | |
| 45 | |
| 46 egl_platform_->ShutdownHardware(); | |
| 47 | |
| 48 state_ = UNINITIALIZED; | |
| 49 } | |
| 50 | |
| 51 intptr_t SurfaceFactoryChromecast::GetNativeDisplay() { | |
| 52 CreateDisplayTypeAndWindowIfNeeded(); | |
| 53 return reinterpret_cast<intptr_t>(display_type_); | |
| 54 } | |
| 55 | |
| 56 void SurfaceFactoryChromecast::CreateDisplayTypeAndWindowIfNeeded() { | |
| 57 if (state_ == UNINITIALIZED) { | |
| 58 InitializeHardware(); | |
| 59 } | |
| 60 if (new_display_size_ != display_size_) { | |
| 61 DestroyDisplayTypeAndWindow(); | |
| 62 display_size_ = new_display_size_; | |
| 63 } | |
| 64 DCHECK_EQ(state_, INITIALIZED); | |
| 65 if (!display_type_) { | |
| 66 display_type_ = egl_platform_->CreateDisplayType(display_size_); | |
| 67 if (display_type_) { | |
| 68 window_ = egl_platform_->CreateWindow(display_type_, display_size_); | |
| 69 if (!window_) { | |
| 70 DestroyDisplayTypeAndWindow(); | |
|
derekjchow1
2015/03/19 21:28:02
Would it be reasonable to call ShutdownHardware he
halliwell
2015/03/19 22:21:58
We're about to terminate here (FATAL) so I'm not c
| |
| 71 state_ = FAILED; | |
| 72 LOG(FATAL) << "Create EGLNativeWindowType(" << display_size_.ToString() | |
| 73 << ") failed."; | |
| 74 } | |
| 75 } else { | |
| 76 state_ = FAILED; | |
|
derekjchow1
2015/03/19 21:28:02
Ditto.
| |
| 77 LOG(FATAL) << "Create EGLNativeDisplayType(" << display_size_.ToString() | |
| 78 << ") failed."; | |
| 79 } | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 intptr_t SurfaceFactoryChromecast::GetNativeWindow() { | |
| 84 CreateDisplayTypeAndWindowIfNeeded(); | |
| 85 return window_; | |
| 86 } | |
| 87 | |
| 88 bool SurfaceFactoryChromecast::ResizeDisplay(gfx::Size size) { | |
| 89 // set size to at least 1280x720 even if passed 1x1 | |
| 90 size.SetToMax(default_display_size_); | |
| 91 if (display_type_ && size != display_size_) { | |
| 92 DestroyDisplayTypeAndWindow(); | |
| 93 } | |
| 94 display_size_ = size; | |
| 95 return true; | |
| 96 } | |
| 97 | |
| 98 void SurfaceFactoryChromecast::DestroyDisplayTypeAndWindow() { | |
| 99 if (window_) { | |
| 100 egl_platform_->DestroyWindow(window_); | |
| 101 window_ = 0; | |
| 102 } | |
| 103 if (display_type_) { | |
| 104 egl_platform_->DestroyDisplayType(display_type_); | |
| 105 display_type_ = 0; | |
| 106 } | |
| 107 } | |
| 108 | |
| 109 scoped_ptr<ui::SurfaceOzoneEGL> | |
| 110 SurfaceFactoryChromecast::CreateEGLSurfaceForWidget( | |
| 111 gfx::AcceleratedWidget widget) { | |
| 112 new_display_size_ = gfx::Size(widget >> 16, widget & 0xFFFF); | |
| 113 new_display_size_.SetToMax(default_display_size_); | |
| 114 destroy_window_pending_state_ = kSurfaceExists; | |
| 115 SendRelinquishResponse(); | |
| 116 return make_scoped_ptr<ui::SurfaceOzoneEGL>( | |
| 117 new SurfaceOzoneEglChromecast(this)); | |
| 118 } | |
| 119 | |
| 120 void SurfaceFactoryChromecast::SetToRelinquishDisplay( | |
| 121 const base::Closure& callback) { | |
| 122 // This is called in response to a RelinquishDisplay message from the | |
| 123 // browser task. This call may come before or after the display surface | |
| 124 // is actually destroyed. | |
| 125 relinquish_display_callback_ = callback; | |
| 126 switch (destroy_window_pending_state_) { | |
| 127 case kNoDestroyPending: | |
| 128 case kSurfaceDestroyedRecently: | |
| 129 DestroyDisplayTypeAndWindow(); | |
| 130 SendRelinquishResponse(); | |
| 131 destroy_window_pending_state_ = kNoDestroyPending; | |
| 132 break; | |
| 133 case kSurfaceExists: | |
| 134 destroy_window_pending_state_ = kWindowDestroyPending; | |
| 135 break; | |
| 136 case kWindowDestroyPending: | |
| 137 break; | |
| 138 default: | |
| 139 NOTREACHED(); | |
| 140 } | |
| 141 } | |
| 142 | |
| 143 void SurfaceFactoryChromecast::ChildDestroyed() { | |
| 144 if (destroy_window_pending_state_ == kWindowDestroyPending) { | |
| 145 DestroyDisplayTypeAndWindow(); | |
| 146 SendRelinquishResponse(); | |
| 147 destroy_window_pending_state_ = kNoDestroyPending; | |
| 148 } else { | |
| 149 destroy_window_pending_state_ = kSurfaceDestroyedRecently; | |
| 150 } | |
| 151 } | |
| 152 | |
| 153 void SurfaceFactoryChromecast::SendRelinquishResponse() { | |
| 154 if (!relinquish_display_callback_.is_null()) { | |
| 155 base::ResetAndReturn(&relinquish_display_callback_).Run(); | |
| 156 } | |
| 157 } | |
| 158 | |
| 159 const int32* SurfaceFactoryChromecast::GetEGLSurfaceProperties( | |
| 160 const int32* desired_list) { | |
| 161 return egl_platform_->GetEGLSurfaceProperties(desired_list); | |
| 162 } | |
| 163 | |
| 164 bool SurfaceFactoryChromecast::LoadEGLGLES2Bindings( | |
| 165 AddGLLibraryCallback add_gl_library, | |
| 166 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { | |
| 167 if (state_ != INITIALIZED) { | |
| 168 InitializeHardware(); | |
| 169 if (state_ != INITIALIZED) { | |
| 170 return false; | |
| 171 } | |
| 172 } | |
| 173 | |
| 174 return egl_platform_->LoadEGLGLES2Bindings(add_gl_library, | |
| 175 set_gl_get_proc_address); | |
| 176 } | |
| 177 | |
| 178 } // namespace ozone | |
| 179 } // namespace chromecast | |
| OLD | NEW |