1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532
|
/*
* Copyright (C) 2024 Igalia S.L.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "WPEScreen.h"
#include <wtf/glib/WTFGType.h>
/**
* WPEScreen:
*
*/
struct _WPEScreenPrivate {
guint32 id;
int x { -1 };
int y { -1 };
int width { -1 };
int height { -1 };
int physicalWidth { -1 };
int physicalHeight { -1 };
gdouble scale { 1 };
int refreshRate { -1 };
};
WEBKIT_DEFINE_ABSTRACT_TYPE(WPEScreen, wpe_screen, G_TYPE_OBJECT)
enum {
PROP_0,
PROP_ID,
PROP_X,
PROP_Y,
PROP_WIDTH,
PROP_HEIGHT,
PROP_PHYSICAL_WIDTH,
PROP_PHYSICAL_HEIGHT,
PROP_SCALE,
PROP_REFRESH_RATE,
N_PROPERTIES
};
static std::array<GParamSpec*, N_PROPERTIES> sObjProperties;
static void wpeScreenSetProperty(GObject* object, guint propId, const GValue* value, GParamSpec* paramSpec)
{
auto* screen = WPE_SCREEN(object);
switch (propId) {
case PROP_ID:
screen->priv->id = g_value_get_uint(value);
break;
case PROP_X:
wpe_screen_set_position(screen, g_value_get_int(value), -1);
break;
case PROP_Y:
wpe_screen_set_position(screen, -1, g_value_get_int(value));
break;
case PROP_WIDTH:
wpe_screen_set_size(screen, g_value_get_int(value), -1);
break;
case PROP_HEIGHT:
wpe_screen_set_size(screen, -1, g_value_get_int(value));
break;
case PROP_PHYSICAL_WIDTH:
wpe_screen_set_physical_size(screen, g_value_get_int(value), -1);
break;
case PROP_PHYSICAL_HEIGHT:
wpe_screen_set_physical_size(screen, -1, g_value_get_int(value));
break;
case PROP_SCALE:
wpe_screen_set_scale(screen, g_value_get_double(value));
break;
case PROP_REFRESH_RATE:
wpe_screen_set_refresh_rate(screen, g_value_get_int(value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
}
}
static void wpeScreenGetProperty(GObject* object, guint propId, GValue* value, GParamSpec* paramSpec)
{
auto* screen = WPE_SCREEN(object);
switch (propId) {
case PROP_ID:
g_value_set_uint(value, wpe_screen_get_id(screen));
break;
case PROP_X:
g_value_set_int(value, wpe_screen_get_x(screen));
break;
case PROP_Y:
g_value_set_int(value, wpe_screen_get_y(screen));
break;
case PROP_WIDTH:
g_value_set_int(value, wpe_screen_get_width(screen));
break;
case PROP_HEIGHT:
g_value_set_int(value, wpe_screen_get_height(screen));
break;
case PROP_PHYSICAL_WIDTH:
g_value_set_int(value, wpe_screen_get_physical_width(screen));
break;
case PROP_PHYSICAL_HEIGHT:
g_value_set_int(value, wpe_screen_get_physical_height(screen));
break;
case PROP_SCALE:
g_value_set_double(value, wpe_screen_get_scale(screen));
break;
case PROP_REFRESH_RATE:
g_value_set_int(value, wpe_screen_get_refresh_rate(screen));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
}
}
static void wpe_screen_class_init(WPEScreenClass* screenClass)
{
GObjectClass* objectClass = G_OBJECT_CLASS(screenClass);
objectClass->set_property = wpeScreenSetProperty;
objectClass->get_property = wpeScreenGetProperty;
/**
* WPEScreen:id:
*
* The identifier of the screen.
*/
sObjProperties[PROP_ID] =
g_param_spec_uint(
"id",
nullptr, nullptr,
0, G_MAXUINT, 0,
static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
/**
* WPEScreen:x:
*
* The x coordinate of the screen position in logical coordinates.
*/
sObjProperties[PROP_X] =
g_param_spec_int(
"x",
nullptr, nullptr,
-1, G_MAXINT, -1,
WEBKIT_PARAM_READWRITE);
/**
* WPEScreen:y:
*
* The y coordinate of the screen position in logical coordinates.
*/
sObjProperties[PROP_Y] =
g_param_spec_int(
"y",
nullptr, nullptr,
-1, G_MAXINT, -1,
WEBKIT_PARAM_READWRITE);
/**
* WPEScreen:width:
*
* The width of the screen in logical coordinates.
*/
sObjProperties[PROP_WIDTH] =
g_param_spec_int(
"width",
nullptr, nullptr,
-1, G_MAXINT, -1,
WEBKIT_PARAM_READWRITE);
/**
* WPEScreen:height:
*
* The height of the screen in logical coordinates.
*/
sObjProperties[PROP_HEIGHT] =
g_param_spec_int(
"height",
nullptr, nullptr,
-1, G_MAXINT, -1,
WEBKIT_PARAM_READWRITE);
/**
* WPEScreen:physical-width:
*
* The physical width of the screen in millimeters.
*/
sObjProperties[PROP_PHYSICAL_WIDTH] =
g_param_spec_int(
"physical-width",
nullptr, nullptr,
-1, G_MAXINT, -1,
WEBKIT_PARAM_READWRITE);
/**
* WPEScreen:physical-height:
*
* The physical height of the screen in millimeters.
*/
sObjProperties[PROP_PHYSICAL_HEIGHT] =
g_param_spec_int(
"physical-height",
nullptr, nullptr,
-1, G_MAXINT, -1,
WEBKIT_PARAM_READWRITE);
/**
* WPEScreen:scale:
*
* The scale factor for the screen.
*
* Scaling factor applied to views displayed on this screen. Those views
* will have the value forwarded to their [property@View:scale] property.
*
* The accepted values are in the `0.05` to `20.0` range, meaning that
* rendering would be done up to 20 times smaller or bigger.
*/
sObjProperties[PROP_SCALE] =
g_param_spec_double(
"scale",
nullptr, nullptr,
0.05, 20., 1.,
WEBKIT_PARAM_READWRITE);
/**
* WPEScreen:refresh-rate:
*
* The refresh rate of the screen in milli-Hertz.
*/
sObjProperties[PROP_REFRESH_RATE] =
g_param_spec_int(
"refresh-rate",
nullptr, nullptr,
-1, G_MAXINT, -1,
WEBKIT_PARAM_READWRITE);
g_object_class_install_properties(objectClass, N_PROPERTIES, sObjProperties.data());
}
/**
* wpe_screen_get_id:
* @screen: a #WPEScreen
*
* Get the @screen identifier.
* The idenifier is a non-zero value to uniquely identify a #WPEScreen.
*
* Returns: the screen identifier
*/
guint32 wpe_screen_get_id(WPEScreen* screen)
{
g_return_val_if_fail(WPE_IS_SCREEN(screen), 0);
return screen->priv->id;
}
/**
* wpe_screen_invalidate:
* @screen: a #WPEScreen
*
* Invalidate @screen. This will release all the platform resources
* associated with @screen. The properties cached will not be
* modified so they are still available after invalidation.
*/
void wpe_screen_invalidate(WPEScreen* screen)
{
g_return_if_fail(WPE_IS_SCREEN(screen));
auto* screenClass = WPE_SCREEN_GET_CLASS(screen);
if (screenClass->invalidate)
screenClass->invalidate(screen);
}
/**
* wpe_screen_get_x:
* @screen: a #WPEScreen
*
* Get the x coordinate of the @screen position in logical coordinates.
*
* Returns: the x coordinate, or -1 if not available
*/
int wpe_screen_get_x(WPEScreen* screen)
{
g_return_val_if_fail(WPE_IS_SCREEN(screen), -1);
return screen->priv->x;
}
/**
* wpe_screen_get_y:
* @screen: a #WPEScreen
*
* Get the y coordinate of the @screen position in logical coordinates.
*
* Returns: the y coordinate, or -1 if not available
*/
int wpe_screen_get_y(WPEScreen* screen)
{
g_return_val_if_fail(WPE_IS_SCREEN(screen), -1);
return screen->priv->y;
}
/**
* wpe_screen_set_position:
* @screen: a #WPEScreen
* @x: the x coordinate, or -1
* @y: the y coordinate, or -1
*
* Set the position of @screen in logical coordinates.
*/
void wpe_screen_set_position(WPEScreen* screen, int x, int y)
{
g_return_if_fail(WPE_IS_SCREEN(screen));
g_return_if_fail(x == -1 || x >= 0);
g_return_if_fail(y == -1 || y >= 0);
if (x != -1 && x != screen->priv->x) {
screen->priv->x = x;
g_object_notify_by_pspec(G_OBJECT(screen), sObjProperties[PROP_X]);
}
if (y != -1 && y != screen->priv->y) {
screen->priv->y = y;
g_object_notify_by_pspec(G_OBJECT(screen), sObjProperties[PROP_Y]);
}
}
/**
* wpe_screen_get_width:
* @screen: a #WPEScreen
*
* Get the width of @screen in logical coordinates.
*
* Returns: the width of @screen, or -1 if not available
*/
int wpe_screen_get_width(WPEScreen* screen)
{
g_return_val_if_fail(WPE_IS_SCREEN(screen), -1);
return screen->priv->width;
}
/**
* wpe_screen_get_height:
* @screen: a #WPEScreen
*
* Get the height of @screen in logical coordinates.
*
* Returns: the height of @screen, or -1 if not available
*/
int wpe_screen_get_height(WPEScreen* screen)
{
g_return_val_if_fail(WPE_IS_SCREEN(screen), -1);
return screen->priv->height;
}
/**
* wpe_screen_set_size:
* @screen: a #WPEScreen
* @width: the width, or -1
* @height: the height, or -1
*
* Set the size of @screen in logical coordinates.
*/
void wpe_screen_set_size(WPEScreen* screen, int width, int height)
{
g_return_if_fail(WPE_IS_SCREEN(screen));
g_return_if_fail(width == -1 || width >= 0);
g_return_if_fail(height == -1 || height >= 0);
g_object_freeze_notify(G_OBJECT(screen));
if (width != -1 && width != screen->priv->width) {
screen->priv->width = width;
g_object_notify_by_pspec(G_OBJECT(screen), sObjProperties[PROP_WIDTH]);
}
if (height != -1 && height != screen->priv->height) {
screen->priv->height = height;
g_object_notify_by_pspec(G_OBJECT(screen), sObjProperties[PROP_HEIGHT]);
}
g_object_thaw_notify(G_OBJECT(screen));
}
/**
* wpe_screen_get_physical_width:
* @screen: a #WPEScreen
*
* Get the physical width of @screen in millimeters.
*
* Returns: the physical width of @screen, or -1 if not available
*/
int wpe_screen_get_physical_width(WPEScreen* screen)
{
g_return_val_if_fail(WPE_IS_SCREEN(screen), -1);
return screen->priv->physicalWidth;
}
/**
* wpe_screen_get_physical_height:
* @screen: a #WPEScreen
*
* Get the physical height of @screen in millimeters.
*
* Returns: the physical height of @screen, or -1 if not available
*/
int wpe_screen_get_physical_height(WPEScreen* screen)
{
g_return_val_if_fail(WPE_IS_SCREEN(screen), -1);
return screen->priv->physicalHeight;
}
/**
* wpe_screen_set_physical_size:
* @screen: a #WPEScreen
* @width: the physical width, or -1
* @height: the physical height, or -1
*
* Set the physical size of @screen in millimeters.
*/
void wpe_screen_set_physical_size(WPEScreen* screen, int width, int height)
{
g_return_if_fail(WPE_IS_SCREEN(screen));
g_return_if_fail(width == -1 || width >= 0);
g_return_if_fail(height == -1 || height >= 0);
if (width != -1 && width != screen->priv->physicalWidth) {
screen->priv->physicalWidth = width;
g_object_notify_by_pspec(G_OBJECT(screen), sObjProperties[PROP_PHYSICAL_WIDTH]);
}
if (height != -1 && height != screen->priv->physicalHeight) {
screen->priv->physicalHeight = height;
g_object_notify_by_pspec(G_OBJECT(screen), sObjProperties[PROP_PHYSICAL_HEIGHT]);
}
}
/**
* wpe_screen_get_scale:
* @screen: a #WPEScreen
*
* Get the @screen scale factor
*
* Returns: the screen scale factor
*/
gdouble wpe_screen_get_scale(WPEScreen* screen)
{
g_return_val_if_fail(WPE_IS_SCREEN(screen), 1);
return screen->priv->scale;
}
/**
* wpe_screen_set_scale:
* @screen: a #WPEScreen
* @scale: the scale factor to set
*
* Set the @screen scale factor
*/
void wpe_screen_set_scale(WPEScreen* screen, double scale)
{
g_return_if_fail(WPE_IS_SCREEN(screen));
g_return_if_fail(scale >= 0.05);
g_return_if_fail(scale <= 20.0);
if (screen->priv->scale == scale)
return;
screen->priv->scale = scale;
g_object_notify_by_pspec(G_OBJECT(screen), sObjProperties[PROP_SCALE]);
}
/**
* wpe_screen_get_refresh_rate:
* @screen: a #WPEScreen
*
* Get the refresh rate of @screen in milli-Hertz.
*
* Returns: the refresh rate, or -1 if not available
*/
int wpe_screen_get_refresh_rate(WPEScreen* screen)
{
g_return_val_if_fail(WPE_IS_SCREEN(screen), -1);
return screen->priv->refreshRate;
}
/**
* wpe_screen_set_refresh_rate:
* @screen: a #WPEScreen
* @refresh_rate: the refresh rate
*
* Set the refresh rate of @screen in milli-Hertz.
*
*/
void wpe_screen_set_refresh_rate(WPEScreen* screen, int refreshRate)
{
g_return_if_fail(WPE_IS_SCREEN(screen));
g_return_if_fail(refreshRate == -1 || refreshRate >= 0);
if (refreshRate == -1 || refreshRate == screen->priv->refreshRate)
return;
screen->priv->refreshRate = refreshRate;
g_object_notify_by_pspec(G_OBJECT(screen), sObjProperties[PROP_REFRESH_RATE]);
}
|