diff options
author | Marissa Wall <marissaw@google.com> | 2016-09-01 14:32:17 -0700 |
---|---|---|
committer | Marissa Wall <marissaw@google.com> | 2017-03-02 12:34:49 -0800 |
commit | 7b6c2aa801dcdc60dc99e08b9291d1d5c0f6c279 (patch) | |
tree | 5d6a1d87ca06f990d6ec03146124cc2233d81486 | |
parent | edc82b338f58ff2a5ebfbf09b4caeee9bcd0ac09 (diff) | |
download | flounder-7b6c2aa801dcdc60dc99e08b9291d1d5c0f6c279.tar.gz |
hwc2: retrieves configs from adf
Retrieve all available configs for all physical displays.
Test: Add "TARGET_USES_HWC2 := true" to BoardConfig.mk.
Recompile.
Run testcases: https://android-review.googlesource.com/#/q/project:
platform/frameworks/native+branch:master+topic:test-hwc2
Change-Id: Iea3bfe01e5dc56001cdf222c3f2b6eea3ab19e07
-rw-r--r-- | hwc2/Android.mk | 3 | ||||
-rw-r--r-- | hwc2/hwc2.h | 27 | ||||
-rw-r--r-- | hwc2/hwc2_config.cpp | 52 | ||||
-rw-r--r-- | hwc2/hwc2_dev.cpp | 23 | ||||
-rw-r--r-- | hwc2/hwc2_display.cpp | 63 |
5 files changed, 164 insertions, 4 deletions
diff --git a/hwc2/Android.mk b/hwc2/Android.mk index 340df9f..cee7a8d 100644 --- a/hwc2/Android.mk +++ b/hwc2/Android.mk @@ -41,7 +41,8 @@ LOCAL_STATIC_LIBRARIES := \ LOCAL_SRC_FILES := \ hwc2.cpp \ hwc2_dev.cpp \ - hwc2_display.cpp + hwc2_display.cpp \ + hwc2_config.cpp LOCAL_MODLE_TAGS := optional diff --git a/hwc2/hwc2.h b/hwc2/hwc2.h index f12be0f..be4658c 100644 --- a/hwc2/hwc2.h +++ b/hwc2/hwc2.h @@ -24,6 +24,25 @@ #include <adf/adf.h> #include <adfhwc/adfhwc.h> +class hwc2_config { +public: + hwc2_config(); + + int set_attribute(hwc2_attribute_t attribute, int32_t value); + +private: + /* Dimensions in pixels */ + int32_t width; + int32_t height; + + /* Vsync period in nanoseconds */ + int32_t vsync_period; + + /* Dots per thousand inches (DPI * 1000) */ + int32_t dpi_x; + int32_t dpi_y; +}; + class hwc2_display { public: hwc2_display(hwc2_display_t id, int adf_intf_fd, @@ -32,6 +51,8 @@ public: hwc2_display_t get_id() const { return id; } + int retrieve_display_configs(struct adf_hwc_helper *adf_helper); + static hwc2_display_t get_next_id(); static void reset_ids() { display_cnt = 0; } @@ -40,6 +61,12 @@ private: /* Identifies the display to the client */ hwc2_display_t id; + /* All the valid configurations for the display */ + std::unordered_map<hwc2_config_t, hwc2_config> configs; + + /* The id of the current active configuration of the display */ + hwc2_config_t active_config; + /* The adf interface file descriptor for the display */ int adf_intf_fd; diff --git a/hwc2/hwc2_config.cpp b/hwc2/hwc2_config.cpp new file mode 100644 index 0000000..4741d6a --- /dev/null +++ b/hwc2/hwc2_config.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <cutils/log.h> + +#include "hwc2.h" + +hwc2_config::hwc2_config() + : width(-1), + height(-1), + vsync_period(-1), + dpi_x(-1), + dpi_y(-1) { } + +int hwc2_config::set_attribute(hwc2_attribute_t attribute, int32_t value) +{ + switch (attribute) { + case HWC2_ATTRIBUTE_WIDTH: + width = value; + break; + case HWC2_ATTRIBUTE_HEIGHT: + height = value; + break; + case HWC2_ATTRIBUTE_VSYNC_PERIOD: + vsync_period = value; + break; + case HWC2_ATTRIBUTE_DPI_X: + dpi_x = value; + break; + case HWC2_ATTRIBUTE_DPI_Y: + dpi_y = value; + break; + default: + ALOGW("unknown attribute %u", attribute); + return -EINVAL; + } + + return 0; +} diff --git a/hwc2/hwc2_dev.cpp b/hwc2/hwc2_dev.cpp index 82faaf6..2f69763 100644 --- a/hwc2/hwc2_dev.cpp +++ b/hwc2/hwc2_dev.cpp @@ -16,6 +16,7 @@ #include <fcntl.h> #include <cutils/log.h> +#include <inttypes.h> #include <cstdlib> #include <vector> @@ -76,17 +77,33 @@ int hwc2_dev::open_adf_device() if (displays.empty()) { ALOGE("failed to open any physical displays"); ret = -EINVAL; - goto err_open; + goto err_dpy_open; } ret = adf_hwc_open(intf_fds.data(), intf_fds.size(), &hwc2_adfhwc_callbacks, this, &adf_helper); if (ret < 0) { ALOGE("failed to open adf helper: %s", strerror(ret)); - displays.clear(); + goto err_hwc_open; } -err_open: + for (auto &dpy: displays) { + ret = dpy.second.retrieve_display_configs(adf_helper); + if (ret < 0) { + ALOGE("dpy %" PRIu64 ": failed to retrieve display configs: %s", + dpy.second.get_id(), strerror(ret)); + goto err_rtrv; + } + } + + free(dev_ids); + return 0; + +err_rtrv: + adf_hwc_close(adf_helper); +err_hwc_open: + displays.clear(); +err_dpy_open: free(dev_ids); return ret; } diff --git a/hwc2/hwc2_display.cpp b/hwc2/hwc2_display.cpp index d066773..e25eded 100644 --- a/hwc2/hwc2_display.cpp +++ b/hwc2/hwc2_display.cpp @@ -14,6 +14,12 @@ * limitations under the License. */ +#include <cutils/log.h> +#include <inttypes.h> + +#include <vector> +#include <array> + #include "hwc2.h" uint64_t hwc2_display::display_cnt = 0; @@ -21,6 +27,8 @@ uint64_t hwc2_display::display_cnt = 0; hwc2_display::hwc2_display(hwc2_display_t id, int adf_intf_fd, const struct adf_device &adf_dev) : id(id), + configs(), + active_config(0), adf_intf_fd(adf_intf_fd), adf_dev(adf_dev) { } @@ -30,6 +38,61 @@ hwc2_display::~hwc2_display() adf_device_close(&adf_dev); } +int hwc2_display::retrieve_display_configs(struct adf_hwc_helper *adf_helper) +{ + size_t num_configs = 0; + + int ret = adf_getDisplayConfigs(adf_helper, id, nullptr, &num_configs); + if (ret < 0 || num_configs == 0) { + ALOGE("dpy %" PRIu64 ": failed to get display configs: %s", id, + strerror(ret)); + return ret; + } + + std::vector<uint32_t> config_handles(num_configs); + + ret = adf_getDisplayConfigs(adf_helper, id, config_handles.data(), + &num_configs); + if (ret < 0) { + ALOGE("dpy %" PRIu64 ": failed to get display configs: %s", id, + strerror(ret)); + return ret; + } + + active_config = config_handles[0]; + + std::array<uint32_t, 6> attributes = {{ + HWC2_ATTRIBUTE_WIDTH, + HWC2_ATTRIBUTE_HEIGHT, + HWC2_ATTRIBUTE_VSYNC_PERIOD, + HWC2_ATTRIBUTE_DPI_X, + HWC2_ATTRIBUTE_DPI_Y, + HWC2_ATTRIBUTE_INVALID }}; + std::array<int32_t, 5> values; + + for (auto config_handle: config_handles) { + ret = adf_getDisplayAttributes_v2(adf_helper, id, config_handle, + attributes.data(), values.data()); + if (ret < 0) { + ALOGW("dpy %" PRIu64 ": failed to get display attributes for config" + " %u: %s", id, config_handle, strerror(ret)); + continue; + } + + configs.emplace(config_handle, hwc2_config()); + + for (size_t attr = 0; attr < attributes.size() - 1; attr++) { + ret = configs[config_handle].set_attribute( + static_cast<hwc2_attribute_t>(attributes[attr]), + values[attr]); + if (ret < 0) + ALOGW("dpy %" PRIu64 ": failed to set attribute", id); + } + } + + return ret; +} + hwc2_display_t hwc2_display::get_next_id() { return display_cnt++; |