David Ghandehari | 9e5b587 | 2016-07-28 09:50:04 -0700 | [diff] [blame] | 1 | // Copyright 2016 Google Inc. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #include "starboard/raspi/shared/window_internal.h" |
| 16 | |
David Ghandehari | 9e5b587 | 2016-07-28 09:50:04 -0700 | [diff] [blame] | 17 | #include "starboard/log.h" |
| 18 | |
| 19 | namespace { |
| 20 | const int32_t kLayer = 0; |
David Ghandehari | 9e5b587 | 2016-07-28 09:50:04 -0700 | [diff] [blame] | 21 | } // namespace |
| 22 | |
Andrew Top | a953d4e | 2016-11-22 22:38:45 -0800 | [diff] [blame] | 23 | using starboard::raspi::shared::DispmanxDisplay; |
| 24 | using starboard::raspi::shared::DispmanxElement; |
| 25 | using starboard::raspi::shared::DispmanxRect; |
| 26 | using starboard::raspi::shared::DispmanxResource; |
David Ghandehari | 9e5b587 | 2016-07-28 09:50:04 -0700 | [diff] [blame] | 27 | |
Andrew Top | a953d4e | 2016-11-22 22:38:45 -0800 | [diff] [blame] | 28 | SbWindowPrivate::SbWindowPrivate(const DispmanxDisplay& display, |
| 29 | const SbWindowOptions* options) { |
David Ghandehari | 9e5b587 | 2016-07-28 09:50:04 -0700 | [diff] [blame] | 30 | uint32_t window_width = 0; |
| 31 | uint32_t window_height = 0; |
| 32 | if (options && options->size.width > 0 && options->size.height > 0) { |
| 33 | window_width = options->size.width; |
| 34 | window_height = options->size.height; |
| 35 | } else { |
| 36 | // Default is the full screen. |
| 37 | int32_t result = |
| 38 | graphics_get_display_size(0, &window_width, &window_height); |
| 39 | SB_DCHECK(result >= 0); |
| 40 | } |
| 41 | |
Andrew Top | a953d4e | 2016-11-22 22:38:45 -0800 | [diff] [blame] | 42 | DispmanxRect destination_rect(0, 0, window_width, window_height); |
| 43 | // The "<< 16"s are part of the examples, but unexplained. It appears to work. |
| 44 | DispmanxRect source_rect(0, 0, window_width << 16, window_height << 16); |
| 45 | // The window doesn't have an image resource associated with it. |
| 46 | DispmanxResource resource; |
David Ghandehari | 9e5b587 | 2016-07-28 09:50:04 -0700 | [diff] [blame] | 47 | // Creating a window (called an "element" here, created by adding it to the |
| 48 | // display) must happen within an "update", which seems to represent a sort of |
| 49 | // window manager transaction. |
Andrew Top | a953d4e | 2016-11-22 22:38:45 -0800 | [diff] [blame] | 50 | element.reset(new DispmanxElement(display, kLayer, destination_rect, resource, |
| 51 | source_rect)); |
David Ghandehari | 9e5b587 | 2016-07-28 09:50:04 -0700 | [diff] [blame] | 52 | // We can then populate this struct, a pointer to which is what EGL expects as |
| 53 | // a "native window" handle. |
Andrew Top | a953d4e | 2016-11-22 22:38:45 -0800 | [diff] [blame] | 54 | window.element = element->handle(); |
David Ghandehari | 9e5b587 | 2016-07-28 09:50:04 -0700 | [diff] [blame] | 55 | window.width = window_width; |
| 56 | window.height = window_height; |
| 57 | } |
| 58 | |
| 59 | SbWindowPrivate::~SbWindowPrivate() { |
Andrew Top | a953d4e | 2016-11-22 22:38:45 -0800 | [diff] [blame] | 60 | element.reset(); |
David Ghandehari | 9e5b587 | 2016-07-28 09:50:04 -0700 | [diff] [blame] | 61 | } |