Merge remote-tracking branch 'aosp/upstream-master' into HEAD
Update aosp/master to upstream master
* aosp/upstream-master:
drm_hwcomposer: Organize files into subdirs
drm_hwcomposer: Add platformmeson for Amlogic SoC support
drm_hwcomposer: Drop modes with DRM_MODE_FLAG_INTERLACE to HWC2
drm_hwcomposer: clean Importer inherited classes
drm_hwcomposer: recalculate vrefresh from clock + resolution
Change-Id: I184e86d31242a536b166fb44ff4fc4de1ae18866
Signed-off-by: John Stultz <john.stultz@linaro.org>
diff --git a/Android.bp b/Android.bp
index 2af4548..5681cb7 100644
--- a/Android.bp
+++ b/Android.bp
@@ -18,7 +18,9 @@
cc_library_static {
name: "libdrmhwc_utils",
- srcs: ["worker.cpp"],
+ srcs: ["utils/worker.cpp"],
+
+ include_dirs: ["external/drm_hwcomposer/include"],
cflags: [
"-Wall",
@@ -45,6 +47,8 @@
"libutils",
],
+ include_dirs: ["external/drm_hwcomposer/include"],
+
static_libs: ["libdrmhwc_utils"],
cflags: [
@@ -64,22 +68,26 @@
name: "drm_hwcomposer",
defaults: ["hwcomposer.drm_defaults"],
srcs: [
- "autolock.cpp",
- "resourcemanager.cpp",
- "drmdevice.cpp",
- "drmconnector.cpp",
- "drmcrtc.cpp",
- "drmdisplaycomposition.cpp",
- "drmdisplaycompositor.cpp",
- "drmencoder.cpp",
- "drmeventlistener.cpp",
"drmhwctwo.cpp",
- "drmmode.cpp",
- "drmplane.cpp",
- "drmproperty.cpp",
- "hwcutils.cpp",
- "platform.cpp",
- "vsyncworker.cpp",
+
+ "compositor/drmdisplaycomposition.cpp",
+ "compositor/drmdisplaycompositor.cpp",
+
+ "drm/drmconnector.cpp",
+ "drm/drmcrtc.cpp",
+ "drm/drmdevice.cpp",
+ "drm/drmencoder.cpp",
+ "drm/drmeventlistener.cpp",
+ "drm/drmmode.cpp",
+ "drm/drmplane.cpp",
+ "drm/drmproperty.cpp",
+ "drm/resourcemanager.cpp",
+ "drm/vsyncworker.cpp",
+
+ "platform/platform.cpp",
+
+ "utils/autolock.cpp",
+ "utils/hwcutils.cpp",
],
}
@@ -87,7 +95,7 @@
name: "hwcomposer.drm",
defaults: ["hwcomposer.drm_defaults"],
whole_static_libs: ["drm_hwcomposer"],
- srcs: ["platformdrmgeneric.cpp"],
+ srcs: ["platform/platformdrmgeneric.cpp"],
cppflags: ["-DUSE_DRM_GENERIC_IMPORTER"],
}
@@ -96,8 +104,8 @@
defaults: ["hwcomposer.drm_defaults"],
whole_static_libs: ["drm_hwcomposer"],
srcs: [
- "platformdrmgeneric.cpp",
- "platformminigbm.cpp",
+ "platform/platformdrmgeneric.cpp",
+ "platform/platformminigbm.cpp",
],
include_dirs: ["external/minigbm/cros_gralloc"],
}
@@ -106,7 +114,16 @@
filegroup {
name: "drm_hwcomposer_platformhisi",
srcs: [
- "platformdrmgeneric.cpp",
- "platformhisi.cpp",
+ "platform/platformdrmgeneric.cpp",
+ "platform/platformhisi.cpp",
+ ],
+}
+
+// Used by hwcomposer.drm_meson
+filegroup {
+ name: "drm_hwcomposer_platformmeson",
+ srcs: [
+ "platform/platformdrmgeneric.cpp",
+ "platform/platformmeson.cpp",
],
}
diff --git a/drmdisplaycomposition.cpp b/compositor/drmdisplaycomposition.cpp
similarity index 100%
rename from drmdisplaycomposition.cpp
rename to compositor/drmdisplaycomposition.cpp
diff --git a/drmdisplaycompositor.cpp b/compositor/drmdisplaycompositor.cpp
similarity index 100%
rename from drmdisplaycompositor.cpp
rename to compositor/drmdisplaycompositor.cpp
diff --git a/drmconnector.cpp b/drm/drmconnector.cpp
similarity index 100%
rename from drmconnector.cpp
rename to drm/drmconnector.cpp
diff --git a/drmcrtc.cpp b/drm/drmcrtc.cpp
similarity index 100%
rename from drmcrtc.cpp
rename to drm/drmcrtc.cpp
diff --git a/drmdevice.cpp b/drm/drmdevice.cpp
similarity index 100%
rename from drmdevice.cpp
rename to drm/drmdevice.cpp
diff --git a/drmencoder.cpp b/drm/drmencoder.cpp
similarity index 100%
rename from drmencoder.cpp
rename to drm/drmencoder.cpp
diff --git a/drmeventlistener.cpp b/drm/drmeventlistener.cpp
similarity index 100%
rename from drmeventlistener.cpp
rename to drm/drmeventlistener.cpp
diff --git a/drmmode.cpp b/drm/drmmode.cpp
similarity index 95%
rename from drmmode.cpp
rename to drm/drmmode.cpp
index 5f2e7c2..c3ab385 100644
--- a/drmmode.cpp
+++ b/drm/drmmode.cpp
@@ -122,8 +122,8 @@
}
float DrmMode::v_refresh() const {
- return v_refresh_ ? v_refresh_ * 1.0f
- : clock_ / (float)(v_total_ * h_total_) * 1000.0f;
+ // Always recalculate refresh to report correct float rate
+ return clock_ / (float)(v_total_ * h_total_) * 1000.0f;
}
uint32_t DrmMode::flags() const {
diff --git a/drmplane.cpp b/drm/drmplane.cpp
similarity index 100%
rename from drmplane.cpp
rename to drm/drmplane.cpp
diff --git a/drmproperty.cpp b/drm/drmproperty.cpp
similarity index 100%
rename from drmproperty.cpp
rename to drm/drmproperty.cpp
diff --git a/resourcemanager.cpp b/drm/resourcemanager.cpp
similarity index 100%
rename from resourcemanager.cpp
rename to drm/resourcemanager.cpp
diff --git a/vsyncworker.cpp b/drm/vsyncworker.cpp
similarity index 100%
rename from vsyncworker.cpp
rename to drm/vsyncworker.cpp
diff --git a/drmhwctwo.cpp b/drmhwctwo.cpp
index 3123b29..b96eb31 100644
--- a/drmhwctwo.cpp
+++ b/drmhwctwo.cpp
@@ -399,17 +399,34 @@
}
}
- auto num_modes = static_cast<uint32_t>(connector_->modes().size());
- if (!configs) {
- *num_configs = num_modes;
- return HWC2::Error::None;
- }
-
uint32_t idx = 0;
for (const DrmMode &mode : connector_->modes()) {
- if (idx >= *num_configs)
+ if (configs && idx >= *num_configs)
break;
- configs[idx++] = mode.id();
+ // Since the upper layers only look at vactive/hactive/refresh, it doesn't
+ // differentiate interlaced from progressive modes. Depending on the order
+ // of modes we return to SF, it could end up choosing a suboptimal
+ // configuration.
+ // To workaround this, don't offer interlaced modes to SF if there is at
+ // least one non-interlaced alternative.
+ //
+ // TODO: Remove this when the Interlaced attribute is in AOSP
+ if (mode.flags() & DRM_MODE_FLAG_INTERLACE) {
+ auto m = std::find_if(connector_->modes().begin(),
+ connector_->modes().end(),
+ [&mode](DrmMode const &m) {
+ return !(m.flags() & DRM_MODE_FLAG_INTERLACE) &&
+ m.h_display() == mode.h_display() &&
+ m.v_display() == mode.v_display();
+ });
+ if (m != connector_->modes().end())
+ continue;
+ }
+ if (configs) {
+ configs[idx++] = mode.id();
+ } else {
+ idx++;
+ }
}
*num_configs = idx;
return HWC2::Error::None;
diff --git a/autofd.h b/include/autofd.h
similarity index 100%
rename from autofd.h
rename to include/autofd.h
diff --git a/autolock.h b/include/autolock.h
similarity index 100%
rename from autolock.h
rename to include/autolock.h
diff --git a/drmconnector.h b/include/drmconnector.h
similarity index 100%
rename from drmconnector.h
rename to include/drmconnector.h
diff --git a/drmcrtc.h b/include/drmcrtc.h
similarity index 100%
rename from drmcrtc.h
rename to include/drmcrtc.h
diff --git a/drmdevice.h b/include/drmdevice.h
similarity index 100%
rename from drmdevice.h
rename to include/drmdevice.h
diff --git a/drmdisplaycomposition.h b/include/drmdisplaycomposition.h
similarity index 100%
rename from drmdisplaycomposition.h
rename to include/drmdisplaycomposition.h
diff --git a/drmdisplaycompositor.h b/include/drmdisplaycompositor.h
similarity index 100%
rename from drmdisplaycompositor.h
rename to include/drmdisplaycompositor.h
diff --git a/drmencoder.h b/include/drmencoder.h
similarity index 100%
rename from drmencoder.h
rename to include/drmencoder.h
diff --git a/drmeventlistener.h b/include/drmeventlistener.h
similarity index 100%
rename from drmeventlistener.h
rename to include/drmeventlistener.h
diff --git a/drmframebuffer.h b/include/drmframebuffer.h
similarity index 100%
rename from drmframebuffer.h
rename to include/drmframebuffer.h
diff --git a/drmhwcgralloc.h b/include/drmhwcgralloc.h
similarity index 100%
rename from drmhwcgralloc.h
rename to include/drmhwcgralloc.h
diff --git a/drmhwcomposer.h b/include/drmhwcomposer.h
similarity index 100%
rename from drmhwcomposer.h
rename to include/drmhwcomposer.h
diff --git a/drmhwctwo.h b/include/drmhwctwo.h
similarity index 100%
rename from drmhwctwo.h
rename to include/drmhwctwo.h
diff --git a/drmmode.h b/include/drmmode.h
similarity index 100%
rename from drmmode.h
rename to include/drmmode.h
diff --git a/drmplane.h b/include/drmplane.h
similarity index 100%
rename from drmplane.h
rename to include/drmplane.h
diff --git a/drmproperty.h b/include/drmproperty.h
similarity index 100%
rename from drmproperty.h
rename to include/drmproperty.h
diff --git a/platform.h b/include/platform.h
similarity index 100%
rename from platform.h
rename to include/platform.h
diff --git a/resourcemanager.h b/include/resourcemanager.h
similarity index 100%
rename from resourcemanager.h
rename to include/resourcemanager.h
diff --git a/vsyncworker.h b/include/vsyncworker.h
similarity index 100%
rename from vsyncworker.h
rename to include/vsyncworker.h
diff --git a/worker.h b/include/worker.h
similarity index 100%
rename from worker.h
rename to include/worker.h
diff --git a/platform.cpp b/platform/platform.cpp
similarity index 100%
rename from platform.cpp
rename to platform/platform.cpp
diff --git a/platformdrmgeneric.cpp b/platform/platformdrmgeneric.cpp
similarity index 97%
rename from platformdrmgeneric.cpp
rename to platform/platformdrmgeneric.cpp
index 503c04a..2fcbe40 100644
--- a/platformdrmgeneric.cpp
+++ b/platform/platformdrmgeneric.cpp
@@ -60,6 +60,10 @@
ALOGE("Failed to open gralloc module");
return ret;
}
+
+ ALOGI("Using %s gralloc module: %s\n", gralloc_->common.name,
+ gralloc_->common.author);
+
return 0;
}
diff --git a/platformdrmgeneric.h b/platform/platformdrmgeneric.h
similarity index 98%
rename from platformdrmgeneric.h
rename to platform/platformdrmgeneric.h
index 233ba55..c6d2be6 100644
--- a/platformdrmgeneric.h
+++ b/platform/platformdrmgeneric.h
@@ -38,9 +38,10 @@
uint32_t ConvertHalFormatToDrm(uint32_t hal_format);
uint32_t DrmFormatToBitsPerPixel(uint32_t drm_format);
- private:
+ protected:
DrmDevice *drm_;
+ private:
const gralloc_module_t *gralloc_;
};
} // namespace android
diff --git a/platformhisi.cpp b/platform/platformhisi.cpp
similarity index 92%
rename from platformhisi.cpp
rename to platform/platformhisi.cpp
index e022010..64b410b 100644
--- a/platformhisi.cpp
+++ b/platform/platformhisi.cpp
@@ -48,28 +48,6 @@
return importer;
}
-HisiImporter::HisiImporter(DrmDevice *drm)
- : DrmGenericImporter(drm), drm_(drm) {
-}
-
-HisiImporter::~HisiImporter() {
-}
-
-int HisiImporter::Init() {
- int ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID,
- (const hw_module_t **)&gralloc_);
- if (ret) {
- ALOGE("Failed to open gralloc module %d", ret);
- return ret;
- }
-
- if (strcasecmp(gralloc_->common.author, "ARM Ltd."))
- ALOGW("Using non-ARM gralloc module: %s/%s\n", gralloc_->common.name,
- gralloc_->common.author);
-
- return 0;
-}
-
#if defined(MALI_GRALLOC_INTFMT_AFBC_BASIC) && \
defined(AFBC_FORMAT_MOD_BLOCK_SIZE_16x16)
uint64_t HisiImporter::ConvertGrallocFormatToDrmModifiers(uint64_t flags,
diff --git a/platformhisi.h b/platform/platformhisi.h
similarity index 89%
rename from platformhisi.h
rename to platform/platformhisi.h
index 14a58b9..9dfea89 100644
--- a/platformhisi.h
+++ b/platform/platformhisi.h
@@ -29,23 +29,15 @@
class HisiImporter : public DrmGenericImporter {
public:
- HisiImporter(DrmDevice *drm);
- ~HisiImporter() override;
-
- int Init();
+ using DrmGenericImporter::DrmGenericImporter;
int ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
-
bool CanImportBuffer(buffer_handle_t handle) override;
private:
uint64_t ConvertGrallocFormatToDrmModifiers(uint64_t flags, bool is_rgb);
bool IsDrmFormatRgb(uint32_t drm_format);
-
- DrmDevice *drm_;
-
- const gralloc_module_t *gralloc_;
};
} // namespace android
diff --git a/platform/platformmeson.cpp b/platform/platformmeson.cpp
new file mode 100644
index 0000000..58ec5c0
--- /dev/null
+++ b/platform/platformmeson.cpp
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+#define LOG_TAG "hwc-platform-meson"
+
+#include "platformmeson.h"
+#include "drmdevice.h"
+#include "platform.h"
+
+#include <drm/drm_fourcc.h>
+#include <stdatomic.h>
+#include <xf86drm.h>
+#include <xf86drmMode.h>
+#include <cinttypes>
+
+#include <hardware/gralloc.h>
+#include <log/log.h>
+#include "gralloc_priv.h"
+
+namespace android {
+
+Importer *Importer::CreateInstance(DrmDevice *drm) {
+ MesonImporter *importer = new MesonImporter(drm);
+ if (!importer)
+ return NULL;
+
+ int ret = importer->Init();
+ if (ret) {
+ ALOGE("Failed to initialize the meson importer %d", ret);
+ delete importer;
+ return NULL;
+ }
+ return importer;
+}
+
+#if defined(MALI_GRALLOC_INTFMT_AFBC_BASIC) && \
+ defined(AFBC_FORMAT_MOD_BLOCK_SIZE_16x16)
+uint64_t MesonImporter::ConvertGrallocFormatToDrmModifiers(uint64_t flags) {
+ uint64_t features = 0UL;
+
+ if (flags & MALI_GRALLOC_INTFMT_AFBC_BASIC)
+ features |= AFBC_FORMAT_MOD_BLOCK_SIZE_16x16;
+
+ if (flags & MALI_GRALLOC_INTFMT_AFBC_SPLITBLK)
+ features |= (AFBC_FORMAT_MOD_SPLIT | AFBC_FORMAT_MOD_SPARSE);
+
+ if (flags & MALI_GRALLOC_INTFMT_AFBC_WIDEBLK)
+ features |= AFBC_FORMAT_MOD_BLOCK_SIZE_32x8;
+
+ if (flags & MALI_GRALLOC_INTFMT_AFBC_TILED_HEADERS)
+ features |= AFBC_FORMAT_MOD_TILED;
+
+ if (features)
+ return DRM_FORMAT_MOD_ARM_AFBC(features | AFBC_FORMAT_MOD_YTR);
+
+ return 0;
+}
+#else
+uint64_t MesonImporter::ConvertGrallocFormatToDrmModifiers(
+ uint64_t /* flags */) {
+ return 0;
+}
+#endif
+
+int MesonImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) {
+ uint64_t modifiers[4] = {0};
+
+ memset(bo, 0, sizeof(hwc_drm_bo_t));
+
+ private_handle_t const *hnd = reinterpret_cast<private_handle_t const *>(
+ handle);
+ if (!hnd)
+ return -EINVAL;
+
+ // We can't import these types of buffers.
+ // These buffers should have been filtered out with CanImportBuffer()
+ if (!(hnd->usage & GRALLOC_USAGE_HW_FB))
+ return -EINVAL;
+
+ uint32_t gem_handle;
+ int ret = drmPrimeFDToHandle(drm_->fd(), hnd->share_fd, &gem_handle);
+ if (ret) {
+ ALOGE("failed to import prime fd %d ret=%d", hnd->share_fd, ret);
+ return ret;
+ }
+
+ int32_t fmt = ConvertHalFormatToDrm(hnd->req_format);
+ if (fmt < 0)
+ return fmt;
+
+ modifiers[0] = ConvertGrallocFormatToDrmModifiers(hnd->internal_format);
+
+ bo->width = hnd->width;
+ bo->height = hnd->height;
+ bo->hal_format = hnd->req_format;
+ bo->format = fmt;
+ bo->usage = hnd->usage;
+ bo->pixel_stride = hnd->stride;
+ bo->pitches[0] = hnd->byte_stride;
+ bo->gem_handles[0] = gem_handle;
+ bo->offsets[0] = 0;
+
+ ret = drmModeAddFB2WithModifiers(drm_->fd(), bo->width, bo->height,
+ bo->format, bo->gem_handles, bo->pitches,
+ bo->offsets, modifiers, &bo->fb_id,
+ modifiers[0] ? DRM_MODE_FB_MODIFIERS : 0);
+
+ if (ret) {
+ ALOGE("could not create drm fb %d", ret);
+ return ret;
+ }
+
+ return ret;
+}
+
+bool MesonImporter::CanImportBuffer(buffer_handle_t handle) {
+ private_handle_t const *hnd = reinterpret_cast<private_handle_t const *>(
+ handle);
+ return hnd && (hnd->usage & GRALLOC_USAGE_HW_FB);
+}
+
+std::unique_ptr<Planner> Planner::CreateInstance(DrmDevice *) {
+ std::unique_ptr<Planner> planner(new Planner);
+ planner->AddStage<PlanStageGreedy>();
+ return planner;
+}
+} // namespace android
diff --git a/platformhisi.h b/platform/platformmeson.h
similarity index 72%
copy from platformhisi.h
copy to platform/platformmeson.h
index 14a58b9..7be7702 100644
--- a/platformhisi.h
+++ b/platform/platformmeson.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2015 The Android Open Source Project
+ * Copyright (C) 2019 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.
@@ -27,25 +27,15 @@
namespace android {
-class HisiImporter : public DrmGenericImporter {
+class MesonImporter : public DrmGenericImporter {
public:
- HisiImporter(DrmDevice *drm);
- ~HisiImporter() override;
-
- int Init();
+ using DrmGenericImporter::DrmGenericImporter;
int ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
-
bool CanImportBuffer(buffer_handle_t handle) override;
private:
- uint64_t ConvertGrallocFormatToDrmModifiers(uint64_t flags, bool is_rgb);
-
- bool IsDrmFormatRgb(uint32_t drm_format);
-
- DrmDevice *drm_;
-
- const gralloc_module_t *gralloc_;
+ uint64_t ConvertGrallocFormatToDrmModifiers(uint64_t flags);
};
} // namespace android
diff --git a/platformminigbm.cpp b/platform/platformminigbm.cpp
similarity index 80%
rename from platformminigbm.cpp
rename to platform/platformminigbm.cpp
index dce1d11..ad0a373 100644
--- a/platformminigbm.cpp
+++ b/platform/platformminigbm.cpp
@@ -45,28 +45,6 @@
return importer;
}
-DrmMinigbmImporter::DrmMinigbmImporter(DrmDevice *drm)
- : DrmGenericImporter(drm), drm_(drm) {
-}
-
-DrmMinigbmImporter::~DrmMinigbmImporter() {
-}
-
-int DrmMinigbmImporter::Init() {
- int ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID,
- (const hw_module_t **)&gralloc_);
- if (ret) {
- ALOGE("Failed to open gralloc module %d", ret);
- return ret;
- }
-
- if (strcasecmp(gralloc_->common.author, "Chrome OS"))
- ALOGW("Using non-minigbm gralloc module: %s/%s\n", gralloc_->common.name,
- gralloc_->common.author);
-
- return 0;
-}
-
int DrmMinigbmImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) {
cros_gralloc_handle *gr_handle = (cros_gralloc_handle *)handle;
if (!gr_handle)
diff --git a/platformminigbm.h b/platform/platformminigbm.h
similarity index 86%
rename from platformminigbm.h
rename to platform/platformminigbm.h
index 25f8404..ff69f14 100644
--- a/platformminigbm.h
+++ b/platform/platformminigbm.h
@@ -27,17 +27,8 @@
class DrmMinigbmImporter : public DrmGenericImporter {
public:
- DrmMinigbmImporter(DrmDevice *drm);
- ~DrmMinigbmImporter() override;
-
- int Init();
-
+ using DrmGenericImporter::DrmGenericImporter;
int ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
-
- private:
- DrmDevice *drm_;
-
- const gralloc_module_t *gralloc_;
};
} // namespace android
diff --git a/tests/Android.bp b/tests/Android.bp
index 058faa0..7e550ff 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -9,5 +9,5 @@
header_libs: ["libhardware_headers"],
static_libs: ["libdrmhwc_utils"],
shared_libs: ["hwcomposer.drm"],
- include_dirs: ["external/drm_hwcomposer"],
+ include_dirs: ["external/drm_hwcomposer/include"],
}
diff --git a/autolock.cpp b/utils/autolock.cpp
similarity index 100%
rename from autolock.cpp
rename to utils/autolock.cpp
diff --git a/hwcutils.cpp b/utils/hwcutils.cpp
similarity index 100%
rename from hwcutils.cpp
rename to utils/hwcutils.cpp
diff --git a/worker.cpp b/utils/worker.cpp
similarity index 100%
rename from worker.cpp
rename to utils/worker.cpp