The Pedigree Project  0.1
GraphicsService.cc
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #include "pedigree/kernel/graphics/GraphicsService.h"
21 #include "pedigree/kernel/Log.h"
22 #include "pedigree/kernel/machine/Display.h"
23 #include "pedigree/kernel/processor/types.h"
24 #include "pedigree/kernel/utilities/Iterator.h"
25 #include "pedigree/kernel/utilities/String.h"
26 #include "pedigree/kernel/utilities/utility.h"
27 
29  ServiceFeatures::Type type, void *pData, size_t dataLen)
30 {
31  if (!pData)
32  return false;
33 
34  // Touch = provide a new display device
35  GraphicsProvider *pProvider = reinterpret_cast<GraphicsProvider *>(pData);
36  if (type & ServiceFeatures::touch)
37  {
39  m_Providers.pushBack(pProvider);
40 
41  ProviderPair bestProvider = determineBestProvider();
42  m_pCurrentProvider = bestProvider.bestBase;
43  m_pCurrentTextProvider = bestProvider.bestText;
44 
45  return true;
46  }
47  else if (type & ServiceFeatures::probe)
48  {
49  GraphicsParameters *params =
50  reinterpret_cast<GraphicsParameters *>(pData);
51 
52  if (params->wantTextMode)
53  {
54  if (m_pCurrentTextProvider)
55  {
56  MemoryCopy(
57  &params->providerResult, m_pCurrentProvider,
58  sizeof(GraphicsProvider));
59  params->providerFound = true;
60 
61  return true;
62  }
63  }
64  else if (m_pCurrentProvider)
65  {
66  MemoryCopy(
67  &params->providerResult, m_pCurrentProvider,
68  sizeof(GraphicsProvider));
69  params->providerFound = true;
70 
71  return true;
72  }
73  }
74 
75  // Invalid command
76  return false;
77 }
78 
79 GraphicsService::ProviderPair GraphicsService::determineBestProvider()
80 {
81  ProviderPair result;
82  result.bestBase = 0;
83  result.bestText = 0;
84 
85  uint64_t bestPoints = 0;
86  uint64_t bestTextPoints = 0;
87  for (List<GraphicsProvider *>::Iterator it = m_Providers.begin();
88  it != m_Providers.end(); it++)
89  {
90  if (!*it)
91  continue;
92 
93  GraphicsProvider *pProvider = *it;
94 
95  uint64_t points = 0;
96  uint64_t textPoints = 0;
97 
98  // Hardware acceleration points
99  if (pProvider->bHardwareAccel)
100  points +=
101  (0x10000ULL * 0x10000ULL) *
102  32ULL; // 16384x16384x32, hard to beat if no hardware accel
103 
104  // Maximums points (highest resolution in bits)
105  points +=
106  pProvider->maxWidth * pProvider->maxHeight * pProvider->maxDepth;
107  textPoints += pProvider->maxTextWidth * pProvider->maxTextHeight;
108 
109  if (!pProvider->bTextModes)
110  {
111  textPoints *= 0;
112  }
113 
114  String name;
115  pProvider->pDisplay->getName(name);
116  DEBUG_LOG(
117  "GraphicsService: provider with display name '"
118  << name << "' got " << points << " points (" << textPoints
119  << " text points)");
120 
121  // Is this the new best?
122  if (points > bestPoints)
123  {
124  bestPoints = points;
125  result.bestBase = pProvider;
126 
127  DEBUG_LOG(" => new best provider");
128  }
129 
130  if (textPoints > bestTextPoints)
131  {
132  bestTextPoints = textPoints;
133  result.bestText = pProvider;
134 
135  DEBUG_LOG(" => new best text provider");
136  }
137  }
138 
139  return result;
140 }
virtual void getName(String &str)
Definition: Display.cc:50
Definition: String.h:49
bool serve(ServiceFeatures::Type type, void *pData, size_t dataLen)
::Iterator< T, node_t > Iterator
Definition: List.h:71
#define DEBUG_LOG(text)
Definition: Log.h:69