1 // Copyright 2012 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 5 #include "base/logging.h" 6 #include "ui/gfx/screen.h" 7 #include "ui/gfx/screen_type_delegate.h" 8 9 namespace gfx { 10 11 namespace { 12 13 Screen* g_screen_[SCREEN_TYPE_LAST + 1]; 14 ScreenTypeDelegate* g_screen_type_delegate_ = NULL; 15 16 } // namespace 17 Screen()18Screen::Screen() { 19 } 20 ~Screen()21Screen::~Screen() { 22 } 23 24 // static GetScreenFor(NativeView view)25Screen* Screen::GetScreenFor(NativeView view) { 26 ScreenType type = SCREEN_TYPE_NATIVE; 27 if (g_screen_type_delegate_) 28 type = g_screen_type_delegate_->GetScreenTypeForNativeView(view); 29 if (type == SCREEN_TYPE_NATIVE) 30 return GetNativeScreen(); 31 DCHECK(g_screen_[type]); 32 return g_screen_[type]; 33 } 34 35 // static SetScreenInstance(ScreenType type,Screen * instance)36void Screen::SetScreenInstance(ScreenType type, Screen* instance) { 37 DCHECK_LE(type, SCREEN_TYPE_LAST); 38 g_screen_[type] = instance; 39 } 40 41 // static GetScreenByType(ScreenType type)42Screen* Screen::GetScreenByType(ScreenType type) { 43 return g_screen_[type]; 44 } 45 46 // static SetScreenTypeDelegate(ScreenTypeDelegate * delegate)47void Screen::SetScreenTypeDelegate(ScreenTypeDelegate* delegate) { 48 g_screen_type_delegate_ = delegate; 49 } 50 51 // static GetNativeScreen()52Screen* Screen::GetNativeScreen() { 53 if (!g_screen_[SCREEN_TYPE_NATIVE]) 54 g_screen_[SCREEN_TYPE_NATIVE] = CreateNativeScreen(); 55 return g_screen_[SCREEN_TYPE_NATIVE]; 56 } 57 58 } // namespace gfx 59