1 /*
2  * This file is part of libbluray
3  * Copyright (C) 2010  William Hahne
4  * Copyright (C) 2019  Petri Hintukainen <phintuka@users.sourceforge.net>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
21 package org.havi.ui;
22 
23 import org.blurayx.s3d.ui.HGraphicsConfigTemplateS3D;
24 import org.blurayx.uhd.ui.HGraphicsConfigurationTemplateUHD;
25 
26 import java.awt.Dimension;
27 
28 import org.videolan.GUIManager;
29 import org.videolan.Logger;
30 
31 public class HGraphicsDevice extends HScreenDevice {
HGraphicsDevice()32     protected HGraphicsDevice() {
33         boolean is_p6 = isProfile6();
34         boolean is_p5 = isProfile5();
35         int length = HScreenConfigTemplate.defaultConfig.length;
36         hgcArray = new HGraphicsConfiguration[length];
37         for (int i = 0; i < length; i++) {
38             HGraphicsConfigTemplate hgct;
39             if (is_p6) {
40                 hgct = new HGraphicsConfigurationTemplateUHD();
41             } else if (is_p5) {
42                 hgct = new HGraphicsConfigTemplateS3D();
43             } else {
44                 hgct = new HGraphicsConfigTemplate();
45             }
46             HScreenConfigTemplate.initDefaultConfigTemplate(hgct, i);
47             hgcArray[i] = new HGraphicsConfiguration(hgct);
48         }
49         hgc = hgcArray[0];
50     }
51 
getConfigurations()52     public HGraphicsConfiguration[] getConfigurations() {
53         return hgcArray;
54     }
55 
getDefaultConfiguration()56     public HGraphicsConfiguration getDefaultConfiguration() {
57         return hgcArray[0];
58     }
59 
getBestConfiguration(HGraphicsConfigTemplate hgct)60     public HGraphicsConfiguration getBestConfiguration(HGraphicsConfigTemplate hgct) {
61         int score = -1;
62         HGraphicsConfiguration hgc = null;
63         for (int i = 0; i < hgcArray.length; i++)
64             if (hgct.match(hgcArray[i]) > score)
65                 hgc = hgcArray[i];
66         return hgc;
67     }
68 
getBestConfiguration(HGraphicsConfigTemplate hgcta[])69     public HGraphicsConfiguration getBestConfiguration(HGraphicsConfigTemplate hgcta[]) {
70         int score = -1;
71         HGraphicsConfiguration hgc = null;
72         for (int i = 0; i < hgcArray.length; i++)
73             for (int j = 0; j < hgcta.length; j++)
74                 if (hgcta[j].match(hgcArray[i]) > score)
75                     hgc = hgcArray[i];
76         return hgc;
77     }
78 
getCurrentConfiguration()79     public HGraphicsConfiguration getCurrentConfiguration() {
80         return hgc;
81     }
82 
setGraphicsConfiguration(HGraphicsConfiguration hgc)83     public boolean setGraphicsConfiguration(HGraphicsConfiguration hgc)
84             throws SecurityException, HPermissionDeniedException,
85             HConfigurationException {
86 
87         logger.unimplemented("setGraphicsConfiguration");
88 
89         GUIManager mgr = GUIManager.getInstance();
90         Dimension d = hgc.getPixelResolution();
91         int curWidth = mgr.getWidth();
92         int curHeight = mgr.getHeight();
93 
94         if (curWidth != d.width || curHeight != d.height) {
95             logger.info("Request to switch graphics resolution from " + curWidth + "x" + curHeight +
96                         " to " + d.width + "x" + d.height);
97 
98             if (mgr.isVisible()) {
99                 mgr.setVisible(false);
100                 mgr.setBounds(0, 0, d.width, d.height);
101                 mgr.setVisible(true);
102             } else {
103                 mgr.setBounds(0, 0, d.width, d.height);
104             }
105 
106             curWidth = mgr.getWidth();
107             curHeight = mgr.getHeight();
108             if (curWidth != d.width || curHeight != d.height) {
109                 logger.error("Request to switch graphics resolution from " + curWidth + "x" + curHeight +
110                             " to " + d.width + "x" + d.height + " FAILED");
111                 return false;
112             }
113         }
114 
115         this.hgc = hgc;
116         return true;
117     }
118 
119     private HGraphicsConfiguration[] hgcArray;
120     private HGraphicsConfiguration hgc;
121 
122     private static final Logger logger = Logger.getLogger(HGraphicsDevice.class.getName());
123 }
124