|
16 | 16 |
|
17 | 17 | import abc |
18 | 18 | import contextlib |
| 19 | +import subprocess |
| 20 | +import sys |
19 | 21 |
|
20 | 22 | from dm_control.mujoco import wrapper |
21 | 23 | from dm_control.viewer import util |
|
44 | 46 | _DEFAULT_RENDER_FLAGS[mujoco.mjtRndFlag.mjRND_SKYBOX.value] = 1 |
45 | 47 | _DEFAULT_RENDER_FLAGS[mujoco.mjtRndFlag.mjRND_CULL_FACE.value] = 1 |
46 | 48 |
|
| 49 | +# Font scale values. |
| 50 | +_DEFAULT_FONT_SCALE = mujoco.mjtFontScale.mjFONTSCALE_100 |
| 51 | +_HIDPI_FONT_SCALE = mujoco.mjtFontScale.mjFONTSCALE_200 |
| 52 | + |
| 53 | + |
| 54 | +def _has_high_dpi() -> bool: |
| 55 | + """Returns True if the display is a high DPI display.""" |
| 56 | + if sys.platform == 'darwin': |
| 57 | + # On macOS, we can use the system_profiler command to determine if the |
| 58 | + # display is retina. |
| 59 | + return subprocess.call( |
| 60 | + 'system_profiler SPDisplaysDataType | grep -i "retina"', |
| 61 | + shell=True, |
| 62 | + stdout=subprocess.DEVNULL, |
| 63 | + stderr=subprocess.DEVNULL |
| 64 | + ) == 0 |
| 65 | + # TODO(zakka): Figure out how to detect high DPI displays on Linux. |
| 66 | + return False |
| 67 | + |
47 | 68 |
|
48 | 69 | class BaseRenderer(metaclass=abc.ABCMeta): |
49 | 70 | """A base class for component-based Mujoco Renderers implementations. |
@@ -150,10 +171,11 @@ def render(self, viewport, scene): |
150 | 171 | new_offheight = max(self._model.vis.global_.offheight, viewport.height) |
151 | 172 | self._model.vis.global_.offwidth = new_offwidth |
152 | 173 | self._model.vis.global_.offheight = new_offheight |
| 174 | + font_scale = _HIDPI_FONT_SCALE if _has_high_dpi() else _DEFAULT_FONT_SCALE |
153 | 175 | self._mujoco_context = wrapper.MjrContext( |
154 | 176 | model=self._model, |
155 | 177 | gl_context=self._surface, |
156 | | - font_scale=mujoco.mjtFontScale.mjFONTSCALE_100) |
| 178 | + font_scale=font_scale) |
157 | 179 | self._rgb_buffer = np.empty( |
158 | 180 | (viewport.height, viewport.width, 3), dtype=np.uint8) |
159 | 181 |
|
|
0 commit comments