composer: refactor ComposerResources into shared library
composer@2.x-hal is a header library. Any of the shared
libraries it depends on must also be included by anyone
who includes composer@2.x-hal. This means when we add a new
version of mapper, anyone who uses composer@2.x-hal must
also include the new version of the mapper. Vendors
that depend on composer@2.x-hal are broken every time we
add a new mapper.
This patch refactors ComposerResources into a seperate
shared library. ComposerResources contains all of the
mapper code. composer@2.x-hal will depend on the new
composer@2.x-resource hal. Everyone downstream must
also add the composer@2.x-resource file now. However,
they will not be broken again when we add a new mapper
version.
Bug: 136016160
Test: Compiles and boots
Change-Id: I208a954a941ed65938074cd3efb8a6893a2bc1eb
diff --git a/graphics/composer/2.2/utils/hal/Android.bp b/graphics/composer/2.2/utils/hal/Android.bp
index 10dcae4..f334a11 100644
--- a/graphics/composer/2.2/utils/hal/Android.bp
+++ b/graphics/composer/2.2/utils/hal/Android.bp
@@ -19,9 +19,11 @@
vendor_available: true,
shared_libs: [
"android.hardware.graphics.composer@2.2",
+ "android.hardware.graphics.composer@2.2-resources",
],
export_shared_lib_headers: [
"android.hardware.graphics.composer@2.2",
+ "android.hardware.graphics.composer@2.2-resources",
],
header_libs: [
"android.hardware.graphics.composer@2.2-command-buffer",
diff --git a/graphics/composer/2.2/utils/hal/include/composer-hal/2.2/ComposerClient.h b/graphics/composer/2.2/utils/hal/include/composer-hal/2.2/ComposerClient.h
index c760d0a..512d39d 100644
--- a/graphics/composer/2.2/utils/hal/include/composer-hal/2.2/ComposerClient.h
+++ b/graphics/composer/2.2/utils/hal/include/composer-hal/2.2/ComposerClient.h
@@ -24,7 +24,7 @@
#include <composer-hal/2.1/ComposerClient.h>
#include <composer-hal/2.2/ComposerCommandEngine.h>
#include <composer-hal/2.2/ComposerHal.h>
-#include <composer-hal/2.2/ComposerResources.h>
+#include <composer-resources/2.2/ComposerResources.h>
namespace android {
namespace hardware {
@@ -89,7 +89,7 @@
auto resources = static_cast<ComposerResources*>(mResources.get());
const native_handle_t* readbackBuffer;
- ComposerResources::ReplacedBufferHandle replacedReadbackBuffer;
+ ComposerResources::ReplacedHandle replacedReadbackBuffer(true);
error = resources->getDisplayReadbackBuffer(display, buffer.getNativeHandle(),
&readbackBuffer, &replacedReadbackBuffer);
if (error != Error::NONE) {
diff --git a/graphics/composer/2.2/utils/hal/include/composer-hal/2.2/ComposerCommandEngine.h b/graphics/composer/2.2/utils/hal/include/composer-hal/2.2/ComposerCommandEngine.h
index 97e3a9e..d9f6226 100644
--- a/graphics/composer/2.2/utils/hal/include/composer-hal/2.2/ComposerCommandEngine.h
+++ b/graphics/composer/2.2/utils/hal/include/composer-hal/2.2/ComposerCommandEngine.h
@@ -23,7 +23,7 @@
#include <composer-command-buffer/2.2/ComposerCommandBuffer.h>
#include <composer-hal/2.1/ComposerCommandEngine.h>
#include <composer-hal/2.2/ComposerHal.h>
-#include <composer-hal/2.2/ComposerResources.h>
+#include <composer-resources/2.2/ComposerResources.h>
namespace android {
namespace hardware {
diff --git a/graphics/composer/2.2/utils/hal/include/composer-hal/2.2/ComposerResources.h b/graphics/composer/2.2/utils/hal/include/composer-hal/2.2/ComposerResources.h
deleted file mode 100644
index 85b6651..0000000
--- a/graphics/composer/2.2/utils/hal/include/composer-hal/2.2/ComposerResources.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright 2018 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.
- */
-
-#pragma once
-
-#ifndef LOG_TAG
-#warning "ComposerResources.h included without LOG_TAG"
-#endif
-
-#include <composer-hal/2.1/ComposerResources.h>
-
-namespace android {
-namespace hardware {
-namespace graphics {
-namespace composer {
-namespace V2_2 {
-namespace hal {
-
-using V2_1::hal::ComposerHandleCache;
-using V2_1::hal::ComposerHandleImporter;
-
-class ComposerDisplayResource : public V2_1::hal::ComposerDisplayResource {
- public:
- ComposerDisplayResource(DisplayType type, ComposerHandleImporter& importer,
- uint32_t outputBufferCacheSize)
- : V2_1::hal::ComposerDisplayResource(type, importer, outputBufferCacheSize),
- mReadbackBufferCache(importer, ComposerHandleCache::HandleType::BUFFER, 1) {}
-
- Error getReadbackBuffer(const native_handle_t* inHandle, const native_handle_t** outHandle,
- const native_handle** outReplacedHandle) {
- const uint32_t slot = 0;
- const bool fromCache = false;
- return mReadbackBufferCache.getHandle(slot, fromCache, inHandle, outHandle,
- outReplacedHandle);
- }
-
- protected:
- ComposerHandleCache mReadbackBufferCache;
-};
-
-class ComposerResources : public V2_1::hal::ComposerResources {
- public:
- static std::unique_ptr<ComposerResources> create() {
- auto resources = std::make_unique<ComposerResources>();
- return resources->init() ? std::move(resources) : nullptr;
- }
-
- Error getDisplayReadbackBuffer(Display display, const native_handle_t* rawHandle,
- const native_handle_t** outHandle,
- ReplacedBufferHandle* outReplacedHandle) {
- // import buffer
- const native_handle_t* importedHandle;
- Error error = mImporter.importBuffer(rawHandle, &importedHandle);
- if (error != Error::NONE) {
- return error;
- }
-
- std::lock_guard<std::mutex> lock(mDisplayResourcesMutex);
-
- auto iter = mDisplayResources.find(display);
- if (iter == mDisplayResources.end()) {
- mImporter.freeBuffer(importedHandle);
- return Error::BAD_DISPLAY;
- }
- ComposerDisplayResource& displayResource =
- *static_cast<ComposerDisplayResource*>(iter->second.get());
-
- // update cache
- const native_handle_t* replacedHandle;
- error = displayResource.getReadbackBuffer(importedHandle, outHandle, &replacedHandle);
- if (error != Error::NONE) {
- mImporter.freeBuffer(importedHandle);
- return error;
- }
-
- outReplacedHandle->reset(&mImporter, replacedHandle);
- return Error::NONE;
- }
-
- protected:
- std::unique_ptr<V2_1::hal::ComposerDisplayResource> createDisplayResource(
- ComposerDisplayResource::DisplayType type, uint32_t outputBufferCacheSize) override {
- return std::make_unique<ComposerDisplayResource>(type, mImporter, outputBufferCacheSize);
- }
-};
-
-} // namespace hal
-} // namespace V2_2
-} // namespace composer
-} // namespace graphics
-} // namespace hardware
-} // namespace android