LocalDisplayAdapter.java revision bd6e1500aedc5461e832f69e76341bff0e55fa2b
1/* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.server.display; 18 19import android.content.Context; 20import android.os.IBinder; 21import android.view.Surface; 22import android.view.Surface.PhysicalDisplayInfo; 23 24/** 25 * A display adapter for the local displays managed by Surface Flinger. 26 * <p> 27 * Display adapters are not thread-safe and must only be accessed 28 * on the display manager service's handler thread. 29 * </p> 30 */ 31public final class LocalDisplayAdapter extends DisplayAdapter { 32 private static final String TAG = "LocalDisplayAdapter"; 33 34 public LocalDisplayAdapter(Context context) { 35 super(context, TAG); 36 } 37 38 @Override 39 protected void onRegister() { 40 // TODO: listen for notifications from Surface Flinger about 41 // built-in displays being added or removed and rescan as needed. 42 IBinder displayToken = Surface.getBuiltInDisplay(Surface.BUILT_IN_DISPLAY_ID_MAIN); 43 sendDisplayDeviceEvent(new LocalDisplayDevice(displayToken, true), 44 DISPLAY_DEVICE_EVENT_ADDED); 45 } 46 47 private final class LocalDisplayDevice extends DisplayDevice { 48 private final boolean mIsDefault; 49 50 public LocalDisplayDevice(IBinder displayToken, boolean isDefault) { 51 super(LocalDisplayAdapter.this, displayToken); 52 mIsDefault = isDefault; 53 } 54 55 @Override 56 public void getInfo(DisplayDeviceInfo outInfo) { 57 PhysicalDisplayInfo phys = new PhysicalDisplayInfo(); 58 Surface.getDisplayInfo(getDisplayToken(), phys); 59 60 outInfo.name = getContext().getResources().getString( 61 com.android.internal.R.string.display_manager_built_in_display_name); 62 outInfo.width = phys.width; 63 outInfo.height = phys.height; 64 outInfo.refreshRate = phys.refreshRate; 65 outInfo.densityDpi = (int)(phys.density * 160 + 0.5f); 66 outInfo.xDpi = phys.xDpi; 67 outInfo.yDpi = phys.yDpi; 68 if (mIsDefault) { 69 outInfo.flags = DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY 70 | DisplayDeviceInfo.FLAG_SECURE; 71 } 72 } 73 } 74} 75