blob: cb03c2d304f314db923ef5997776405ef4e67851 [file] [log] [blame]
David Ghandehari9e5b5872016-07-28 09:50:04 -07001// 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 Ghandehari9e5b5872016-07-28 09:50:04 -070017#include "starboard/log.h"
18
19namespace {
20const int32_t kLayer = 0;
David Ghandehari9e5b5872016-07-28 09:50:04 -070021} // namespace
22
Andrew Topa953d4e2016-11-22 22:38:45 -080023using starboard::raspi::shared::DispmanxDisplay;
24using starboard::raspi::shared::DispmanxElement;
25using starboard::raspi::shared::DispmanxRect;
26using starboard::raspi::shared::DispmanxResource;
David Ghandehari9e5b5872016-07-28 09:50:04 -070027
Andrew Topa953d4e2016-11-22 22:38:45 -080028SbWindowPrivate::SbWindowPrivate(const DispmanxDisplay& display,
29 const SbWindowOptions* options) {
David Ghandehari9e5b5872016-07-28 09:50:04 -070030 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 Topa953d4e2016-11-22 22:38:45 -080042 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 Ghandehari9e5b5872016-07-28 09:50:04 -070047 // 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 Topa953d4e2016-11-22 22:38:45 -080050 element.reset(new DispmanxElement(display, kLayer, destination_rect, resource,
51 source_rect));
David Ghandehari9e5b5872016-07-28 09:50:04 -070052 // We can then populate this struct, a pointer to which is what EGL expects as
53 // a "native window" handle.
Andrew Topa953d4e2016-11-22 22:38:45 -080054 window.element = element->handle();
David Ghandehari9e5b5872016-07-28 09:50:04 -070055 window.width = window_width;
56 window.height = window_height;
57}
58
59SbWindowPrivate::~SbWindowPrivate() {
Andrew Topa953d4e2016-11-22 22:38:45 -080060 element.reset();
David Ghandehari9e5b5872016-07-28 09:50:04 -070061}