| 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 "chromecast/ozone/surface_factory_cast.h" | 5 #include "ui/ozone/platform/cast/surface_factory_cast.h" |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "chromecast/ozone/cast_egl_platform.h" | 8 #include "chromecast/public/cast_egl_platform.h" |
| 9 #include "chromecast/ozone/surface_ozone_egl_cast.h" | 9 #include "ui/ozone/platform/cast/surface_ozone_egl_cast.h" |
| 10 | 10 |
| 11 namespace chromecast { | 11 using chromecast::CastEglPlatform; |
| 12 namespace ozone { | 12 |
| 13 namespace ui { |
| 14 namespace { |
| 15 CastEglPlatform::Size FromGfxSize(const gfx::Size& size) { |
| 16 return CastEglPlatform::Size(size.width(), size.height()); |
| 17 } |
| 18 gfx::Size ToGfxSize(const CastEglPlatform::Size& size) { |
| 19 return gfx::Size(size.width, size.height); |
| 20 } |
| 21 } |
| 13 | 22 |
| 14 SurfaceFactoryCast::SurfaceFactoryCast(scoped_ptr<CastEglPlatform> egl_platform) | 23 SurfaceFactoryCast::SurfaceFactoryCast(scoped_ptr<CastEglPlatform> egl_platform) |
| 15 : state_(kUninitialized), | 24 : state_(kUninitialized), |
| 16 destroy_window_pending_state_(kNoDestroyPending), | 25 destroy_window_pending_state_(kNoDestroyPending), |
| 17 display_type_(0), | 26 display_type_(0), |
| 18 window_(0), | 27 window_(0), |
| 19 default_display_size_(egl_platform->GetDefaultDisplaySize()), | 28 default_display_size_(ToGfxSize(egl_platform->GetDefaultDisplaySize())), |
| 20 display_size_(default_display_size_), | 29 display_size_(default_display_size_), |
| 21 new_display_size_(default_display_size_), | 30 new_display_size_(default_display_size_), |
| 22 egl_platform_(egl_platform.Pass()) { | 31 egl_platform_(egl_platform.Pass()) { |
| 23 } | 32 } |
| 24 | 33 |
| 25 SurfaceFactoryCast::~SurfaceFactoryCast() { | 34 SurfaceFactoryCast::~SurfaceFactoryCast() { |
| 26 DestroyDisplayTypeAndWindow(); | 35 DestroyDisplayTypeAndWindow(); |
| 27 } | 36 } |
| 28 | 37 |
| 29 void SurfaceFactoryCast::InitializeHardware() { | 38 void SurfaceFactoryCast::InitializeHardware() { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 56 void SurfaceFactoryCast::CreateDisplayTypeAndWindowIfNeeded() { | 65 void SurfaceFactoryCast::CreateDisplayTypeAndWindowIfNeeded() { |
| 57 if (state_ == kUninitialized) { | 66 if (state_ == kUninitialized) { |
| 58 InitializeHardware(); | 67 InitializeHardware(); |
| 59 } | 68 } |
| 60 if (new_display_size_ != display_size_) { | 69 if (new_display_size_ != display_size_) { |
| 61 DestroyDisplayTypeAndWindow(); | 70 DestroyDisplayTypeAndWindow(); |
| 62 display_size_ = new_display_size_; | 71 display_size_ = new_display_size_; |
| 63 } | 72 } |
| 64 DCHECK_EQ(state_, kInitialized); | 73 DCHECK_EQ(state_, kInitialized); |
| 65 if (!display_type_) { | 74 if (!display_type_) { |
| 66 display_type_ = egl_platform_->CreateDisplayType(display_size_); | 75 CastEglPlatform::Size create_size = FromGfxSize(display_size_); |
| 76 display_type_ = egl_platform_->CreateDisplayType(create_size); |
| 67 if (display_type_) { | 77 if (display_type_) { |
| 68 window_ = egl_platform_->CreateWindow(display_type_, display_size_); | 78 window_ = egl_platform_->CreateWindow(display_type_, create_size); |
| 69 if (!window_) { | 79 if (!window_) { |
| 70 DestroyDisplayTypeAndWindow(); | 80 DestroyDisplayTypeAndWindow(); |
| 71 state_ = kFailed; | 81 state_ = kFailed; |
| 72 LOG(FATAL) << "Create EGLNativeWindowType(" << display_size_.ToString() | 82 LOG(FATAL) << "Create EGLNativeWindowType(" << display_size_.ToString() |
| 73 << ") failed."; | 83 << ") failed."; |
| 74 } | 84 } |
| 75 } else { | 85 } else { |
| 76 state_ = kFailed; | 86 state_ = kFailed; |
| 77 LOG(FATAL) << "Create EGLNativeDisplayType(" << display_size_.ToString() | 87 LOG(FATAL) << "Create EGLNativeDisplayType(" << display_size_.ToString() |
| 78 << ") failed."; | 88 << ") failed."; |
| 79 } | 89 } |
| 80 } | 90 } |
| 81 } | 91 } |
| 82 | 92 |
| 83 intptr_t SurfaceFactoryCast::GetNativeWindow() { | 93 intptr_t SurfaceFactoryCast::GetNativeWindow() { |
| 84 CreateDisplayTypeAndWindowIfNeeded(); | 94 CreateDisplayTypeAndWindowIfNeeded(); |
| 85 return window_; | 95 return reinterpret_cast<intptr_t>(window_); |
| 86 } | 96 } |
| 87 | 97 |
| 88 bool SurfaceFactoryCast::ResizeDisplay(gfx::Size size) { | 98 bool SurfaceFactoryCast::ResizeDisplay(gfx::Size size) { |
| 89 // set size to at least 1280x720 even if passed 1x1 | 99 // set size to at least 1280x720 even if passed 1x1 |
| 90 size.SetToMax(default_display_size_); | 100 size.SetToMax(default_display_size_); |
| 91 if (display_type_ && size != display_size_) { | 101 if (display_type_ && size != display_size_) { |
| 92 DestroyDisplayTypeAndWindow(); | 102 DestroyDisplayTypeAndWindow(); |
| 93 } | 103 } |
| 94 display_size_ = size; | 104 display_size_ = size; |
| 95 return true; | 105 return true; |
| 96 } | 106 } |
| 97 | 107 |
| 98 void SurfaceFactoryCast::DestroyDisplayTypeAndWindow() { | 108 void SurfaceFactoryCast::DestroyDisplayTypeAndWindow() { |
| 99 if (window_) { | 109 if (window_) { |
| 100 egl_platform_->DestroyWindow(window_); | 110 egl_platform_->DestroyWindow(window_); |
| 101 window_ = 0; | 111 window_ = 0; |
| 102 } | 112 } |
| 103 if (display_type_) { | 113 if (display_type_) { |
| 104 egl_platform_->DestroyDisplayType(display_type_); | 114 egl_platform_->DestroyDisplayType(display_type_); |
| 105 display_type_ = 0; | 115 display_type_ = 0; |
| 106 } | 116 } |
| 107 } | 117 } |
| 108 | 118 |
| 109 scoped_ptr<ui::SurfaceOzoneEGL> SurfaceFactoryCast::CreateEGLSurfaceForWidget( | 119 scoped_ptr<SurfaceOzoneEGL> SurfaceFactoryCast::CreateEGLSurfaceForWidget( |
| 110 gfx::AcceleratedWidget widget) { | 120 gfx::AcceleratedWidget widget) { |
| 111 new_display_size_ = gfx::Size(widget >> 16, widget & 0xFFFF); | 121 new_display_size_ = gfx::Size(widget >> 16, widget & 0xFFFF); |
| 112 new_display_size_.SetToMax(default_display_size_); | 122 new_display_size_.SetToMax(default_display_size_); |
| 113 destroy_window_pending_state_ = kSurfaceExists; | 123 destroy_window_pending_state_ = kSurfaceExists; |
| 114 SendRelinquishResponse(); | 124 SendRelinquishResponse(); |
| 115 return make_scoped_ptr<ui::SurfaceOzoneEGL>(new SurfaceOzoneEglCast(this)); | 125 return make_scoped_ptr<SurfaceOzoneEGL>(new SurfaceOzoneEglCast(this)); |
| 116 } | 126 } |
| 117 | 127 |
| 118 void SurfaceFactoryCast::SetToRelinquishDisplay(const base::Closure& callback) { | 128 void SurfaceFactoryCast::SetToRelinquishDisplay(const base::Closure& callback) { |
| 119 // This is called in response to a RelinquishDisplay message from the | 129 // This is called in response to a RelinquishDisplay message from the |
| 120 // browser task. This call may come before or after the display surface | 130 // browser task. This call may come before or after the display surface |
| 121 // is actually destroyed. | 131 // is actually destroyed. |
| 122 relinquish_display_callback_ = callback; | 132 relinquish_display_callback_ = callback; |
| 123 switch (destroy_window_pending_state_) { | 133 switch (destroy_window_pending_state_) { |
| 124 case kNoDestroyPending: | 134 case kNoDestroyPending: |
| 125 case kSurfaceDestroyedRecently: | 135 case kSurfaceDestroyedRecently: |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 bool SurfaceFactoryCast::LoadEGLGLES2Bindings( | 171 bool SurfaceFactoryCast::LoadEGLGLES2Bindings( |
| 162 AddGLLibraryCallback add_gl_library, | 172 AddGLLibraryCallback add_gl_library, |
| 163 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { | 173 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { |
| 164 if (state_ != kInitialized) { | 174 if (state_ != kInitialized) { |
| 165 InitializeHardware(); | 175 InitializeHardware(); |
| 166 if (state_ != kInitialized) { | 176 if (state_ != kInitialized) { |
| 167 return false; | 177 return false; |
| 168 } | 178 } |
| 169 } | 179 } |
| 170 | 180 |
| 171 return egl_platform_->LoadEGLGLES2Bindings(add_gl_library, | 181 void* lib_egl = egl_platform_->GetEglLibrary(); |
| 172 set_gl_get_proc_address); | 182 void* lib_gles2 = egl_platform_->GetGles2Library(); |
| 183 GLGetProcAddressProc gl_proc = egl_platform_->GetGLProcAddressProc(); |
| 184 if (!lib_egl || !lib_gles2 || !gl_proc) { |
| 185 return false; |
| 186 } |
| 187 |
| 188 set_gl_get_proc_address.Run(gl_proc); |
| 189 add_gl_library.Run(lib_egl); |
| 190 add_gl_library.Run(lib_gles2); |
| 191 return true; |
| 173 } | 192 } |
| 174 | 193 |
| 175 } // namespace ozone | 194 } // namespace ui |
| 176 } // namespace chromecast | |
| OLD | NEW |