1/* 2 * Copyright 2011 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stefano Ceccherini, burton666@libero.it 7 * Axel Dörfler, axeld@pinc-software.de 8 * John Scipione, jscipione@gmail.com 9 * 10 * Corresponds to: 11 * headers/os/interface/Screen.h rev 42759 12 * src/kits/interface/Screen.cpp rev 42759 13 */ 14 15 16/*! 17 \file Screen.h 18 \ingroup interface 19 \ingroup libbe 20 \brief Defines the BScreen class and support structures. 21*/ 22 23 24/*! 25 \class BScreen 26 \ingroup interface 27 \ingroup libbe 28 \brief The BScreen class provides methods to retrieve and change display 29 settings. 30 31 Each BScreen object describes one display connected to the computer. 32 Multiple BScreen objects can represent the same physical display. 33 34 \attention Haiku currently supports only a single display. The main 35 screen with id \c B_MAIN_SCREEN_ID contains the origin in its top left 36 corner. Additional displays, when they become supported, will extend 37 the coordinates of the main screen. 38 39 Some utility methods provided by this class are ColorSpace() to get the 40 color space of the screen, Frame() to get the frame rectangle, and ID() 41 to get the identifier of the screen. 42 43 Methods to convert between 8-bit and 32-bit colors are provided by 44 IndexForColor() and ColorForIndex(). 45 46 You can also use this class to take a screenshot of the entire screen or 47 a particular portion of it. To take a screenshot use either the GetBitmap() 48 or ReadBitmap() method. 49 50 Furthermore, you can use this class get and set the background color of a 51 workspace. To get the background color call DesktopColor() or to set the 52 background color use SetDesktopColor(). 53 54 This class provides methods to get and set the resolution, pixel depth, 55 and color map of a display. To get a list of the display modes supported 56 by the graphics card use the GetModeList() method. You can get and set 57 the screen resolution by calling the GetMode() and SetMode() methods. 58 The color map of the display can be retrieved by calling the ColorMap() 59 method. 60 61 You can use this class to get information about the graphics card and 62 monitor connected to the computer by calling the GetDeviceInfo() and 63 GetMonitorInfo() methods. 64 65 VESA Display Power Management Signaling support allow you to put the 66 monitor into a low-power mode. Call DPMSCapabilites() to check what 67 modes are supported by your monitor. DPMSState() tells you what state 68 your monitor is currently in and SetDPMS() allows you to change it. 69 70 \since BeOS R3 71*/ 72 73 74/*! 75 \fn BScreen::BScreen(screen_id id) 76 \brief Creates a BScreen object which represents the display 77 connected to the computer with the given screen_id. 78 79 In the current implementation, there is only one display 80 (\c B_MAIN_SCREEN_ID). To be sure that the object was constructed 81 correctly, call IsValid(). 82 83 \param id The screen_id of the screen to create a BScreen object from. 84 85 \since BeOS R3 86*/ 87 88 89/*! 90 \fn BScreen::BScreen(BWindow* window) 91 \brief Creates a BScreen object which represents the display that 92 contains \a window. 93 94 In the current implementation, there is only one display 95 (\c B_MAIN_SCREEN_ID). To be sure that the object was constructed 96 correctly, call IsValid(). 97 98 \param window A BWindow object. 99 100 \since BeOS R3 101*/ 102 103 104/*! 105 \fn BScreen::~BScreen() 106 \brief Frees the resources used by the BScreen object and unlocks the 107 screen. 108 109 \note The main screen object will never go away, even if you disconnect 110 all monitors. 111 112 \since BeOS R3 113*/ 114 115 116/*! 117 \name Utility Methods 118*/ 119 120 121//! @{ 122 123 124/*! 125 \fn bool BScreen::IsValid() 126 \brief Checks that the BScreen object represents a real display that is 127 connected to the computer. 128 129 \return \c true if the BScreen object is valid, \c false otherwise. 130 131 \since BeOS R3 132*/ 133 134 135/*! 136 \fn status_t BScreen::SetToNext() 137 \brief Sets the BScreen object to the next display in the screen list. 138 139 \return \c B_OK if successful, otherwise \c B_ERROR. 140 141 \since BeOS R5 142*/ 143 144 145/*! 146 \fn color_space BScreen::ColorSpace() 147 \brief Returns the color_space of the display. 148 149 \return \c B_CMAP8, \c B_RGB15, \c B_RGB32, or \c B_NO_COLOR_SPACE 150 if the BScreen object is invalid. 151 152 \since BeOS R3 153*/ 154 155 156/*! 157 \fn BRect BScreen::Frame() 158 \brief Gets the frame of the screen in the screen's coordinate system. 159 160 For example if the BScreen object points to the main screen with a 161 resolution of 1,366x768 then this method returns 162 BRect(0.0, 0.0, 1365.0, 767.0). If the BScreen object is invalid then 163 this method returns an empty rectangle i.e. BRect(0.0, 0.0, 0.0, 0.0) 164 165 You can set the frame programmatically by calling the SetMode() method. 166 167 \return a BRect frame of the screen in the screen's coordinate system. 168 169 \since BeOS R3 170*/ 171 172 173/*! 174 \fn screen_id BScreen::ID() 175 \brief Gets the identifier of the display. 176 177 In the current implementation this method returns \c B_MAIN_SCREEN_ID 178 even if the object is invalid. 179 180 \return A screen_id that identifies the screen. 181 182 \since BeOS R3 183*/ 184 185 186/*! 187 \fn status_t BScreen::WaitForRetrace() 188 \brief Blocks until the monitor has finished its current vertical retrace. 189 190 \return \c B_OK or \c B_ERROR if the screen object is invalid. 191 192 \since BeOS R3 193*/ 194 195 196/*! 197 \fn status_t BScreen::WaitForRetrace(bigtime_t timeout) 198 \brief Blocks until the monitor has finished its current vertical retrace 199 or until \a timeout has expired. 200 201 \param timeout The amount of time to wait before returning. 202 203 \return \c B_OK if the monitor has retraced in the given \a timeout 204 duration, \c B_ERROR otherwise. 205 206 \since BeOS R5 207*/ 208 209 210//! @} 211 212 213/*! 214 \name Color 215*/ 216 217 218//! @{ 219 220 221/*! 222 \fn inline uint8 BScreen::IndexForColor(rgb_color color) 223 \brief Returns the 8-bit color index that most closely matches a 224 32-bit \a color. 225 226 \param color The 32-bit \a color to get the 8-bit index of. 227 228 \return An 8-bit color index in the screen's color_map. 229 230 \since BeOS R3 231*/ 232 233 234/*! 235 \fn uint8 BScreen::IndexForColor(uint8 red, uint8 green, uint8 blue, 236 uint8 alpha) 237 \brief Returns the 8-bit color index that most closely matches a set of 238 \a red, \a green, \a blue, and \a alpha values. 239 240 \param red The \a red value. 241 \param green The \a green value. 242 \param blue The \a blue value. 243 \param alpha The \a alpha value. 244 245 \return An 8-bit color index in the screen's color_map. 246 247 \since BeOS R3 248*/ 249 250 251/*! 252 \fn rgb_color BScreen::ColorForIndex(const uint8 index) 253 \brief Gets the 32-bit color representation of an 8-bit color \a index. 254 255 \param index The 8-bit color \a index to convert to a 32-bit color. 256 257 \return A 32-bit rgb_color structure. 258 259 \since BeOS R3 260*/ 261 262 263/*! 264 \fn uint8 BScreen::InvertIndex(uint8 index) 265 \brief Gets the "Inversion" of an 8-bit color \a index. 266 267 Inverted colors are useful for highlighting. 268 269 \param index The 8-bit color \a index. 270 271 \return An 8-bit color \a index that represents the "Inversion" of the 272 given color in the screen's color_map. 273 274 \since BeOS R3 275*/ 276 277 278/*! 279 \fn const color_map* BScreen::ColorMap() 280 \brief Gets the color_map of the BScreen. 281 282 \return A pointer to the BScreen object's color_map. 283 284 \since BeOS R3 285*/ 286 287 288//! @} 289 290 291/*! 292 \name Bitmap 293*/ 294 295 296//! @{ 297 298 299/*! 300 \fn status_t BScreen::GetBitmap(BBitmap** _bitmap, bool drawCursor, 301 BRect* bounds) 302 \brief Allocates a BBitmap and copies the contents of the screen into it. 303 304 \note GetBitmap() will allocate a BBitmap object for you while 305 ReadBitmap() requires you to pre-allocate a BBitmap object first. 306 307 \note The caller is responsible for freeing the BBitmap object. 308 309 \param _bitmap A pointer to a BBitmap pointer where this method will 310 store the contents of the display. 311 \param drawCursor Specifies whether or not to draw the cursor. 312 \param bounds Specifies the screen area that you want copied. If 313 \a bounds is \c NULL then the entire screen is copied. 314 315 \return \c B_OK if the operation was successful, \c B_ERROR otherwise. 316 317 \since BeOS R4 318*/ 319 320 321/*! 322 \fn status_t BScreen::ReadBitmap(BBitmap* bitmap, bool drawCursor, 323 BRect* bounds) 324 \brief Copies the contents of the screen into a BBitmap. 325 326 \note ReadBitmap() requires you to pre-allocate a BBitmap object first, 327 while GetBitmap() will allocate a BBitmap object for you. 328 329 \param bitmap A pointer to a pre-allocated BBitmap where this 330 method will store the contents of the display. 331 \param drawCursor Specifies whether or not to draw the cursor. 332 \param bounds Specifies the screen area that you want copied. If 333 \a bounds is \c NULL then the entire screen is copied. 334 335 \return \c B_OK if the operation was successful, \c B_ERROR otherwise. 336 337 \since BeOS R4 338*/ 339 340 341//! @} 342 343 344/*! 345 \name Desktop Color 346*/ 347 348 349//! @{ 350 351 352/*! 353 \fn rgb_color BScreen::DesktopColor() 354 \brief Gets the background color of the current workspace. 355 356 \return A 32-bit rgb_color structure containing the background color 357 of the current workspace. 358 359 \since BeOS R3 360*/ 361 362 363/*! 364 \fn rgb_color BScreen::DesktopColor(uint32 workspace) 365 \brief Gets the background color of the specified \a workspace. 366 367 \param workspace The \a workspace index to get the desktop background 368 color of. 369 370 \return An 32-bit rgb_color structure containing the background color 371 of the specified \a workspace. 372 373 \since Haiku R1 374*/ 375 376 377/*! 378 \fn void BScreen::SetDesktopColor(rgb_color color, bool stick) 379 \brief Set the background \a color of the current workspace. 380 381 \param color The 32-bit \a color to paint the desktop background. 382 \param stick Whether or not the \a color will stay after a reboot. 383 384 \since BeOS R3 385*/ 386 387 388/*! 389 \fn void BScreen::SetDesktopColor(rgb_color color, uint32 workspace, 390 bool stick) 391 \brief Set the background \a color of the specified \a workspace. 392 393 \param color The 32-bit \a color to paint the desktop background. 394 \param workspace The \a workspace index to update. 395 \param stick Whether or not the \a color will stay after a reboot. 396 397 \since Haiku R1 398*/ 399 400 401//! @} 402 403 404/*! 405 \name Display Mode 406 407 The following methods retrieve and alter the display_mode structure 408 of a screen. The display_mode structure contains screen size, 409 pixel depth, and display timings settings. 410*/ 411 412 413//! @{ 414 415 416/*! 417 \fn status_t BScreen::ProposeMode(display_mode* target, 418 const display_mode* low, const display_mode* high) 419 \brief Adjust the \a target mode to make it a supported mode. 420 421 The list of supported modes for the graphics card is supplied by 422 the GetModeList() method. 423 424 \param target The mode you want adjust. 425 \param low The lower display mode limit. 426 \param high The higher display mode limit. 427 428 \returns A status code. 429 \retval B_OK if \a target is supported and falls within the 430 \a low and \a high limits. 431 \retval B_BAD_VALUE if \a target is supported but does not 432 fall within the \a low and \a high limits. 433 \retval B_ERROR if the target mode isn't supported. 434 435 \since BeOS R5 436*/ 437 438 439/*! 440 \fn status_t BScreen::GetModeList(display_mode** _modeList, uint32* _count) 441 \brief Allocates and returns a list of the display modes supported by the 442 graphics card into \a _modeList. 443 444 \warning The monitor may not be able to display all of the modes that 445 GetModeList() retrieves. 446 447 \note The caller is responsible for freeing the display_mode object. 448 449 \param _modeList A pointer to a display_mode pointer, where the function 450 will allocate an array of display_mode structures. 451 \param _count A pointer to an integer used to store the count of 452 available display modes. 453 454 \retval B_OK if the operation was successful. 455 \retval B_ERROR for all other errors. 456 457 \since BeOS R5 458*/ 459 460 461/*! 462 \fn status_t BScreen::GetMode(display_mode* mode) 463 \brief Fills out the display_mode struct from the current workspace. 464 465 \param mode A pointer to a display_mode struct to copy into. 466 467 \retval B_OK if the operation was successful. 468 \retval B_BAD_VALUE if \a mode is invalid. 469 \retval B_ERROR for all other errors. 470 471 \since BeOS R5 472*/ 473 474 475/*! 476 \fn status_t BScreen::GetMode(uint32 workspace, display_mode* mode) 477 \brief Fills out the display_mode struct from the specified 478 \a workspace. 479 480 \param workspace The index of the \a workspace to query. 481 \param mode A pointer to a display_mode structure to copy into. 482 483 \retval B_OK if the operation was successful 484 \retval B_BAD_VALUE if \a mode is invalid. 485 \retval B_ERROR for all other errors. 486 487 \since Haiku R1 488*/ 489 490 491/*! 492 \fn status_t BScreen::SetMode(display_mode* mode, bool makeDefault) 493 \brief Sets the screen in the current workspace to the given \a mode. 494 495 \param mode A pointer to a display_mode struct. 496 \param makeDefault Whether or not \a mode is set as the default. 497 498 \return \c B_OK if the operation was successful, \c B_ERROR otherwise. 499 500 \since BeOS R5 501*/ 502 503 504/*! 505 \fn status_t BScreen::SetMode(uint32 workspace, display_mode* mode, 506 bool makeDefault) 507 \brief Set the screen in the specified \a workspace to the given \a mode. 508 509 \param workspace The index of the workspace to set the \a mode of. 510 \param mode A pointer to a display_mode struct. 511 \param makeDefault Whether or not the \a mode is set as the default 512 for the specified \a workspace. 513 514 \return \c B_OK if the operation was successful, \c B_ERROR otherwise. 515 516 \since Haiku R1 517*/ 518 519 520//! @} 521 522 523/*! 524 \name Display and Graphics Card Info 525*/ 526 527 528//! @{ 529 530 531/*! 532 \fn status_t BScreen::GetDeviceInfo(accelerant_device_info* info) 533 \brief Fills out the \a info struct with information about a graphics card. 534 535 \param info An accelerant_device_info struct to store the device 536 \a info. 537 538 \retval B_OK if the operation was successful. 539 \retval B_BAD_VALUE if \a info is invalid. 540 \retval B_ERROR for all other errors. 541 542 \since BeOS R5 543*/ 544 545 546/*! 547 \fn status_t BScreen::GetMonitorInfo(monitor_info* info) 548 \brief Fills out the \a info struct with information about a monitor. 549 550 \param info A monitor_info struct to store the monitor \a info. 551 552 \retval B_OK if the operation was successful. 553 \retval B_BAD_VALUE if \a info is invalid. 554 \retval B_ERROR for all other errors. 555 556 \since Haiku R1 557*/ 558 559 560/*! 561 \fn status_t BScreen::GetPixelClockLimits(display_mode* mode, 562 uint32* _low, uint32* _high) 563 \brief Gets the minimum and maximum pixel clock rates that are possible 564 for the specified \a mode. 565 566 \param mode A pointer to a display_mode structure. 567 \param _low A pointer to a uint32 where the method stores the lowest 568 available pixel clock. 569 \param _high A pointer to a uint32 where the method stores the highest 570 available pixel clock. 571 572 \retval B_OK if the operation was successful. 573 \retval B_BAD_VALUE if \a mode, \a low, or \a high is invalid. 574 \retval B_ERROR for all other errors. 575 576 \since BeOS R5 577*/ 578 579 580/*! 581 \fn status_t BScreen::GetTimingConstraints( 582 display_timing_constraints* constraints) 583 \brief Fills out the \a constraints structure with the timing constraints 584 of the current display mode. 585 586 \param constraints A pointer to a display_timing_constraints structure 587 to store the timing constraints. 588 589 \retval B_OK if the operation was successful. 590 \retval B_BAD_VALUE if \a constraints is invalid. 591 \retval B_ERROR for all other errors. 592 593 \since BeOS R5 594*/ 595 596 597//! @} 598 599 600/*! 601 \name VESA Display Power Management Signaling Settings 602 603 VESA Display Power Management Signaling (or DPMS) is a standard from the 604 VESA consortium for managing the power usage of displays through the 605 graphics card. DPMS allows you to shut off the display after the computer 606 has been unused for some time to save power. 607 608 DPMS states include: 609 - \c B_DPMS_ON Normal display operation. 610 - \c B_DPMS_STAND_BY Image not visible normal operation and returns to 611 normal after ~1 second. 612 - \c B_DPMS_SUSPEND Image not visible, returns to normal after ~5 613 seconds. 614 - \c B_DPMS_OFF Image not visible, display is off except for power to 615 monitoring circuitry. Returns to normal after ~8-20 seconds. 616 617 Power usage in each of the above states depends on the monitor used. CRT 618 monitors typically receive larger power savings than LCD monitors in 619 low-power states. 620*/ 621 622 623//! @{ 624 625 626/*! 627 \fn status_t BScreen::SetDPMS(uint32 dpmsState) 628 \brief Sets the VESA Display Power Management Signaling (DPMS) state for 629 the display. 630 631 \param dpmsState The DPMS state to set, valid values are: 632 - \c B_DPMS_ON 633 - \c B_DPMS_STAND_BY 634 - \c B_DPMS_SUSPEND 635 - \c B_DPMS_OFF 636 637 \return \c B_OK if the operation was successful, otherwise an error code. 638 639 \since BeOS R5 640*/ 641 642 643/*! 644 \fn uint32 BScreen::DPMSState() 645 \brief Gets the current VESA Display Power Management Signaling (DPMS) 646 state of the screen. 647 648 \return The current VESA Display Power Management Signaling (DPMS) state 649 of the display or 0 in the case of an error. 650 651 \since BeOS R5 652*/ 653 654 655 656/*! 657 \fn uint32 BScreen::DPMSCapabilites() 658 \brief Gets the VESA Display Power Management Signaling (DPMS) 659 modes that the display supports as a bit mask. 660 661 - \c B_DPMS_ON is worth 1 662 - \c B_DPMS_STAND_BY is worth 2 663 - \c B_DPMS_SUSPEND is worth 4 664 - \c B_DPMS_OFF is worth 8 665 666 \return A bit mask of the VESA Display Power Management Signaling (DPMS) 667 modes that the display supports or 0 in the case of an error. 668 669 \since BeOS R5 670*/ 671 672 673//! @} 674 675 676/*! 677 \name Deprecated Methods 678*/ 679 680 681//! @{ 682 683 684/*! 685 \fn BPrivate::BPrivateScreen* BScreen::private_screen() 686 \brief Returns the BPrivateScreen used by the BScreen object. 687 688 \return A pointer to the BPrivateScreen class internally used by the 689 BScreen object. 690 691 \since Haiku R1 692*/ 693 694 695/*! 696 \fn status_t BScreen::ProposeDisplayMode(display_mode* target, 697 const display_mode* low, const display_mode* high) 698 \brief Deprecated, use ProposeMode() instead. 699 700 \since BeOS R5 701*/ 702 703 704/*! 705 \fn void* BScreen::BaseAddress() 706 \brief Returns the base address of the frame buffer. 707 708 \since Haiku R1 709*/ 710 711 712/*! 713 \fn uint32 BScreen::BytesPerRow() 714 \brief Returns the bytes per row of the frame buffer. 715 716 \since Haiku R1 717*/ 718 719 720//! @} 721