Merge "Remove setGeometryAppliesWithResize"
diff --git a/Android.bp b/Android.bp
index de9ea86..bf4cf5d 100644
--- a/Android.bp
+++ b/Android.bp
@@ -20,3 +20,25 @@
vendor: true,
export_include_dirs: ["include_sensor"],
}
+
+filegroup {
+ name: "framework_native_aidl_binder",
+ srcs: ["aidl/binder/**/*.aidl"],
+ path: "aidl/binder",
+ visibility: ["//frameworks/native"],
+}
+
+filegroup {
+ name: "framework_native_aidl_gui",
+ srcs: ["aidl/gui/**/*.aidl"],
+ path: "aidl/gui",
+ visibility: ["//frameworks/native"],
+}
+
+filegroup {
+ name: "framework_native_aidl",
+ srcs: [
+ ":framework_native_aidl_binder",
+ ":framework_native_aidl_gui",
+ ],
+}
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index a8e6738..b781da3 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -2328,9 +2328,6 @@
// clang-format off
case 'd': do_add_date = true; break;
case 'z': do_zip_file = true; break;
- // o=use_outfile not supported anymore.
- // TODO(b/111441001): Remove when all callers have migrated.
- case 'o': break;
case 's': use_socket = true; break;
case 'S': use_control_socket = true; break;
case 'v': show_header_only = true; break;
diff --git a/cmds/dumpstate/dumpstate.rc b/cmds/dumpstate/dumpstate.rc
index 14937b8..e491a4b 100644
--- a/cmds/dumpstate/dumpstate.rc
+++ b/cmds/dumpstate/dumpstate.rc
@@ -11,8 +11,7 @@
# dumpstatez generates a zipped bugreport but also uses a socket to print the file location once
# it is finished.
-service dumpstatez /system/bin/dumpstate -S -d -z \
- -o /data/user_de/0/com.android.shell/files/bugreports/bugreport
+service dumpstatez /system/bin/dumpstate -S -d -z
socket dumpstate stream 0660 shell log
class main
disabled
diff --git a/cmds/dumpstate/tests/dumpstate_smoke_test.cpp b/cmds/dumpstate/tests/dumpstate_smoke_test.cpp
index 181046a..dbbcdff 100644
--- a/cmds/dumpstate/tests/dumpstate_smoke_test.cpp
+++ b/cmds/dumpstate/tests/dumpstate_smoke_test.cpp
@@ -201,9 +201,7 @@
(char*)"dumpstate",
(char*)"-d",
(char*)"-z",
- (char*)"-B",
- (char*)"-o",
- (char*)dirname(android::base::GetExecutablePath().c_str())
+ (char*)"-B"
};
// clang-format on
sp<DumpstateListener> listener(new DumpstateListener(dup(fileno(stdout)), sections));
diff --git a/cmds/dumpsys/tests/dumpsys_test.cpp b/cmds/dumpsys/tests/dumpsys_test.cpp
index 3ada153..cbac839 100644
--- a/cmds/dumpsys/tests/dumpsys_test.cpp
+++ b/cmds/dumpsys/tests/dumpsys_test.cpp
@@ -53,7 +53,7 @@
MOCK_CONST_METHOD1(checkService, sp<IBinder>(const String16&));
MOCK_METHOD4(addService, status_t(const String16&, const sp<IBinder>&, bool, int));
MOCK_METHOD1(listServices, Vector<String16>(int));
-
+ MOCK_METHOD1(waitForService, sp<IBinder>(const String16&));
protected:
MOCK_METHOD0(onAsBinder, IBinder*());
};
diff --git a/cmds/installd/dexopt.h b/cmds/installd/dexopt.h
index a8c48c5..ef739ba 100644
--- a/cmds/installd/dexopt.h
+++ b/cmds/installd/dexopt.h
@@ -32,15 +32,15 @@
static constexpr int DEX2OAT_FOR_BOOT_IMAGE = 2;
static constexpr int DEX2OAT_FOR_FILTER = 3;
-#define ANDROID_RUNTIME_APEX_BIN "/apex/com.android.runtime/bin"
+#define ANDROID_ART_APEX_BIN "/apex/com.android.art/bin"
// Location of binaries in the Android Runtime APEX.
-static constexpr const char* kDex2oatPath = ANDROID_RUNTIME_APEX_BIN "/dex2oat";
-static constexpr const char* kDex2oatDebugPath = ANDROID_RUNTIME_APEX_BIN "/dex2oatd";
-static constexpr const char* kProfmanPath = ANDROID_RUNTIME_APEX_BIN "/profman";
-static constexpr const char* kProfmanDebugPath = ANDROID_RUNTIME_APEX_BIN "/profmand";
-static constexpr const char* kDexoptanalyzerPath = ANDROID_RUNTIME_APEX_BIN "/dexoptanalyzer";
-static constexpr const char* kDexoptanalyzerDebugPath = ANDROID_RUNTIME_APEX_BIN "/dexoptanalyzerd";
-#undef ANDROID_RUNTIME_APEX_BIN
+static constexpr const char* kDex2oatPath = ANDROID_ART_APEX_BIN "/dex2oat";
+static constexpr const char* kDex2oatDebugPath = ANDROID_ART_APEX_BIN "/dex2oatd";
+static constexpr const char* kProfmanPath = ANDROID_ART_APEX_BIN "/profman";
+static constexpr const char* kProfmanDebugPath = ANDROID_ART_APEX_BIN "/profmand";
+static constexpr const char* kDexoptanalyzerPath = ANDROID_ART_APEX_BIN "/dexoptanalyzer";
+static constexpr const char* kDexoptanalyzerDebugPath = ANDROID_ART_APEX_BIN "/dexoptanalyzerd";
+#undef ANDROID_ART_APEX_BIN
// Clear the reference profile identified by the given profile name.
bool clear_primary_reference_profile(const std::string& pkgname, const std::string& profile_name);
diff --git a/cmds/installd/installd.cpp b/cmds/installd/installd.cpp
index 673ff0d..b5bc28c 100644
--- a/cmds/installd/installd.cpp
+++ b/cmds/installd/installd.cpp
@@ -74,7 +74,7 @@
// Read current filesystem layout version to handle upgrade paths
char version_path[PATH_MAX];
- snprintf(version_path, PATH_MAX, "%s.layout_version", android_data_dir.c_str());
+ snprintf(version_path, PATH_MAX, "%smisc/installd/layout_version", android_data_dir.c_str());
int oldVersion;
if (fs_read_atomic_int(version_path, &oldVersion) == -1) {
diff --git a/cmds/installd/otapreopt_chroot.cpp b/cmds/installd/otapreopt_chroot.cpp
index b4bcd53..3ff9d11 100644
--- a/cmds/installd/otapreopt_chroot.cpp
+++ b/cmds/installd/otapreopt_chroot.cpp
@@ -233,17 +233,17 @@
}
// Try to mount APEX packages in "/apex" in the chroot dir. We need at least
- // the Android Runtime APEX, as it is required by otapreopt to run dex2oat.
+ // the ART APEX, as it is required by otapreopt to run dex2oat.
std::vector<apex::ApexFile> active_packages = ActivateApexPackages();
- // Check that an Android Runtime APEX has been activated; clean up and exit
+ // Check that an ART APEX has been activated; clean up and exit
// early otherwise.
if (std::none_of(active_packages.begin(),
active_packages.end(),
[](const apex::ApexFile& package){
- return package.GetManifest().name() == "com.android.runtime";
+ return package.GetManifest().name() == "com.android.art";
})) {
- LOG(FATAL_WITHOUT_ABORT) << "No activated com.android.runtime APEX package.";
+ LOG(FATAL_WITHOUT_ABORT) << "No activated com.android.art APEX package.";
DeactivateApexPackages(active_packages);
exit(217);
}
diff --git a/cmds/servicemanager/ServiceManager.cpp b/cmds/servicemanager/ServiceManager.cpp
index f35f360..b3aa342 100644
--- a/cmds/servicemanager/ServiceManager.cpp
+++ b/cmds/servicemanager/ServiceManager.cpp
@@ -25,6 +25,20 @@
namespace android {
ServiceManager::ServiceManager(std::unique_ptr<Access>&& access) : mAccess(std::move(access)) {}
+ServiceManager::~ServiceManager() {
+ // this should only happen in tests
+
+ for (const auto& [name, callbacks] : mNameToCallback) {
+ CHECK(!callbacks.empty()) << name;
+ for (const auto& callback : callbacks) {
+ CHECK(callback != nullptr) << name;
+ }
+ }
+
+ for (const auto& [name, service] : mNameToService) {
+ CHECK(service.binder != nullptr) << name;
+ }
+}
Status ServiceManager::getService(const std::string& name, sp<IBinder>* outBinder) {
// Servicemanager is single-threaded and cannot block. This method exists for legacy reasons.
@@ -67,7 +81,7 @@
if (name.size() > 127) return false;
for (char c : name) {
- if (c == '_' || c == '-' || c == '.') continue;
+ if (c == '_' || c == '-' || c == '.' || c == '/') continue;
if (c >= 'a' && c <= 'z') continue;
if (c >= 'A' && c <= 'Z') continue;
if (c >= '0' && c <= '9') continue;
@@ -110,6 +124,14 @@
.dumpPriority = dumpPriority,
};
+ auto it = mNameToCallback.find(name);
+ if (it != mNameToCallback.end()) {
+ for (const sp<IServiceCallback>& cb : it->second) {
+ // permission checked in registerForNotifications
+ cb->onRegistration(name, binder);
+ }
+ }
+
return Status::ok();
}
@@ -139,6 +161,84 @@
return Status::ok();
}
+Status ServiceManager::registerForNotifications(
+ const std::string& name, const sp<IServiceCallback>& callback) {
+ auto ctx = mAccess->getCallingContext();
+
+ if (!mAccess->canFind(ctx, name)) {
+ return Status::fromExceptionCode(Status::EX_SECURITY);
+ }
+
+ if (!isValidServiceName(name)) {
+ LOG(ERROR) << "Invalid service name: " << name;
+ return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT);
+ }
+
+ if (callback == nullptr) {
+ return Status::fromExceptionCode(Status::EX_NULL_POINTER);
+ }
+
+ if (OK != IInterface::asBinder(callback)->linkToDeath(this)) {
+ LOG(ERROR) << "Could not linkToDeath when adding " << name;
+ return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE);
+ }
+
+ mNameToCallback[name].push_back(callback);
+
+ if (auto it = mNameToService.find(name); it != mNameToService.end()) {
+ const sp<IBinder>& binder = it->second.binder;
+
+ // never null if an entry exists
+ CHECK(binder != nullptr) << name;
+ callback->onRegistration(name, binder);
+ }
+
+ return Status::ok();
+}
+Status ServiceManager::unregisterForNotifications(
+ const std::string& name, const sp<IServiceCallback>& callback) {
+ auto ctx = mAccess->getCallingContext();
+
+ if (!mAccess->canFind(ctx, name)) {
+ return Status::fromExceptionCode(Status::EX_SECURITY);
+ }
+
+ bool found = false;
+
+ auto it = mNameToCallback.find(name);
+ if (it != mNameToCallback.end()) {
+ removeCallback(IInterface::asBinder(callback), &it, &found);
+ }
+
+ if (!found) {
+ LOG(ERROR) << "Trying to unregister callback, but none exists " << name;
+ return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE);
+ }
+
+ return Status::ok();
+}
+
+void ServiceManager::removeCallback(const wp<IBinder>& who,
+ CallbackMap::iterator* it,
+ bool* found) {
+ std::vector<sp<IServiceCallback>>& listeners = (*it)->second;
+
+ for (auto lit = listeners.begin(); lit != listeners.end();) {
+ if (IInterface::asBinder(*lit) == who) {
+ if(found) *found = true;
+ lit = listeners.erase(lit);
+ } else {
+ ++lit;
+ }
+ }
+
+ if (listeners.empty()) {
+ *it = mNameToCallback.erase(*it);
+ } else {
+ it++;
+ }
+}
+
void ServiceManager::binderDied(const wp<IBinder>& who) {
for (auto it = mNameToService.begin(); it != mNameToService.end();) {
if (who == it->second.binder) {
@@ -147,6 +247,10 @@
++it;
}
}
+
+ for (auto it = mNameToCallback.begin(); it != mNameToCallback.end();) {
+ removeCallback(who, &it, nullptr /*found*/);
+ }
}
} // namespace android
diff --git a/cmds/servicemanager/ServiceManager.h b/cmds/servicemanager/ServiceManager.h
index 78e4805..fcc5124 100644
--- a/cmds/servicemanager/ServiceManager.h
+++ b/cmds/servicemanager/ServiceManager.h
@@ -17,30 +17,50 @@
#pragma once
#include <android/os/BnServiceManager.h>
+#include <android/os/IServiceCallback.h>
#include "Access.h"
namespace android {
+using os::IServiceCallback;
+
class ServiceManager : public os::BnServiceManager, public IBinder::DeathRecipient {
public:
ServiceManager(std::unique_ptr<Access>&& access);
+ ~ServiceManager();
binder::Status getService(const std::string& name, sp<IBinder>* outBinder) override;
binder::Status checkService(const std::string& name, sp<IBinder>* outBinder) override;
- binder::Status addService(const std::string& name, const sp<IBinder>& binder, bool allowIsolated, int32_t dumpPriority) override;
+ binder::Status addService(const std::string& name, const sp<IBinder>& binder,
+ bool allowIsolated, int32_t dumpPriority) override;
binder::Status listServices(int32_t dumpPriority, std::vector<std::string>* outList) override;
+ binder::Status registerForNotifications(const std::string& name,
+ const sp<IServiceCallback>& callback) override;
+ binder::Status unregisterForNotifications(const std::string& name,
+ const sp<IServiceCallback>& callback) override;
void binderDied(const wp<IBinder>& who) override;
private:
struct Service {
- sp<IBinder> binder;
+ sp<IBinder> binder; // not null
bool allowIsolated;
int32_t dumpPriority;
};
- std::map<std::string, Service> mNameToService;
+ using CallbackMap = std::map<std::string, std::vector<sp<IServiceCallback>>>;
+ using ServiceMap = std::map<std::string, Service>;
+
+ // removes a callback from mNameToCallback, removing it if the vector is empty
+ // this updates iterator to the next location
+ void removeCallback(const wp<IBinder>& who,
+ CallbackMap::iterator* it,
+ bool* found);
+
+ CallbackMap mNameToCallback;
+ ServiceMap mNameToService;
+
std::unique_ptr<Access> mAccess;
};
diff --git a/cmds/servicemanager/test_sm.cpp b/cmds/servicemanager/test_sm.cpp
index 91485e4..3c211d2 100644
--- a/cmds/servicemanager/test_sm.cpp
+++ b/cmds/servicemanager/test_sm.cpp
@@ -14,7 +14,10 @@
* limitations under the License.
*/
+#include <android/os/BnServiceCallback.h>
+#include <binder/Binder.h>
#include <binder/ProcessState.h>
+#include <binder/IServiceManager.h>
#include <cutils/android_filesystem_config.h>
#include <gtest/gtest.h>
#include <gmock/gmock.h>
@@ -24,8 +27,11 @@
using android::sp;
using android::Access;
+using android::BBinder;
using android::IBinder;
using android::ServiceManager;
+using android::binder::Status;
+using android::os::BnServiceCallback;
using android::os::IServiceManager;
using testing::_;
using testing::ElementsAre;
@@ -33,9 +39,14 @@
using testing::Return;
static sp<IBinder> getBinder() {
- // It doesn't matter what remote binder it is, we just need one so that linkToDeath will work.
- // The context manager (servicemanager) is easy to get and is in another process.
- return android::ProcessState::self()->getContextObject(nullptr);
+ class LinkableBinder : public BBinder {
+ android::status_t linkToDeath(const sp<DeathRecipient>&, void*, uint32_t) override {
+ // let SM linkToDeath
+ return android::OK;
+ }
+ };
+
+ return new LinkableBinder;
}
class MockAccess : public Access {
@@ -132,12 +143,14 @@
TEST(GetService, HappyHappy) {
auto sm = getPermissiveServiceManager();
- EXPECT_TRUE(sm->addService("foo", getBinder(), false /*allowIsolated*/,
+ sp<IBinder> service = getBinder();
+
+ EXPECT_TRUE(sm->addService("foo", service, false /*allowIsolated*/,
IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT).isOk());
sp<IBinder> out;
EXPECT_TRUE(sm->getService("foo", &out).isOk());
- EXPECT_EQ(getBinder(), out);
+ EXPECT_EQ(service, out);
}
TEST(GetService, NonExistant) {
@@ -181,12 +194,13 @@
sp<ServiceManager> sm = new ServiceManager(std::move(access));
- EXPECT_TRUE(sm->addService("foo", getBinder(), true /*allowIsolated*/,
+ sp<IBinder> service = getBinder();
+ EXPECT_TRUE(sm->addService("foo", service, true /*allowIsolated*/,
IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT).isOk());
sp<IBinder> out;
EXPECT_TRUE(sm->getService("foo", &out).isOk());
- EXPECT_EQ(getBinder(), out.get());
+ EXPECT_EQ(service, out.get());
}
TEST(GetService, NotAllowedFromIsolated) {
@@ -265,3 +279,145 @@
// all there and in the right order
EXPECT_THAT(out, ElementsAre("sa"));
}
+
+class CallbackHistorian : public BnServiceCallback {
+ Status onRegistration(const std::string& name, const sp<IBinder>& binder) override {
+ registrations.push_back(name);
+ binders.push_back(binder);
+ return Status::ok();
+ }
+
+ android::status_t linkToDeath(const sp<DeathRecipient>&, void*, uint32_t) override {
+ // let SM linkToDeath
+ return android::OK;
+ }
+
+public:
+ std::vector<std::string> registrations;
+ std::vector<sp<IBinder>> binders;
+};
+
+TEST(ServiceNotifications, NoPermissionsRegister) {
+ std::unique_ptr<MockAccess> access = std::make_unique<NiceMock<MockAccess>>();
+
+ EXPECT_CALL(*access, getCallingContext()).WillOnce(Return(Access::CallingContext{}));
+ EXPECT_CALL(*access, canFind(_,_)).WillOnce(Return(false));
+
+ sp<ServiceManager> sm = new ServiceManager(std::move(access));
+
+ sp<CallbackHistorian> cb = new CallbackHistorian;
+
+ EXPECT_EQ(sm->registerForNotifications("foofoo", cb).exceptionCode(),
+ Status::EX_SECURITY);
+}
+
+TEST(ServiceNotifications, NoPermissionsUnregister) {
+ std::unique_ptr<MockAccess> access = std::make_unique<NiceMock<MockAccess>>();
+
+ EXPECT_CALL(*access, getCallingContext()).WillOnce(Return(Access::CallingContext{}));
+ EXPECT_CALL(*access, canFind(_,_)).WillOnce(Return(false));
+
+ sp<ServiceManager> sm = new ServiceManager(std::move(access));
+
+ sp<CallbackHistorian> cb = new CallbackHistorian;
+
+ // should always hit security error first
+ EXPECT_EQ(sm->unregisterForNotifications("foofoo", cb).exceptionCode(),
+ Status::EX_SECURITY);
+}
+
+TEST(ServiceNotifications, InvalidName) {
+ auto sm = getPermissiveServiceManager();
+
+ sp<CallbackHistorian> cb = new CallbackHistorian;
+
+ EXPECT_EQ(sm->registerForNotifications("foo@foo", cb).exceptionCode(),
+ Status::EX_ILLEGAL_ARGUMENT);
+}
+
+TEST(ServiceNotifications, NullCallback) {
+ auto sm = getPermissiveServiceManager();
+
+ EXPECT_EQ(sm->registerForNotifications("foofoo", nullptr).exceptionCode(),
+ Status::EX_NULL_POINTER);
+}
+
+TEST(ServiceNotifications, Unregister) {
+ auto sm = getPermissiveServiceManager();
+
+ sp<CallbackHistorian> cb = new CallbackHistorian;
+
+ EXPECT_TRUE(sm->registerForNotifications("foofoo", cb).isOk());
+ EXPECT_EQ(sm->unregisterForNotifications("foofoo", cb).exceptionCode(), 0);
+}
+
+TEST(ServiceNotifications, UnregisterWhenNoRegistrationExists) {
+ auto sm = getPermissiveServiceManager();
+
+ sp<CallbackHistorian> cb = new CallbackHistorian;
+
+ EXPECT_EQ(sm->unregisterForNotifications("foofoo", cb).exceptionCode(),
+ Status::EX_ILLEGAL_STATE);
+}
+
+TEST(ServiceNotifications, NoNotification) {
+ auto sm = getPermissiveServiceManager();
+
+ sp<CallbackHistorian> cb = new CallbackHistorian;
+
+ EXPECT_TRUE(sm->registerForNotifications("foofoo", cb).isOk());
+ EXPECT_TRUE(sm->addService("otherservice", getBinder(),
+ false /*allowIsolated*/, IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT).isOk());
+
+ EXPECT_THAT(cb->registrations, ElementsAre());
+ EXPECT_THAT(cb->binders, ElementsAre());
+}
+
+TEST(ServiceNotifications, GetNotification) {
+ auto sm = getPermissiveServiceManager();
+
+ sp<CallbackHistorian> cb = new CallbackHistorian;
+
+ sp<IBinder> service = getBinder();
+
+ EXPECT_TRUE(sm->registerForNotifications("asdfasdf", cb).isOk());
+ EXPECT_TRUE(sm->addService("asdfasdf", service,
+ false /*allowIsolated*/, IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT).isOk());
+
+ EXPECT_THAT(cb->registrations, ElementsAre("asdfasdf"));
+ EXPECT_THAT(cb->binders, ElementsAre(service));
+}
+
+TEST(ServiceNotifications, GetNotificationForAlreadyRegisteredService) {
+ auto sm = getPermissiveServiceManager();
+
+ sp<CallbackHistorian> cb = new CallbackHistorian;
+
+ sp<IBinder> service = getBinder();
+
+ EXPECT_TRUE(sm->addService("asdfasdf", service,
+ false /*allowIsolated*/, IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT).isOk());
+
+ EXPECT_TRUE(sm->registerForNotifications("asdfasdf", cb).isOk());
+
+ EXPECT_THAT(cb->registrations, ElementsAre("asdfasdf"));
+ EXPECT_THAT(cb->binders, ElementsAre(service));
+}
+
+TEST(ServiceNotifications, GetMultipleNotification) {
+ auto sm = getPermissiveServiceManager();
+
+ sp<CallbackHistorian> cb = new CallbackHistorian;
+
+ sp<IBinder> binder1 = getBinder();
+ sp<IBinder> binder2 = getBinder();
+
+ EXPECT_TRUE(sm->registerForNotifications("asdfasdf", cb).isOk());
+ EXPECT_TRUE(sm->addService("asdfasdf", binder1,
+ false /*allowIsolated*/, IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT).isOk());
+ EXPECT_TRUE(sm->addService("asdfasdf", binder2,
+ false /*allowIsolated*/, IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT).isOk());
+
+ EXPECT_THAT(cb->registrations, ElementsAre("asdfasdf", "asdfasdf"));
+ EXPECT_THAT(cb->registrations, ElementsAre("asdfasdf", "asdfasdf"));
+}
diff --git a/libs/binder/Android.bp b/libs/binder/Android.bp
index c6ce576..6ece4a2 100644
--- a/libs/binder/Android.bp
+++ b/libs/binder/Android.bp
@@ -38,6 +38,11 @@
},
double_loadable: true,
+ // libbinder does not offer a stable wire protocol.
+ // if a second copy of it is installed, then it may break after security
+ // or dessert updates. Instead, apex users should use libbinder_ndk.
+ no_apex: true,
+
srcs: [
"ActivityManager.cpp",
"AppOpsManager.cpp",
@@ -81,10 +86,8 @@
vendor: {
exclude_srcs: [
"ActivityManager.cpp",
- "AppOpsManager.cpp",
"IActivityManager.cpp",
"IAppOpsCallback.cpp",
- "IAppOpsService.cpp",
"IBatteryStats.cpp",
"IMediaResourceMonitor.cpp",
"IPermissionController.cpp",
@@ -140,6 +143,7 @@
name: "libbinder_aidl",
srcs: [
"aidl/android/content/pm/IPackageManagerNative.aidl",
+ "aidl/android/os/IServiceCallback.aidl",
"aidl/android/os/IServiceManager.aidl",
],
path: "aidl",
diff --git a/libs/binder/AppOpsManager.cpp b/libs/binder/AppOpsManager.cpp
index 525685c..e2af01c 100644
--- a/libs/binder/AppOpsManager.cpp
+++ b/libs/binder/AppOpsManager.cpp
@@ -21,10 +21,18 @@
#include <utils/SystemClock.h>
+#include <sys/types.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "AppOpsManager"
+
namespace android {
namespace {
+#ifndef __ANDROID_VNDK__
#if defined(__BRILLO__)
// Because Brillo has no application model, security policy is managed
// statically (at build time) with SELinux controls.
@@ -33,13 +41,17 @@
#else
const int APP_OPS_MANAGER_UNAVAILABLE_MODE = AppOpsManager::MODE_IGNORED;
#endif // defined(__BRILLO__)
+#endif // __ANDROID_VNDK__
} // namespace
static String16 _appops("appops");
+#ifndef __ANDROID_VNDK__
static pthread_mutex_t gTokenMutex = PTHREAD_MUTEX_INITIALIZER;
+#endif // __ANDROID_VNDK__
static sp<IBinder> gToken;
+#ifndef __ANDROID_VNDK__
static const sp<IBinder>& getToken(const sp<IAppOpsService>& service) {
pthread_mutex_lock(&gTokenMutex);
if (gToken == nullptr || gToken->pingBinder() != NO_ERROR) {
@@ -48,6 +60,17 @@
pthread_mutex_unlock(&gTokenMutex);
return gToken;
}
+#endif // __ANDROID_VNDK__
+
+thread_local uint64_t notedAppOpsInThisBinderTransaction[2];
+thread_local int32_t uidOfThisBinderTransaction = -1;
+
+// Whether an appop should be collected: 0 == not initialized, 1 == don't note, 2 == note
+#ifndef __ANDROID_VNDK__
+uint8_t appOpsToNote[AppOpsManager::_NUM_OP] = {0};
+#else
+uint8_t appOpsToNote[128] = {0};
+#endif // __ANDROID_VNDK__
AppOpsManager::AppOpsManager()
{
@@ -85,6 +108,7 @@
}
#endif // defined(__BRILLO__)
+#ifndef __ANDROID_VNDK__
int32_t AppOpsManager::checkOp(int32_t op, int32_t uid, const String16& callingPackage)
{
sp<IAppOpsService> service = getService();
@@ -102,18 +126,41 @@
}
int32_t AppOpsManager::noteOp(int32_t op, int32_t uid, const String16& callingPackage) {
+ return noteOp(op, uid, callingPackage, String16("noteOp from native code"));
+}
+
+int32_t AppOpsManager::noteOp(int32_t op, int32_t uid, const String16& callingPackage,
+ const String16& message) {
sp<IAppOpsService> service = getService();
- return service != nullptr
+ int32_t mode = service != nullptr
? service->noteOperation(op, uid, callingPackage)
: APP_OPS_MANAGER_UNAVAILABLE_MODE;
+
+ if (mode == AppOpsManager::MODE_ALLOWED) {
+ markAppOpNoted(uid, callingPackage, op, message);
+ }
+
+ return mode;
}
int32_t AppOpsManager::startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage,
bool startIfModeDefault) {
+ return startOpNoThrow(op, uid, callingPackage, startIfModeDefault,
+ String16("startOpNoThrow from native code"));
+}
+
+int32_t AppOpsManager::startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage,
+ bool startIfModeDefault, const String16& message) {
sp<IAppOpsService> service = getService();
- return service != nullptr
+ int32_t mode = service != nullptr
? service->startOperation(getToken(service), op, uid, callingPackage,
startIfModeDefault) : APP_OPS_MANAGER_UNAVAILABLE_MODE;
+
+ if (mode == AppOpsManager::MODE_ALLOWED) {
+ markAppOpNoted(uid, callingPackage, op, message);
+ }
+
+ return mode;
}
void AppOpsManager::finishOp(int32_t op, int32_t uid, const String16& callingPackage) {
@@ -146,5 +193,47 @@
return -1;
}
+void AppOpsManager::setCameraAudioRestriction(int32_t mode) {
+ sp<IAppOpsService> service = getService();
+ if (service != nullptr) {
+ service->setCameraAudioRestriction(mode);
+ }
+}
+
+#endif // __ANDROID_VNDK__
+
+bool AppOpsManager::shouldCollectNotes(int32_t opcode) {
+ sp<IAppOpsService> service = getService();
+ if (service != nullptr) {
+ return service->shouldCollectNotes(opcode);
+ }
+ return false;
+}
+
+void AppOpsManager::markAppOpNoted(int32_t uid, const String16& packageName, int32_t opCode,
+ const String16& message) {
+ // check it the appops needs to be collected and cache result
+ if (appOpsToNote[opCode] == 0) {
+ if (shouldCollectNotes(opCode)) {
+ appOpsToNote[opCode] = 2;
+ } else {
+ appOpsToNote[opCode] = 1;
+ }
+ }
+
+ if (appOpsToNote[opCode] != 2) {
+ return;
+ }
+
+ noteAsyncOp(String16(), uid, packageName, opCode, message);
+}
+
+void AppOpsManager::noteAsyncOp(const String16& callingPackageName, int32_t uid,
+ const String16& packageName, int32_t opCode, const String16& message) {
+ sp<IAppOpsService> service = getService();
+ if (service != nullptr) {
+ return service->noteAsyncOp(callingPackageName, uid, packageName, opCode, message);
+ }
+}
}; // namespace android
diff --git a/libs/binder/IAppOpsService.cpp b/libs/binder/IAppOpsService.cpp
index c426f3a..b6360cb 100644
--- a/libs/binder/IAppOpsService.cpp
+++ b/libs/binder/IAppOpsService.cpp
@@ -34,6 +34,7 @@
{
}
+#ifndef __ANDROID_VNDK__
virtual int32_t checkOperation(int32_t code, int32_t uid, const String16& packageName) {
Parcel data, reply;
data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor());
@@ -111,7 +112,6 @@
return reply.readStrongBinder();
}
-
virtual int32_t permissionToOpCode(const String16& permission) {
Parcel data, reply;
data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor());
@@ -137,6 +137,52 @@
}
return reply.readInt32();
}
+
+ virtual void setCameraAudioRestriction(int32_t mode) {
+ Parcel data, reply;
+ data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor());
+ data.writeInt32(mode);
+ remote()->transact(SET_CAMERA_AUDIO_RESTRICTION_TRANSACTION, data, &reply);
+ }
+
+#endif
+ virtual void noteAsyncOp(const String16& callingPackageName, int32_t uid,
+ const String16& packageName, int32_t opCode, const String16& message) {
+ Parcel data, reply;
+ data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor());
+
+ // Convert empty callingPackage into null string
+ if (callingPackageName.size() != 0) {
+ data.writeString16(callingPackageName);
+ } else {
+ data.writeString16(nullptr, 0);
+ }
+
+ data.writeInt32(uid);
+
+ // Convert empty packageName into null string
+ if (packageName.size() != 0) {
+ data.writeString16(packageName);
+ } else {
+ data.writeString16(nullptr, 0);
+ }
+
+ data.writeInt32(opCode);
+ data.writeString16(message);
+ remote()->transact(NOTE_ASYNC_OP_TRANSACTION, data, &reply);
+ }
+
+ virtual bool shouldCollectNotes(int32_t opCode) {
+ Parcel data, reply;
+ data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor());
+ data.writeInt32(opCode);
+ remote()->transact(SHOULD_COLLECT_NOTES_TRANSACTION, data, &reply);
+ // fail on exception
+ if (reply.readExceptionCode() != 0) {
+ return false;
+ }
+ return reply.readBool();
+ }
};
IMPLEMENT_META_INTERFACE(AppOpsService, "com.android.internal.app.IAppOpsService");
@@ -149,6 +195,7 @@
{
//printf("AppOpsService received: "); data.print();
switch(code) {
+#ifndef __ANDROID_VNDK__
case CHECK_OPERATION_TRANSACTION: {
CHECK_INTERFACE(IAppOpsService, data, reply);
int32_t code = data.readInt32();
@@ -234,6 +281,33 @@
reply->writeInt32(res);
return NO_ERROR;
} break;
+ case SET_CAMERA_AUDIO_RESTRICTION_TRANSACTION: {
+ CHECK_INTERFACE(IAppOpsService, data, reply);
+ const int32_t mode = data.readInt32();
+ setCameraAudioRestriction(mode);
+ reply->writeNoException();
+ return NO_ERROR;
+ } break;
+#endif // __ANDROID_VNDK__
+ case NOTE_ASYNC_OP_TRANSACTION: {
+ CHECK_INTERFACE(IAppOpsService, data, reply);
+ String16 callingPackageName = data.readString16();
+ int32_t uid = data.readInt32();
+ String16 packageName = data.readString16();
+ int32_t opCode = data.readInt32();
+ String16 message = data.readString16();
+ noteAsyncOp(callingPackageName, uid, packageName, opCode, message);
+ reply->writeNoException();
+ return NO_ERROR;
+ } break;
+ case SHOULD_COLLECT_NOTES_TRANSACTION: {
+ CHECK_INTERFACE(IAppOpsService, data, reply);
+ int32_t opCode = data.readInt32();
+ bool shouldCollect = shouldCollectNotes(opCode);
+ reply->writeNoException();
+ reply->writeBool(shouldCollect);
+ return NO_ERROR;
+ } break;
default:
return BBinder::onTransact(code, data, reply, flags);
}
diff --git a/libs/binder/IServiceManager.cpp b/libs/binder/IServiceManager.cpp
index 74f1f47..715a460 100644
--- a/libs/binder/IServiceManager.cpp
+++ b/libs/binder/IServiceManager.cpp
@@ -18,6 +18,7 @@
#include <binder/IServiceManager.h>
+#include <android/os/BnServiceCallback.h>
#include <android/os/IServiceManager.h>
#include <utils/Log.h>
#include <binder/IPCThreadState.h>
@@ -212,6 +213,64 @@
return res;
}
+ sp<IBinder> waitForService(const String16& name16) override {
+ class Waiter : public android::os::BnServiceCallback {
+ Status onRegistration(const std::string& /*name*/,
+ const sp<IBinder>& binder) override {
+ std::unique_lock<std::mutex> lock(mMutex);
+ mBinder = binder;
+ lock.unlock();
+ mCv.notify_one();
+ return Status::ok();
+ }
+ public:
+ sp<IBinder> mBinder;
+ std::mutex mMutex;
+ std::condition_variable mCv;
+ };
+
+ const std::string name = String8(name16).c_str();
+
+ sp<IBinder> out;
+ if(!mTheRealServiceManager->checkService(name, &out).isOk()) {
+ return nullptr;
+ }
+ if(out != nullptr) return out;
+
+ sp<Waiter> waiter = new Waiter;
+ if (!mTheRealServiceManager->registerForNotifications(
+ name, waiter).isOk()) {
+ return nullptr;
+ }
+
+ while(true) {
+ {
+ std::unique_lock<std::mutex> lock(waiter->mMutex);
+ using std::literals::chrono_literals::operator""s;
+ waiter->mCv.wait_for(lock, 1s, [&] {
+ return waiter->mBinder != nullptr;
+ });
+ if (waiter->mBinder != nullptr) return waiter->mBinder;
+ }
+
+ // Handle race condition for lazy services. Here is what can happen:
+ // - the service dies (not processed by init yet).
+ // - sm processes death notification.
+ // - sm gets checkService and calls init to start service.
+ // - init gets the start signal, but the service already appears
+ // started, so it does nothing.
+ // - init gets death signal, but doesn't know it needs to restart
+ // the service
+ // - we need to request service again to get it to start
+ if(!mTheRealServiceManager->checkService(name, &out).isOk()) {
+ return nullptr;
+ }
+ if(out != nullptr) return out;
+
+ ALOGW("Waited one second for %s", name.c_str());
+ }
+ }
+
private:
sp<AidlServiceManager> mTheRealServiceManager;
};
diff --git a/libs/binder/IpPrefix.cpp b/libs/binder/IpPrefix.cpp
index 3a8a63c..8d62266 100644
--- a/libs/binder/IpPrefix.cpp
+++ b/libs/binder/IpPrefix.cpp
@@ -30,7 +30,6 @@
using android::Parcel;
using android::status_t;
using android::UNEXPECTED_NULL;
-using namespace ::android::binder;
namespace android {
diff --git a/libs/binder/aidl/android/os/IServiceCallback.aidl b/libs/binder/aidl/android/os/IServiceCallback.aidl
new file mode 100644
index 0000000..b29dfed
--- /dev/null
+++ b/libs/binder/aidl/android/os/IServiceCallback.aidl
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+
+package android.os;
+
+/**
+ * @hide
+ */
+oneway interface IServiceCallback {
+ /**
+ * Called when a service is registered.
+ *
+ * @param name the service name that has been registered with
+ * @param binder the binder that is registered
+ */
+ void onRegistration(@utf8InCpp String name, IBinder binder);
+}
diff --git a/libs/binder/aidl/android/os/IServiceManager.aidl b/libs/binder/aidl/android/os/IServiceManager.aidl
index 50a72aa..60c2cce 100644
--- a/libs/binder/aidl/android/os/IServiceManager.aidl
+++ b/libs/binder/aidl/android/os/IServiceManager.aidl
@@ -16,6 +16,8 @@
package android.os;
+import android.os.IServiceCallback;
+
/**
* Basic interface for finding and publishing system services.
*
@@ -77,4 +79,14 @@
* Return a list of all currently running services.
*/
@utf8InCpp String[] listServices(int dumpPriority);
+
+ /**
+ * Request a callback when a service is registered.
+ */
+ void registerForNotifications(@utf8InCpp String name, IServiceCallback callback);
+
+ /**
+ * Unregisters all requests for notifications for a specific callback.
+ */
+ void unregisterForNotifications(@utf8InCpp String name, IServiceCallback callback);
}
diff --git a/libs/binder/include/binder/AppOpsManager.h b/libs/binder/include/binder/AppOpsManager.h
index 17493b4..dff4d49 100644
--- a/libs/binder/include/binder/AppOpsManager.h
+++ b/libs/binder/include/binder/AppOpsManager.h
@@ -17,8 +17,6 @@
#ifndef ANDROID_APP_OPS_MANAGER_H
#define ANDROID_APP_OPS_MANAGER_H
-#ifndef __ANDROID_VNDK__
-
#include <binder/IAppOpsService.h>
#include <utils/threads.h>
@@ -35,6 +33,7 @@
MODE_ERRORED = IAppOpsService::MODE_ERRORED
};
+#ifndef __ANDROID_VNDK__
enum {
OP_NONE = -1,
OP_COARSE_LOCATION = 0,
@@ -109,34 +108,60 @@
OP_START_FOREGROUND = 76,
OP_BLUETOOTH_SCAN = 77,
OP_USE_BIOMETRIC = 78,
+ OP_ACTIVITY_RECOGNITION = 79,
+ OP_SMS_FINANCIAL_TRANSACTIONS = 80,
+ OP_READ_MEDIA_AUDIO = 81,
+ OP_WRITE_MEDIA_AUDIO = 82,
+ OP_READ_MEDIA_VIDEO = 83,
+ OP_WRITE_MEDIA_VIDEO = 84,
+ OP_READ_MEDIA_IMAGES = 85,
+ OP_WRITE_MEDIA_IMAGES = 86,
+ OP_LEGACY_STORAGE = 87,
+ OP_ACCESS_ACCESSIBILITY = 88,
+ OP_READ_DEVICE_IDENTIFIERS = 89,
+ _NUM_OP = 90
};
+#endif // __ANDROID_VNDK__
AppOpsManager();
+#ifndef __ANDROID_VNDK__
int32_t checkOp(int32_t op, int32_t uid, const String16& callingPackage);
int32_t checkAudioOpNoThrow(int32_t op, int32_t usage, int32_t uid,
const String16& callingPackage);
+ // @Deprecated, use noteOp(int32_t, int32_t uid, const String16&, const String16&) instead
int32_t noteOp(int32_t op, int32_t uid, const String16& callingPackage);
+ int32_t noteOp(int32_t op, int32_t uid, const String16& callingPackage,
+ const String16& message);
+ // @Deprecated, use startOpNoThrow(int32_t, int32_t, const String16&, bool, const String16&)
+ // instead
int32_t startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage,
bool startIfModeDefault);
+ int32_t startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage,
+ bool startIfModeDefault, const String16& message);
void finishOp(int32_t op, int32_t uid, const String16& callingPackage);
void startWatchingMode(int32_t op, const String16& packageName,
const sp<IAppOpsCallback>& callback);
void stopWatchingMode(const sp<IAppOpsCallback>& callback);
int32_t permissionToOpCode(const String16& permission);
+ void setCameraAudioRestriction(int32_t mode);
+#endif // __ANDROID_VNDK__
+ void noteAsyncOp(const String16& callingPackageName, int32_t uid, const String16& packageName,
+ int32_t opCode, const String16& message);
private:
Mutex mLock;
sp<IAppOpsService> mService;
sp<IAppOpsService> getService();
+ void markAppOpNoted(int32_t uid, const String16& packageName, int32_t opCode,
+ const String16& message);
+ bool shouldCollectNotes(int32_t opCode);
};
}; // namespace android
+
// ---------------------------------------------------------------------------
-#else // __ANDROID_VNDK__
-#error "This header is not visible to vendors"
-#endif // __ANDROID_VNDK__
#endif // ANDROID_APP_OPS_MANAGER_H
diff --git a/libs/binder/include/binder/IAppOpsService.h b/libs/binder/include/binder/IAppOpsService.h
index 3dbd0d9..009ef6c 100644
--- a/libs/binder/include/binder/IAppOpsService.h
+++ b/libs/binder/include/binder/IAppOpsService.h
@@ -19,8 +19,8 @@
#define ANDROID_IAPP_OPS_SERVICE_H
#ifndef __ANDROID_VNDK__
-
#include <binder/IAppOpsCallback.h>
+#endif
#include <binder/IInterface.h>
namespace android {
@@ -32,6 +32,7 @@
public:
DECLARE_META_INTERFACE(AppOpsService)
+#ifndef __ANDROID_VNDK__
virtual int32_t checkOperation(int32_t code, int32_t uid, const String16& packageName) = 0;
virtual int32_t noteOperation(int32_t code, int32_t uid, const String16& packageName) = 0;
virtual int32_t startOperation(const sp<IBinder>& token, int32_t code, int32_t uid,
@@ -45,8 +46,14 @@
virtual int32_t permissionToOpCode(const String16& permission) = 0;
virtual int32_t checkAudioOperation(int32_t code, int32_t usage,int32_t uid,
const String16& packageName) = 0;
+ virtual void setCameraAudioRestriction(int32_t mode) = 0;
+#endif // __ANDROID_VNDK__
+ virtual void noteAsyncOp(const String16& callingPackageName, int32_t uid,
+ const String16& packageName, int32_t opCode, const String16& message) = 0;
+ virtual bool shouldCollectNotes(int32_t opCode) = 0;
enum {
+#ifndef __ANDROID_VNDK__
CHECK_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION,
NOTE_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+1,
START_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+2,
@@ -56,6 +63,13 @@
GET_TOKEN_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+6,
PERMISSION_TO_OP_CODE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+7,
CHECK_AUDIO_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+8,
+#endif // __ANDROID_VNDK__
+ NOTE_ASYNC_OP_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+9,
+ SHOULD_COLLECT_NOTES_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+10,
+#ifndef __ANDROID_VNDK__
+ SET_CAMERA_AUDIO_RESTRICTION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+11,
+#endif // __ANDROID_VNDK__
+
};
enum {
@@ -81,8 +95,4 @@
}; // namespace android
-#else // __ANDROID_VNDK__
-#error "This header is not visible to vendors"
-#endif // __ANDROID_VNDK__
-
#endif // ANDROID_IAPP_OPS_SERVICE_H
diff --git a/libs/binder/include/binder/IServiceManager.h b/libs/binder/include/binder/IServiceManager.h
index 30786fa..8ae860d 100644
--- a/libs/binder/include/binder/IServiceManager.h
+++ b/libs/binder/include/binder/IServiceManager.h
@@ -71,11 +71,24 @@
*/
// NOLINTNEXTLINE(google-default-arguments)
virtual Vector<String16> listServices(int dumpsysFlags = DUMP_FLAG_PRIORITY_ALL) = 0;
+
+ /**
+ * Efficiently wait for a service.
+ *
+ * Returns nullptr only for permission problem or fatal error.
+ */
+ virtual sp<IBinder> waitForService(const String16& name) = 0;
};
sp<IServiceManager> defaultServiceManager();
template<typename INTERFACE>
+sp<INTERFACE> waitForService(const String16& name) {
+ const sp<IServiceManager> sm = defaultServiceManager();
+ return interface_cast<INTERFACE>(sm->waitForService(name));
+}
+
+template<typename INTERFACE>
status_t getService(const String16& name, sp<INTERFACE>* outService)
{
const sp<IServiceManager> sm = defaultServiceManager();
diff --git a/libs/binder/include/binder/Parcel.h b/libs/binder/include/binder/Parcel.h
index f5aafc7..c2f6d55 100644
--- a/libs/binder/include/binder/Parcel.h
+++ b/libs/binder/include/binder/Parcel.h
@@ -45,10 +45,6 @@
class String8;
class TextOutput;
-namespace binder {
-class Value;
-};
-
class Parcel {
friend class IPCThreadState;
public:
diff --git a/libs/binder/ndk/ibinder.cpp b/libs/binder/ndk/ibinder.cpp
index bd6886d..b06ca86 100644
--- a/libs/binder/ndk/ibinder.cpp
+++ b/libs/binder/ndk/ibinder.cpp
@@ -589,3 +589,40 @@
recipient->decStrong(nullptr);
}
+
+binder_status_t AIBinder_getExtension(AIBinder* binder, AIBinder** outExt) {
+ if (binder == nullptr || outExt == nullptr) {
+ if (outExt != nullptr) {
+ *outExt = nullptr;
+ }
+ return STATUS_UNEXPECTED_NULL;
+ }
+
+ sp<IBinder> ext;
+ status_t res = binder->getBinder()->getExtension(&ext);
+
+ if (res != android::OK) {
+ *outExt = nullptr;
+ return PruneStatusT(res);
+ }
+
+ sp<AIBinder> ret = ABpBinder::lookupOrCreateFromBinder(ext);
+ if (ret != nullptr) ret->incStrong(binder);
+
+ *outExt = ret.get();
+ return STATUS_OK;
+}
+
+binder_status_t AIBinder_setExtension(AIBinder* binder, AIBinder* ext) {
+ if (binder == nullptr || ext == nullptr) {
+ return STATUS_UNEXPECTED_NULL;
+ }
+
+ ABBinder* rawBinder = binder->asABBinder();
+ if (rawBinder == nullptr) {
+ return STATUS_INVALID_OPERATION;
+ }
+
+ rawBinder->setExtension(ext->getBinder());
+ return STATUS_OK;
+}
diff --git a/libs/binder/ndk/include_ndk/android/binder_ibinder.h b/libs/binder/ndk/include_ndk/android/binder_ibinder.h
index 80d1254..160739b 100644
--- a/libs/binder/ndk/include_ndk/android/binder_ibinder.h
+++ b/libs/binder/ndk/include_ndk/android/binder_ibinder.h
@@ -510,6 +510,76 @@
void AIBinder_DeathRecipient_delete(AIBinder_DeathRecipient* recipient) __INTRODUCED_IN(29);
#endif //__ANDROID_API__ >= __ANDROID_API_Q__
+
+#if __ANDROID_API__ >= __ANDROID_API_R__
+
+/**
+ * Gets the extension registered with AIBinder_setExtension.
+ *
+ * See AIBinder_setExtension.
+ *
+ * \param binder the object to get the extension of.
+ * \param outExt the returned extension object. Will be null if there is no extension set or
+ * non-null with one strong ref count.
+ *
+ * \return error of getting the interface (may be a transaction error if this is
+ * remote binder). STATUS_UNEXPECTED_NULL if binder is null.
+ */
+binder_status_t AIBinder_getExtension(AIBinder* binder, AIBinder** outExt) __INTRODUCED_IN(30);
+
+/**
+ * Gets the extension of a binder interface. This allows a downstream developer to add
+ * an extension to an interface without modifying its interface file. This should be
+ * called immediately when the object is created before it is passed to another thread.
+ * No thread safety is required.
+ *
+ * For instance, imagine if we have this interface:
+ * interface IFoo { void doFoo(); }
+ *
+ * A). Historical option that has proven to be BAD! Only the original
+ * author of an interface should change an interface. If someone
+ * downstream wants additional functionality, they should not ever
+ * change the interface or use this method.
+ *
+ * BAD TO DO: interface IFoo { BAD TO DO
+ * BAD TO DO: void doFoo(); BAD TO DO
+ * BAD TO DO: + void doBar(); // adding a method BAD TO DO
+ * BAD TO DO: } BAD TO DO
+ *
+ * B). Option that this method enables.
+ * Leave the original interface unchanged (do not change IFoo!).
+ * Instead, create a new interface in a downstream package:
+ *
+ * package com.<name>; // new functionality in a new package
+ * interface IBar { void doBar(); }
+ *
+ * When registering the interface, add:
+ * std::shared_ptr<MyFoo> foo = new MyFoo; // class in AOSP codebase
+ * std::shared_ptr<MyBar> bar = new MyBar; // custom extension class
+ * ... = AIBinder_setExtension(foo->asBinder().get(), bar->asBinder().get());
+ * // handle error
+ *
+ * Then, clients of IFoo can get this extension:
+ * SpAIBinder binder = ...;
+ * std::shared_ptr<IFoo> foo = IFoo::fromBinder(binder); // handle if null
+ * SpAIBinder barBinder;
+ * ... = AIBinder_getExtension(barBinder.get());
+ * // handle error
+ * std::shared_ptr<IBar> bar = IBar::fromBinder(barBinder);
+ * // type is checked with AIBinder_associateClass
+ * // if bar is null, then there is no extension or a different
+ * // type of extension
+ *
+ * \param binder the object to get the extension on. Must be local.
+ * \param ext the extension to set (binder will hold a strong reference to this)
+ *
+ * \return OK on success, STATUS_INVALID_OPERATION if binder is not local, STATUS_UNEXPECTED_NULL
+ * if either binder is null.
+ */
+binder_status_t AIBinder_setExtension(AIBinder* binder, AIBinder* ext) __INTRODUCED_IN(30);
+
+#endif //__ANDROID_API__ >= __ANDROID_API_R__
+
__END_DECLS
/** @} */
diff --git a/libs/binder/ndk/libbinder_ndk.map.txt b/libs/binder/ndk/libbinder_ndk.map.txt
index feedde6..d4d5387 100644
--- a/libs/binder/ndk/libbinder_ndk.map.txt
+++ b/libs/binder/ndk/libbinder_ndk.map.txt
@@ -101,6 +101,9 @@
LIBBINDER_NDK30 { # introduced=30
global:
+ AIBinder_getExtension;
+ AIBinder_setExtension;
+
AIBinder_markSystemStability; # apex
AIBinder_markVendorStability; # vndk
AIBinder_markVintfStability; # apex vndk
diff --git a/libs/gui/BufferQueueConsumer.cpp b/libs/gui/BufferQueueConsumer.cpp
index 528bfb1..3a7cb44 100644
--- a/libs/gui/BufferQueueConsumer.cpp
+++ b/libs/gui/BufferQueueConsumer.cpp
@@ -166,7 +166,9 @@
mCore->mFreeBuffers.push_back(front->mSlot);
}
- listener = mCore->mConnectedProducerListener;
+ if (mCore->mBufferReleasedCbEnabled) {
+ listener = mCore->mConnectedProducerListener;
+ }
++numDroppedBuffers;
}
@@ -457,7 +459,9 @@
mCore->mFreeBuffers.push_back(slot);
}
- listener = mCore->mConnectedProducerListener;
+ if (mCore->mBufferReleasedCbEnabled) {
+ listener = mCore->mConnectedProducerListener;
+ }
BQ_LOGV("releaseBuffer: releasing slot %d", slot);
mCore->mDequeueCondition.notify_all();
@@ -668,7 +672,7 @@
BQ_LOGV("setMaxAcquiredBufferCount: %d", maxAcquiredBuffers);
mCore->mMaxAcquiredBufferCount = maxAcquiredBuffers;
VALIDATE_CONSISTENCY();
- if (delta < 0) {
+ if (delta < 0 && mCore->mBufferReleasedCbEnabled) {
listener = mCore->mConsumerListener;
}
}
diff --git a/libs/gui/BufferQueueCore.cpp b/libs/gui/BufferQueueCore.cpp
index b429d38..d6009d6 100644
--- a/libs/gui/BufferQueueCore.cpp
+++ b/libs/gui/BufferQueueCore.cpp
@@ -65,6 +65,7 @@
mConnectedApi(NO_CONNECTED_API),
mLinkedToDeath(),
mConnectedProducerListener(),
+ mBufferReleasedCbEnabled(false),
mSlots(),
mQueue(),
mFreeSlots(),
@@ -264,6 +265,12 @@
}
void BufferQueueCore::discardFreeBuffersLocked() {
+ // Notify producer about the discarded buffers.
+ if (mConnectedProducerListener != nullptr && mFreeBuffers.size() > 0) {
+ std::vector<int32_t> freeBuffers(mFreeBuffers.begin(), mFreeBuffers.end());
+ mConnectedProducerListener->onBuffersDiscarded(freeBuffers);
+ }
+
for (int s : mFreeBuffers) {
mFreeSlots.insert(s);
clearBufferSlotLocked(s);
diff --git a/libs/gui/BufferQueueProducer.cpp b/libs/gui/BufferQueueProducer.cpp
index d149674..5674674 100644
--- a/libs/gui/BufferQueueProducer.cpp
+++ b/libs/gui/BufferQueueProducer.cpp
@@ -1223,9 +1223,8 @@
}
mCore->mLinkedToDeath = listener;
}
- if (listener->needsReleaseNotify()) {
- mCore->mConnectedProducerListener = listener;
- }
+ mCore->mConnectedProducerListener = listener;
+ mCore->mBufferReleasedCbEnabled = listener->needsReleaseNotify();
}
break;
default:
diff --git a/libs/gui/IProducerListener.cpp b/libs/gui/IProducerListener.cpp
index 936063a..808e336 100644
--- a/libs/gui/IProducerListener.cpp
+++ b/libs/gui/IProducerListener.cpp
@@ -24,6 +24,7 @@
enum {
ON_BUFFER_RELEASED = IBinder::FIRST_CALL_TRANSACTION,
NEEDS_RELEASE_NOTIFY,
+ ON_BUFFERS_DISCARDED,
};
class BpProducerListener : public BpInterface<IProducerListener>
@@ -56,6 +57,13 @@
}
return result;
}
+
+ virtual void onBuffersDiscarded(const std::vector<int>& discardedSlots) {
+ Parcel data, reply;
+ data.writeInterfaceToken(IProducerListener::getInterfaceDescriptor());
+ data.writeInt32Vector(discardedSlots);
+ remote()->transact(ON_BUFFERS_DISCARDED, data, &reply, IBinder::FLAG_ONEWAY);
+ }
};
// Out-of-line virtual method definition to trigger vtable emission in this
@@ -76,6 +84,10 @@
virtual bool needsReleaseNotify() override {
return mBase->needsReleaseNotify();
}
+
+ virtual void onBuffersDiscarded(const std::vector<int32_t>& discardedSlots) override {
+ return mBase->onBuffersDiscarded(discardedSlots);
+ }
};
IMPLEMENT_HYBRID_META_INTERFACE(ProducerListener,
@@ -92,6 +104,17 @@
CHECK_INTERFACE(IProducerListener, data, reply);
reply->writeBool(needsReleaseNotify());
return NO_ERROR;
+ case ON_BUFFERS_DISCARDED: {
+ CHECK_INTERFACE(IProducerListener, data, reply);
+ std::vector<int32_t> discardedSlots;
+ status_t result = data.readInt32Vector(&discardedSlots);
+ if (result != NO_ERROR) {
+ ALOGE("ON_BUFFERS_DISCARDED failed to read discardedSlots: %d", result);
+ return result;
+ }
+ onBuffersDiscarded(discardedSlots);
+ return NO_ERROR;
+ }
}
return BBinder::onTransact(code, data, reply, flags);
}
@@ -104,4 +127,7 @@
return true;
}
+void BnProducerListener::onBuffersDiscarded(const std::vector<int32_t>& /*discardedSlots*/) {
+}
+
} // namespace android
diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp
index 4e6a4e7..7e356e4 100644
--- a/libs/gui/Surface.cpp
+++ b/libs/gui/Surface.cpp
@@ -35,6 +35,7 @@
#include <ui/DisplayStatInfo.h>
#include <ui/Fence.h>
+#include <ui/GraphicBuffer.h>
#include <ui/HdrCapabilities.h>
#include <ui/Region.h>
@@ -1300,6 +1301,14 @@
}
int Surface::connect(
+ int api, bool reportBufferRemoval, const sp<SurfaceListener>& sListener) {
+ if (sListener != nullptr) {
+ mListenerProxy = new ProducerListenerProxy(this, sListener);
+ }
+ return connect(api, mListenerProxy, reportBufferRemoval);
+}
+
+int Surface::connect(
int api, const sp<IProducerListener>& listener, bool reportBufferRemoval) {
ATRACE_CALL();
ALOGV("Surface::connect");
@@ -1354,6 +1363,7 @@
mTransform = 0;
mStickyTransform = 0;
mAutoPrerotation = false;
+ mEnableFrameTimestamps = false;
if (api == NATIVE_WINDOW_API_CPU) {
mConnectedToCpu = false;
@@ -1699,6 +1709,28 @@
}
}
+status_t Surface::getAndFlushBuffersFromSlots(const std::vector<int32_t>& slots,
+ std::vector<sp<GraphicBuffer>>* outBuffers) {
+ ALOGV("Surface::getAndFlushBuffersFromSlots");
+ for (int32_t i : slots) {
+ if (i < 0 || i >= NUM_BUFFER_SLOTS) {
+ ALOGE("%s: Invalid slotIndex: %d", __FUNCTION__, i);
+ return BAD_VALUE;
+ }
+ }
+
+ Mutex::Autolock lock(mMutex);
+ for (int32_t i : slots) {
+ if (mSlots[i].buffer == nullptr) {
+ ALOGW("%s: Discarded slot %d doesn't contain buffer!", __FUNCTION__, i);
+ continue;
+ }
+ outBuffers->push_back(mSlots[i].buffer);
+ mSlots[i].buffer = nullptr;
+ }
+ return OK;
+}
+
void Surface::setSurfaceDamage(android_native_rect_t* rects, size_t numRects) {
ATRACE_CALL();
ALOGV("Surface::setSurfaceDamage");
@@ -1984,4 +2016,22 @@
return err;
}
+void Surface::ProducerListenerProxy::onBuffersDiscarded(const std::vector<int32_t>& slots) {
+ ATRACE_CALL();
+ sp<Surface> parent = mParent.promote();
+ if (parent == nullptr) {
+ return;
+ }
+
+ std::vector<sp<GraphicBuffer>> discardedBufs;
+ status_t res = parent->getAndFlushBuffersFromSlots(slots, &discardedBufs);
+ if (res != OK) {
+ ALOGE("%s: Failed to get buffers from slots: %s(%d)", __FUNCTION__,
+ strerror(-res), res);
+ return;
+ }
+
+ mSurfaceListener->onBuffersDiscarded(discardedBufs);
+}
+
}; // namespace android
diff --git a/libs/gui/TEST_MAPPING b/libs/gui/TEST_MAPPING
new file mode 100644
index 0000000..1c43530
--- /dev/null
+++ b/libs/gui/TEST_MAPPING
@@ -0,0 +1,7 @@
+{
+ "imports": [
+ {
+ "path": "frameworks/native/libs/nativewindow"
+ }
+ ]
+}
diff --git a/libs/gui/include/gui/BufferQueueCore.h b/libs/gui/include/gui/BufferQueueCore.h
index 205e79c..3c96089 100644
--- a/libs/gui/include/gui/BufferQueueCore.h
+++ b/libs/gui/include/gui/BufferQueueCore.h
@@ -189,8 +189,12 @@
sp<IProducerListener> mLinkedToDeath;
// mConnectedProducerListener is used to handle the onBufferReleased
- // notification.
+ // and onBuffersDiscarded notification.
sp<IProducerListener> mConnectedProducerListener;
+ // mBufferReleasedCbEnabled is used to indicate whether onBufferReleased()
+ // callback is registered by the listener. When set to false,
+ // mConnectedProducerListener will not trigger onBufferReleased() callback.
+ bool mBufferReleasedCbEnabled;
// mSlots is an array of buffer slots that must be mirrored on the producer
// side. This allows buffer ownership to be transferred between the producer
diff --git a/libs/gui/include/gui/IProducerListener.h b/libs/gui/include/gui/IProducerListener.h
index a13d8e4..32a3690 100644
--- a/libs/gui/include/gui/IProducerListener.h
+++ b/libs/gui/include/gui/IProducerListener.h
@@ -17,6 +17,8 @@
#ifndef ANDROID_GUI_IPRODUCERLISTENER_H
#define ANDROID_GUI_IPRODUCERLISTENER_H
+#include <vector>
+
#include <android/hardware/graphics/bufferqueue/1.0/IProducerListener.h>
#include <android/hardware/graphics/bufferqueue/2.0/IProducerListener.h>
#include <binder/IInterface.h>
@@ -44,6 +46,9 @@
// multiple threads.
virtual void onBufferReleased() = 0; // Asynchronous
virtual bool needsReleaseNotify() = 0;
+ // onBuffersFreed is called from IGraphicBufferConsumer::discardFreeBuffers
+ // to notify the producer that certain free buffers are discarded by the consumer.
+ virtual void onBuffersDiscarded(const std::vector<int32_t>& slots) = 0; // Asynchronous
};
class IProducerListener : public ProducerListener, public IInterface
@@ -65,6 +70,7 @@
virtual status_t onTransact(uint32_t code, const Parcel& data,
Parcel* reply, uint32_t flags = 0);
virtual bool needsReleaseNotify();
+ virtual void onBuffersDiscarded(const std::vector<int32_t>& slots);
};
class DummyProducerListener : public BnProducerListener
diff --git a/libs/gui/include/gui/Surface.h b/libs/gui/include/gui/Surface.h
index fe528b3..28f5a26 100644
--- a/libs/gui/include/gui/Surface.h
+++ b/libs/gui/include/gui/Surface.h
@@ -20,6 +20,7 @@
#include <gui/BufferQueueDefs.h>
#include <gui/HdrMetadata.h>
#include <gui/IGraphicBufferProducer.h>
+#include <gui/IProducerListener.h>
#include <ui/ANativeObjectBase.h>
#include <ui/GraphicTypes.h>
@@ -35,6 +36,21 @@
class ISurfaceComposer;
+/* This is the same as ProducerListener except that onBuffersDiscarded is
+ * called with a vector of graphic buffers instead of buffer slots.
+ */
+class SurfaceListener : public virtual RefBase
+{
+public:
+ SurfaceListener() = default;
+ virtual ~SurfaceListener() = default;
+
+ virtual void onBufferReleased() = 0;
+ virtual bool needsReleaseNotify() = 0;
+
+ virtual void onBuffersDiscarded(const std::vector<sp<GraphicBuffer>>& buffers) = 0;
+};
+
/*
* An implementation of ANativeWindow that feeds graphics buffers into a
* BufferQueue.
@@ -285,6 +301,10 @@
sp<Fence>* outFence);
virtual int attachBuffer(ANativeWindowBuffer*);
+ virtual int connect(
+ int api, bool reportBufferRemoval,
+ const sp<SurfaceListener>& sListener);
+
// When client connects to Surface with reportBufferRemoval set to true, any buffers removed
// from this Surface will be collected and returned here. Once this method returns, these
// buffers will no longer be referenced by this Surface unless they are attached to this
@@ -301,6 +321,26 @@
enum { NUM_BUFFER_SLOTS = BufferQueueDefs::NUM_BUFFER_SLOTS };
enum { DEFAULT_FORMAT = PIXEL_FORMAT_RGBA_8888 };
+ class ProducerListenerProxy : public BnProducerListener {
+ public:
+ ProducerListenerProxy(wp<Surface> parent, sp<SurfaceListener> listener)
+ : mParent(parent), mSurfaceListener(listener) {}
+ virtual ~ProducerListenerProxy() {}
+
+ virtual void onBufferReleased() {
+ mSurfaceListener->onBufferReleased();
+ }
+
+ virtual bool needsReleaseNotify() {
+ return mSurfaceListener->needsReleaseNotify();
+ }
+
+ virtual void onBuffersDiscarded(const std::vector<int32_t>& slots);
+ private:
+ wp<Surface> mParent;
+ sp<SurfaceListener> mSurfaceListener;
+ };
+
void querySupportedTimestampsLocked() const;
void freeAllBuffers();
@@ -470,6 +510,10 @@
bool mReportRemovedBuffers = false;
std::vector<sp<GraphicBuffer>> mRemovedBuffers;
int mMaxBufferCount;
+
+ sp<IProducerListener> mListenerProxy;
+ status_t getAndFlushBuffersFromSlots(const std::vector<int32_t>& slots,
+ std::vector<sp<GraphicBuffer>>* outBuffers);
};
} // namespace android
diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h
index d65e679..8a6920c 100644
--- a/libs/gui/include/gui/SurfaceComposerClient.h
+++ b/libs/gui/include/gui/SurfaceComposerClient.h
@@ -290,7 +290,7 @@
std::unordered_set<sp<SurfaceControl>, SCHash> surfaceControls;
};
- class Transaction : Parcelable {
+ class Transaction : public Parcelable {
std::unordered_map<sp<IBinder>, ComposerState, IBinderHash> mComposerStates;
SortedVector<DisplayState > mDisplayStates;
std::unordered_map<sp<ITransactionCompletedListener>, CallbackInfo, TCLHash>
diff --git a/libs/gui/tests/BufferQueue_test.cpp b/libs/gui/tests/BufferQueue_test.cpp
index 98dc1e6..6d7b6bb 100644
--- a/libs/gui/tests/BufferQueue_test.cpp
+++ b/libs/gui/tests/BufferQueue_test.cpp
@@ -1010,12 +1010,31 @@
ASSERT_EQ(true, thirdSegment.usedThirdBuffer);
}
+struct BufferDiscardedListener : public BnProducerListener {
+public:
+ BufferDiscardedListener() = default;
+ virtual ~BufferDiscardedListener() = default;
+
+ virtual void onBufferReleased() {}
+ virtual bool needsReleaseNotify() { return false; }
+ virtual void onBuffersDiscarded(const std::vector<int32_t>& slots) {
+ mDiscardedSlots.insert(mDiscardedSlots.end(), slots.begin(), slots.end());
+ }
+
+ const std::vector<int32_t>& getDiscardedSlots() const { return mDiscardedSlots; }
+private:
+ // No need to use lock given the test triggers the listener in the same
+ // thread context.
+ std::vector<int32_t> mDiscardedSlots;
+};
+
TEST_F(BufferQueueTest, TestDiscardFreeBuffers) {
createBufferQueue();
sp<DummyConsumer> dc(new DummyConsumer);
ASSERT_EQ(OK, mConsumer->consumerConnect(dc, false));
IGraphicBufferProducer::QueueBufferOutput output;
- ASSERT_EQ(OK, mProducer->connect(new DummyProducerListener,
+ sp<BufferDiscardedListener> pl(new BufferDiscardedListener);
+ ASSERT_EQ(OK, mProducer->connect(pl,
NATIVE_WINDOW_API_CPU, false, &output));
int slot = BufferQueue::INVALID_BUFFER_SLOT;
@@ -1056,12 +1075,19 @@
ASSERT_EQ(OK, mConsumer->acquireBuffer(&item, 0));
ASSERT_EQ(OK, mConsumer->releaseBuffer(item.mSlot, item.mFrameNumber,
EGL_NO_DISPLAY, EGL_NO_SYNC_KHR, Fence::NO_FENCE));
+ int releasedSlot = item.mSlot;
+
// Acquire 1 buffer, leaving 1 filled buffer in queue
ASSERT_EQ(OK, mConsumer->acquireBuffer(&item, 0));
// Now discard the free buffers
ASSERT_EQ(OK, mConsumer->discardFreeBuffers());
+ // Check onBuffersDiscarded is called with correct slots
+ auto buffersDiscarded = pl->getDiscardedSlots();
+ ASSERT_EQ(buffersDiscarded.size(), 1);
+ ASSERT_EQ(buffersDiscarded[0], releasedSlot);
+
// Check no free buffers in dump
String8 dumpString;
mConsumer->dumpState(String8{}, &dumpString);
diff --git a/libs/gui/tests/Surface_test.cpp b/libs/gui/tests/Surface_test.cpp
index 7718bc1..5a121d7 100644
--- a/libs/gui/tests/Surface_test.cpp
+++ b/libs/gui/tests/Surface_test.cpp
@@ -57,6 +57,37 @@
static constexpr uint64_t NO_FRAME_INDEX = std::numeric_limits<uint64_t>::max();
+class DummySurfaceListener : public SurfaceListener {
+public:
+ DummySurfaceListener(bool enableReleasedCb = false) :
+ mEnableReleaseCb(enableReleasedCb),
+ mBuffersReleased(0) {}
+ virtual ~DummySurfaceListener() = default;
+
+ virtual void onBufferReleased() {
+ mBuffersReleased++;
+ }
+ virtual bool needsReleaseNotify() {
+ return mEnableReleaseCb;
+ }
+ virtual void onBuffersDiscarded(const std::vector<sp<GraphicBuffer>>& buffers) {
+ mDiscardedBuffers.insert(mDiscardedBuffers.end(), buffers.begin(), buffers.end());
+ }
+
+ int getReleaseNotifyCount() const {
+ return mBuffersReleased;
+ }
+ const std::vector<sp<GraphicBuffer>>& getDiscardedBuffers() const {
+ return mDiscardedBuffers;
+ }
+private:
+ // No need to use lock given the test triggers the listener in the same
+ // thread context.
+ bool mEnableReleaseCb;
+ int32_t mBuffersReleased;
+ std::vector<sp<GraphicBuffer>> mDiscardedBuffers;
+};
+
class SurfaceTest : public ::testing::Test {
protected:
SurfaceTest() {
@@ -88,6 +119,86 @@
mComposerClient->dispose();
}
+ void testSurfaceListener(bool hasSurfaceListener, bool enableReleasedCb,
+ int32_t extraDiscardedBuffers) {
+ sp<IGraphicBufferProducer> producer;
+ sp<IGraphicBufferConsumer> consumer;
+ BufferQueue::createBufferQueue(&producer, &consumer);
+
+ sp<DummyConsumer> dummyConsumer(new DummyConsumer);
+ consumer->consumerConnect(dummyConsumer, false);
+ consumer->setConsumerName(String8("TestConsumer"));
+
+ sp<Surface> surface = new Surface(producer);
+ sp<ANativeWindow> window(surface);
+ sp<DummySurfaceListener> listener;
+ if (hasSurfaceListener) {
+ listener = new DummySurfaceListener(enableReleasedCb);
+ }
+ ASSERT_EQ(OK, surface->connect(
+ NATIVE_WINDOW_API_CPU,
+ /*reportBufferRemoval*/true,
+ /*listener*/listener));
+ const int BUFFER_COUNT = 4 + extraDiscardedBuffers;
+ ASSERT_EQ(NO_ERROR, native_window_set_buffer_count(window.get(), BUFFER_COUNT));
+
+ ANativeWindowBuffer* buffers[BUFFER_COUNT];
+ // Dequeue first to allocate a number of buffers
+ for (int i = 0; i < BUFFER_COUNT; i++) {
+ ASSERT_EQ(NO_ERROR, native_window_dequeue_buffer_and_wait(window.get(), &buffers[i]));
+ }
+ for (int i = 0; i < BUFFER_COUNT; i++) {
+ ASSERT_EQ(NO_ERROR, window->cancelBuffer(window.get(), buffers[i], -1));
+ }
+
+ ANativeWindowBuffer* buffer;
+ // Fill BUFFER_COUNT-1 buffers
+ for (int i = 0; i < BUFFER_COUNT-1; i++) {
+ ASSERT_EQ(NO_ERROR, native_window_dequeue_buffer_and_wait(window.get(), &buffer));
+ ASSERT_EQ(NO_ERROR, window->queueBuffer(window.get(), buffer, -1));
+ }
+
+ // Dequeue 1 buffer
+ ASSERT_EQ(NO_ERROR, native_window_dequeue_buffer_and_wait(window.get(), &buffer));
+
+ // Acquire and free 1+extraDiscardedBuffers buffer, check onBufferReleased is called.
+ std::vector<BufferItem> releasedItems;
+ releasedItems.resize(1+extraDiscardedBuffers);
+ for (int i = 0; i < releasedItems.size(); i++) {
+ ASSERT_EQ(NO_ERROR, consumer->acquireBuffer(&releasedItems[i], 0));
+ ASSERT_EQ(NO_ERROR, consumer->releaseBuffer(releasedItems[i].mSlot,
+ releasedItems[i].mFrameNumber, EGL_NO_DISPLAY, EGL_NO_SYNC_KHR,
+ Fence::NO_FENCE));
+ }
+ int32_t expectedReleaseCb = (enableReleasedCb ? releasedItems.size() : 0);
+ if (hasSurfaceListener) {
+ ASSERT_EQ(expectedReleaseCb, listener->getReleaseNotifyCount());
+ }
+
+ // Acquire 1 buffer, leaving 1+extraDiscardedBuffers filled buffer in queue
+ BufferItem item;
+ ASSERT_EQ(NO_ERROR, consumer->acquireBuffer(&item, 0));
+
+ // Discard free buffers
+ ASSERT_EQ(NO_ERROR, consumer->discardFreeBuffers());
+
+ if (hasSurfaceListener) {
+ ASSERT_EQ(expectedReleaseCb, listener->getReleaseNotifyCount());
+
+ // Check onBufferDiscarded is called with correct buffer
+ auto discardedBuffers = listener->getDiscardedBuffers();
+ ASSERT_EQ(discardedBuffers.size(), releasedItems.size());
+ for (int i = 0; i < releasedItems.size(); i++) {
+ ASSERT_EQ(discardedBuffers[i], releasedItems[i].mGraphicBuffer);
+ }
+
+ ASSERT_EQ(expectedReleaseCb, listener->getReleaseNotifyCount());
+ }
+
+ // Disconnect the surface
+ ASSERT_EQ(NO_ERROR, surface->disconnect(NATIVE_WINDOW_API_CPU));
+ }
+
sp<Surface> mSurface;
sp<SurfaceComposerClient> mComposerClient;
sp<SurfaceControl> mSurfaceControl;
@@ -480,6 +591,21 @@
ASSERT_LE(removedBuffers.size(), 1u);
}
+TEST_F(SurfaceTest, SurfaceListenerTest) {
+ // Test discarding 1 free buffers with no listener
+ testSurfaceListener(/*hasListener*/false, /*enableReleaseCb*/false, /*extraDiscardedBuffers*/0);
+ // Test discarding 2 free buffers with no listener
+ testSurfaceListener(/*hasListener*/false, /*enableReleaseCb*/false, /*extraDiscardedBuffers*/1);
+ // Test discarding 1 free buffers with a listener, disabling onBufferReleased
+ testSurfaceListener(/*hasListener*/true, /*enableReleasedCb*/false, /*extraDiscardedBuffers*/0);
+ // Test discarding 2 free buffers with a listener, disabling onBufferReleased
+ testSurfaceListener(/*hasListener*/true, /*enableReleasedCb*/false, /*extraDiscardedBuffers*/1);
+ // Test discarding 1 free buffers with a listener, enabling onBufferReleased
+ testSurfaceListener(/*hasListener*/true, /*enableReleasedCb*/true, /*extraDiscardedBuffers*/0);
+ // Test discarding 3 free buffers with a listener, enabling onBufferReleased
+ testSurfaceListener(/*hasListener*/true, /*enableReleasedCb*/true, /*extraDiscardedBuffers*/2);
+}
+
TEST_F(SurfaceTest, TestGetLastDequeueStartTime) {
sp<ANativeWindow> anw(mSurface);
ASSERT_EQ(NO_ERROR, native_window_api_connect(anw.get(), NATIVE_WINDOW_API_CPU));
diff --git a/libs/nativewindow/ANativeWindow.cpp b/libs/nativewindow/ANativeWindow.cpp
index 1751443..4c59e6c 100644
--- a/libs/nativewindow/ANativeWindow.cpp
+++ b/libs/nativewindow/ANativeWindow.cpp
@@ -266,3 +266,11 @@
int ANativeWindow_setAutoPrerotation(ANativeWindow* window, bool autoPrerotation) {
return native_window_set_auto_prerotation(window, autoPrerotation);
}
+
+/**************************************************************************************************
+ * apex-stable
+ **************************************************************************************************/
+
+int ANativeWindow_getLastDequeueDuration(ANativeWindow* window) {
+ return query(window, NATIVE_WINDOW_LAST_DEQUEUE_DURATION);
+}
diff --git a/libs/nativewindow/TEST_MAPPING b/libs/nativewindow/TEST_MAPPING
new file mode 100644
index 0000000..3d7f3c2
--- /dev/null
+++ b/libs/nativewindow/TEST_MAPPING
@@ -0,0 +1,7 @@
+{
+ "presubmit": [
+ {
+ "name": "libnativewindow_test"
+ }
+ ]
+}
diff --git a/libs/nativewindow/include/apex/window.h b/libs/nativewindow/include/apex/window.h
new file mode 100644
index 0000000..0260cbc
--- /dev/null
+++ b/libs/nativewindow/include/apex/window.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright 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.
+ */
+
+#pragma once
+
+#include <nativebase/nativebase.h>
+
+// apex is a superset of the NDK
+#include <android/native_window.h>
+
+__BEGIN_DECLS
+
+/**
+ * Retrieves how long it took for the last time a buffer was dequeued.
+ *
+ * \return a negative value on error, otherwise returns the duration in
+ * microseconds.
+ */
+int ANativeWindow_getLastDequeueDuration(ANativeWindow* window);
+
+__END_DECLS
diff --git a/libs/nativewindow/include/system/window.h b/libs/nativewindow/include/system/window.h
index 8cbf0a4..78354bb 100644
--- a/libs/nativewindow/include/system/window.h
+++ b/libs/nativewindow/include/system/window.h
@@ -41,7 +41,8 @@
#include <unistd.h>
#include <stdbool.h>
-// system/window.h is a superset of the vndk
+// system/window.h is a superset of the vndk and apex apis
+#include <apex/window.h>
#include <vndk/window.h>
diff --git a/libs/nativewindow/libnativewindow.map.txt b/libs/nativewindow/libnativewindow.map.txt
index 119a07d..7fe4df0 100644
--- a/libs/nativewindow/libnativewindow.map.txt
+++ b/libs/nativewindow/libnativewindow.map.txt
@@ -22,6 +22,7 @@
ANativeWindow_getBuffersDataSpace; # introduced=28
ANativeWindow_getFormat;
ANativeWindow_getHeight;
+ ANativeWindow_getLastDequeueDuration; # apex # introduced=30
ANativeWindow_getWidth;
ANativeWindow_lock;
ANativeWindow_query; # vndk
diff --git a/libs/nativewindow/tests/ANativeWindowTest.cpp b/libs/nativewindow/tests/ANativeWindowTest.cpp
new file mode 100644
index 0000000..5247e04
--- /dev/null
+++ b/libs/nativewindow/tests/ANativeWindowTest.cpp
@@ -0,0 +1,84 @@
+/*
+ * Copyright 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 "ANativeWindow_test"
+//#define LOG_NDEBUG 0
+
+#include <gtest/gtest.h>
+#include <gui/BufferItemConsumer.h>
+#include <gui/BufferQueue.h>
+#include <gui/Surface.h>
+#include <log/log.h>
+#include <sync/sync.h>
+// We need to use the private system apis since not everything is visible to
+// apexes yet.
+#include <system/window.h>
+
+using namespace android;
+
+class TestableSurface final : public Surface {
+public:
+ explicit TestableSurface(const sp<IGraphicBufferProducer>& bufferProducer)
+ : Surface(bufferProducer) {}
+
+ // Exposes the internal last dequeue duration that's stored on the Surface.
+ nsecs_t getLastDequeueDuration() const { return mLastDequeueDuration; }
+};
+
+class ANativeWindowTest : public ::testing::Test {
+protected:
+ void SetUp() override {
+ const ::testing::TestInfo* const test_info =
+ ::testing::UnitTest::GetInstance()->current_test_info();
+ ALOGV("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
+ BufferQueue::createBufferQueue(&mProducer, &mConsumer);
+ mItemConsumer = new BufferItemConsumer(mConsumer, GRALLOC_USAGE_SW_READ_OFTEN);
+ mWindow = new TestableSurface(mProducer);
+ const int success = native_window_api_connect(mWindow.get(), NATIVE_WINDOW_API_CPU);
+ EXPECT_EQ(0, success);
+ }
+
+ void TearDown() override {
+ const ::testing::TestInfo* const test_info =
+ ::testing::UnitTest::GetInstance()->current_test_info();
+ ALOGV("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
+ const int success = native_window_api_disconnect(mWindow.get(), NATIVE_WINDOW_API_CPU);
+ EXPECT_EQ(0, success);
+ }
+ sp<IGraphicBufferProducer> mProducer;
+ sp<IGraphicBufferConsumer> mConsumer;
+ sp<BufferItemConsumer> mItemConsumer;
+
+ sp<TestableSurface> mWindow;
+};
+
+TEST_F(ANativeWindowTest, getLastDequeueDuration_noDequeue_returnsZero) {
+ int result = ANativeWindow_getLastDequeueDuration(mWindow.get());
+ EXPECT_EQ(0, result);
+ EXPECT_EQ(0, mWindow->getLastDequeueDuration() / 1000);
+}
+
+TEST_F(ANativeWindowTest, getLastDequeueDuration_withDequeue_returnsTime) {
+ ANativeWindowBuffer* buffer;
+ int fd;
+ int result = ANativeWindow_dequeueBuffer(mWindow.get(), &buffer, &fd);
+ close(fd);
+ EXPECT_EQ(0, result);
+
+ result = ANativeWindow_getLastDequeueDuration(mWindow.get());
+ EXPECT_GT(result, 0);
+ EXPECT_EQ(result, mWindow->getLastDequeueDuration() / 1000);
+}
diff --git a/libs/nativewindow/tests/Android.bp b/libs/nativewindow/tests/Android.bp
index 20071be..cdb3d20 100644
--- a/libs/nativewindow/tests/Android.bp
+++ b/libs/nativewindow/tests/Android.bp
@@ -15,13 +15,22 @@
//
cc_test {
- name: "AHardwareBufferTest",
+ name: "libnativewindow_test",
+ test_suites: [
+ "device-tests",
+ ],
shared_libs: [
+ "libgui",
+ "liblog",
"libnativewindow",
+ "libsync",
+ "libutils",
"android.hardware.graphics.common@1.0",
],
srcs: [
"AHardwareBufferTest.cpp",
- "c_compatibility.c"],
+ "ANativeWindowTest.cpp",
+ "c_compatibility.c",
+ ],
cflags: ["-Wall", "-Werror"],
}
diff --git a/libs/nativewindow/tests/c_compatibility.c b/libs/nativewindow/tests/c_compatibility.c
index befd88f..aa9b4f7 100644
--- a/libs/nativewindow/tests/c_compatibility.c
+++ b/libs/nativewindow/tests/c_compatibility.c
@@ -16,6 +16,7 @@
#include <android/hardware_buffer.h>
#include <android/native_window.h>
+#include <apex/window.h>
#include <vndk/hardware_buffer.h>
#include <vndk/window.h>
diff --git a/libs/ui/Android.bp b/libs/ui/Android.bp
index 2bbb0ee..8462fe7 100644
--- a/libs/ui/Android.bp
+++ b/libs/ui/Android.bp
@@ -65,6 +65,7 @@
"Gralloc.cpp",
"Gralloc2.cpp",
"Gralloc3.cpp",
+ "Gralloc4.cpp",
"GraphicBuffer.cpp",
"GraphicBufferAllocator.cpp",
"GraphicBufferMapper.cpp",
@@ -89,10 +90,12 @@
"android.frameworks.bufferhub@1.0",
"android.hardware.graphics.allocator@2.0",
"android.hardware.graphics.allocator@3.0",
+ "android.hardware.graphics.allocator@4.0",
"android.hardware.graphics.common@1.2",
"android.hardware.graphics.mapper@2.0",
"android.hardware.graphics.mapper@2.1",
"android.hardware.graphics.mapper@3.0",
+ "android.hardware.graphics.mapper@4.0",
"libbase",
"libcutils",
"libhidlbase",
diff --git a/libs/ui/Gralloc4.cpp b/libs/ui/Gralloc4.cpp
new file mode 100644
index 0000000..dc105c0
--- /dev/null
+++ b/libs/ui/Gralloc4.cpp
@@ -0,0 +1,405 @@
+/*
+ * Copyright 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 "Gralloc4"
+
+#include <hidl/ServiceManagement.h>
+#include <hwbinder/IPCThreadState.h>
+#include <ui/Gralloc4.h>
+
+#include <inttypes.h>
+#include <log/log.h>
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wzero-length-array"
+#include <sync/sync.h>
+#pragma clang diagnostic pop
+
+using android::hardware::graphics::allocator::V4_0::IAllocator;
+using android::hardware::graphics::common::V1_2::BufferUsage;
+using android::hardware::graphics::mapper::V4_0::BufferDescriptor;
+using android::hardware::graphics::mapper::V4_0::Error;
+using android::hardware::graphics::mapper::V4_0::IMapper;
+using android::hardware::graphics::mapper::V4_0::YCbCrLayout;
+
+namespace android {
+
+namespace {
+
+static constexpr Error kTransactionError = Error::NO_RESOURCES;
+
+uint64_t getValidUsageBits() {
+ static const uint64_t validUsageBits = []() -> uint64_t {
+ uint64_t bits = 0;
+ for (const auto bit :
+ hardware::hidl_enum_range<hardware::graphics::common::V1_2::BufferUsage>()) {
+ bits = bits | bit;
+ }
+ return bits;
+ }();
+ return validUsageBits;
+}
+
+static inline IMapper::Rect sGralloc4Rect(const Rect& rect) {
+ IMapper::Rect outRect{};
+ outRect.left = rect.left;
+ outRect.top = rect.top;
+ outRect.width = rect.width();
+ outRect.height = rect.height();
+ return outRect;
+}
+static inline void sBufferDescriptorInfo(uint32_t width, uint32_t height,
+ android::PixelFormat format, uint32_t layerCount,
+ uint64_t usage,
+ IMapper::BufferDescriptorInfo* outDescriptorInfo) {
+ outDescriptorInfo->width = width;
+ outDescriptorInfo->height = height;
+ outDescriptorInfo->layerCount = layerCount;
+ outDescriptorInfo->format = static_cast<hardware::graphics::common::V1_2::PixelFormat>(format);
+ outDescriptorInfo->usage = usage;
+}
+
+} // anonymous namespace
+
+void Gralloc4Mapper::preload() {
+ android::hardware::preloadPassthroughService<IMapper>();
+}
+
+Gralloc4Mapper::Gralloc4Mapper() {
+ mMapper = IMapper::getService();
+ if (mMapper == nullptr) {
+ ALOGI("mapper 4.x is not supported");
+ return;
+ }
+ if (mMapper->isRemote()) {
+ LOG_ALWAYS_FATAL("gralloc-mapper must be in passthrough mode");
+ }
+}
+
+bool Gralloc4Mapper::isLoaded() const {
+ return mMapper != nullptr;
+}
+
+status_t Gralloc4Mapper::validateBufferDescriptorInfo(
+ IMapper::BufferDescriptorInfo* descriptorInfo) const {
+ uint64_t validUsageBits = getValidUsageBits();
+
+ if (descriptorInfo->usage & ~validUsageBits) {
+ ALOGE("buffer descriptor contains invalid usage bits 0x%" PRIx64,
+ descriptorInfo->usage & ~validUsageBits);
+ return BAD_VALUE;
+ }
+ return NO_ERROR;
+}
+
+status_t Gralloc4Mapper::createDescriptor(void* bufferDescriptorInfo,
+ void* outBufferDescriptor) const {
+ IMapper::BufferDescriptorInfo* descriptorInfo =
+ static_cast<IMapper::BufferDescriptorInfo*>(bufferDescriptorInfo);
+ BufferDescriptor* outDescriptor = static_cast<BufferDescriptor*>(outBufferDescriptor);
+
+ status_t status = validateBufferDescriptorInfo(descriptorInfo);
+ if (status != NO_ERROR) {
+ return status;
+ }
+
+ Error error;
+ auto hidl_cb = [&](const auto& tmpError, const auto& tmpDescriptor) {
+ error = tmpError;
+ if (error != Error::NONE) {
+ return;
+ }
+ *outDescriptor = tmpDescriptor;
+ };
+
+ hardware::Return<void> ret = mMapper->createDescriptor(*descriptorInfo, hidl_cb);
+
+ return static_cast<status_t>((ret.isOk()) ? error : kTransactionError);
+}
+
+status_t Gralloc4Mapper::importBuffer(const hardware::hidl_handle& rawHandle,
+ buffer_handle_t* outBufferHandle) const {
+ Error error;
+ auto ret = mMapper->importBuffer(rawHandle, [&](const auto& tmpError, const auto& tmpBuffer) {
+ error = tmpError;
+ if (error != Error::NONE) {
+ return;
+ }
+ *outBufferHandle = static_cast<buffer_handle_t>(tmpBuffer);
+ });
+
+ return static_cast<status_t>((ret.isOk()) ? error : kTransactionError);
+}
+
+void Gralloc4Mapper::freeBuffer(buffer_handle_t bufferHandle) const {
+ auto buffer = const_cast<native_handle_t*>(bufferHandle);
+ auto ret = mMapper->freeBuffer(buffer);
+
+ auto error = (ret.isOk()) ? static_cast<Error>(ret) : kTransactionError;
+ ALOGE_IF(error != Error::NONE, "freeBuffer(%p) failed with %d", buffer, error);
+}
+
+status_t Gralloc4Mapper::validateBufferSize(buffer_handle_t bufferHandle, uint32_t width,
+ uint32_t height, android::PixelFormat format,
+ uint32_t layerCount, uint64_t usage,
+ uint32_t stride) const {
+ IMapper::BufferDescriptorInfo descriptorInfo;
+ sBufferDescriptorInfo(width, height, format, layerCount, usage, &descriptorInfo);
+
+ auto buffer = const_cast<native_handle_t*>(bufferHandle);
+ auto ret = mMapper->validateBufferSize(buffer, descriptorInfo, stride);
+
+ return static_cast<status_t>((ret.isOk()) ? static_cast<Error>(ret) : kTransactionError);
+}
+
+void Gralloc4Mapper::getTransportSize(buffer_handle_t bufferHandle, uint32_t* outNumFds,
+ uint32_t* outNumInts) const {
+ *outNumFds = uint32_t(bufferHandle->numFds);
+ *outNumInts = uint32_t(bufferHandle->numInts);
+
+ Error error;
+ auto buffer = const_cast<native_handle_t*>(bufferHandle);
+ auto ret = mMapper->getTransportSize(buffer,
+ [&](const auto& tmpError, const auto& tmpNumFds,
+ const auto& tmpNumInts) {
+ error = tmpError;
+ if (error != Error::NONE) {
+ return;
+ }
+ *outNumFds = tmpNumFds;
+ *outNumInts = tmpNumInts;
+ });
+
+ error = (ret.isOk()) ? error : kTransactionError;
+
+ ALOGE_IF(error != Error::NONE, "getTransportSize(%p) failed with %d", buffer, error);
+}
+
+status_t Gralloc4Mapper::lock(buffer_handle_t bufferHandle, uint64_t usage, const Rect& bounds,
+ int acquireFence, void** outData, int32_t* outBytesPerPixel,
+ int32_t* outBytesPerStride) const {
+ auto buffer = const_cast<native_handle_t*>(bufferHandle);
+
+ IMapper::Rect accessRegion = sGralloc4Rect(bounds);
+
+ // put acquireFence in a hidl_handle
+ hardware::hidl_handle acquireFenceHandle;
+ NATIVE_HANDLE_DECLARE_STORAGE(acquireFenceStorage, 1, 0);
+ if (acquireFence >= 0) {
+ auto h = native_handle_init(acquireFenceStorage, 1, 0);
+ h->data[0] = acquireFence;
+ acquireFenceHandle = h;
+ }
+
+ Error error;
+ auto ret = mMapper->lock(buffer, usage, accessRegion, acquireFenceHandle,
+ [&](const auto& tmpError, const auto& tmpData,
+ const auto& tmpBytesPerPixel, const auto& tmpBytesPerStride) {
+ error = tmpError;
+ if (error != Error::NONE) {
+ return;
+ }
+ *outData = tmpData;
+ if (outBytesPerPixel) {
+ *outBytesPerPixel = tmpBytesPerPixel;
+ }
+ if (outBytesPerStride) {
+ *outBytesPerStride = tmpBytesPerStride;
+ }
+ });
+
+ // we own acquireFence even on errors
+ if (acquireFence >= 0) {
+ close(acquireFence);
+ }
+
+ error = (ret.isOk()) ? error : kTransactionError;
+
+ ALOGW_IF(error != Error::NONE, "lock(%p, ...) failed: %d", bufferHandle, error);
+
+ return static_cast<status_t>(error);
+}
+
+status_t Gralloc4Mapper::lock(buffer_handle_t bufferHandle, uint64_t usage, const Rect& bounds,
+ int acquireFence, android_ycbcr* ycbcr) const {
+ auto buffer = const_cast<native_handle_t*>(bufferHandle);
+
+ IMapper::Rect accessRegion = sGralloc4Rect(bounds);
+
+ // put acquireFence in a hidl_handle
+ hardware::hidl_handle acquireFenceHandle;
+ NATIVE_HANDLE_DECLARE_STORAGE(acquireFenceStorage, 1, 0);
+ if (acquireFence >= 0) {
+ auto h = native_handle_init(acquireFenceStorage, 1, 0);
+ h->data[0] = acquireFence;
+ acquireFenceHandle = h;
+ }
+
+ YCbCrLayout layout;
+ Error error;
+ auto ret = mMapper->lockYCbCr(buffer, usage, accessRegion, acquireFenceHandle,
+ [&](const auto& tmpError, const auto& tmpLayout) {
+ error = tmpError;
+ if (error != Error::NONE) {
+ return;
+ }
+
+ layout = tmpLayout;
+ });
+
+ if (error == Error::NONE) {
+ ycbcr->y = layout.y;
+ ycbcr->cb = layout.cb;
+ ycbcr->cr = layout.cr;
+ ycbcr->ystride = static_cast<size_t>(layout.yStride);
+ ycbcr->cstride = static_cast<size_t>(layout.cStride);
+ ycbcr->chroma_step = static_cast<size_t>(layout.chromaStep);
+ }
+
+ // we own acquireFence even on errors
+ if (acquireFence >= 0) {
+ close(acquireFence);
+ }
+
+ return static_cast<status_t>((ret.isOk()) ? error : kTransactionError);
+}
+
+int Gralloc4Mapper::unlock(buffer_handle_t bufferHandle) const {
+ auto buffer = const_cast<native_handle_t*>(bufferHandle);
+
+ int releaseFence = -1;
+ Error error;
+ auto ret = mMapper->unlock(buffer, [&](const auto& tmpError, const auto& tmpReleaseFence) {
+ error = tmpError;
+ if (error != Error::NONE) {
+ return;
+ }
+
+ auto fenceHandle = tmpReleaseFence.getNativeHandle();
+ if (fenceHandle && fenceHandle->numFds == 1) {
+ int fd = dup(fenceHandle->data[0]);
+ if (fd >= 0) {
+ releaseFence = fd;
+ } else {
+ ALOGD("failed to dup unlock release fence");
+ sync_wait(fenceHandle->data[0], -1);
+ }
+ }
+ });
+
+ if (!ret.isOk()) {
+ error = kTransactionError;
+ }
+
+ if (error != Error::NONE) {
+ ALOGE("unlock(%p) failed with %d", buffer, error);
+ }
+
+ return releaseFence;
+}
+
+status_t Gralloc4Mapper::isSupported(uint32_t width, uint32_t height, android::PixelFormat format,
+ uint32_t layerCount, uint64_t usage,
+ bool* outSupported) const {
+ IMapper::BufferDescriptorInfo descriptorInfo;
+ sBufferDescriptorInfo(width, height, format, layerCount, usage, &descriptorInfo);
+
+ Error error;
+ auto ret = mMapper->isSupported(descriptorInfo,
+ [&](const auto& tmpError, const auto& tmpSupported) {
+ error = tmpError;
+ if (error != Error::NONE) {
+ return;
+ }
+ if (outSupported) {
+ *outSupported = tmpSupported;
+ }
+ });
+
+ if (!ret.isOk()) {
+ error = kTransactionError;
+ }
+
+ if (error != Error::NONE) {
+ ALOGE("isSupported(%u, %u, %d, %u, ...) failed with %d", width, height, format, layerCount,
+ error);
+ }
+
+ return static_cast<status_t>(error);
+}
+
+Gralloc4Allocator::Gralloc4Allocator(const Gralloc4Mapper& mapper) : mMapper(mapper) {
+ mAllocator = IAllocator::getService();
+ if (mAllocator == nullptr) {
+ ALOGW("allocator 3.x is not supported");
+ return;
+ }
+}
+
+bool Gralloc4Allocator::isLoaded() const {
+ return mAllocator != nullptr;
+}
+
+std::string Gralloc4Allocator::dumpDebugInfo() const {
+ std::string debugInfo;
+
+ mAllocator->dumpDebugInfo([&](const auto& tmpDebugInfo) { debugInfo = tmpDebugInfo.c_str(); });
+
+ return debugInfo;
+}
+
+status_t Gralloc4Allocator::allocate(uint32_t width, uint32_t height, android::PixelFormat format,
+ uint32_t layerCount, uint64_t usage, uint32_t bufferCount,
+ uint32_t* outStride, buffer_handle_t* outBufferHandles) const {
+ IMapper::BufferDescriptorInfo descriptorInfo;
+ sBufferDescriptorInfo(width, height, format, layerCount, usage, &descriptorInfo);
+
+ BufferDescriptor descriptor;
+ status_t error = mMapper.createDescriptor(static_cast<void*>(&descriptorInfo),
+ static_cast<void*>(&descriptor));
+ if (error != NO_ERROR) {
+ return error;
+ }
+
+ auto ret = mAllocator->allocate(descriptor, bufferCount,
+ [&](const auto& tmpError, const auto& tmpStride,
+ const auto& tmpBuffers) {
+ error = static_cast<status_t>(tmpError);
+ if (tmpError != Error::NONE) {
+ return;
+ }
+
+ // import buffers
+ for (uint32_t i = 0; i < bufferCount; i++) {
+ error = mMapper.importBuffer(tmpBuffers[i],
+ &outBufferHandles[i]);
+ if (error != NO_ERROR) {
+ for (uint32_t j = 0; j < i; j++) {
+ mMapper.freeBuffer(outBufferHandles[j]);
+ outBufferHandles[j] = nullptr;
+ }
+ return;
+ }
+ }
+ *outStride = tmpStride;
+ });
+
+ // make sure the kernel driver sees BC_FREE_BUFFER and closes the fds now
+ hardware::IPCThreadState::self()->flushCommands();
+
+ return (ret.isOk()) ? error : static_cast<status_t>(kTransactionError);
+}
+
+} // namespace android
diff --git a/libs/ui/GraphicBufferAllocator.cpp b/libs/ui/GraphicBufferAllocator.cpp
index 9c7d1fd..eb787a2 100644
--- a/libs/ui/GraphicBufferAllocator.cpp
+++ b/libs/ui/GraphicBufferAllocator.cpp
@@ -33,6 +33,7 @@
#include <ui/Gralloc.h>
#include <ui/Gralloc2.h>
#include <ui/Gralloc3.h>
+#include <ui/Gralloc4.h>
#include <ui/GraphicBufferMapper.h>
namespace android {
@@ -47,16 +48,23 @@
GraphicBufferAllocator::alloc_rec_t> GraphicBufferAllocator::sAllocList;
GraphicBufferAllocator::GraphicBufferAllocator() : mMapper(GraphicBufferMapper::getInstance()) {
+ mAllocator = std::make_unique<const Gralloc4Allocator>(
+ reinterpret_cast<const Gralloc4Mapper&>(mMapper.getGrallocMapper()));
+ if (mAllocator->isLoaded()) {
+ return;
+ }
mAllocator = std::make_unique<const Gralloc3Allocator>(
reinterpret_cast<const Gralloc3Mapper&>(mMapper.getGrallocMapper()));
- if (!mAllocator->isLoaded()) {
- mAllocator = std::make_unique<const Gralloc2Allocator>(
- reinterpret_cast<const Gralloc2Mapper&>(mMapper.getGrallocMapper()));
+ if (mAllocator->isLoaded()) {
+ return;
+ }
+ mAllocator = std::make_unique<const Gralloc2Allocator>(
+ reinterpret_cast<const Gralloc2Mapper&>(mMapper.getGrallocMapper()));
+ if (mAllocator->isLoaded()) {
+ return;
}
- if (!mAllocator->isLoaded()) {
- LOG_ALWAYS_FATAL("gralloc-allocator is missing");
- }
+ LOG_ALWAYS_FATAL("gralloc-allocator is missing");
}
GraphicBufferAllocator::~GraphicBufferAllocator() {}
diff --git a/libs/ui/GraphicBufferMapper.cpp b/libs/ui/GraphicBufferMapper.cpp
index 25b7247..4d087d1 100644
--- a/libs/ui/GraphicBufferMapper.cpp
+++ b/libs/ui/GraphicBufferMapper.cpp
@@ -35,6 +35,7 @@
#include <ui/Gralloc.h>
#include <ui/Gralloc2.h>
#include <ui/Gralloc3.h>
+#include <ui/Gralloc4.h>
#include <ui/GraphicBuffer.h>
#include <system/graphics.h>
@@ -47,20 +48,27 @@
void GraphicBufferMapper::preloadHal() {
Gralloc2Mapper::preload();
Gralloc3Mapper::preload();
+ Gralloc4Mapper::preload();
}
GraphicBufferMapper::GraphicBufferMapper() {
+ mMapper = std::make_unique<const Gralloc4Mapper>();
+ if (mMapper->isLoaded()) {
+ mMapperVersion = Version::GRALLOC_4;
+ return;
+ }
mMapper = std::make_unique<const Gralloc3Mapper>();
- if (!mMapper->isLoaded()) {
- mMapper = std::make_unique<const Gralloc2Mapper>();
- mMapperVersion = Version::GRALLOC_2;
- } else {
+ if (mMapper->isLoaded()) {
mMapperVersion = Version::GRALLOC_3;
+ return;
+ }
+ mMapper = std::make_unique<const Gralloc2Mapper>();
+ if (mMapper->isLoaded()) {
+ mMapperVersion = Version::GRALLOC_2;
+ return;
}
- if (!mMapper->isLoaded()) {
- LOG_ALWAYS_FATAL("gralloc-mapper is missing");
- }
+ LOG_ALWAYS_FATAL("gralloc-mapper is missing");
}
status_t GraphicBufferMapper::importBuffer(buffer_handle_t rawHandle,
diff --git a/libs/ui/include/ui/Gralloc4.h b/libs/ui/include/ui/Gralloc4.h
new file mode 100644
index 0000000..14b65bc
--- /dev/null
+++ b/libs/ui/include/ui/Gralloc4.h
@@ -0,0 +1,95 @@
+/*
+ * Copyright 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.
+ */
+
+#ifndef ANDROID_UI_GRALLOC4_H
+#define ANDROID_UI_GRALLOC4_H
+
+#include <string>
+
+#include <android/hardware/graphics/allocator/4.0/IAllocator.h>
+#include <android/hardware/graphics/common/1.1/types.h>
+#include <android/hardware/graphics/mapper/4.0/IMapper.h>
+#include <ui/Gralloc.h>
+#include <ui/PixelFormat.h>
+#include <ui/Rect.h>
+#include <utils/StrongPointer.h>
+
+namespace android {
+
+class Gralloc4Mapper : public GrallocMapper {
+public:
+ static void preload();
+
+ Gralloc4Mapper();
+
+ bool isLoaded() const override;
+
+ status_t createDescriptor(void* bufferDescriptorInfo, void* outBufferDescriptor) const override;
+
+ status_t importBuffer(const hardware::hidl_handle& rawHandle,
+ buffer_handle_t* outBufferHandle) const override;
+
+ void freeBuffer(buffer_handle_t bufferHandle) const override;
+
+ status_t validateBufferSize(buffer_handle_t bufferHandle, uint32_t width, uint32_t height,
+ android::PixelFormat format, uint32_t layerCount, uint64_t usage,
+ uint32_t stride) const override;
+
+ void getTransportSize(buffer_handle_t bufferHandle, uint32_t* outNumFds,
+ uint32_t* outNumInts) const override;
+
+ status_t lock(buffer_handle_t bufferHandle, uint64_t usage, const Rect& bounds,
+ int acquireFence, void** outData, int32_t* outBytesPerPixel,
+ int32_t* outBytesPerStride) const override;
+
+ status_t lock(buffer_handle_t bufferHandle, uint64_t usage, const Rect& bounds,
+ int acquireFence, android_ycbcr* ycbcr) const override;
+
+ int unlock(buffer_handle_t bufferHandle) const override;
+
+ status_t isSupported(uint32_t width, uint32_t height, android::PixelFormat format,
+ uint32_t layerCount, uint64_t usage, bool* outSupported) const override;
+
+private:
+ // Determines whether the passed info is compatible with the mapper.
+ status_t validateBufferDescriptorInfo(
+ hardware::graphics::mapper::V4_0::IMapper::BufferDescriptorInfo* descriptorInfo) const;
+
+ sp<hardware::graphics::mapper::V4_0::IMapper> mMapper;
+};
+
+class Gralloc4Allocator : public GrallocAllocator {
+public:
+ // An allocator relies on a mapper, and that mapper must be alive at all
+ // time.
+ Gralloc4Allocator(const Gralloc4Mapper& mapper);
+
+ bool isLoaded() const override;
+
+ std::string dumpDebugInfo() const override;
+
+ status_t allocate(uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount,
+ uint64_t usage, uint32_t bufferCount, uint32_t* outStride,
+ buffer_handle_t* outBufferHandles) const override;
+
+private:
+ const Gralloc4Mapper& mMapper;
+ sp<hardware::graphics::allocator::V4_0::IAllocator> mAllocator;
+};
+
+} // namespace android
+
+#endif // ANDROID_UI_GRALLOC4_H
diff --git a/libs/ui/include/ui/GraphicBufferMapper.h b/libs/ui/include/ui/GraphicBufferMapper.h
index 2461454..c401a48 100644
--- a/libs/ui/include/ui/GraphicBufferMapper.h
+++ b/libs/ui/include/ui/GraphicBufferMapper.h
@@ -44,6 +44,7 @@
enum Version {
GRALLOC_2,
GRALLOC_3,
+ GRALLOC_4,
};
static void preloadHal();
static inline GraphicBufferMapper& get() { return getInstance(); }
diff --git a/libs/vr/libdisplay/display_client.cpp b/libs/vr/libdisplay/display_client.cpp
index f67e258..62856df 100644
--- a/libs/vr/libdisplay/display_client.cpp
+++ b/libs/vr/libdisplay/display_client.cpp
@@ -178,6 +178,10 @@
return status;
}
+Status<uint8_t> DisplayClient::GetDisplayIdentificationPort() {
+ return InvokeRemoteMethod<DisplayProtocol::GetDisplayIdentificationPort>();
+}
+
Status<std::unique_ptr<Surface>> DisplayClient::CreateSurface(
const SurfaceAttributes& attributes) {
int error;
diff --git a/libs/vr/libdisplay/include/private/dvr/display_client.h b/libs/vr/libdisplay/include/private/dvr/display_client.h
index f8f5b3d..81546ac 100644
--- a/libs/vr/libdisplay/include/private/dvr/display_client.h
+++ b/libs/vr/libdisplay/include/private/dvr/display_client.h
@@ -72,6 +72,7 @@
public:
pdx::Status<Metrics> GetDisplayMetrics();
pdx::Status<std::string> GetConfigurationData(ConfigFileType config_type);
+ pdx::Status<uint8_t> GetDisplayIdentificationPort();
pdx::Status<std::unique_ptr<IonBuffer>> SetupGlobalBuffer(
DvrGlobalBufferKey key, size_t size, uint64_t usage);
pdx::Status<void> DeleteGlobalBuffer(DvrGlobalBufferKey key);
diff --git a/libs/vr/libdisplay/include/private/dvr/display_protocol.h b/libs/vr/libdisplay/include/private/dvr/display_protocol.h
index 861dc6c..9f4cc4a 100644
--- a/libs/vr/libdisplay/include/private/dvr/display_protocol.h
+++ b/libs/vr/libdisplay/include/private/dvr/display_protocol.h
@@ -211,6 +211,7 @@
kOpGetSurfaceInfo,
kOpCreateQueue,
kOpSetAttributes,
+ kOpGetDisplayIdentificationPort,
};
// Aliases.
@@ -221,6 +222,8 @@
PDX_REMOTE_METHOD(GetMetrics, kOpGetMetrics, Metrics(Void));
PDX_REMOTE_METHOD(GetConfigurationData, kOpGetConfigurationData,
std::string(ConfigFileType config_type));
+ PDX_REMOTE_METHOD(GetDisplayIdentificationPort,
+ kOpGetDisplayIdentificationPort, uint8_t(Void));
PDX_REMOTE_METHOD(SetupGlobalBuffer, kOpSetupGlobalBuffer,
LocalNativeBufferHandle(DvrGlobalBufferKey key, size_t size,
uint64_t usage));
diff --git a/libs/vr/libvrflinger/Android.bp b/libs/vr/libvrflinger/Android.bp
index 2829353..4441672 100644
--- a/libs/vr/libvrflinger/Android.bp
+++ b/libs/vr/libvrflinger/Android.bp
@@ -35,7 +35,7 @@
]
sharedLibraries = [
- "android.frameworks.vr.composer@1.0",
+ "android.frameworks.vr.composer@2.0",
"android.hardware.graphics.allocator@2.0",
"android.hardware.graphics.composer@2.1",
"android.hardware.graphics.composer@2.2",
diff --git a/libs/vr/libvrflinger/display_service.cpp b/libs/vr/libvrflinger/display_service.cpp
index 8980a92..5a9360c 100644
--- a/libs/vr/libvrflinger/display_service.cpp
+++ b/libs/vr/libvrflinger/display_service.cpp
@@ -47,7 +47,8 @@
uint8_t port;
const auto error = hidl->getDisplayIdentificationData(
- primary_display_id, &port, &display_identification_data_);
+ primary_display_id, &display_identification_port_,
+ &display_identification_data_);
if (error != android::hardware::graphics::composer::V2_1::Error::NONE) {
if (error !=
android::hardware::graphics::composer::V2_1::Error::UNSUPPORTED) {
@@ -151,6 +152,11 @@
*this, &DisplayService::OnGetConfigurationData, message);
return {};
+ case DisplayProtocol::GetDisplayIdentificationPort::Opcode:
+ DispatchRemoteMethod<DisplayProtocol::GetDisplayIdentificationPort>(
+ *this, &DisplayService::OnGetDisplayIdentificationPort, message);
+ return {};
+
case DisplayProtocol::CreateSurface::Opcode:
DispatchRemoteMethod<DisplayProtocol::CreateSurface>(
*this, &DisplayService::OnCreateSurface, message);
@@ -238,6 +244,11 @@
return std::move(data);
}
+pdx::Status<uint8_t> DisplayService::OnGetDisplayIdentificationPort(
+ pdx::Message& /*message*/) {
+ return display_identification_port_;
+}
+
// Creates a new DisplaySurface and associates it with this channel. This may
// only be done once per channel.
Status<display::SurfaceInfo> DisplayService::OnCreateSurface(
diff --git a/libs/vr/libvrflinger/display_service.h b/libs/vr/libvrflinger/display_service.h
index d45a61f..06ba566 100644
--- a/libs/vr/libvrflinger/display_service.h
+++ b/libs/vr/libvrflinger/display_service.h
@@ -82,6 +82,7 @@
pdx::Status<display::Metrics> OnGetMetrics(pdx::Message& message);
pdx::Status<std::string> OnGetConfigurationData(
pdx::Message& message, display::ConfigFileType config_type);
+ pdx::Status<uint8_t> OnGetDisplayIdentificationPort(pdx::Message& message);
pdx::Status<display::SurfaceInfo> OnCreateSurface(
pdx::Message& message, const display::SurfaceAttributes& attributes);
pdx::Status<BorrowedNativeBufferHandle> OnSetupGlobalBuffer(
@@ -121,6 +122,7 @@
void operator=(const DisplayService&) = delete;
DisplayIdentificationData display_identification_data_;
+ uint8_t display_identification_port_;
};
} // namespace dvr
diff --git a/libs/vr/libvrflinger/hardware_composer.cpp b/libs/vr/libvrflinger/hardware_composer.cpp
index e1240d6..9072d89 100644
--- a/libs/vr/libvrflinger/hardware_composer.cpp
+++ b/libs/vr/libvrflinger/hardware_composer.cpp
@@ -51,8 +51,6 @@
const char kRightEyeOffsetProperty[] = "dvr.right_eye_offset_ns";
-const char kUseExternalDisplayProperty[] = "persist.vr.use_external_display";
-
// Surface flinger uses "VSYNC-sf" and "VSYNC-app" for its version of these
// events. Name ours similarly.
const char kVsyncTraceEventName[] = "VSYNC-vrflinger";
@@ -965,18 +963,9 @@
external_display_ = GetDisplayParams(composer_.get(),
*displays.external_display, /*is_primary*/ false);
- if (property_get_bool(kUseExternalDisplayProperty, false)) {
- ALOGI("External display connected. Switching to external display.");
- target_display_ = &(*external_display_);
- target_display_changed = true;
- } else {
- ALOGI("External display connected, but sysprop %s is unset, so"
- " using primary display.", kUseExternalDisplayProperty);
- if (was_using_external_display) {
- target_display_ = &primary_display_;
- target_display_changed = true;
- }
- }
+ ALOGI("External display connected. Switching to external display.");
+ target_display_ = &(*external_display_);
+ target_display_changed = true;
} else {
// External display was disconnected
external_display_ = std::nullopt;
diff --git a/opengl/libagl/Android.bp b/opengl/libagl/Android.bp
deleted file mode 100644
index 6ec24b3..0000000
--- a/opengl/libagl/Android.bp
+++ /dev/null
@@ -1,99 +0,0 @@
-//
-// Build the software OpenGL ES library
-//
-
-cc_defaults {
- name: "libGLES_android_defaults",
-
- cflags: [
- "-DLOG_TAG=\"libagl\"",
- "-DGL_GLEXT_PROTOTYPES",
- "-DEGL_EGLEXT_PROTOTYPES",
- "-fvisibility=hidden",
- "-Wall",
- "-Werror",
- ],
-
- shared_libs: [
- "libcutils",
- "libhardware",
- "libutils",
- "liblog",
- "libpixelflinger",
- "libETC1",
- "libui",
- "libnativewindow",
- ],
-
- // we need to access the private Bionic header <bionic_tls.h>
- include_dirs: ["bionic/libc/private"],
-
- arch: {
- arm: {
- cflags: ["-fstrict-aliasing"],
- },
-
- mips: {
- cflags: [
- "-fstrict-aliasing",
- // The graphics code can generate division by zero
- "-mno-check-zero-division",
- ],
- },
- },
-}
-
-cc_library_shared {
- name: "libGLES_android",
- defaults: ["libGLES_android_defaults"],
-
- whole_static_libs: ["libGLES_android_arm"],
-
- srcs: [
- "egl.cpp",
- "state.cpp",
- "texture.cpp",
- "Tokenizer.cpp",
- "TokenManager.cpp",
- "TextureObjectManager.cpp",
- "BufferObjectManager.cpp",
- ],
-
- arch: {
- arm: {
- srcs: [
- "fixed_asm.S",
- "iterators.S",
- ],
- },
-
- mips: {
- rev6: {
- srcs: ["arch-mips/fixed_asm.S"],
- },
- },
- },
-
- relative_install_path: "egl",
-}
-
-cc_library_static {
- name: "libGLES_android_arm",
- defaults: ["libGLES_android_defaults"],
-
- srcs: [
- "array.cpp",
- "fp.cpp",
- "light.cpp",
- "matrix.cpp",
- "mipmap.cpp",
- "primitives.cpp",
- "vertex.cpp",
- ],
-
- arch: {
- arm: {
- instruction_set: "arm",
- },
- },
-}
diff --git a/opengl/libagl/BufferObjectManager.cpp b/opengl/libagl/BufferObjectManager.cpp
deleted file mode 100644
index 3d93c19..0000000
--- a/opengl/libagl/BufferObjectManager.cpp
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- ** Copyright 2008, 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 <stdint.h>
-#include <stddef.h>
-#include <sys/types.h>
-
-#include <cutils/atomic.h>
-#include <utils/RefBase.h>
-#include <utils/KeyedVector.h>
-#include <utils/Errors.h>
-
-#include <GLES/gl.h>
-
-#include "BufferObjectManager.h"
-
-
-namespace android {
-
-using namespace gl;
-
-// ----------------------------------------------------------------------------
-
-EGLBufferObjectManager::EGLBufferObjectManager()
-: TokenManager(), mCount(0)
-{
-}
-
-EGLBufferObjectManager::~EGLBufferObjectManager()
-{
- // destroy all the buffer objects and their storage
- GLsizei n = mBuffers.size();
- for (GLsizei i=0 ; i<n ; i++) {
- buffer_t* bo = mBuffers.valueAt(i);
- free(bo->data);
- delete bo;
- }
-}
-
-buffer_t const* EGLBufferObjectManager::bind(GLuint buffer)
-{
- Mutex::Autolock _l(mLock);
- int32_t i = mBuffers.indexOfKey(buffer);
- if (i >= 0) {
- return mBuffers.valueAt(i);
- }
- buffer_t* bo = new buffer_t;
- bo->data = 0;
- bo->usage = GL_STATIC_DRAW;
- bo->size = 0;
- bo->name = buffer;
- mBuffers.add(buffer, bo);
- return bo;
-}
-
-int EGLBufferObjectManager::allocateStore(buffer_t* bo,
- GLsizeiptr size, GLenum usage)
-{
- Mutex::Autolock _l(mLock);
- if (size != bo->size) {
- uint8_t* data = (uint8_t*)malloc(size);
- if (data == 0)
- return -1;
- free(bo->data);
- bo->data = data;
- bo->size = size;
- }
- bo->usage = usage;
- return 0;
-}
-
-void EGLBufferObjectManager::deleteBuffers(GLsizei n, const GLuint* buffers)
-{
- Mutex::Autolock _l(mLock);
- while (n--) {
- const GLuint t = *buffers++;
- if (t) {
- int32_t index = mBuffers.indexOfKey(t);
- if (index >= 0) {
- buffer_t* bo = mBuffers.valueAt(index);
- free(bo->data);
- mBuffers.removeItemsAt(index);
- delete bo;
- }
- }
- }
-}
-
-// ----------------------------------------------------------------------------
-}; // namespace android
diff --git a/opengl/libagl/BufferObjectManager.h b/opengl/libagl/BufferObjectManager.h
deleted file mode 100644
index fcdae5b..0000000
--- a/opengl/libagl/BufferObjectManager.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- **
- ** Copyright 2006, 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.
- */
-
-#ifndef ANDROID_OPENGLES_BUFFER_OBJECT_MANAGER_H
-#define ANDROID_OPENGLES_BUFFER_OBJECT_MANAGER_H
-
-#include <atomic>
-#include <stdint.h>
-#include <stddef.h>
-#include <sys/types.h>
-
-#include <utils/RefBase.h>
-#include <utils/KeyedVector.h>
-#include <utils/Errors.h>
-
-#include <GLES/gl.h>
-
-#include "Tokenizer.h"
-#include "TokenManager.h"
-
-
-namespace android {
-
-// ----------------------------------------------------------------------------
-
-namespace gl {
-
-struct buffer_t {
- GLsizeiptr size;
- GLenum usage;
- uint8_t* data;
- uint32_t name;
-};
-
-};
-
-class EGLBufferObjectManager : public TokenManager
-{
-public:
- EGLBufferObjectManager();
- ~EGLBufferObjectManager();
-
- // protocol for sp<>
- inline void incStrong(const void* id) const;
- inline void decStrong(const void* id) const;
- typedef void weakref_type;
-
- gl::buffer_t const* bind(GLuint buffer);
- int allocateStore(gl::buffer_t* bo, GLsizeiptr size, GLenum usage);
- void deleteBuffers(GLsizei n, const GLuint* buffers);
-
-private:
- mutable std::atomic_size_t mCount;
- mutable Mutex mLock;
- KeyedVector<GLuint, gl::buffer_t*> mBuffers;
-};
-
-void EGLBufferObjectManager::incStrong(const void* /*id*/) const {
- mCount.fetch_add(1, std::memory_order_relaxed);
-}
-void EGLBufferObjectManager::decStrong(const void* /*id*/) const {
- if (mCount.fetch_sub(1, std::memory_order_release) == 0) {
- std::atomic_thread_fence(std::memory_order_acquire);
- delete this;
- }
-}
-
-// ----------------------------------------------------------------------------
-}; // namespace android
-
-#endif // ANDROID_OPENGLES_BUFFER_OBJECT_MANAGER_H
-
diff --git a/opengl/libagl/TextureObjectManager.cpp b/opengl/libagl/TextureObjectManager.cpp
deleted file mode 100644
index 06d45cc..0000000
--- a/opengl/libagl/TextureObjectManager.cpp
+++ /dev/null
@@ -1,325 +0,0 @@
-/*
- ** Copyright 2006, 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 <stdio.h>
-#include <stdlib.h>
-#include "context.h"
-#include "TextureObjectManager.h"
-
-namespace android {
-// ----------------------------------------------------------------------------
-
-EGLTextureObject::EGLTextureObject()
- : mSize(0)
-{
- init();
-}
-
-EGLTextureObject::~EGLTextureObject()
-{
- if (!direct) {
- if (mSize && surface.data)
- free(surface.data);
- if (mMipmaps)
- freeMipmaps();
- }
-}
-
-void EGLTextureObject::init()
-{
- memset(&surface, 0, sizeof(surface));
- surface.version = sizeof(surface);
- mMipmaps = 0;
- mNumExtraLod = 0;
- mIsComplete = false;
- wraps = GL_REPEAT;
- wrapt = GL_REPEAT;
- min_filter = GL_LINEAR;
- mag_filter = GL_LINEAR;
- internalformat = 0;
- memset(crop_rect, 0, sizeof(crop_rect));
- generate_mipmap = GL_FALSE;
- direct = GL_FALSE;
- buffer = 0;
-}
-
-void EGLTextureObject::copyParameters(const sp<EGLTextureObject>& old)
-{
- wraps = old->wraps;
- wrapt = old->wrapt;
- min_filter = old->min_filter;
- mag_filter = old->mag_filter;
- memcpy(crop_rect, old->crop_rect, sizeof(crop_rect));
- generate_mipmap = old->generate_mipmap;
- direct = old->direct;
-}
-
-status_t EGLTextureObject::allocateMipmaps()
-{
- // here, by construction, mMipmaps=0 && mNumExtraLod=0
-
- if (!surface.data)
- return NO_INIT;
-
- int w = surface.width;
- int h = surface.height;
- const int numLods = 31 - gglClz(max(w,h));
- if (numLods <= 0)
- return NO_ERROR;
-
- mMipmaps = (GGLSurface*)malloc(numLods * sizeof(GGLSurface));
- if (!mMipmaps)
- return NO_MEMORY;
-
- memset(mMipmaps, 0, numLods * sizeof(GGLSurface));
- mNumExtraLod = numLods;
- return NO_ERROR;
-}
-
-void EGLTextureObject::freeMipmaps()
-{
- if (mMipmaps) {
- for (int i=0 ; i<mNumExtraLod ; i++) {
- if (mMipmaps[i].data) {
- free(mMipmaps[i].data);
- }
- }
- free(mMipmaps);
- mMipmaps = 0;
- mNumExtraLod = 0;
- }
-}
-
-const GGLSurface& EGLTextureObject::mip(int lod) const
-{
- if (lod<=0 || !mMipmaps)
- return surface;
- lod = min(lod-1, mNumExtraLod-1);
- return mMipmaps[lod];
-}
-
-GGLSurface& EGLTextureObject::editMip(int lod)
-{
- return const_cast<GGLSurface&>(mip(lod));
-}
-
-status_t EGLTextureObject::setSurface(GGLSurface const* s)
-{
- // XXX: glFlush() on 's'
- if (mSize && surface.data) {
- free(surface.data);
- }
- surface = *s;
- internalformat = 0;
- buffer = 0;
-
- // we should keep the crop_rect, but it's delicate because
- // the new size of the surface could make it invalid.
- // so for now, we just loose it.
- memset(crop_rect, 0, sizeof(crop_rect));
-
- // it would be nice if we could keep the generate_mipmap flag,
- // we would have to generate them right now though.
- generate_mipmap = GL_FALSE;
-
- direct = GL_TRUE;
- mSize = 0; // we don't own this surface
- if (mMipmaps)
- freeMipmaps();
- mIsComplete = true;
- return NO_ERROR;
-}
-
-status_t EGLTextureObject::setImage(ANativeWindowBuffer* native_buffer)
-{
- GGLSurface sur;
- sur.version = sizeof(GGLSurface);
- sur.width = native_buffer->width;
- sur.height= native_buffer->height;
- sur.stride= native_buffer->stride;
- sur.format= native_buffer->format;
- sur.data = 0;
- setSurface(&sur);
- buffer = native_buffer;
- return NO_ERROR;
-}
-
-status_t EGLTextureObject::reallocate(
- GLint level, int w, int h, int s,
- int format, int compressedFormat, int bpr)
-{
- const size_t size = h * bpr;
- if (level == 0)
- {
- if (size!=mSize || !surface.data) {
- if (mSize && surface.data) {
- free(surface.data);
- }
- surface.data = (GGLubyte*)malloc(size);
- if (!surface.data) {
- mSize = 0;
- mIsComplete = false;
- return NO_MEMORY;
- }
- mSize = size;
- }
- surface.version = sizeof(GGLSurface);
- surface.width = w;
- surface.height = h;
- surface.stride = s;
- surface.format = format;
- surface.compressedFormat = compressedFormat;
- if (mMipmaps)
- freeMipmaps();
- mIsComplete = true;
- }
- else
- {
- if (!mMipmaps) {
- if (allocateMipmaps() != NO_ERROR)
- return NO_MEMORY;
- }
-
- ALOGW_IF(level-1 >= mNumExtraLod,
- "specifying mipmap level %d, but # of level is %d",
- level, mNumExtraLod+1);
-
- GGLSurface& mipmap = editMip(level);
- if (mipmap.data)
- free(mipmap.data);
-
- mipmap.data = (GGLubyte*)malloc(size);
- if (!mipmap.data) {
- memset(&mipmap, 0, sizeof(GGLSurface));
- mIsComplete = false;
- return NO_MEMORY;
- }
-
- mipmap.version = sizeof(GGLSurface);
- mipmap.width = w;
- mipmap.height = h;
- mipmap.stride = s;
- mipmap.format = format;
- mipmap.compressedFormat = compressedFormat;
-
- // check if the texture is complete
- mIsComplete = true;
- const GGLSurface* prev = &surface;
- for (int i=0 ; i<mNumExtraLod ; i++) {
- const GGLSurface* curr = mMipmaps + i;
- if (curr->format != surface.format) {
- mIsComplete = false;
- break;
- }
-
- uint32_t w = (prev->width >> 1) ? : 1;
- uint32_t h = (prev->height >> 1) ? : 1;
- if (w != curr->width || h != curr->height) {
- mIsComplete = false;
- break;
- }
- prev = curr;
- }
- }
- return NO_ERROR;
-}
-
-// ----------------------------------------------------------------------------
-
-EGLSurfaceManager::EGLSurfaceManager()
- : TokenManager()
-{
-}
-
-EGLSurfaceManager::~EGLSurfaceManager()
-{
- // everything gets freed automatically here...
-}
-
-sp<EGLTextureObject> EGLSurfaceManager::createTexture(GLuint name)
-{
- sp<EGLTextureObject> result;
-
- Mutex::Autolock _l(mLock);
- if (mTextures.indexOfKey(name) >= 0)
- return result; // already exists!
-
- result = new EGLTextureObject();
-
- status_t err = mTextures.add(name, result);
- if (err < 0)
- result.clear();
-
- return result;
-}
-
-sp<EGLTextureObject> EGLSurfaceManager::removeTexture(GLuint name)
-{
- Mutex::Autolock _l(mLock);
- const ssize_t index = mTextures.indexOfKey(name);
- if (index >= 0) {
- sp<EGLTextureObject> result(mTextures.valueAt(index));
- mTextures.removeItemsAt(index);
- return result;
- }
- return 0;
-}
-
-sp<EGLTextureObject> EGLSurfaceManager::replaceTexture(GLuint name)
-{
- sp<EGLTextureObject> tex;
- Mutex::Autolock _l(mLock);
- const ssize_t index = mTextures.indexOfKey(name);
- if (index >= 0) {
- const sp<EGLTextureObject>& old = mTextures.valueAt(index);
- const uint32_t refs = old->getStrongCount();
- if (ggl_likely(refs == 1)) {
- // we're the only owner
- tex = old;
- } else {
- // keep the texture's parameters
- tex = new EGLTextureObject();
- tex->copyParameters(old);
- mTextures.removeItemsAt(index);
- mTextures.add(name, tex);
- }
- }
- return tex;
-}
-
-void EGLSurfaceManager::deleteTextures(GLsizei n, const GLuint *tokens)
-{
- // free all textures
- Mutex::Autolock _l(mLock);
- for (GLsizei i=0 ; i<n ; i++) {
- const GLuint t(*tokens++);
- if (t) {
- mTextures.removeItem(t);
- }
- }
-}
-
-sp<EGLTextureObject> EGLSurfaceManager::texture(GLuint name)
-{
- Mutex::Autolock _l(mLock);
- const ssize_t index = mTextures.indexOfKey(name);
- if (index >= 0)
- return mTextures.valueAt(index);
- return 0;
-}
-
-// ----------------------------------------------------------------------------
-}; // namespace android
diff --git a/opengl/libagl/TextureObjectManager.h b/opengl/libagl/TextureObjectManager.h
deleted file mode 100644
index 9cf8771..0000000
--- a/opengl/libagl/TextureObjectManager.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
-** Copyright 2006, 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.
-*/
-
-#ifndef ANDROID_OPENGLES_SURFACE_H
-#define ANDROID_OPENGLES_SURFACE_H
-
-#include <stdint.h>
-#include <stddef.h>
-#include <sys/types.h>
-
-#include <cutils/atomic.h>
-#include <utils/threads.h>
-#include <utils/RefBase.h>
-#include <utils/KeyedVector.h>
-#include <utils/Errors.h>
-
-#include <private/pixelflinger/ggl_context.h>
-
-#include <GLES/gl.h>
-#include <EGL/egl.h>
-#include <EGL/eglext.h>
-
-#include "Tokenizer.h"
-#include "TokenManager.h"
-
-
-namespace android {
-
-// ----------------------------------------------------------------------------
-
-class EGLTextureObject : public LightRefBase<EGLTextureObject>
-{
-public:
- EGLTextureObject();
- ~EGLTextureObject();
-
- status_t setSurface(GGLSurface const* s);
- status_t setImage(ANativeWindowBuffer* buffer);
- void setImageBits(void* vaddr) { surface.data = (GGLubyte*)vaddr; }
-
- status_t reallocate(GLint level,
- int w, int h, int s,
- int format, int compressedFormat, int bpr);
- inline size_t size() const { return mSize; }
- const GGLSurface& mip(int lod) const;
- GGLSurface& editMip(int lod);
- bool hasMipmaps() const { return mMipmaps!=0; }
- bool isComplete() const { return mIsComplete; }
- void copyParameters(const sp<EGLTextureObject>& old);
-
-private:
- status_t allocateMipmaps();
- void freeMipmaps();
- void init();
- size_t mSize;
- GGLSurface *mMipmaps;
- int mNumExtraLod;
- bool mIsComplete;
-
-public:
- GGLSurface surface;
- GLenum wraps;
- GLenum wrapt;
- GLenum min_filter;
- GLenum mag_filter;
- GLenum internalformat;
- GLint crop_rect[4];
- GLint generate_mipmap;
- GLint direct;
- ANativeWindowBuffer* buffer;
-};
-
-// ----------------------------------------------------------------------------
-
-class EGLSurfaceManager :
- public LightRefBase<EGLSurfaceManager>,
- public TokenManager
-{
-public:
- EGLSurfaceManager();
- ~EGLSurfaceManager();
-
- sp<EGLTextureObject> createTexture(GLuint name);
- sp<EGLTextureObject> removeTexture(GLuint name);
- sp<EGLTextureObject> replaceTexture(GLuint name);
- void deleteTextures(GLsizei n, const GLuint *tokens);
- sp<EGLTextureObject> texture(GLuint name);
-
-private:
- mutable Mutex mLock;
- KeyedVector< GLuint, sp<EGLTextureObject> > mTextures;
-};
-
-// ----------------------------------------------------------------------------
-}; // namespace android
-
-#endif // ANDROID_OPENGLES_SURFACE_H
-
diff --git a/opengl/libagl/TokenManager.cpp b/opengl/libagl/TokenManager.cpp
deleted file mode 100644
index eea6025..0000000
--- a/opengl/libagl/TokenManager.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-/* libs/opengles/surface.cpp
-**
-** Copyright 2006, 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 <stdio.h>
-#include <stdlib.h>
-#include "TokenManager.h"
-
-namespace android {
-// ----------------------------------------------------------------------------
-
-TokenManager::TokenManager()
-{
- // token 0 is always reserved
- mTokenizer.reserve(0);
-}
-
-TokenManager::~TokenManager()
-{
-}
-
-status_t TokenManager::getToken(GLsizei n, GLuint *tokens)
-{
- Mutex::Autolock _l(mLock);
- for (GLsizei i=0 ; i<n ; i++)
- *tokens++ = mTokenizer.acquire();
- return NO_ERROR;
-}
-
-void TokenManager::recycleTokens(GLsizei n, const GLuint *tokens)
-{
- Mutex::Autolock _l(mLock);
- for (int i=0 ; i<n ; i++) {
- const GLuint token = *tokens++;
- if (token) {
- mTokenizer.release(token);
- }
- }
-}
-
-bool TokenManager::isTokenValid(GLuint token) const
-{
- Mutex::Autolock _l(mLock);
- return mTokenizer.isAcquired(token);
-}
-
-// ----------------------------------------------------------------------------
-}; // namespace android
-
diff --git a/opengl/libagl/TokenManager.h b/opengl/libagl/TokenManager.h
deleted file mode 100644
index 49c1469..0000000
--- a/opengl/libagl/TokenManager.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
-** Copyright 2006, 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.
-*/
-
-#ifndef ANDROID_OPENGLES_TOKEN_MANAGER_H
-#define ANDROID_OPENGLES_TOKEN_MANAGER_H
-
-#include <stdint.h>
-#include <stddef.h>
-#include <sys/types.h>
-
-#include <utils/threads.h>
-
-#include <GLES/gl.h>
-
-#include "Tokenizer.h"
-
-namespace android {
-
-// ----------------------------------------------------------------------------
-
-class TokenManager
-{
-public:
- TokenManager();
- ~TokenManager();
-
- status_t getToken(GLsizei n, GLuint *tokens);
- void recycleTokens(GLsizei n, const GLuint *tokens);
- bool isTokenValid(GLuint token) const;
-
-private:
- mutable Mutex mLock;
- Tokenizer mTokenizer;
-};
-
-// ----------------------------------------------------------------------------
-}; // namespace android
-
-#endif // ANDROID_OPENGLES_TOKEN_MANAGER_H
-
diff --git a/opengl/libagl/Tokenizer.cpp b/opengl/libagl/Tokenizer.cpp
deleted file mode 100644
index ac0a48c..0000000
--- a/opengl/libagl/Tokenizer.cpp
+++ /dev/null
@@ -1,173 +0,0 @@
-/* libs/opengles/Tokenizer.cpp
-**
-** Copyright 2006, 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 <stdio.h>
-
-#include "Tokenizer.h"
-
-// ----------------------------------------------------------------------------
-
-namespace android {
-
-ANDROID_BASIC_TYPES_TRAITS(Tokenizer::run_t)
-
-Tokenizer::Tokenizer()
-{
-}
-
-Tokenizer::Tokenizer(const Tokenizer& other)
- : mRanges(other.mRanges)
-{
-}
-
-Tokenizer::~Tokenizer()
-{
-}
-
-uint32_t Tokenizer::acquire()
-{
- if (!mRanges.size() || mRanges[0].first) {
- _insertTokenAt(0,0);
- return 0;
- }
-
- // just extend the first run
- const run_t& run = mRanges[0];
- uint32_t token = run.first + run.length;
- _insertTokenAt(token, 1);
- return token;
-}
-
-bool Tokenizer::isAcquired(uint32_t token) const
-{
- return (_indexOrderOf(token) >= 0);
-}
-
-status_t Tokenizer::reserve(uint32_t token)
-{
- size_t o;
- const ssize_t i = _indexOrderOf(token, &o);
- if (i >= 0) {
- return BAD_VALUE; // this token is already taken
- }
- ssize_t err = _insertTokenAt(token, o);
- return (err<0) ? err : status_t(NO_ERROR);
-}
-
-status_t Tokenizer::release(uint32_t token)
-{
- const ssize_t i = _indexOrderOf(token);
- if (i >= 0) {
- const run_t& run = mRanges[i];
- if ((token >= run.first) && (token < run.first+run.length)) {
- // token in this range, we need to split
- run_t& run = mRanges.editItemAt(i);
- if ((token == run.first) || (token == run.first+run.length-1)) {
- if (token == run.first) {
- run.first += 1;
- }
- run.length -= 1;
- if (run.length == 0) {
- // XXX: should we systematically remove a run that's empty?
- mRanges.removeItemsAt(i);
- }
- } else {
- // split the run
- run_t new_run;
- new_run.first = token+1;
- new_run.length = run.first+run.length - new_run.first;
- run.length = token - run.first;
- mRanges.insertAt(new_run, i+1);
- }
- return NO_ERROR;
- }
- }
- return NAME_NOT_FOUND;
-}
-
-ssize_t Tokenizer::_indexOrderOf(uint32_t token, size_t* order) const
-{
- // binary search
- ssize_t err = NAME_NOT_FOUND;
- ssize_t l = 0;
- ssize_t h = mRanges.size()-1;
- ssize_t mid;
- const run_t* a = mRanges.array();
- while (l <= h) {
- mid = l + (h - l)/2;
- const run_t* const curr = a + mid;
- int c = 0;
- if (token < curr->first) c = 1;
- else if (token >= curr->first+curr->length) c = -1;
- if (c == 0) {
- err = l = mid;
- break;
- } else if (c < 0) {
- l = mid + 1;
- } else {
- h = mid - 1;
- }
- }
- if (order) *order = l;
- return err;
-}
-
-ssize_t Tokenizer::_insertTokenAt(uint32_t token, size_t index)
-{
- const size_t c = mRanges.size();
-
- if (index >= 1) {
- // do we need to merge with the previous run?
- run_t& p = mRanges.editItemAt(index-1);
- if (p.first+p.length == token) {
- p.length += 1;
- if (index < c) {
- const run_t& n = mRanges[index];
- if (token+1 == n.first) {
- p.length += n.length;
- mRanges.removeItemsAt(index);
- }
- }
- return index;
- }
- }
-
- if (index < c) {
- // do we need to merge with the next run?
- run_t& n = mRanges.editItemAt(index);
- if (token+1 == n.first) {
- n.first -= 1;
- n.length += 1;
- return index;
- }
- }
-
- return mRanges.insertAt(run_t(token,1), index);
-}
-
-void Tokenizer::dump() const
-{
- const run_t* ranges = mRanges.array();
- const size_t c = mRanges.size();
- ALOGD("Tokenizer (%p, size = %zu)\n", this, c);
- for (size_t i=0 ; i<c ; i++) {
- ALOGD("%zu: (%u, %u)\n", i, ranges[i].first, ranges[i].length);
- }
-}
-
-}; // namespace android
-
diff --git a/opengl/libagl/Tokenizer.h b/opengl/libagl/Tokenizer.h
deleted file mode 100644
index ac555cb..0000000
--- a/opengl/libagl/Tokenizer.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/* libs/opengles/Tokenizer.h
-**
-** Copyright 2006, 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.
-*/
-
-
-#ifndef ANDROID_OPENGLES_TOKENIZER_H
-#define ANDROID_OPENGLES_TOKENIZER_H
-
-#include <utils/Vector.h>
-#include <utils/Errors.h>
-
-// ----------------------------------------------------------------------------
-
-namespace android {
-
-class Tokenizer
-{
-public:
- Tokenizer();
- Tokenizer(const Tokenizer& other);
- ~Tokenizer();
-
- uint32_t acquire();
- status_t reserve(uint32_t token);
- status_t release(uint32_t token);
- bool isAcquired(uint32_t token) const;
-
- void dump() const;
-
- struct run_t {
- run_t() {};
- run_t(uint32_t f, uint32_t l) : first(f), length(l) {}
- uint32_t first;
- uint32_t length;
- };
-private:
- ssize_t _indexOrderOf(uint32_t token, size_t* order=0) const;
- ssize_t _insertTokenAt(uint32_t token, size_t index);
- Vector<run_t> mRanges;
-};
-
-}; // namespace android
-
-// ----------------------------------------------------------------------------
-
-#endif // ANDROID_OPENGLES_TOKENIZER_H
diff --git a/opengl/libagl/arch-mips/fixed_asm.S b/opengl/libagl/arch-mips/fixed_asm.S
deleted file mode 100644
index a30ffc5..0000000
--- a/opengl/libagl/arch-mips/fixed_asm.S
+++ /dev/null
@@ -1,61 +0,0 @@
-/* libs/opengles/arch-mips/fixed_asm.S
-**
-** Copyright 2012, 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.
-*/
-
-
- .text
- .align 4
-
-/*
- * this version rounds-to-nearest and saturates numbers
- * outside the range (but not NaNs).
- */
-
- .global gglFloatToFixed
- .ent gglFloatToFixed
- .type gglFloatToFixed, @function
-gglFloatToFixed:
-#if !defined(__mips_soft_float)
- mfc1 $a0,$f12
-#endif
- srl $t0,$a0,31 /* t0 <- sign bit */
- srl $t1,$a0,23
- andi $t1,$t1,0xff /* get the e */
- li $t2,0x8e
- subu $t1,$t2,$t1 /* t1=127+15-e */
- blez $t1,0f /* t1<=0? */
- sll $t2,$a0,8 /* mantissa<<8 */
- lui $t3,0x8000
- or $t2,$t2,$t3 /* add the missing 1 */
- subu $t1,$t1,1
- srl $v0,$t2,$t1
- sltiu $t3,$t1,32 /* t3=1 if t1<32, else t3=0. t1>=32 means the float value is too small. */
- andi $t4,$v0,0x1
- srl $v0,$v0,1 /* scale to 16.16 */
- addu $v0,$v0,$t4 /* round-to-nearest */
- subu $t2,$zero,$v0
- movn $v0,$t2,$t0 /* if negative? */
- or $t1,$a0,$zero /* a0=0? */
- movz $v0,$zero,$t1
- movz $v0,$zero,$t3 /* t3=0 then res=0 */
- jr $ra
-0:
- lui $t1,0x8000
- and $v0,$a0,$t1 /* keep only the sign bit */
- li $t1,0x7fffffff
- movz $v0,$t1,$t0 /* positive, maximum value */
- jr $ra
- .end gglFloatToFixed
diff --git a/opengl/libagl/array.cpp b/opengl/libagl/array.cpp
deleted file mode 100644
index 2d36c61..0000000
--- a/opengl/libagl/array.cpp
+++ /dev/null
@@ -1,1590 +0,0 @@
-/*
-** Copyright 2006, 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 <stdlib.h>
-#include <stdio.h>
-
-#include "context.h"
-#include "fp.h"
-#include "state.h"
-#include "matrix.h"
-#include "vertex.h"
-#include "light.h"
-#include "primitives.h"
-#include "texture.h"
-#include "BufferObjectManager.h"
-
-// ----------------------------------------------------------------------------
-
-#define VC_CACHE_STATISTICS 0
-#define VC_CACHE_TYPE_NONE 0
-#define VC_CACHE_TYPE_INDEXED 1
-#define VC_CACHE_TYPE_LRU 2
-#define VC_CACHE_TYPE VC_CACHE_TYPE_INDEXED
-
-#if VC_CACHE_STATISTICS
-#include <utils/Timers.h>
-#endif
-
-// ----------------------------------------------------------------------------
-
-namespace android {
-
-static void validate_arrays(ogles_context_t* c, GLenum mode);
-
-static void compileElements__generic(ogles_context_t*,
- vertex_t*, GLint, GLsizei);
-static void compileElement__generic(ogles_context_t*,
- vertex_t*, GLint);
-
-static void drawPrimitivesPoints(ogles_context_t*, GLint, GLsizei);
-static void drawPrimitivesLineStrip(ogles_context_t*, GLint, GLsizei);
-static void drawPrimitivesLineLoop(ogles_context_t*, GLint, GLsizei);
-static void drawPrimitivesLines(ogles_context_t*, GLint, GLsizei);
-static void drawPrimitivesTriangleStrip(ogles_context_t*, GLint, GLsizei);
-static void drawPrimitivesTriangleFan(ogles_context_t*, GLint, GLsizei);
-static void drawPrimitivesTriangles(ogles_context_t*, GLint, GLsizei);
-
-static void drawIndexedPrimitivesPoints(ogles_context_t*,
- GLsizei, const GLvoid*);
-static void drawIndexedPrimitivesLineStrip(ogles_context_t*,
- GLsizei, const GLvoid*);
-static void drawIndexedPrimitivesLineLoop(ogles_context_t*,
- GLsizei, const GLvoid*);
-static void drawIndexedPrimitivesLines(ogles_context_t*,
- GLsizei, const GLvoid*);
-static void drawIndexedPrimitivesTriangleStrip(ogles_context_t*,
- GLsizei, const GLvoid*);
-static void drawIndexedPrimitivesTriangleFan(ogles_context_t*,
- GLsizei, const GLvoid*);
-static void drawIndexedPrimitivesTriangles(ogles_context_t*,
- GLsizei, const GLvoid*);
-
-// ----------------------------------------------------------------------------
-
-typedef void (*arrays_prims_fct_t)(ogles_context_t*, GLint, GLsizei);
-static const arrays_prims_fct_t drawArraysPrims[] = {
- drawPrimitivesPoints,
- drawPrimitivesLines,
- drawPrimitivesLineLoop,
- drawPrimitivesLineStrip,
- drawPrimitivesTriangles,
- drawPrimitivesTriangleStrip,
- drawPrimitivesTriangleFan
-};
-
-typedef void (*elements_prims_fct_t)(ogles_context_t*, GLsizei, const GLvoid*);
-static const elements_prims_fct_t drawElementsPrims[] = {
- drawIndexedPrimitivesPoints,
- drawIndexedPrimitivesLines,
- drawIndexedPrimitivesLineLoop,
- drawIndexedPrimitivesLineStrip,
- drawIndexedPrimitivesTriangles,
- drawIndexedPrimitivesTriangleStrip,
- drawIndexedPrimitivesTriangleFan
-};
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#endif
-
-void ogles_init_array(ogles_context_t* c)
-{
- c->arrays.vertex.size = 4;
- c->arrays.vertex.type = GL_FLOAT;
- c->arrays.color.size = 4;
- c->arrays.color.type = GL_FLOAT;
- c->arrays.normal.size = 4;
- c->arrays.normal.type = GL_FLOAT;
- for (int i=0 ; i<GGL_TEXTURE_UNIT_COUNT ; i++) {
- c->arrays.texture[i].size = 4;
- c->arrays.texture[i].type = GL_FLOAT;
- }
- c->vc.init();
-
- if (!c->vc.vBuffer) {
- // this could have failed
- ogles_error(c, GL_OUT_OF_MEMORY);
- }
-}
-
-void ogles_uninit_array(ogles_context_t* c)
-{
- c->vc.uninit();
-}
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#pragma mark Array fetchers
-#endif
-
-static void currentColor(ogles_context_t* c, GLfixed* v, const GLvoid*) {
- memcpy(v, c->current.color.v, sizeof(vec4_t));
-}
-static void currentNormal(ogles_context_t* c, GLfixed* v, const GLvoid*) {
- memcpy(v, c->currentNormal.v, sizeof(vec3_t));
-}
-static void currentTexCoord(ogles_context_t* c, GLfixed* v, const GLvoid*) {
- memcpy(v, c->current.texture[c->arrays.tmu].v, sizeof(vec4_t));
-}
-
-
-static void fetchNop(ogles_context_t*, GLfixed*, const GLvoid*) {
-}
-static void fetch2b(ogles_context_t*, GLfixed* v, const GLbyte* p) {
- v[0] = gglIntToFixed(p[0]);
- v[1] = gglIntToFixed(p[1]);
-}
-static void fetch2s(ogles_context_t*, GLfixed* v, const GLshort* p) {
- v[0] = gglIntToFixed(p[0]);
- v[1] = gglIntToFixed(p[1]);
-}
-static void fetch2x(ogles_context_t*, GLfixed* v, const GLfixed* p) {
- memcpy(v, p, 2*sizeof(GLfixed));
-}
-static void fetch2f(ogles_context_t*, GLfixed* v, const GLfloat* p) {
- v[0] = gglFloatToFixed(p[0]);
- v[1] = gglFloatToFixed(p[1]);
-}
-static void fetch3b(ogles_context_t*, GLfixed* v, const GLbyte* p) {
- v[0] = gglIntToFixed(p[0]);
- v[1] = gglIntToFixed(p[1]);
- v[2] = gglIntToFixed(p[2]);
-}
-static void fetch3s(ogles_context_t*, GLfixed* v, const GLshort* p) {
- v[0] = gglIntToFixed(p[0]);
- v[1] = gglIntToFixed(p[1]);
- v[2] = gglIntToFixed(p[2]);
-}
-static void fetch3x(ogles_context_t*, GLfixed* v, const GLfixed* p) {
- memcpy(v, p, 3*sizeof(GLfixed));
-}
-static void fetch3f(ogles_context_t*, GLfixed* v, const GLfloat* p) {
- v[0] = gglFloatToFixed(p[0]);
- v[1] = gglFloatToFixed(p[1]);
- v[2] = gglFloatToFixed(p[2]);
-}
-static void fetch4b(ogles_context_t*, GLfixed* v, const GLbyte* p) {
- v[0] = gglIntToFixed(p[0]);
- v[1] = gglIntToFixed(p[1]);
- v[2] = gglIntToFixed(p[2]);
- v[3] = gglIntToFixed(p[3]);
-}
-static void fetch4s(ogles_context_t*, GLfixed* v, const GLshort* p) {
- v[0] = gglIntToFixed(p[0]);
- v[1] = gglIntToFixed(p[1]);
- v[2] = gglIntToFixed(p[2]);
- v[3] = gglIntToFixed(p[3]);
-}
-static void fetch4x(ogles_context_t*, GLfixed* v, const GLfixed* p) {
- memcpy(v, p, 4*sizeof(GLfixed));
-}
-static void fetch4f(ogles_context_t*, GLfixed* v, const GLfloat* p) {
- v[0] = gglFloatToFixed(p[0]);
- v[1] = gglFloatToFixed(p[1]);
- v[2] = gglFloatToFixed(p[2]);
- v[3] = gglFloatToFixed(p[3]);
-}
-static void fetchExpand4ub(ogles_context_t*, GLfixed* v, const GLubyte* p) {
- v[0] = GGL_UB_TO_X(p[0]);
- v[1] = GGL_UB_TO_X(p[1]);
- v[2] = GGL_UB_TO_X(p[2]);
- v[3] = GGL_UB_TO_X(p[3]);
-}
-static void fetchClamp4x(ogles_context_t*, GLfixed* v, const GLfixed* p) {
- v[0] = gglClampx(p[0]);
- v[1] = gglClampx(p[1]);
- v[2] = gglClampx(p[2]);
- v[3] = gglClampx(p[3]);
-}
-static void fetchClamp4f(ogles_context_t*, GLfixed* v, const GLfloat* p) {
- v[0] = gglClampx(gglFloatToFixed(p[0]));
- v[1] = gglClampx(gglFloatToFixed(p[1]));
- v[2] = gglClampx(gglFloatToFixed(p[2]));
- v[3] = gglClampx(gglFloatToFixed(p[3]));
-}
-static void fetchExpand3ub(ogles_context_t*, GLfixed* v, const GLubyte* p) {
- v[0] = GGL_UB_TO_X(p[0]);
- v[1] = GGL_UB_TO_X(p[1]);
- v[2] = GGL_UB_TO_X(p[2]);
- v[3] = 0x10000;
-}
-static void fetchClamp3x(ogles_context_t*, GLfixed* v, const GLfixed* p) {
- v[0] = gglClampx(p[0]);
- v[1] = gglClampx(p[1]);
- v[2] = gglClampx(p[2]);
- v[3] = 0x10000;
-}
-static void fetchClamp3f(ogles_context_t*, GLfixed* v, const GLfloat* p) {
- v[0] = gglClampx(gglFloatToFixed(p[0]));
- v[1] = gglClampx(gglFloatToFixed(p[1]));
- v[2] = gglClampx(gglFloatToFixed(p[2]));
- v[3] = 0x10000;
-}
-static void fetchExpand3b(ogles_context_t*, GLfixed* v, const GLbyte* p) {
- v[0] = GGL_B_TO_X(p[0]);
- v[1] = GGL_B_TO_X(p[1]);
- v[2] = GGL_B_TO_X(p[2]);
-}
-static void fetchExpand3s(ogles_context_t*, GLfixed* v, const GLshort* p) {
- v[0] = GGL_S_TO_X(p[0]);
- v[1] = GGL_S_TO_X(p[1]);
- v[2] = GGL_S_TO_X(p[2]);
-}
-
-typedef array_t::fetcher_t fn_t;
-
-static const fn_t color_fct[2][16] = { // size={3,4}, type={ub,f,x}
- { 0, (fn_t)fetchExpand3ub, 0, 0, 0, 0,
- (fn_t)fetch3f, 0, 0, 0, 0, 0,
- (fn_t)fetch3x },
- { 0, (fn_t)fetchExpand4ub, 0, 0, 0, 0,
- (fn_t)fetch4f, 0, 0, 0, 0, 0,
- (fn_t)fetch4x },
-};
-static const fn_t color_clamp_fct[2][16] = { // size={3,4}, type={ub,f,x}
- { 0, (fn_t)fetchExpand3ub, 0, 0, 0, 0,
- (fn_t)fetchClamp3f, 0, 0, 0, 0, 0,
- (fn_t)fetchClamp3x },
- { 0, (fn_t)fetchExpand4ub, 0, 0, 0, 0,
- (fn_t)fetchClamp4f, 0, 0, 0, 0, 0,
- (fn_t)fetchClamp4x },
-};
-static const fn_t normal_fct[1][16] = { // size={3}, type={b,s,f,x}
- { (fn_t)fetchExpand3b, 0,
- (fn_t)fetchExpand3s, 0, 0, 0,
- (fn_t)fetch3f, 0, 0, 0, 0, 0,
- (fn_t)fetch3x },
-};
-static const fn_t vertex_fct[3][16] = { // size={2,3,4}, type={b,s,f,x}
- { (fn_t)fetch2b, 0,
- (fn_t)fetch2s, 0, 0, 0,
- (fn_t)fetch2f, 0, 0, 0, 0, 0,
- (fn_t)fetch3x },
- { (fn_t)fetch3b, 0,
- (fn_t)fetch3s, 0, 0, 0,
- (fn_t)fetch3f, 0, 0, 0, 0, 0,
- (fn_t)fetch3x },
- { (fn_t)fetch4b, 0,
- (fn_t)fetch4s, 0, 0, 0,
- (fn_t)fetch4f, 0, 0, 0, 0, 0,
- (fn_t)fetch4x }
-};
-static const fn_t texture_fct[3][16] = { // size={2,3,4}, type={b,s,f,x}
- { (fn_t)fetch2b, 0,
- (fn_t)fetch2s, 0, 0, 0,
- (fn_t)fetch2f, 0, 0, 0, 0, 0,
- (fn_t)fetch2x },
- { (fn_t)fetch3b, 0,
- (fn_t)fetch3s, 0, 0, 0,
- (fn_t)fetch3f, 0, 0, 0, 0, 0,
- (fn_t)fetch3x },
- { (fn_t)fetch4b, 0,
- (fn_t)fetch4s, 0, 0, 0,
- (fn_t)fetch4f, 0, 0, 0, 0, 0,
- (fn_t)fetch4x }
-};
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#pragma mark array_t
-#endif
-
-void array_t::init(
- GLint size, GLenum type, GLsizei stride,
- const GLvoid *pointer, const buffer_t* bo, GLsizei count)
-{
- if (!stride) {
- stride = size;
- switch (type) {
- case GL_SHORT:
- case GL_UNSIGNED_SHORT:
- stride *= 2;
- break;
- case GL_FLOAT:
- case GL_FIXED:
- stride *= 4;
- break;
- }
- }
- this->size = size;
- this->type = type;
- this->stride = stride;
- this->pointer = pointer;
- this->bo = bo;
- this->bounds = count;
-}
-
-inline void array_t::resolve()
-{
- physical_pointer = (bo) ? (bo->data + uintptr_t(pointer)) : pointer;
-}
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#pragma mark vertex_cache_t
-#endif
-
-void vertex_cache_t::init()
-{
- // make sure the size of vertex_t allows cache-line alignment
- CTA<(sizeof(vertex_t) & 0x1F) == 0> assertAlignedSize;
- (void)assertAlignedSize; // suppress unused warning.
-
- const int align = 32;
- const size_t s = VERTEX_BUFFER_SIZE + VERTEX_CACHE_SIZE;
- const size_t size = s*sizeof(vertex_t) + align;
- base = malloc(size);
- if (base) {
- memset(base, 0, size);
- vBuffer = (vertex_t*)((size_t(base) + align - 1) & ~(align-1));
- vCache = vBuffer + VERTEX_BUFFER_SIZE;
- sequence = 0;
- }
-}
-
-void vertex_cache_t::uninit()
-{
- free(base);
- base = vBuffer = vCache = 0;
-}
-
-void vertex_cache_t::clear()
-{
-#if VC_CACHE_STATISTICS
- startTime = systemTime(SYSTEM_TIME_THREAD);
- total = 0;
- misses = 0;
-#endif
-
-#if VC_CACHE_TYPE == VC_CACHE_TYPE_LRU
- vertex_t* v = vBuffer;
- size_t count = VERTEX_BUFFER_SIZE + VERTEX_CACHE_SIZE;
- do {
- v->mru = 0;
- v++;
- } while (--count);
-#endif
-
- sequence += INDEX_SEQ;
- if (sequence >= 0x80000000LU) {
- sequence = INDEX_SEQ;
- vertex_t* v = vBuffer;
- size_t count = VERTEX_BUFFER_SIZE + VERTEX_CACHE_SIZE;
- do {
- v->index = 0;
- v++;
- } while (--count);
- }
-}
-
-#if VC_CACHE_STATISTICS
-void vertex_cache_t::dump_stats(GLenum mode)
-{
- nsecs_t time = systemTime(SYSTEM_TIME_THREAD) - startTime;
- uint32_t hits = total - misses;
- uint32_t prim_count;
- switch (mode) {
- case GL_POINTS: prim_count = total; break;
- case GL_LINE_STRIP: prim_count = total - 1; break;
- case GL_LINE_LOOP: prim_count = total - 1; break;
- case GL_LINES: prim_count = total / 2; break;
- case GL_TRIANGLE_STRIP: prim_count = total - 2; break;
- case GL_TRIANGLE_FAN: prim_count = total - 2; break;
- case GL_TRIANGLES: prim_count = total / 3; break;
- default: return;
- }
- printf( "total=%5u, hits=%5u, miss=%5u, hitrate=%3u%%,"
- " prims=%5u, time=%6u us, prims/s=%d, v/t=%f\n",
- total, hits, misses, (hits*100)/total,
- prim_count, int(ns2us(time)), int(prim_count*float(seconds(1))/time),
- float(misses) / prim_count);
-}
-#else
-void vertex_cache_t::dump_stats(GLenum /*mode*/)
-{
-}
-#endif
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#endif
-
-static __attribute__((noinline))
-void enableDisableClientState(ogles_context_t* c, GLenum array, bool enable)
-{
- const int tmu = c->arrays.activeTexture;
- array_t* a;
- switch (array) {
- case GL_COLOR_ARRAY: a = &c->arrays.color; break;
- case GL_NORMAL_ARRAY: a = &c->arrays.normal; break;
- case GL_TEXTURE_COORD_ARRAY: a = &c->arrays.texture[tmu]; break;
- case GL_VERTEX_ARRAY: a = &c->arrays.vertex; break;
- default:
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- a->enable = enable ? GL_TRUE : GL_FALSE;
-}
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#pragma mark Vertex Cache
-#endif
-
-static __attribute__((noinline))
-vertex_t* cache_vertex(ogles_context_t* c, vertex_t* v, uint32_t index)
-{
- #if VC_CACHE_STATISTICS
- c->vc.misses++;
- #endif
- if (ggl_unlikely(v->locked)) {
- // we're just looking for an entry in the cache that is not locked.
- // and we know that there cannot be more than 2 locked entries
- // because a triangle needs at most 3 vertices.
- // We never use the first and second entries because they might be in
- // use by the striper or faner. Any other entry will do as long as
- // it's not locked.
- // We compute directly the index of a "free" entry from the locked
- // state of v[2] and v[3].
- v = c->vc.vBuffer + 2;
- v += v[0].locked | (v[1].locked<<1);
- }
- // note: compileElement clears v->flags
- c->arrays.compileElement(c, v, index);
- v->locked = 1;
- return v;
-}
-
-static __attribute__((noinline))
-vertex_t* fetch_vertex(ogles_context_t* c, size_t index)
-{
- index |= c->vc.sequence;
-
-#if VC_CACHE_TYPE == VC_CACHE_TYPE_INDEXED
-
- vertex_t* const v = c->vc.vCache +
- (index & (vertex_cache_t::VERTEX_CACHE_SIZE-1));
-
- if (ggl_likely(v->index == index)) {
- v->locked = 1;
- return v;
- }
- return cache_vertex(c, v, index);
-
-#elif VC_CACHE_TYPE == VC_CACHE_TYPE_LRU
-
- vertex_t* v = c->vc.vCache +
- (index & ((vertex_cache_t::VERTEX_CACHE_SIZE-1)>>1))*2;
-
- // always record LRU in v[0]
- if (ggl_likely(v[0].index == index)) {
- v[0].locked = 1;
- v[0].mru = 0;
- return &v[0];
- }
-
- if (ggl_likely(v[1].index == index)) {
- v[1].locked = 1;
- v[0].mru = 1;
- return &v[1];
- }
-
- const int lru = 1 - v[0].mru;
- v[0].mru = lru;
- return cache_vertex(c, &v[lru], index);
-
-#elif VC_CACHE_TYPE == VC_CACHE_TYPE_NONE
-
- // just for debugging...
- vertex_t* v = c->vc.vBuffer + 2;
- return cache_vertex(c, v, index);
-
-#endif
-}
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#pragma mark Primitive Assembly
-#endif
-
-void drawPrimitivesPoints(ogles_context_t* c, GLint first, GLsizei count)
-{
- if (ggl_unlikely(count < 1))
- return;
-
- // vertex cache size must be multiple of 1
- const GLsizei vcs =
- (vertex_cache_t::VERTEX_BUFFER_SIZE +
- vertex_cache_t::VERTEX_CACHE_SIZE);
- do {
- vertex_t* v = c->vc.vBuffer;
- GLsizei num = count > vcs ? vcs : count;
- c->arrays.cull = vertex_t::CLIP_ALL;
- c->arrays.compileElements(c, v, first, num);
- first += num;
- count -= num;
- if (!c->arrays.cull) {
- // quick/trivial reject of the whole batch
- do {
- const uint32_t cc = v[0].flags;
- if (ggl_likely(!(cc & vertex_t::CLIP_ALL)))
- c->prims.renderPoint(c, v);
- v++;
- num--;
- } while (num);
- }
- } while (count);
-}
-
-// ----------------------------------------------------------------------------
-
-void drawPrimitivesLineStrip(ogles_context_t* c, GLint first, GLsizei count)
-{
- if (ggl_unlikely(count < 2))
- return;
-
- vertex_t *v, *v0, *v1;
- c->arrays.cull = vertex_t::CLIP_ALL;
- c->arrays.compileElement(c, c->vc.vBuffer, first);
- first += 1;
- count -= 1;
-
- // vertex cache size must be multiple of 1
- const GLsizei vcs =
- (vertex_cache_t::VERTEX_BUFFER_SIZE +
- vertex_cache_t::VERTEX_CACHE_SIZE - 1);
- do {
- v0 = c->vc.vBuffer + 0;
- v = c->vc.vBuffer + 1;
- GLsizei num = count > vcs ? vcs : count;
- c->arrays.compileElements(c, v, first, num);
- first += num;
- count -= num;
- if (!c->arrays.cull) {
- // quick/trivial reject of the whole batch
- do {
- v1 = v++;
- const uint32_t cc = v0->flags & v1->flags;
- if (ggl_likely(!(cc & vertex_t::CLIP_ALL)))
- c->prims.renderLine(c, v0, v1);
- v0 = v1;
- num--;
- } while (num);
- }
- // copy back the last processed vertex
- c->vc.vBuffer[0] = *v0;
- c->arrays.cull = v0->flags & vertex_t::CLIP_ALL;
- } while (count);
-}
-
-void drawPrimitivesLineLoop(ogles_context_t* c, GLint first, GLsizei count)
-{
- if (ggl_unlikely(count < 2))
- return;
- drawPrimitivesLineStrip(c, first, count);
- if (ggl_likely(count >= 3)) {
- vertex_t* v0 = c->vc.vBuffer;
- vertex_t* v1 = c->vc.vBuffer + 1;
- c->arrays.compileElement(c, v1, first);
- const uint32_t cc = v0->flags & v1->flags;
- if (ggl_likely(!(cc & vertex_t::CLIP_ALL)))
- c->prims.renderLine(c, v0, v1);
- }
-}
-
-void drawPrimitivesLines(ogles_context_t* c, GLint first, GLsizei count)
-{
- if (ggl_unlikely(count < 2))
- return;
-
- // vertex cache size must be multiple of 2
- const GLsizei vcs =
- ((vertex_cache_t::VERTEX_BUFFER_SIZE +
- vertex_cache_t::VERTEX_CACHE_SIZE) / 2) * 2;
- do {
- vertex_t* v = c->vc.vBuffer;
- GLsizei num = count > vcs ? vcs : count;
- c->arrays.cull = vertex_t::CLIP_ALL;
- c->arrays.compileElements(c, v, first, num);
- first += num;
- count -= num;
- if (!c->arrays.cull) {
- // quick/trivial reject of the whole batch
- num -= 2;
- do {
- const uint32_t cc = v[0].flags & v[1].flags;
- if (ggl_likely(!(cc & vertex_t::CLIP_ALL)))
- c->prims.renderLine(c, v, v+1);
- v += 2;
- num -= 2;
- } while (num >= 0);
- }
- } while (count >= 2);
-}
-
-// ----------------------------------------------------------------------------
-
-static void drawPrimitivesTriangleFanOrStrip(ogles_context_t* c,
- GLint first, GLsizei count, int winding)
-{
- // winding == 2 : fan
- // winding == 1 : strip
-
- if (ggl_unlikely(count < 3))
- return;
-
- vertex_t *v, *v0, *v1, *v2;
- c->arrays.cull = vertex_t::CLIP_ALL;
- c->arrays.compileElements(c, c->vc.vBuffer, first, 2);
- first += 2;
- count -= 2;
-
- // vertex cache size must be multiple of 2. This is extremely important
- // because it allows us to preserve the same winding when the whole
- // batch is culled. We also need 2 extra vertices in the array, because
- // we always keep the two first ones.
- const GLsizei vcs =
- ((vertex_cache_t::VERTEX_BUFFER_SIZE +
- vertex_cache_t::VERTEX_CACHE_SIZE - 2) / 2) * 2;
- do {
- v0 = c->vc.vBuffer + 0;
- v1 = c->vc.vBuffer + 1;
- v = c->vc.vBuffer + 2;
- GLsizei num = count > vcs ? vcs : count;
- c->arrays.compileElements(c, v, first, num);
- first += num;
- count -= num;
- if (!c->arrays.cull) {
- // quick/trivial reject of the whole batch
- do {
- v2 = v++;
- const uint32_t cc = v0->flags & v1->flags & v2->flags;
- if (ggl_likely(!(cc & vertex_t::CLIP_ALL)))
- c->prims.renderTriangle(c, v0, v1, v2);
- swap(((winding^=1) ? v1 : v0), v2);
- num--;
- } while (num);
- }
- if (count) {
- v0 = c->vc.vBuffer + 2 + vcs - 2;
- v1 = c->vc.vBuffer + 2 + vcs - 1;
- if ((winding&2) == 0) {
- // for strips copy back the two last compiled vertices
- c->vc.vBuffer[0] = *v0;
- }
- c->vc.vBuffer[1] = *v1;
- c->arrays.cull = v0->flags & v1->flags & vertex_t::CLIP_ALL;
- }
- } while (count > 0);
-}
-
-void drawPrimitivesTriangleStrip(ogles_context_t* c,
- GLint first, GLsizei count) {
- drawPrimitivesTriangleFanOrStrip(c, first, count, 1);
-}
-
-void drawPrimitivesTriangleFan(ogles_context_t* c,
- GLint first, GLsizei count) {
- drawPrimitivesTriangleFanOrStrip(c, first, count, 2);
-}
-
-void drawPrimitivesTriangles(ogles_context_t* c, GLint first, GLsizei count)
-{
- if (ggl_unlikely(count < 3))
- return;
-
- // vertex cache size must be multiple of 3
- const GLsizei vcs =
- ((vertex_cache_t::VERTEX_BUFFER_SIZE +
- vertex_cache_t::VERTEX_CACHE_SIZE) / 3) * 3;
- do {
- vertex_t* v = c->vc.vBuffer;
- GLsizei num = count > vcs ? vcs : count;
- c->arrays.cull = vertex_t::CLIP_ALL;
- c->arrays.compileElements(c, v, first, num);
- first += num;
- count -= num;
- if (!c->arrays.cull) {
- // quick/trivial reject of the whole batch
- num -= 3;
- do {
- const uint32_t cc = v[0].flags & v[1].flags & v[2].flags;
- if (ggl_likely(!(cc & vertex_t::CLIP_ALL)))
- c->prims.renderTriangle(c, v, v+1, v+2);
- v += 3;
- num -= 3;
- } while (num >= 0);
- }
- } while (count >= 3);
-}
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#endif
-
-// this looks goofy, but gcc does a great job with this...
-static inline unsigned int read_index(int type, const GLvoid*& p) {
- unsigned int r;
- if (type) {
- r = *(const GLubyte*)p;
- p = (const GLubyte*)p + 1;
- } else {
- r = *(const GLushort*)p;
- p = (const GLushort*)p + 1;
- }
- return r;
-}
-
-// ----------------------------------------------------------------------------
-
-void drawIndexedPrimitivesPoints(ogles_context_t* c,
- GLsizei count, const GLvoid *indices)
-{
- if (ggl_unlikely(count < 1))
- return;
- const int type = (c->arrays.indicesType == GL_UNSIGNED_BYTE);
- do {
- vertex_t * v = fetch_vertex(c, read_index(type, indices));
- if (ggl_likely(!(v->flags & vertex_t::CLIP_ALL)))
- c->prims.renderPoint(c, v);
- v->locked = 0;
- count--;
- } while(count);
-}
-
-// ----------------------------------------------------------------------------
-
-void drawIndexedPrimitivesLineStrip(ogles_context_t* c,
- GLsizei count, const GLvoid *indices)
-{
- if (ggl_unlikely(count < 2))
- return;
-
- vertex_t * const v = c->vc.vBuffer;
- vertex_t* v0 = v;
- vertex_t* v1;
-
- const int type = (c->arrays.indicesType == GL_UNSIGNED_BYTE);
- c->arrays.compileElement(c, v0, read_index(type, indices));
- count -= 1;
- do {
- v1 = fetch_vertex(c, read_index(type, indices));
- const uint32_t cc = v0->flags & v1->flags;
- if (ggl_likely(!(cc & vertex_t::CLIP_ALL)))
- c->prims.renderLine(c, v0, v1);
- v0->locked = 0;
- v0 = v1;
- count--;
- } while (count);
- v1->locked = 0;
-}
-
-void drawIndexedPrimitivesLineLoop(ogles_context_t* c,
- GLsizei count, const GLvoid *indices)
-{
- if (ggl_unlikely(count <= 2)) {
- drawIndexedPrimitivesLines(c, count, indices);
- return;
- }
-
- vertex_t * const v = c->vc.vBuffer;
- vertex_t* v0 = v;
- vertex_t* v1;
-
- const int type = (c->arrays.indicesType == GL_UNSIGNED_BYTE);
- c->arrays.compileElement(c, v0, read_index(type, indices));
- count -= 1;
- do {
- v1 = fetch_vertex(c, read_index(type, indices));
- const uint32_t cc = v0->flags & v1->flags;
- if (ggl_likely(!(cc & vertex_t::CLIP_ALL)))
- c->prims.renderLine(c, v0, v1);
- v0->locked = 0;
- v0 = v1;
- count--;
- } while (count);
- v1->locked = 0;
-
- v1 = c->vc.vBuffer;
- const uint32_t cc = v0->flags & v1->flags;
- if (ggl_likely(!(cc & vertex_t::CLIP_ALL)))
- c->prims.renderLine(c, v0, v1);
-}
-
-void drawIndexedPrimitivesLines(ogles_context_t* c,
- GLsizei count, const GLvoid *indices)
-{
- if (ggl_unlikely(count < 2))
- return;
-
- count -= 2;
- const int type = (c->arrays.indicesType == GL_UNSIGNED_BYTE);
- do {
- vertex_t* const v0 = fetch_vertex(c, read_index(type, indices));
- vertex_t* const v1 = fetch_vertex(c, read_index(type, indices));
- const uint32_t cc = v0->flags & v1->flags;
- if (ggl_likely(!(cc & vertex_t::CLIP_ALL)))
- c->prims.renderLine(c, v0, v1);
- v0->locked = 0;
- v1->locked = 0;
- count -= 2;
- } while (count >= 0);
-}
-
-// ----------------------------------------------------------------------------
-
-static void drawIndexedPrimitivesTriangleFanOrStrip(ogles_context_t* c,
- GLsizei count, const GLvoid *indices, int winding)
-{
- // winding == 2 : fan
- // winding == 1 : strip
-
- if (ggl_unlikely(count < 3))
- return;
-
- vertex_t * const v = c->vc.vBuffer;
- vertex_t* v0 = v;
- vertex_t* v1 = v+1;
- vertex_t* v2;
-
- const int type = (c->arrays.indicesType == GL_UNSIGNED_BYTE);
- c->arrays.compileElement(c, v0, read_index(type, indices));
- c->arrays.compileElement(c, v1, read_index(type, indices));
- count -= 2;
-
- // note: GCC 4.1.1 here makes a prety interesting optimization
- // where it duplicates the loop below based on c->arrays.indicesType
-
- do {
- v2 = fetch_vertex(c, read_index(type, indices));
- const uint32_t cc = v0->flags & v1->flags & v2->flags;
- if (ggl_likely(!(cc & vertex_t::CLIP_ALL)))
- c->prims.renderTriangle(c, v0, v1, v2);
- vertex_t* & consumed = ((winding^=1) ? v1 : v0);
- consumed->locked = 0;
- consumed = v2;
- count--;
- } while (count);
- v0->locked = v1->locked = 0;
- v2->locked = 0;
-}
-
-void drawIndexedPrimitivesTriangleStrip(ogles_context_t* c,
- GLsizei count, const GLvoid *indices) {
- drawIndexedPrimitivesTriangleFanOrStrip(c, count, indices, 1);
-}
-
-void drawIndexedPrimitivesTriangleFan(ogles_context_t* c,
- GLsizei count, const GLvoid *indices) {
- drawIndexedPrimitivesTriangleFanOrStrip(c, count, indices, 2);
-}
-
-void drawIndexedPrimitivesTriangles(ogles_context_t* c,
- GLsizei count, const GLvoid *indices)
-{
- if (ggl_unlikely(count < 3))
- return;
-
- count -= 3;
- if (ggl_likely(c->arrays.indicesType == GL_UNSIGNED_SHORT)) {
- // This case is probably our most common case...
- uint16_t const * p = (uint16_t const *)indices;
- do {
- vertex_t* const v0 = fetch_vertex(c, *p++);
- vertex_t* const v1 = fetch_vertex(c, *p++);
- vertex_t* const v2 = fetch_vertex(c, *p++);
- const uint32_t cc = v0->flags & v1->flags & v2->flags;
- if (ggl_likely(!(cc & vertex_t::CLIP_ALL)))
- c->prims.renderTriangle(c, v0, v1, v2);
- v0->locked = 0;
- v1->locked = 0;
- v2->locked = 0;
- count -= 3;
- } while (count >= 0);
- } else {
- uint8_t const * p = (uint8_t const *)indices;
- do {
- vertex_t* const v0 = fetch_vertex(c, *p++);
- vertex_t* const v1 = fetch_vertex(c, *p++);
- vertex_t* const v2 = fetch_vertex(c, *p++);
- const uint32_t cc = v0->flags & v1->flags & v2->flags;
- if (ggl_likely(!(cc & vertex_t::CLIP_ALL)))
- c->prims.renderTriangle(c, v0, v1, v2);
- v0->locked = 0;
- v1->locked = 0;
- v2->locked = 0;
- count -= 3;
- } while (count >= 0);
- }
-}
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#pragma mark Array compilers
-#endif
-
-void compileElement__generic(ogles_context_t* c,
- vertex_t* v, GLint first)
-{
- v->flags = 0;
- v->index = first;
- first &= vertex_cache_t::INDEX_MASK;
- const GLubyte* vp = c->arrays.vertex.element(first);
- v->obj.z = 0;
- v->obj.w = 0x10000;
- c->arrays.vertex.fetch(c, v->obj.v, vp);
- c->arrays.mvp_transform(&c->transforms.mvp, &v->clip, &v->obj);
- c->arrays.perspective(c, v);
-}
-
-void compileElements__generic(ogles_context_t* c,
- vertex_t* v, GLint first, GLsizei count)
-{
- const GLubyte* vp = c->arrays.vertex.element(
- first & vertex_cache_t::INDEX_MASK);
- const size_t stride = c->arrays.vertex.stride;
- transform_t const* const mvp = &c->transforms.mvp;
- do {
- v->flags = 0;
- v->index = first++;
- v->obj.z = 0;
- v->obj.w = 0x10000;
- c->arrays.vertex.fetch(c, v->obj.v, vp);
- c->arrays.mvp_transform(mvp, &v->clip, &v->obj);
- c->arrays.perspective(c, v);
- vp += stride;
- v++;
- } while (--count);
-}
-
-/*
-void compileElements__3x_full(ogles_context_t* c,
- vertex_t* v, GLint first, GLsizei count)
-{
- const GLfixed* vp = (const GLfixed*)c->arrays.vertex.element(first);
- const size_t stride = c->arrays.vertex.stride / 4;
-// const GLfixed* const& m = c->transforms.mvp.matrix.m;
-
- GLfixed m[16];
- memcpy(&m, c->transforms.mvp.matrix.m, sizeof(m));
-
- do {
- const GLfixed rx = vp[0];
- const GLfixed ry = vp[1];
- const GLfixed rz = vp[2];
- vp += stride;
- v->index = first++;
- v->clip.x = mla3a(rx, m[ 0], ry, m[ 4], rz, m[ 8], m[12]);
- v->clip.y = mla3a(rx, m[ 1], ry, m[ 5], rz, m[ 9], m[13]);
- v->clip.z = mla3a(rx, m[ 2], ry, m[ 6], rz, m[10], m[14]);
- v->clip.w = mla3a(rx, m[ 3], ry, m[ 7], rz, m[11], m[15]);
-
- const GLfixed w = v->clip.w;
- uint32_t clip = 0;
- if (v->clip.x < -w) clip |= vertex_t::CLIP_L;
- if (v->clip.x > w) clip |= vertex_t::CLIP_R;
- if (v->clip.y < -w) clip |= vertex_t::CLIP_B;
- if (v->clip.y > w) clip |= vertex_t::CLIP_T;
- if (v->clip.z < -w) clip |= vertex_t::CLIP_N;
- if (v->clip.z > w) clip |= vertex_t::CLIP_F;
- v->flags = clip;
- c->arrays.cull &= clip;
-
- //c->arrays.perspective(c, v);
- v++;
- } while (--count);
-}
-*/
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#pragma mark clippers
-#endif
-
-static void clipVec4(vec4_t& nv,
- GLfixed t, const vec4_t& s, const vec4_t& p)
-{
- for (int i=0; i<4 ; i++)
- nv.v[i] = gglMulAddx(t, s.v[i] - p.v[i], p.v[i], 28);
-}
-
-static void clipVertex(ogles_context_t* c, vertex_t* nv,
- GLfixed t, const vertex_t* s, const vertex_t* p)
-{
- clipVec4(nv->clip, t, s->clip, p->clip);
- nv->fog = gglMulAddx(t, s->fog - p->fog, p->fog, 28);
- ogles_vertex_project(c, nv);
- nv->flags |= vertex_t::LIT | vertex_t::EYE | vertex_t::TT;
- nv->flags &= ~vertex_t::CLIP_ALL;
-}
-
-static void clipVertexC(ogles_context_t* c, vertex_t* nv,
- GLfixed t, const vertex_t* s, const vertex_t* p)
-{
- clipVec4(nv->color, t, s->color, p->color);
- clipVertex(c, nv, t, s, p);
-}
-
-static void clipVertexT(ogles_context_t* c, vertex_t* nv,
- GLfixed t, const vertex_t* s, const vertex_t* p)
-{
- for (int i=0 ; i<GGL_TEXTURE_UNIT_COUNT ; i++) {
- if (c->rasterizer.state.texture[i].enable)
- clipVec4(nv->texture[i], t, s->texture[i], p->texture[i]);
- }
- clipVertex(c, nv, t, s, p);
-}
-
-static void clipVertexAll(ogles_context_t* c, vertex_t* nv,
- GLfixed t, const vertex_t* s, const vertex_t* p)
-{
- clipVec4(nv->color, t, s->color, p->color);
- clipVertexT(c, nv, t, s, p);
-}
-
-static void clipEye(ogles_context_t* c, vertex_t* nv,
- GLfixed t, const vertex_t* s, const vertex_t* p)
-{
- nv->clear();
- c->arrays.clipVertex(c, nv, t, p, s);
- clipVec4(nv->eye, t, s->eye, p->eye);
-}
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#endif
-
-void validate_arrays(ogles_context_t* c, GLenum mode)
-{
- uint32_t enables = c->rasterizer.state.enables;
-
- // Perspective correction is not need if Ortho transform, but
- // the user can still provide the w coordinate manually, so we can't
- // automatically turn it off (in fact we could when the 4th coordinate
- // is not spcified in the vertex array).
- // W interpolation is never needed for points.
- GLboolean perspective =
- c->perspective && mode!=GL_POINTS && (enables & GGL_ENABLE_TMUS);
- c->rasterizer.procs.enableDisable(c, GGL_W_LERP, perspective);
-
- // set anti-aliasing
- GLboolean smooth = GL_FALSE;
- switch (mode) {
- case GL_POINTS:
- smooth = c->point.smooth;
- break;
- case GL_LINES:
- case GL_LINE_LOOP:
- case GL_LINE_STRIP:
- smooth = c->line.smooth;
- break;
- }
- if (((enables & GGL_ENABLE_AA)?1:0) != smooth)
- c->rasterizer.procs.enableDisable(c, GGL_AA, smooth);
-
- // set the shade model for this primitive
- c->rasterizer.procs.shadeModel(c,
- (mode == GL_POINTS) ? GL_FLAT : c->lighting.shadeModel);
-
- // compute all the matrices we'll need...
- uint32_t want =
- transform_state_t::MVP |
- transform_state_t::VIEWPORT;
- if (c->lighting.enable) { // needs normal transforms and eye coords
- want |= transform_state_t::MVUI;
- want |= transform_state_t::MODELVIEW;
- }
- if (enables & GGL_ENABLE_TMUS) { // needs texture transforms
- want |= transform_state_t::TEXTURE;
- }
- if (c->clipPlanes.enable || (enables & GGL_ENABLE_FOG)) {
- want |= transform_state_t::MODELVIEW; // needs eye coords
- }
- ogles_validate_transform(c, want);
-
- // textures...
- if (enables & GGL_ENABLE_TMUS)
- ogles_validate_texture(c);
-
- // vertex compilers
- c->arrays.compileElement = compileElement__generic;
- c->arrays.compileElements = compileElements__generic;
-
- // vertex transform
- c->arrays.mvp_transform =
- c->transforms.mvp.pointv[c->arrays.vertex.size - 2];
-
- c->arrays.mv_transform =
- c->transforms.modelview.transform.pointv[c->arrays.vertex.size - 2];
-
- /*
- * ***********************************************************************
- * pick fetchers
- * ***********************************************************************
- */
-
- array_machine_t& am = c->arrays;
- am.vertex.fetch = fetchNop;
- am.normal.fetch = currentNormal;
- am.color.fetch = currentColor;
-
- if (am.vertex.enable) {
- am.vertex.resolve();
- if (am.vertex.bo || am.vertex.pointer) {
- am.vertex.fetch = vertex_fct[am.vertex.size-2][am.vertex.type & 0xF];
- }
- }
-
- if (am.normal.enable) {
- am.normal.resolve();
- if (am.normal.bo || am.normal.pointer) {
- am.normal.fetch = normal_fct[am.normal.size-3][am.normal.type & 0xF];
- }
- }
-
- if (am.color.enable) {
- am.color.resolve();
- if (c->lighting.enable) {
- if (am.color.bo || am.color.pointer) {
- am.color.fetch = color_fct[am.color.size-3][am.color.type & 0xF];
- }
- } else {
- if (am.color.bo || am.color.pointer) {
- am.color.fetch = color_clamp_fct[am.color.size-3][am.color.type & 0xF];
- }
- }
- }
-
- int activeTmuCount = 0;
- for (int i=0 ; i<GGL_TEXTURE_UNIT_COUNT ; i++) {
- am.texture[i].fetch = currentTexCoord;
- if (c->rasterizer.state.texture[i].enable) {
-
- // texture fetchers...
- if (am.texture[i].enable) {
- am.texture[i].resolve();
- if (am.texture[i].bo || am.texture[i].pointer) {
- am.texture[i].fetch = texture_fct[am.texture[i].size-2][am.texture[i].type & 0xF];
- }
- }
-
- // texture transform...
- const int index = c->arrays.texture[i].size - 2;
- c->arrays.tex_transform[i] =
- c->transforms.texture[i].transform.pointv[index];
-
- am.tmu = i;
- activeTmuCount++;
- }
- }
-
- // pick the vertex-clipper
- uint32_t clipper = 0;
- // we must reload 'enables' here
- enables = c->rasterizer.state.enables;
- if (enables & GGL_ENABLE_SMOOTH)
- clipper |= 1; // we need to interpolate colors
- if (enables & GGL_ENABLE_TMUS)
- clipper |= 2; // we need to interpolate textures
- switch (clipper) {
- case 0: c->arrays.clipVertex = clipVertex; break;
- case 1: c->arrays.clipVertex = clipVertexC; break;
- case 2: c->arrays.clipVertex = clipVertexT; break;
- case 3: c->arrays.clipVertex = clipVertexAll; break;
- }
- c->arrays.clipEye = clipEye;
-
- // pick the primitive rasterizer
- ogles_validate_primitives(c);
-}
-
-// ----------------------------------------------------------------------------
-}; // namespace android
-// ----------------------------------------------------------------------------
-
-using namespace android;
-
-#if 0
-#pragma mark -
-#pragma mark array API
-#endif
-
-void glVertexPointer(
- GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (size<2 || size>4 || stride<0) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
- switch (type) {
- case GL_BYTE:
- case GL_SHORT:
- case GL_FIXED:
- case GL_FLOAT:
- break;
- default:
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- c->arrays.vertex.init(size, type, stride, pointer, c->arrays.array_buffer, 0);
-}
-
-void glColorPointer(
- GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (size!=4 || stride<0) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
- switch (type) {
- case GL_UNSIGNED_BYTE:
- case GL_FIXED:
- case GL_FLOAT:
- break;
- default:
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- c->arrays.color.init(size, type, stride, pointer, c->arrays.array_buffer, 0);
-}
-
-void glNormalPointer(
- GLenum type, GLsizei stride, const GLvoid *pointer)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (stride<0) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
- switch (type) {
- case GL_BYTE:
- case GL_SHORT:
- case GL_FIXED:
- case GL_FLOAT:
- break;
- default:
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- c->arrays.normal.init(3, type, stride, pointer, c->arrays.array_buffer, 0);
-}
-
-void glTexCoordPointer(
- GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (size<2 || size>4 || stride<0) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
- switch (type) {
- case GL_BYTE:
- case GL_SHORT:
- case GL_FIXED:
- case GL_FLOAT:
- break;
- default:
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- const int tmu = c->arrays.activeTexture;
- c->arrays.texture[tmu].init(size, type, stride, pointer,
- c->arrays.array_buffer, 0);
-}
-
-
-void glEnableClientState(GLenum array) {
- ogles_context_t* c = ogles_context_t::get();
- enableDisableClientState(c, array, true);
-}
-
-void glDisableClientState(GLenum array) {
- ogles_context_t* c = ogles_context_t::get();
- enableDisableClientState(c, array, false);
-}
-
-void glClientActiveTexture(GLenum texture)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (texture<GL_TEXTURE0 || texture>=GL_TEXTURE0+GGL_TEXTURE_UNIT_COUNT) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- c->arrays.activeTexture = texture - GL_TEXTURE0;
-}
-
-void glDrawArrays(GLenum mode, GLint first, GLsizei count)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (count<0) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
- switch (mode) {
- case GL_POINTS:
- case GL_LINE_STRIP:
- case GL_LINE_LOOP:
- case GL_LINES:
- case GL_TRIANGLE_STRIP:
- case GL_TRIANGLE_FAN:
- case GL_TRIANGLES:
- break;
- default:
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
-
- if (count == 0 || !c->arrays.vertex.enable)
- return;
- if ((c->cull.enable) && (c->cull.cullFace == GL_FRONT_AND_BACK))
- return; // all triangles are culled
-
-
- validate_arrays(c, mode);
-
- const uint32_t enables = c->rasterizer.state.enables;
- if (enables & GGL_ENABLE_TMUS)
- ogles_lock_textures(c);
-
- drawArraysPrims[mode](c, first, count);
-
- if (enables & GGL_ENABLE_TMUS)
- ogles_unlock_textures(c);
-
-#if VC_CACHE_STATISTICS
- c->vc.total = count;
- c->vc.dump_stats(mode);
-#endif
-}
-
-void glDrawElements(
- GLenum mode, GLsizei count, GLenum type, const GLvoid *indices)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (count<0) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
- switch (mode) {
- case GL_POINTS:
- case GL_LINE_STRIP:
- case GL_LINE_LOOP:
- case GL_LINES:
- case GL_TRIANGLE_STRIP:
- case GL_TRIANGLE_FAN:
- case GL_TRIANGLES:
- break;
- default:
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- switch (type) {
- case GL_UNSIGNED_BYTE:
- case GL_UNSIGNED_SHORT:
- c->arrays.indicesType = type;
- break;
- default:
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- if (count == 0 || !c->arrays.vertex.enable)
- return;
- if ((c->cull.enable) && (c->cull.cullFace == GL_FRONT_AND_BACK))
- return; // all triangles are culled
-
- // clear the vertex-cache
- c->vc.clear();
- validate_arrays(c, mode);
-
- // if indices are in a buffer object, the pointer is treated as an
- // offset in that buffer.
- if (c->arrays.element_array_buffer) {
- indices = c->arrays.element_array_buffer->data + uintptr_t(indices);
- }
-
- const uint32_t enables = c->rasterizer.state.enables;
- if (enables & GGL_ENABLE_TMUS)
- ogles_lock_textures(c);
-
- drawElementsPrims[mode](c, count, indices);
-
- if (enables & GGL_ENABLE_TMUS)
- ogles_unlock_textures(c);
-
-
-#if VC_CACHE_STATISTICS
- c->vc.total = count;
- c->vc.dump_stats(mode);
-#endif
-}
-
-// ----------------------------------------------------------------------------
-// buffers
-// ----------------------------------------------------------------------------
-
-void glBindBuffer(GLenum target, GLuint buffer)
-{
- ogles_context_t* c = ogles_context_t::get();
- if ((target!=GL_ARRAY_BUFFER) && (target!=GL_ELEMENT_ARRAY_BUFFER)) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- // create a buffer object, or bind an existing one
- buffer_t const* bo = 0;
- if (buffer) {
- bo = c->bufferObjectManager->bind(buffer);
- if (!bo) {
- ogles_error(c, GL_OUT_OF_MEMORY);
- return;
- }
- }
- ((target == GL_ARRAY_BUFFER) ?
- c->arrays.array_buffer : c->arrays.element_array_buffer) = bo;
-}
-
-void glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
-{
- ogles_context_t* c = ogles_context_t::get();
- if ((target!=GL_ARRAY_BUFFER) && (target!=GL_ELEMENT_ARRAY_BUFFER)) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- if (size<0) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
- if ((usage!=GL_STATIC_DRAW) && (usage!=GL_DYNAMIC_DRAW)) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- buffer_t const* bo = ((target == GL_ARRAY_BUFFER) ?
- c->arrays.array_buffer : c->arrays.element_array_buffer);
-
- if (bo == 0) {
- // can't modify buffer 0
- ogles_error(c, GL_INVALID_OPERATION);
- return;
- }
-
- buffer_t* edit_bo = const_cast<buffer_t*>(bo);
- if (c->bufferObjectManager->allocateStore(edit_bo, size, usage) != 0) {
- ogles_error(c, GL_OUT_OF_MEMORY);
- return;
- }
- if (data) {
- memcpy(bo->data, data, size);
- }
-}
-
-void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
-{
- ogles_context_t* c = ogles_context_t::get();
- if ((target!=GL_ARRAY_BUFFER) && (target!=GL_ELEMENT_ARRAY_BUFFER)) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- if (offset<0 || size<0 || data==0) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
- buffer_t const* bo = ((target == GL_ARRAY_BUFFER) ?
- c->arrays.array_buffer : c->arrays.element_array_buffer);
-
- if (bo == 0) {
- // can't modify buffer 0
- ogles_error(c, GL_INVALID_OPERATION);
- return;
- }
- if (offset+size > bo->size) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
- memcpy(bo->data + offset, data, size);
-}
-
-void glDeleteBuffers(GLsizei n, const GLuint* buffers)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (n<0) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
-
- for (int i=0 ; i<n ; i++) {
- GLuint name = buffers[i];
- if (name) {
- // unbind bound deleted buffers...
- if (c->arrays.element_array_buffer) {
- if (c->arrays.element_array_buffer->name == name) {
- c->arrays.element_array_buffer = 0;
- }
- }
- if (c->arrays.array_buffer) {
- if (c->arrays.array_buffer->name == name) {
- c->arrays.array_buffer = 0;
- }
- }
- if (c->arrays.vertex.bo) {
- if (c->arrays.vertex.bo->name == name) {
- c->arrays.vertex.bo = 0;
- }
- }
- if (c->arrays.normal.bo) {
- if (c->arrays.normal.bo->name == name) {
- c->arrays.normal.bo = 0;
- }
- }
- if (c->arrays.color.bo) {
- if (c->arrays.color.bo->name == name) {
- c->arrays.color.bo = 0;
- }
- }
- for (int t=0 ; t<GGL_TEXTURE_UNIT_COUNT ; t++) {
- if (c->arrays.texture[t].bo) {
- if (c->arrays.texture[t].bo->name == name) {
- c->arrays.texture[t].bo = 0;
- }
- }
- }
- }
- }
- c->bufferObjectManager->deleteBuffers(n, buffers);
- c->bufferObjectManager->recycleTokens(n, buffers);
-}
-
-void glGenBuffers(GLsizei n, GLuint* buffers)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (n<0) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
- c->bufferObjectManager->getToken(n, buffers);
-}
diff --git a/opengl/libagl/array.h b/opengl/libagl/array.h
deleted file mode 100644
index e156978..0000000
--- a/opengl/libagl/array.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/* libs/opengles/array.h
-**
-** Copyright 2006, 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.
-*/
-
-#ifndef ANDROID_OPENGLES_ARRAY_H
-#define ANDROID_OPENGLES_ARRAY_H
-
-#include <stdint.h>
-#include <stddef.h>
-#include <sys/types.h>
-
-namespace android {
-
-namespace gl {
-struct ogles_context_t;
-};
-
-void ogles_init_array(ogles_context_t* c);
-void ogles_uninit_array(ogles_context_t* c);
-
-}; // namespace android
-
-#endif // ANDROID_OPENGLES_ARRAY_H
-
diff --git a/opengl/libagl/context.h b/opengl/libagl/context.h
deleted file mode 100644
index 18ef7d5..0000000
--- a/opengl/libagl/context.h
+++ /dev/null
@@ -1,647 +0,0 @@
-/*
- * Copyright (C) 2006 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.
- */
-
-#ifndef ANDROID_OPENGLES_CONTEXT_H
-#define ANDROID_OPENGLES_CONTEXT_H
-
-#include <stdint.h>
-#include <stddef.h>
-#include <sys/types.h>
-#include <pthread.h>
-#ifdef __ANDROID__
-#include <bionic_tls.h>
-#endif
-
-#include <private/pixelflinger/ggl_context.h>
-
-#include <system/window.h>
-
-#include <GLES/gl.h>
-#include <GLES/glext.h>
-
-namespace android {
-
-
-const unsigned int OGLES_NUM_COMPRESSED_TEXTURE_FORMATS = 10
-#ifdef GL_OES_compressed_ETC1_RGB8_texture
- + 1
-#endif
- ;
-
-class EGLTextureObject;
-class EGLSurfaceManager;
-class EGLBufferObjectManager;
-
-namespace gl {
-
-struct ogles_context_t;
-struct matrixx_t;
-struct transform_t;
-struct buffer_t;
-
-ogles_context_t* getGlContext();
-
-template<typename T>
-static inline void swap(T& a, T& b) {
- T t(a); a = b; b = t;
-}
-template<typename T>
-inline T max(T a, T b) {
- return a<b ? b : a;
-}
-template<typename T>
-inline T max(T a, T b, T c) {
- return max(a, max(b, c));
-}
-template<typename T>
-inline T min(T a, T b) {
- return a<b ? a : b;
-}
-template<typename T>
-inline T min(T a, T b, T c) {
- return min(a, min(b, c));
-}
-template<typename T>
-inline T min(T a, T b, T c, T d) {
- return min(min(a,b), min(c,d));
-}
-
-// ----------------------------------------------------------------------------
-// vertices
-// ----------------------------------------------------------------------------
-
-struct vec3_t {
- union {
- struct { GLfixed x, y, z; };
- struct { GLfixed r, g, b; };
- struct { GLfixed S, T, R; };
- GLfixed v[3];
- };
-};
-
-struct vec4_t {
- union {
- struct { GLfixed x, y, z, w; };
- struct { GLfixed r, g, b, a; };
- struct { GLfixed S, T, R, Q; };
- GLfixed v[4];
- };
-};
-
-struct vertex_t {
- enum {
- // these constant matter for our clipping
- CLIP_L = 0x0001, // clipping flags
- CLIP_R = 0x0002,
- CLIP_B = 0x0004,
- CLIP_T = 0x0008,
- CLIP_N = 0x0010,
- CLIP_F = 0x0020,
-
- EYE = 0x0040,
- RESERVED = 0x0080,
-
- USER_CLIP_0 = 0x0100, // user clipping flags
- USER_CLIP_1 = 0x0200,
- USER_CLIP_2 = 0x0400,
- USER_CLIP_3 = 0x0800,
- USER_CLIP_4 = 0x1000,
- USER_CLIP_5 = 0x2000,
-
- LIT = 0x4000, // lighting has been applied
- TT = 0x8000, // texture coords transformed
-
- FRUSTUM_CLIP_ALL= 0x003F,
- USER_CLIP_ALL = 0x3F00,
- CLIP_ALL = 0x3F3F,
- };
-
- // the fields below are arranged to minimize d-cache usage
- // we group together, by cache-line, the fields most likely to be used
-
- union {
- vec4_t obj;
- vec4_t eye;
- };
- vec4_t clip;
-
- uint32_t flags;
- size_t index; // cache tag, and vertex index
- GLfixed fog;
- uint8_t locked;
- uint8_t mru;
- uint8_t reserved[2];
- vec4_t window;
-
- vec4_t color;
- vec4_t texture[GGL_TEXTURE_UNIT_COUNT];
-#ifdef __LP64__
- uint32_t reserved1[2];
-#else
- uint32_t reserved1[4];
-#endif
-
- inline void clear() {
- flags = index = locked = mru = 0;
- }
-};
-
-struct point_size_t {
- GGLcoord size;
- GLboolean smooth;
-};
-
-struct line_width_t {
- GGLcoord width;
- GLboolean smooth;
-};
-
-struct polygon_offset_t {
- GLfixed factor;
- GLfixed units;
- GLboolean enable;
-};
-
-// ----------------------------------------------------------------------------
-// arrays
-// ----------------------------------------------------------------------------
-
-struct array_t {
- typedef void (*fetcher_t)(ogles_context_t*, GLfixed*, const GLvoid*);
- fetcher_t fetch;
- GLvoid const* physical_pointer;
- GLint size;
- GLsizei stride;
- GLvoid const* pointer;
- buffer_t const* bo;
- uint16_t type;
- GLboolean enable;
- GLboolean pad;
- GLsizei bounds;
- void init(GLint, GLenum, GLsizei, const GLvoid *, const buffer_t*, GLsizei);
- inline void resolve();
- inline const GLubyte* element(GLint i) const {
- return (const GLubyte*)physical_pointer + i * stride;
- }
-};
-
-struct array_machine_t {
- array_t vertex;
- array_t normal;
- array_t color;
- array_t texture[GGL_TEXTURE_UNIT_COUNT];
- uint8_t activeTexture;
- uint8_t tmu;
- uint16_t cull;
- uint32_t flags;
- GLenum indicesType;
- buffer_t const* array_buffer;
- buffer_t const* element_array_buffer;
-
- void (*compileElements)(ogles_context_t*, vertex_t*, GLint, GLsizei);
- void (*compileElement)(ogles_context_t*, vertex_t*, GLint);
-
- void (*mvp_transform)(transform_t const*, vec4_t*, vec4_t const*);
- void (*mv_transform)(transform_t const*, vec4_t*, vec4_t const*);
- void (*tex_transform[2])(transform_t const*, vec4_t*, vec4_t const*);
- void (*perspective)(ogles_context_t*c, vertex_t* v);
- void (*clipVertex)(ogles_context_t* c, vertex_t* nv,
- GGLfixed t, const vertex_t* s, const vertex_t* p);
- void (*clipEye)(ogles_context_t* c, vertex_t* nv,
- GGLfixed t, const vertex_t* s, const vertex_t* p);
-};
-
-struct vertex_cache_t {
- enum {
- // must be at least 4
- // 3 vertice for triangles
- // or 2 + 2 for indexed triangles w/ cache contention
- VERTEX_BUFFER_SIZE = 8,
- // must be a power of two and at least 3
- VERTEX_CACHE_SIZE = 64, // 8 KB
-
- INDEX_BITS = 16,
- INDEX_MASK = ((1LU<<INDEX_BITS)-1),
- INDEX_SEQ = 1LU<<INDEX_BITS,
- };
- vertex_t* vBuffer;
- vertex_t* vCache;
- uint32_t sequence;
- void* base;
- uint32_t total;
- uint32_t misses;
- int64_t startTime;
- void init();
- void uninit();
- void clear();
- void dump_stats(GLenum mode);
-};
-
-// ----------------------------------------------------------------------------
-// fog
-// ----------------------------------------------------------------------------
-
-struct fog_t {
- GLfixed density;
- GLfixed start;
- GLfixed end;
- GLfixed invEndMinusStart;
- GLenum mode;
- GLfixed (*fog)(ogles_context_t* c, GLfixed z);
-};
-
-// ----------------------------------------------------------------------------
-// user clip planes
-// ----------------------------------------------------------------------------
-
-const unsigned int OGLES_MAX_CLIP_PLANES = 6;
-
-struct clip_plane_t {
- vec4_t equation;
-};
-
-struct user_clip_planes_t {
- clip_plane_t plane[OGLES_MAX_CLIP_PLANES];
- uint32_t enable;
-};
-
-// ----------------------------------------------------------------------------
-// lighting
-// ----------------------------------------------------------------------------
-
-const unsigned int OGLES_MAX_LIGHTS = 8;
-
-struct light_t {
- vec4_t ambient;
- vec4_t diffuse;
- vec4_t specular;
- vec4_t implicitAmbient;
- vec4_t implicitDiffuse;
- vec4_t implicitSpecular;
- vec4_t position; // position in eye space
- vec4_t objPosition;
- vec4_t normalizedObjPosition;
- vec4_t spotDir;
- vec4_t normalizedSpotDir;
- GLfixed spotExp;
- GLfixed spotCutoff;
- GLfixed spotCutoffCosine;
- GLfixed attenuation[3];
- GLfixed rConstAttenuation;
- GLboolean enable;
-};
-
-struct material_t {
- vec4_t ambient;
- vec4_t diffuse;
- vec4_t specular;
- vec4_t emission;
- GLfixed shininess;
-};
-
-struct light_model_t {
- vec4_t ambient;
- GLboolean twoSide;
-};
-
-struct color_material_t {
- GLenum face;
- GLenum mode;
- GLboolean enable;
-};
-
-struct lighting_t {
- light_t lights[OGLES_MAX_LIGHTS];
- material_t front;
- light_model_t lightModel;
- color_material_t colorMaterial;
- vec4_t implicitSceneEmissionAndAmbient;
- vec4_t objViewer;
- uint32_t enabledLights;
- GLboolean enable;
- GLenum shadeModel;
- typedef void (*light_fct_t)(ogles_context_t*, vertex_t*);
- void (*lightVertex)(ogles_context_t* c, vertex_t* v);
- void (*lightTriangle)(ogles_context_t* c,
- vertex_t* v0, vertex_t* v1, vertex_t* v2);
-};
-
-struct culling_t {
- GLenum cullFace;
- GLenum frontFace;
- GLboolean enable;
-};
-
-// ----------------------------------------------------------------------------
-// textures
-// ----------------------------------------------------------------------------
-
-struct texture_unit_t {
- GLuint name;
- EGLTextureObject* texture;
- uint8_t dirty;
-};
-
-struct texture_state_t
-{
- texture_unit_t tmu[GGL_TEXTURE_UNIT_COUNT];
- int active; // active tmu
- EGLTextureObject* defaultTexture;
- GGLContext* ggl;
- uint8_t packAlignment;
- uint8_t unpackAlignment;
-};
-
-// ----------------------------------------------------------------------------
-// transformation and matrices
-// ----------------------------------------------------------------------------
-
-struct matrixf_t;
-
-struct matrixx_t {
- GLfixed m[16];
- void load(const matrixf_t& rhs);
-};
-
-struct matrix_stack_t;
-
-
-struct matrixf_t {
- void loadIdentity();
- void load(const matrixf_t& rhs);
-
- inline GLfloat* editElements() { return m; }
- inline GLfloat const* elements() const { return m; }
-
- void set(const GLfixed* rhs);
- void set(const GLfloat* rhs);
-
- static void multiply(matrixf_t& r,
- const matrixf_t& lhs, const matrixf_t& rhs);
-
- void dump(const char* what);
-
-private:
- friend struct matrix_stack_t;
- GLfloat m[16];
- void load(const GLfixed* rhs);
- void load(const GLfloat* rhs);
- void multiply(const matrixf_t& rhs);
- void translate(GLfloat x, GLfloat y, GLfloat z);
- void scale(GLfloat x, GLfloat y, GLfloat z);
- void rotate(GLfloat a, GLfloat x, GLfloat y, GLfloat z);
-};
-
-enum {
- OP_IDENTITY = 0x00,
- OP_TRANSLATE = 0x01,
- OP_UNIFORM_SCALE = 0x02,
- OP_SCALE = 0x05,
- OP_ROTATE = 0x08,
- OP_SKEW = 0x10,
- OP_ALL = 0x1F
-};
-
-struct transform_t {
- enum {
- FLAGS_2D_PROJECTION = 0x1
- };
- matrixx_t matrix;
- uint32_t flags;
- uint32_t ops;
-
- union {
- struct {
- void (*point2)(transform_t const* t, vec4_t*, vec4_t const*);
- void (*point3)(transform_t const* t, vec4_t*, vec4_t const*);
- void (*point4)(transform_t const* t, vec4_t*, vec4_t const*);
- };
- void (*pointv[3])(transform_t const* t, vec4_t*, vec4_t const*);
- };
-
- void loadIdentity();
- void picker();
- void dump(const char* what);
-};
-
-struct mvui_transform_t : public transform_t
-{
- void picker();
-};
-
-struct matrix_stack_t {
- enum {
- DO_PICKER = 0x1,
- DO_FLOAT_TO_FIXED = 0x2
- };
- transform_t transform;
- uint8_t maxDepth;
- uint8_t depth;
- uint8_t dirty;
- uint8_t reserved;
- matrixf_t *stack;
- uint8_t *ops;
- void init(int depth);
- void uninit();
- void loadIdentity();
- void load(const GLfixed* rhs);
- void load(const GLfloat* rhs);
- void multiply(const matrixf_t& rhs);
- void translate(GLfloat x, GLfloat y, GLfloat z);
- void scale(GLfloat x, GLfloat y, GLfloat z);
- void rotate(GLfloat a, GLfloat x, GLfloat y, GLfloat z);
- GLint push();
- GLint pop();
- void validate();
- matrixf_t& top() { return stack[depth]; }
- const matrixf_t& top() const { return stack[depth]; }
- uint32_t top_ops() const { return ops[depth]; }
- inline bool isRigidBody() const {
- return !(ops[depth] & ~(OP_TRANSLATE|OP_UNIFORM_SCALE|OP_ROTATE));
- }
-};
-
-struct vp_transform_t {
- transform_t transform;
- matrixf_t matrix;
- GLfloat zNear;
- GLfloat zFar;
- void loadIdentity();
-};
-
-struct transform_state_t {
- enum {
- MODELVIEW = 0x01,
- PROJECTION = 0x02,
- VIEWPORT = 0x04,
- TEXTURE = 0x08,
- MVUI = 0x10,
- MVIT = 0x20,
- MVP = 0x40,
- };
- matrix_stack_t *current;
- matrix_stack_t modelview;
- matrix_stack_t projection;
- matrix_stack_t texture[GGL_TEXTURE_UNIT_COUNT];
-
- // modelview * projection
- transform_t mvp __attribute__((aligned(32)));
- // viewport transformation
- vp_transform_t vpt __attribute__((aligned(32)));
- // same for 4-D vertices
- transform_t mvp4;
- // full modelview inverse transpose
- transform_t mvit4;
- // upper 3x3 of mv-inverse-transpose (for normals)
- mvui_transform_t mvui;
-
- GLenum matrixMode;
- GLenum rescaleNormals;
- uint32_t dirty;
- void invalidate();
- void update_mvp();
- void update_mvit();
- void update_mvui();
-};
-
-struct viewport_t {
- GLint x;
- GLint y;
- GLsizei w;
- GLsizei h;
- struct {
- GLint x;
- GLint y;
- } surfaceport;
- struct {
- GLint x;
- GLint y;
- GLsizei w;
- GLsizei h;
- } scissor;
-};
-
-// ----------------------------------------------------------------------------
-// Lerping
-// ----------------------------------------------------------------------------
-
-struct compute_iterators_t
-{
- void initTriangle(
- vertex_t const* v0,
- vertex_t const* v1,
- vertex_t const* v2);
-
- void initLine(
- vertex_t const* v0,
- vertex_t const* v1);
-
- inline void initLerp(vertex_t const* v0, uint32_t enables);
-
- int iteratorsScale(int32_t it[3],
- int32_t c0, int32_t c1, int32_t c2) const;
-
- void iterators1616(GGLfixed it[3],
- GGLfixed c0, GGLfixed c1, GGLfixed c2) const;
-
- void iterators0032(int32_t it[3],
- int32_t c0, int32_t c1, int32_t c2) const;
-
- void iterators0032(int64_t it[3],
- int32_t c0, int32_t c1, int32_t c2) const;
-
- GGLcoord area() const { return m_area; }
-
-private:
- // don't change order of members here -- used by iterators.S
- GGLcoord m_dx01, m_dy10, m_dx20, m_dy02;
- GGLcoord m_x0, m_y0;
- GGLcoord m_area;
- uint8_t m_scale;
- uint8_t m_area_scale;
- uint8_t m_reserved[2];
-
-};
-
-// ----------------------------------------------------------------------------
-// state
-// ----------------------------------------------------------------------------
-
-#ifdef __ANDROID__
- // We have a dedicated TLS slot in bionic
- inline void setGlThreadSpecific(ogles_context_t *value) {
- __get_tls()[TLS_SLOT_OPENGL] = value;
- }
- inline ogles_context_t* getGlThreadSpecific() {
- return static_cast<ogles_context_t*>(__get_tls()[TLS_SLOT_OPENGL]);
- }
-#else
- extern pthread_key_t gGLKey;
- inline void setGlThreadSpecific(ogles_context_t *value) {
- pthread_setspecific(gGLKey, value);
- }
- inline ogles_context_t* getGlThreadSpecific() {
- return static_cast<ogles_context_t*>(pthread_getspecific(gGLKey));
- }
-#endif
-
-
-struct prims_t {
- typedef ogles_context_t* GL;
- void (*renderPoint)(GL, vertex_t*);
- void (*renderLine)(GL, vertex_t*, vertex_t*);
- void (*renderTriangle)(GL, vertex_t*, vertex_t*, vertex_t*);
-};
-
-struct ogles_context_t {
- context_t rasterizer;
- array_machine_t arrays __attribute__((aligned(32)));
- texture_state_t textures;
- transform_state_t transforms;
- vertex_cache_t vc;
- prims_t prims;
- culling_t cull;
- lighting_t lighting;
- user_clip_planes_t clipPlanes;
- compute_iterators_t lerp __attribute__((aligned(32)));
- vertex_t current;
- vec4_t currentColorClamped;
- vec3_t currentNormal;
- viewport_t viewport;
- point_size_t point;
- line_width_t line;
- polygon_offset_t polygonOffset;
- fog_t fog;
- uint32_t perspective : 1;
- uint32_t transformTextures : 1;
- EGLSurfaceManager* surfaceManager;
- EGLBufferObjectManager* bufferObjectManager;
-
- GLenum error;
-
- static inline ogles_context_t* get() {
- return getGlThreadSpecific();
- }
-
-};
-
-}; // namespace gl
-}; // namespace android
-
-using namespace android::gl;
-
-#endif // ANDROID_OPENGLES_CONTEXT_H
-
diff --git a/opengl/libagl/dxt.cpp b/opengl/libagl/dxt.cpp
deleted file mode 100644
index 238c81f..0000000
--- a/opengl/libagl/dxt.cpp
+++ /dev/null
@@ -1,636 +0,0 @@
-/* libs/opengles/dxt.cpp
-**
-** Copyright 2007, 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 TIMING 0
-
-#if TIMING
-#include <sys/time.h> // for optimization timing
-#include <stdio.h>
-#include <stdlib.h>
-#endif
-
-#include <GLES/gl.h>
-#include <utils/Endian.h>
-
-#include "context.h"
-
-#define TIMING 0
-
-namespace android {
-
-static uint8_t avg23tab[64*64];
-static volatile int tables_initialized = 0;
-
-// Definitions below are equivalent to these over the valid range of arguments
-// #define div5(x) ((x)/5)
-// #define div7(x) ((x)/7)
-
-// Use fixed-point to divide by 5 and 7
-// 3277 = 2^14/5 + 1
-// 2341 = 2^14/7 + 1
-#define div5(x) (((x)*3277) >> 14)
-#define div7(x) (((x)*2341) >> 14)
-
-// Table with entry [a << 6 | b] = (2*a + b)/3 for 0 <= a,b < 64
-#define avg23(x0,x1) avg23tab[((x0) << 6) | (x1)]
-
-// Extract 5/6/5 RGB
-#define red(x) (((x) >> 11) & 0x1f)
-#define green(x) (((x) >> 5) & 0x3f)
-#define blue(x) ( (x) & 0x1f)
-
-/*
- * Convert 5/6/5 RGB (as 3 ints) to 8/8/8
- *
- * Operation count: 8 <<, 0 &, 5 |
- */
-inline static int rgb565SepTo888(int r, int g, int b)
-
-{
- return ((((r << 3) | (r >> 2)) << 16) |
- (((g << 2) | (g >> 4)) << 8) |
- ((b << 3) | (b >> 2)));
-}
-
-/*
- * Convert 5/6/5 RGB (as a single 16-bit word) to 8/8/8
- *
- * r4r3r2r1 r0g5g4g3 g2g1g0b4 b3b2b1b0 rgb
- * r4r3r2 r1r0g5g4 g3g2g1g0 b4b3b2b1 b0 0 0 0 rgb << 3
- * r4r3r2r1 r0r4r3r2 g5g4g3g2 g1g0g5g4 b4b3b2b1 b0b4b3b2 desired result
- *
- * Construct the 24-bit RGB word as:
- *
- * r4r3r2r1 r0------ -------- -------- -------- -------- (rgb << 8) & 0xf80000
- * r4r3r2 -------- -------- -------- -------- (rgb << 3) & 0x070000
- * g5g4g3g2 g1g0---- -------- -------- (rgb << 5) & 0x00fc00
- * g5g4 -------- -------- (rgb >> 1) & 0x000300
- * b4b3b2b1 b0------ (rgb << 3) & 0x0000f8
- * b4b3b2 (rgb >> 2) & 0x000007
- *
- * Operation count: 5 <<, 6 &, 5 | (n.b. rgb >> 3 is used twice)
- */
-inline static int rgb565To888(int rgb)
-
-{
- int rgb3 = rgb >> 3;
- return (((rgb << 8) & 0xf80000) |
- ( rgb3 & 0x070000) |
- ((rgb << 5) & 0x00fc00) |
- ((rgb >> 1) & 0x000300) |
- ( rgb3 & 0x0000f8) |
- ((rgb >> 2) & 0x000007));
-}
-
-#if __BYTE_ORDER == __BIG_ENDIAN
-static uint32_t swap(uint32_t x) {
- int b0 = (x >> 24) & 0xff;
- int b1 = (x >> 16) & 0xff;
- int b2 = (x >> 8) & 0xff;
- int b3 = (x ) & 0xff;
-
- return (uint32_t)((b3 << 24) | (b2 << 16) | (b1 << 8) | b0);
-}
-#endif
-
-static void
-init_tables()
-{
- if (tables_initialized) {
- return;
- }
-
- for (int i = 0; i < 64; i++) {
- for (int j = 0; j < 64; j++) {
- int avg = (2*i + j)/3;
- avg23tab[(i << 6) | j] = avg;
- }
- }
-
- asm volatile ("" : : : "memory");
- tables_initialized = 1;
-}
-
-/*
- * Utility to scan a DXT1 compressed texture to determine whether it
- * contains a transparent pixel (color0 < color1, code == 3). This
- * may be useful if the application lacks information as to whether
- * the true format is GL_COMPRESSED_RGB_S3TC_DXT1_EXT or
- * GL_COMPRESSED_RGBA_S3TC_DXT1_EXT.
- */
-bool
-DXT1HasAlpha(const GLvoid *data, int width, int height) {
-#if TIMING
- struct timeval start_t, end_t;
- struct timezone tz;
-
- gettimeofday(&start_t, &tz);
-#endif
-
- bool hasAlpha = false;
-
- int xblocks = (width + 3)/4;
- int yblocks = (height + 3)/4;
- int numblocks = xblocks*yblocks;
-
- uint32_t const *d32 = (uint32_t *)data;
- for (int b = 0; b < numblocks; b++) {
- uint32_t colors = *d32++;
-
-#if __BYTE_ORDER == __BIG_ENDIAN
- colors = swap(colors);
-#endif
-
- uint16_t color0 = colors & 0xffff;
- uint16_t color1 = colors >> 16;
-
- if (color0 < color1) {
- // There's no need to endian-swap within 'bits'
- // since we don't care which pixel is the transparent one
- uint32_t bits = *d32++;
-
- // Detect if any (odd, even) pair of bits are '11'
- // bits: b31 b30 b29 ... b3 b2 b1 b0
- // bits >> 1: b31 b31 b30 ... b4 b3 b2 b1
- // &: b31 (b31 & b30) (b29 & b28) ... (b2 & b1) (b1 & b0)
- // & 0x55..: 0 (b31 & b30) 0 ... 0 (b1 & b0)
- if (((bits & (bits >> 1)) & 0x55555555) != 0) {
- hasAlpha = true;
- goto done;
- }
- } else {
- // Skip 4 bytes
- ++d32;
- }
- }
-
- done:
-#if TIMING
- gettimeofday(&end_t, &tz);
- long usec = (end_t.tv_sec - start_t.tv_sec)*1000000 +
- (end_t.tv_usec - start_t.tv_usec);
-
- printf("Scanned w=%d h=%d in %ld usec\n", width, height, usec);
-#endif
-
- return hasAlpha;
-}
-
-static void
-decodeDXT1(const GLvoid *data, int width, int height,
- void *surface, int stride,
- bool hasAlpha)
-
-{
- init_tables();
-
- uint32_t const *d32 = (uint32_t *)data;
-
- // Color table for the current block
- uint16_t c[4];
- c[0] = c[1] = c[2] = c[3] = 0;
-
- // Specified colors from the previous block
- uint16_t prev_color0 = 0x0000;
- uint16_t prev_color1 = 0x0000;
-
- uint16_t* rowPtr = (uint16_t*)surface;
- for (int base_y = 0; base_y < height; base_y += 4, rowPtr += 4*stride) {
- uint16_t *blockPtr = rowPtr;
- for (int base_x = 0; base_x < width; base_x += 4, blockPtr += 4) {
- uint32_t colors = *d32++;
- uint32_t bits = *d32++;
-
-#if __BYTE_ORDER == __BIG_ENDIAN
- colors = swap(colors);
- bits = swap(bits);
-#endif
-
- // Raw colors
- uint16_t color0 = colors & 0xffff;
- uint16_t color1 = colors >> 16;
-
- // If the new block has the same base colors as the
- // previous one, we don't need to recompute the color
- // table c[]
- if (color0 != prev_color0 || color1 != prev_color1) {
- // Store raw colors for comparison with next block
- prev_color0 = color0;
- prev_color1 = color1;
-
- int r0 = red(color0);
- int g0 = green(color0);
- int b0 = blue(color0);
-
- int r1 = red(color1);
- int g1 = green(color1);
- int b1 = blue(color1);
-
- if (hasAlpha) {
- c[0] = (r0 << 11) | ((g0 >> 1) << 6) | (b0 << 1) | 0x1;
- c[1] = (r1 << 11) | ((g1 >> 1) << 6) | (b1 << 1) | 0x1;
- } else {
- c[0] = color0;
- c[1] = color1;
- }
-
- int r2, g2, b2, r3, g3, b3, a3;
-
- int bbits = bits >> 1;
- bool has2 = ((bbits & ~bits) & 0x55555555) != 0;
- bool has3 = ((bbits & bits) & 0x55555555) != 0;
-
- if (has2 || has3) {
- if (color0 > color1) {
- r2 = avg23(r0, r1);
- g2 = avg23(g0, g1);
- b2 = avg23(b0, b1);
-
- r3 = avg23(r1, r0);
- g3 = avg23(g1, g0);
- b3 = avg23(b1, b0);
- a3 = 1;
- } else {
- r2 = (r0 + r1) >> 1;
- g2 = (g0 + g1) >> 1;
- b2 = (b0 + b1) >> 1;
-
- r3 = g3 = b3 = a3 = 0;
- }
- if (hasAlpha) {
- c[2] = (r2 << 11) | ((g2 >> 1) << 6) |
- (b2 << 1) | 0x1;
- c[3] = (r3 << 11) | ((g3 >> 1) << 6) |
- (b3 << 1) | a3;
- } else {
- c[2] = (r2 << 11) | (g2 << 5) | b2;
- c[3] = (r3 << 11) | (g3 << 5) | b3;
- }
- }
- }
-
- uint16_t* blockRowPtr = blockPtr;
- for (int y = 0; y < 4; y++, blockRowPtr += stride) {
- // Don't process rows past the botom
- if (base_y + y >= height) {
- break;
- }
-
- int w = min(width - base_x, 4);
- for (int x = 0; x < w; x++) {
- int code = bits & 0x3;
- bits >>= 2;
-
- blockRowPtr[x] = c[code];
- }
- }
- }
- }
-}
-
-// Output data as internalformat=GL_RGBA, type=GL_UNSIGNED_BYTE
-static void
-decodeDXT3(const GLvoid *data, int width, int height,
- void *surface, int stride)
-
-{
- init_tables();
-
- uint32_t const *d32 = (uint32_t *)data;
-
- // Specified colors from the previous block
- uint16_t prev_color0 = 0x0000;
- uint16_t prev_color1 = 0x0000;
-
- // Color table for the current block
- uint32_t c[4];
- c[0] = c[1] = c[2] = c[3] = 0;
-
- uint32_t* rowPtr = (uint32_t*)surface;
- for (int base_y = 0; base_y < height; base_y += 4, rowPtr += 4*stride) {
- uint32_t *blockPtr = rowPtr;
- for (int base_x = 0; base_x < width; base_x += 4, blockPtr += 4) {
-
-#if __BYTE_ORDER == __BIG_ENDIAN
- uint32_t alphahi = *d32++;
- uint32_t alphalo = *d32++;
- alphahi = swap(alphahi);
- alphalo = swap(alphalo);
-#else
- uint32_t alphalo = *d32++;
- uint32_t alphahi = *d32++;
-#endif
-
- uint32_t colors = *d32++;
- uint32_t bits = *d32++;
-
-#if __BYTE_ORDER == __BIG_ENDIAN
- colors = swap(colors);
- bits = swap(bits);
-#endif
-
- uint64_t alpha = ((uint64_t)alphahi << 32) | alphalo;
-
- // Raw colors
- uint16_t color0 = colors & 0xffff;
- uint16_t color1 = colors >> 16;
-
- // If the new block has the same base colors as the
- // previous one, we don't need to recompute the color
- // table c[]
- if (color0 != prev_color0 || color1 != prev_color1) {
- // Store raw colors for comparison with next block
- prev_color0 = color0;
- prev_color1 = color1;
-
- int bbits = bits >> 1;
- bool has2 = ((bbits & ~bits) & 0x55555555) != 0;
- bool has3 = ((bbits & bits) & 0x55555555) != 0;
-
- if (has2 || has3) {
- int r0 = red(color0);
- int g0 = green(color0);
- int b0 = blue(color0);
-
- int r1 = red(color1);
- int g1 = green(color1);
- int b1 = blue(color1);
-
- int r2 = avg23(r0, r1);
- int g2 = avg23(g0, g1);
- int b2 = avg23(b0, b1);
-
- int r3 = avg23(r1, r0);
- int g3 = avg23(g1, g0);
- int b3 = avg23(b1, b0);
-
- c[0] = rgb565SepTo888(r0, g0, b0);
- c[1] = rgb565SepTo888(r1, g1, b1);
- c[2] = rgb565SepTo888(r2, g2, b2);
- c[3] = rgb565SepTo888(r3, g3, b3);
- } else {
- // Convert to 8 bits
- c[0] = rgb565To888(color0);
- c[1] = rgb565To888(color1);
- }
- }
-
- uint32_t* blockRowPtr = blockPtr;
- for (int y = 0; y < 4; y++, blockRowPtr += stride) {
- // Don't process rows past the botom
- if (base_y + y >= height) {
- break;
- }
-
- int w = min(width - base_x, 4);
- for (int x = 0; x < w; x++) {
- int a = alpha & 0xf;
- alpha >>= 4;
-
- int code = bits & 0x3;
- bits >>= 2;
-
- blockRowPtr[x] = c[code] | (a << 28) | (a << 24);
- }
- }
- }
- }
-}
-
-// Output data as internalformat=GL_RGBA, type=GL_UNSIGNED_BYTE
-static void
-decodeDXT5(const GLvoid *data, int width, int height,
- void *surface, int stride)
-
-{
- init_tables();
-
- uint32_t const *d32 = (uint32_t *)data;
-
- // Specified alphas from the previous block
- uint8_t prev_alpha0 = 0x00;
- uint8_t prev_alpha1 = 0x00;
-
- // Specified colors from the previous block
- uint16_t prev_color0 = 0x0000;
- uint16_t prev_color1 = 0x0000;
-
- // Alpha table for the current block
- uint8_t a[8];
- a[0] = a[1] = a[2] = a[3] = a[4] = a[5] = a[6] = a[7] = 0;
-
- // Color table for the current block
- uint32_t c[4];
- c[0] = c[1] = c[2] = c[3] = 0;
-
- int good_a5 = 0;
- int bad_a5 = 0;
- int good_a6 = 0;
- int bad_a6 = 0;
- int good_a7 = 0;
- int bad_a7 = 0;
-
- uint32_t* rowPtr = (uint32_t*)surface;
- for (int base_y = 0; base_y < height; base_y += 4, rowPtr += 4*stride) {
- uint32_t *blockPtr = rowPtr;
- for (int base_x = 0; base_x < width; base_x += 4, blockPtr += 4) {
-
-#if __BYTE_ORDER == __BIG_ENDIAN
- uint32_t alphahi = *d32++;
- uint32_t alphalo = *d32++;
- alphahi = swap(alphahi);
- alphalo = swap(alphalo);
-#else
- uint32_t alphalo = *d32++;
- uint32_t alphahi = *d32++;
-#endif
-
- uint32_t colors = *d32++;
- uint32_t bits = *d32++;
-
-#if __BYTE_ORDER == __BIG_ENDIANx
- colors = swap(colors);
- bits = swap(bits);
-#endif
-
- uint64_t alpha = ((uint64_t)alphahi << 32) | alphalo;
- uint64_t alpha0 = alpha & 0xff;
- alpha >>= 8;
- uint64_t alpha1 = alpha & 0xff;
- alpha >>= 8;
-
- if (alpha0 != prev_alpha0 || alpha1 != prev_alpha1) {
- prev_alpha0 = alpha0;
- prev_alpha1 = alpha1;
-
- a[0] = alpha0;
- a[1] = alpha1;
- int a01 = alpha0 + alpha1 - 1;
- if (alpha0 > alpha1) {
- a[2] = div7(6*alpha0 + alpha1);
- a[4] = div7(4*alpha0 + 3*alpha1);
- a[6] = div7(2*alpha0 + 5*alpha1);
-
- // Use symmetry to derive half of the values
- // A few values will be off by 1 (~.5%)
- // Alternate which values are computed directly
- // and which are derived to try to reduce bias
- a[3] = a01 - a[6];
- a[5] = a01 - a[4];
- a[7] = a01 - a[2];
- } else {
- a[2] = div5(4*alpha0 + alpha1);
- a[4] = div5(2*alpha0 + 3*alpha1);
- a[3] = a01 - a[4];
- a[5] = a01 - a[2];
- a[6] = 0x00;
- a[7] = 0xff;
- }
- }
-
- // Raw colors
- uint16_t color0 = colors & 0xffff;
- uint16_t color1 = colors >> 16;
-
- // If the new block has the same base colors as the
- // previous one, we don't need to recompute the color
- // table c[]
- if (color0 != prev_color0 || color1 != prev_color1) {
- // Store raw colors for comparison with next block
- prev_color0 = color0;
- prev_color1 = color1;
-
- int bbits = bits >> 1;
- bool has2 = ((bbits & ~bits) & 0x55555555) != 0;
- bool has3 = ((bbits & bits) & 0x55555555) != 0;
-
- if (has2 || has3) {
- int r0 = red(color0);
- int g0 = green(color0);
- int b0 = blue(color0);
-
- int r1 = red(color1);
- int g1 = green(color1);
- int b1 = blue(color1);
-
- int r2 = avg23(r0, r1);
- int g2 = avg23(g0, g1);
- int b2 = avg23(b0, b1);
-
- int r3 = avg23(r1, r0);
- int g3 = avg23(g1, g0);
- int b3 = avg23(b1, b0);
-
- c[0] = rgb565SepTo888(r0, g0, b0);
- c[1] = rgb565SepTo888(r1, g1, b1);
- c[2] = rgb565SepTo888(r2, g2, b2);
- c[3] = rgb565SepTo888(r3, g3, b3);
- } else {
- // Convert to 8 bits
- c[0] = rgb565To888(color0);
- c[1] = rgb565To888(color1);
- }
- }
-
- uint32_t* blockRowPtr = blockPtr;
- for (int y = 0; y < 4; y++, blockRowPtr += stride) {
- // Don't process rows past the botom
- if (base_y + y >= height) {
- break;
- }
-
- int w = min(width - base_x, 4);
- for (int x = 0; x < w; x++) {
- int acode = alpha & 0x7;
- alpha >>= 3;
-
- int code = bits & 0x3;
- bits >>= 2;
-
- blockRowPtr[x] = c[code] | (a[acode] << 24);
- }
- }
- }
- }
-}
-
-/*
- * Decode a DXT-compressed texture into memory. DXT textures consist of
- * a series of 4x4 pixel blocks in left-to-right, top-down order.
- * The number of blocks is given by ceil(width/4)*ceil(height/4).
- *
- * 'data' points to the texture data. 'width' and 'height' indicate the
- * dimensions of the texture. We assume width and height are >= 0 but
- * do not require them to be powers of 2 or divisible by any factor.
- *
- * The output is written to 'surface' with each scanline separated by
- * 'stride' 2- or 4-byte words.
- *
- * 'format' indicates the type of compression and must be one of the following:
- *
- * GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
- * The output is written as 5/6/5 opaque RGB (16 bit words).
- * 8 bytes are read from 'data' for each block.
- *
- * GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
- * The output is written as 5/5/5/1 RGBA (16 bit words)
- * 8 bytes are read from 'data' for each block.
- *
- * GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
- * GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
- * The output is written as 8/8/8/8 ARGB (32 bit words)
- * 16 bytes are read from 'data' for each block.
- */
-void
-decodeDXT(const GLvoid *data, int width, int height,
- void *surface, int stride, int format)
-{
-#if TIMING
- struct timeval start_t, end_t;
- struct timezone tz;
-
- gettimeofday(&start_t, &tz);
-#endif
-
- switch (format) {
- case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
- decodeDXT1(data, width, height, surface, stride, false);
- break;
-
- case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
- decodeDXT1(data, width, height, surface, stride, true);
- break;
-
- case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
- decodeDXT3(data, width, height, surface, stride);
- break;
-
- case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
- decodeDXT5(data, width, height, surface, stride);
- break;
- }
-
-#if TIMING
- gettimeofday(&end_t, &tz);
- long usec = (end_t.tv_sec - start_t.tv_sec)*1000000 +
- (end_t.tv_usec - start_t.tv_usec);
-
- printf("Loaded w=%d h=%d in %ld usec\n", width, height, usec);
-#endif
-}
-
-} // namespace android
diff --git a/opengl/libagl/dxt.h b/opengl/libagl/dxt.h
deleted file mode 100644
index d95a36c..0000000
--- a/opengl/libagl/dxt.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/* libs/opengles/dxt.h
-**
-** Copyright 2007, 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.
-*/
-
-#ifndef ANDROID_OPENGLES_TEXTURE_H
-#define ANDROID_OPENGLES_TEXTURE_H
-
-#include <stdlib.h>
-
-#include <GLES/gl.h>
-
-namespace android {
-
- bool DXT1HasAlpha(const GLvoid *data, int width, int height);
- void decodeDXT(const GLvoid *data, int width, int height,
- void *surface, int stride, int format);
-
-} // namespace android
-
-#endif // ANDROID_OPENGLES_TEXTURE_H
diff --git a/opengl/libagl/egl.cpp b/opengl/libagl/egl.cpp
deleted file mode 100644
index be43705..0000000
--- a/opengl/libagl/egl.cpp
+++ /dev/null
@@ -1,2230 +0,0 @@
-/*
-**
-** Copyright 2007 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 <assert.h>
-#include <atomic>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <unistd.h>
-
-#include <log/log.h>
-
-#include <utils/threads.h>
-#include <ui/ANativeObjectBase.h>
-#include <ui/Fence.h>
-#include <ui/GraphicBufferMapper.h>
-#include <ui/Rect.h>
-
-#include <EGL/egl.h>
-#include <EGL/eglext.h>
-#include <GLES/gl.h>
-#include <GLES/glext.h>
-
-#include <pixelflinger/format.h>
-#include <pixelflinger/pixelflinger.h>
-
-#include "context.h"
-#include "state.h"
-#include "texture.h"
-#include "matrix.h"
-
-#undef NELEM
-#define NELEM(x) (sizeof(x)/sizeof(*(x)))
-
-// ----------------------------------------------------------------------------
-
-EGLBoolean EGLAPI eglSetSwapRectangleANDROID(EGLDisplay dpy, EGLSurface draw,
- EGLint left, EGLint top, EGLint width, EGLint height);
-
-
-typedef struct egl_native_pixmap_t
-{
- int32_t version; /* must be 32 */
- int32_t width;
- int32_t height;
- int32_t stride;
- uint8_t* data;
- uint8_t format;
- uint8_t rfu[3];
- union {
- uint32_t compressedFormat;
- int32_t vstride;
- };
- int32_t reserved;
-} egl_native_pixmap_t;
-
-
-// ----------------------------------------------------------------------------
-namespace android {
-
-// ----------------------------------------------------------------------------
-
-const unsigned int NUM_DISPLAYS = 1;
-
-#ifndef __ANDROID__
-static pthread_mutex_t gInitMutex = PTHREAD_MUTEX_INITIALIZER;
-#endif
-static pthread_mutex_t gErrorKeyMutex = PTHREAD_MUTEX_INITIALIZER;
-static pthread_key_t gEGLErrorKey = -1;
-#ifndef __ANDROID__
-namespace gl {
-pthread_key_t gGLKey = -1;
-}; // namespace gl
-#endif
-
-template<typename T>
-static T setError(GLint error, T returnValue) {
- if (ggl_unlikely(gEGLErrorKey == -1)) {
- pthread_mutex_lock(&gErrorKeyMutex);
- if (gEGLErrorKey == -1)
- pthread_key_create(&gEGLErrorKey, NULL);
- pthread_mutex_unlock(&gErrorKeyMutex);
- }
- pthread_setspecific(gEGLErrorKey, (void*)(uintptr_t)error);
- return returnValue;
-}
-
-static GLint getError() {
- if (ggl_unlikely(gEGLErrorKey == -1))
- return EGL_SUCCESS;
- GLint error = (GLint)(uintptr_t)pthread_getspecific(gEGLErrorKey);
- if (error == 0) {
- // The TLS key has been created by another thread, but the value for
- // this thread has not been initialized.
- return EGL_SUCCESS;
- }
- pthread_setspecific(gEGLErrorKey, (void*)(uintptr_t)EGL_SUCCESS);
- return error;
-}
-
-// ----------------------------------------------------------------------------
-
-struct egl_display_t
-{
- egl_display_t() : type(0), initialized(0) { }
-
- static egl_display_t& get_display(EGLDisplay dpy);
-
- static EGLBoolean is_valid(EGLDisplay dpy) {
- return ((uintptr_t(dpy)-1U) >= NUM_DISPLAYS) ? EGL_FALSE : EGL_TRUE;
- }
-
- NativeDisplayType type;
- std::atomic_size_t initialized;
-};
-
-static egl_display_t gDisplays[NUM_DISPLAYS];
-
-egl_display_t& egl_display_t::get_display(EGLDisplay dpy) {
- return gDisplays[uintptr_t(dpy)-1U];
-}
-
-struct egl_context_t {
- enum {
- IS_CURRENT = 0x00010000,
- NEVER_CURRENT = 0x00020000
- };
- uint32_t flags;
- EGLDisplay dpy;
- EGLConfig config;
- EGLSurface read;
- EGLSurface draw;
-
- static inline egl_context_t* context(EGLContext ctx) {
- ogles_context_t* const gl = static_cast<ogles_context_t*>(ctx);
- return static_cast<egl_context_t*>(gl->rasterizer.base);
- }
-};
-
-// ----------------------------------------------------------------------------
-
-struct egl_surface_t
-{
- enum {
- PAGE_FLIP = 0x00000001,
- MAGIC = 0x31415265
- };
-
- uint32_t magic;
- EGLDisplay dpy;
- EGLConfig config;
- EGLContext ctx;
- bool zombie;
-
- egl_surface_t(EGLDisplay dpy, EGLConfig config, int32_t depthFormat);
- virtual ~egl_surface_t();
- bool isValid() const;
- virtual bool initCheck() const = 0;
-
- virtual EGLBoolean bindDrawSurface(ogles_context_t* gl) = 0;
- virtual EGLBoolean bindReadSurface(ogles_context_t* gl) = 0;
- virtual EGLBoolean connect() { return EGL_TRUE; }
- virtual void disconnect() {}
- virtual EGLint getWidth() const = 0;
- virtual EGLint getHeight() const = 0;
-
- virtual EGLint getHorizontalResolution() const;
- virtual EGLint getVerticalResolution() const;
- virtual EGLint getRefreshRate() const;
- virtual EGLint getSwapBehavior() const;
- virtual EGLBoolean swapBuffers();
- virtual EGLBoolean setSwapRectangle(EGLint l, EGLint t, EGLint w, EGLint h);
-protected:
- GGLSurface depth;
-};
-
-egl_surface_t::egl_surface_t(EGLDisplay dpy,
- EGLConfig config,
- int32_t depthFormat)
- : magic(MAGIC), dpy(dpy), config(config), ctx(0), zombie(false)
-{
- depth.version = sizeof(GGLSurface);
- depth.data = 0;
- depth.format = depthFormat;
-}
-egl_surface_t::~egl_surface_t()
-{
- magic = 0;
- free(depth.data);
-}
-bool egl_surface_t::isValid() const {
- ALOGE_IF(magic != MAGIC, "invalid EGLSurface (%p)", this);
- return magic == MAGIC;
-}
-
-EGLBoolean egl_surface_t::swapBuffers() {
- return EGL_FALSE;
-}
-EGLint egl_surface_t::getHorizontalResolution() const {
- return (0 * EGL_DISPLAY_SCALING) * (1.0f / 25.4f);
-}
-EGLint egl_surface_t::getVerticalResolution() const {
- return (0 * EGL_DISPLAY_SCALING) * (1.0f / 25.4f);
-}
-EGLint egl_surface_t::getRefreshRate() const {
- return (60 * EGL_DISPLAY_SCALING);
-}
-EGLint egl_surface_t::getSwapBehavior() const {
- return EGL_BUFFER_PRESERVED;
-}
-EGLBoolean egl_surface_t::setSwapRectangle(
- EGLint /*l*/, EGLint /*t*/, EGLint /*w*/, EGLint /*h*/)
-{
- return EGL_FALSE;
-}
-
-// ----------------------------------------------------------------------------
-
-struct egl_window_surface_v2_t : public egl_surface_t
-{
- egl_window_surface_v2_t(
- EGLDisplay dpy, EGLConfig config,
- int32_t depthFormat,
- ANativeWindow* window);
-
- ~egl_window_surface_v2_t();
-
- virtual bool initCheck() const { return true; } // TODO: report failure if ctor fails
- virtual EGLBoolean swapBuffers();
- virtual EGLBoolean bindDrawSurface(ogles_context_t* gl);
- virtual EGLBoolean bindReadSurface(ogles_context_t* gl);
- virtual EGLBoolean connect();
- virtual void disconnect();
- virtual EGLint getWidth() const { return width; }
- virtual EGLint getHeight() const { return height; }
- virtual EGLint getHorizontalResolution() const;
- virtual EGLint getVerticalResolution() const;
- virtual EGLint getRefreshRate() const;
- virtual EGLint getSwapBehavior() const;
- virtual EGLBoolean setSwapRectangle(EGLint l, EGLint t, EGLint w, EGLint h);
-
-private:
- status_t lock(ANativeWindowBuffer* buf, int usage, void** vaddr);
- status_t unlock(ANativeWindowBuffer* buf);
- ANativeWindow* nativeWindow;
- ANativeWindowBuffer* buffer;
- ANativeWindowBuffer* previousBuffer;
- int width;
- int height;
- void* bits;
- GGLFormat const* pixelFormatTable;
-
- struct Rect {
- inline Rect() { };
- inline Rect(int32_t w, int32_t h)
- : left(0), top(0), right(w), bottom(h) { }
- inline Rect(int32_t l, int32_t t, int32_t r, int32_t b)
- : left(l), top(t), right(r), bottom(b) { }
- Rect& andSelf(const Rect& r) {
- left = max(left, r.left);
- top = max(top, r.top);
- right = min(right, r.right);
- bottom = min(bottom, r.bottom);
- return *this;
- }
- bool isEmpty() const {
- return (left>=right || top>=bottom);
- }
- void dump(char const* what) {
- ALOGD("%s { %5d, %5d, w=%5d, h=%5d }",
- what, left, top, right-left, bottom-top);
- }
-
- int32_t left;
- int32_t top;
- int32_t right;
- int32_t bottom;
- };
-
- struct Region {
- inline Region() : count(0) { }
- typedef Rect const* const_iterator;
- const_iterator begin() const { return storage; }
- const_iterator end() const { return storage+count; }
- static Region subtract(const Rect& lhs, const Rect& rhs) {
- Region reg;
- Rect* storage = reg.storage;
- if (!lhs.isEmpty()) {
- if (lhs.top < rhs.top) { // top rect
- storage->left = lhs.left;
- storage->top = lhs.top;
- storage->right = lhs.right;
- storage->bottom = rhs.top;
- storage++;
- }
- const int32_t top = max(lhs.top, rhs.top);
- const int32_t bot = min(lhs.bottom, rhs.bottom);
- if (top < bot) {
- if (lhs.left < rhs.left) { // left-side rect
- storage->left = lhs.left;
- storage->top = top;
- storage->right = rhs.left;
- storage->bottom = bot;
- storage++;
- }
- if (lhs.right > rhs.right) { // right-side rect
- storage->left = rhs.right;
- storage->top = top;
- storage->right = lhs.right;
- storage->bottom = bot;
- storage++;
- }
- }
- if (lhs.bottom > rhs.bottom) { // bottom rect
- storage->left = lhs.left;
- storage->top = rhs.bottom;
- storage->right = lhs.right;
- storage->bottom = lhs.bottom;
- storage++;
- }
- reg.count = storage - reg.storage;
- }
- return reg;
- }
- bool isEmpty() const {
- return count<=0;
- }
- private:
- Rect storage[4];
- ssize_t count;
- };
-
- void copyBlt(
- ANativeWindowBuffer* dst, void* dst_vaddr,
- ANativeWindowBuffer* src, void const* src_vaddr,
- const Region& clip);
-
- Rect dirtyRegion;
- Rect oldDirtyRegion;
-};
-
-egl_window_surface_v2_t::egl_window_surface_v2_t(EGLDisplay dpy,
- EGLConfig config,
- int32_t depthFormat,
- ANativeWindow* window)
- : egl_surface_t(dpy, config, depthFormat),
- nativeWindow(window), buffer(0), previousBuffer(0), bits(NULL)
-{
-
- pixelFormatTable = gglGetPixelFormatTable();
-
- // keep a reference on the window
- nativeWindow->common.incRef(&nativeWindow->common);
- nativeWindow->query(nativeWindow, NATIVE_WINDOW_WIDTH, &width);
- nativeWindow->query(nativeWindow, NATIVE_WINDOW_HEIGHT, &height);
-}
-
-egl_window_surface_v2_t::~egl_window_surface_v2_t() {
- if (buffer) {
- buffer->common.decRef(&buffer->common);
- }
- if (previousBuffer) {
- previousBuffer->common.decRef(&previousBuffer->common);
- }
- nativeWindow->common.decRef(&nativeWindow->common);
-}
-
-EGLBoolean egl_window_surface_v2_t::connect()
-{
- // we're intending to do software rendering
- native_window_set_usage(nativeWindow,
- GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);
-
- // dequeue a buffer
- int fenceFd = -1;
- if (nativeWindow->dequeueBuffer(nativeWindow, &buffer,
- &fenceFd) != NO_ERROR) {
- return setError(EGL_BAD_ALLOC, EGL_FALSE);
- }
-
- // wait for the buffer
- sp<Fence> fence(new Fence(fenceFd));
- if (fence->wait(Fence::TIMEOUT_NEVER) != NO_ERROR) {
- nativeWindow->cancelBuffer(nativeWindow, buffer, fenceFd);
- return setError(EGL_BAD_ALLOC, EGL_FALSE);
- }
-
- // allocate a corresponding depth-buffer
- width = buffer->width;
- height = buffer->height;
- if (depth.format) {
- depth.width = width;
- depth.height = height;
- depth.stride = depth.width; // use the width here
- uint64_t allocSize = static_cast<uint64_t>(depth.stride) *
- static_cast<uint64_t>(depth.height) * 2;
- if (depth.stride < 0 || depth.height > INT_MAX ||
- allocSize > UINT32_MAX) {
- return setError(EGL_BAD_ALLOC, EGL_FALSE);
- }
- depth.data = (GGLubyte*)malloc(allocSize);
- if (depth.data == 0) {
- return setError(EGL_BAD_ALLOC, EGL_FALSE);
- }
- }
-
- // keep a reference on the buffer
- buffer->common.incRef(&buffer->common);
-
- // pin the buffer down
- if (lock(buffer, GRALLOC_USAGE_SW_READ_OFTEN |
- GRALLOC_USAGE_SW_WRITE_OFTEN, &bits) != NO_ERROR) {
- ALOGE("connect() failed to lock buffer %p (%ux%u)",
- buffer, buffer->width, buffer->height);
- return setError(EGL_BAD_ACCESS, EGL_FALSE);
- // FIXME: we should make sure we're not accessing the buffer anymore
- }
- return EGL_TRUE;
-}
-
-void egl_window_surface_v2_t::disconnect()
-{
- if (buffer && bits) {
- bits = NULL;
- unlock(buffer);
- }
- if (buffer) {
- nativeWindow->cancelBuffer(nativeWindow, buffer, -1);
- buffer->common.decRef(&buffer->common);
- buffer = 0;
- }
- if (previousBuffer) {
- previousBuffer->common.decRef(&previousBuffer->common);
- previousBuffer = 0;
- }
-}
-
-status_t egl_window_surface_v2_t::lock(
- ANativeWindowBuffer* buf, int usage, void** vaddr)
-{
- auto& mapper = GraphicBufferMapper::get();
- return mapper.lock(buf->handle, usage,
- android::Rect(buf->width, buf->height), vaddr);
-}
-
-status_t egl_window_surface_v2_t::unlock(ANativeWindowBuffer* buf)
-{
- if (!buf) return BAD_VALUE;
- auto& mapper = GraphicBufferMapper::get();
- return mapper.unlock(buf->handle);
-}
-
-void egl_window_surface_v2_t::copyBlt(
- ANativeWindowBuffer* dst, void* dst_vaddr,
- ANativeWindowBuffer* src, void const* src_vaddr,
- const Region& clip)
-{
- // NOTE: dst and src must be the same format
-
- Region::const_iterator cur = clip.begin();
- Region::const_iterator end = clip.end();
-
- const size_t bpp = pixelFormatTable[src->format].size;
- const size_t dbpr = dst->stride * bpp;
- const size_t sbpr = src->stride * bpp;
-
- uint8_t const * const src_bits = (uint8_t const *)src_vaddr;
- uint8_t * const dst_bits = (uint8_t *)dst_vaddr;
-
- while (cur != end) {
- const Rect& r(*cur++);
- ssize_t w = r.right - r.left;
- ssize_t h = r.bottom - r.top;
- if (w <= 0 || h<=0) continue;
- size_t size = w * bpp;
- uint8_t const * s = src_bits + (r.left + src->stride * r.top) * bpp;
- uint8_t * d = dst_bits + (r.left + dst->stride * r.top) * bpp;
- if (dbpr==sbpr && size==sbpr) {
- size *= h;
- h = 1;
- }
- do {
- memcpy(d, s, size);
- d += dbpr;
- s += sbpr;
- } while (--h > 0);
- }
-}
-
-EGLBoolean egl_window_surface_v2_t::swapBuffers()
-{
- if (!buffer) {
- return setError(EGL_BAD_ACCESS, EGL_FALSE);
- }
-
- /*
- * Handle eglSetSwapRectangleANDROID()
- * We copyback from the front buffer
- */
- if (!dirtyRegion.isEmpty()) {
- dirtyRegion.andSelf(Rect(buffer->width, buffer->height));
- if (previousBuffer) {
- // This was const Region copyBack, but that causes an
- // internal compile error on simulator builds
- /*const*/ Region copyBack(Region::subtract(oldDirtyRegion, dirtyRegion));
- if (!copyBack.isEmpty()) {
- void* prevBits;
- if (lock(previousBuffer,
- GRALLOC_USAGE_SW_READ_OFTEN, &prevBits) == NO_ERROR) {
- // copy from previousBuffer to buffer
- copyBlt(buffer, bits, previousBuffer, prevBits, copyBack);
- unlock(previousBuffer);
- }
- }
- }
- oldDirtyRegion = dirtyRegion;
- }
-
- if (previousBuffer) {
- previousBuffer->common.decRef(&previousBuffer->common);
- previousBuffer = 0;
- }
-
- unlock(buffer);
- previousBuffer = buffer;
- nativeWindow->queueBuffer(nativeWindow, buffer, -1);
- buffer = 0;
-
- // dequeue a new buffer
- int fenceFd = -1;
- if (nativeWindow->dequeueBuffer(nativeWindow, &buffer, &fenceFd) == NO_ERROR) {
- sp<Fence> fence(new Fence(fenceFd));
- if (fence->wait(Fence::TIMEOUT_NEVER)) {
- nativeWindow->cancelBuffer(nativeWindow, buffer, fenceFd);
- return setError(EGL_BAD_ALLOC, EGL_FALSE);
- }
-
- // reallocate the depth-buffer if needed
- if ((width != buffer->width) || (height != buffer->height)) {
- // TODO: we probably should reset the swap rect here
- // if the window size has changed
- width = buffer->width;
- height = buffer->height;
- if (depth.data) {
- free(depth.data);
- depth.width = width;
- depth.height = height;
- depth.stride = buffer->stride;
- uint64_t allocSize = static_cast<uint64_t>(depth.stride) *
- static_cast<uint64_t>(depth.height) * 2;
- if (depth.stride < 0 || depth.height > INT_MAX ||
- allocSize > UINT32_MAX) {
- setError(EGL_BAD_ALLOC, EGL_FALSE);
- return EGL_FALSE;
- }
- depth.data = (GGLubyte*)malloc(allocSize);
- if (depth.data == 0) {
- setError(EGL_BAD_ALLOC, EGL_FALSE);
- return EGL_FALSE;
- }
- }
- }
-
- // keep a reference on the buffer
- buffer->common.incRef(&buffer->common);
-
- // finally pin the buffer down
- if (lock(buffer, GRALLOC_USAGE_SW_READ_OFTEN |
- GRALLOC_USAGE_SW_WRITE_OFTEN, &bits) != NO_ERROR) {
- ALOGE("eglSwapBuffers() failed to lock buffer %p (%ux%u)",
- buffer, buffer->width, buffer->height);
- return setError(EGL_BAD_ACCESS, EGL_FALSE);
- // FIXME: we should make sure we're not accessing the buffer anymore
- }
- } else {
- return setError(EGL_BAD_CURRENT_SURFACE, EGL_FALSE);
- }
-
- return EGL_TRUE;
-}
-
-EGLBoolean egl_window_surface_v2_t::setSwapRectangle(
- EGLint l, EGLint t, EGLint w, EGLint h)
-{
- dirtyRegion = Rect(l, t, l+w, t+h);
- return EGL_TRUE;
-}
-
-EGLBoolean egl_window_surface_v2_t::bindDrawSurface(ogles_context_t* gl)
-{
- GGLSurface buffer;
- buffer.version = sizeof(GGLSurface);
- buffer.width = this->buffer->width;
- buffer.height = this->buffer->height;
- buffer.stride = this->buffer->stride;
- buffer.data = (GGLubyte*)bits;
- buffer.format = this->buffer->format;
- gl->rasterizer.procs.colorBuffer(gl, &buffer);
- if (depth.data != gl->rasterizer.state.buffers.depth.data)
- gl->rasterizer.procs.depthBuffer(gl, &depth);
-
- return EGL_TRUE;
-}
-EGLBoolean egl_window_surface_v2_t::bindReadSurface(ogles_context_t* gl)
-{
- GGLSurface buffer;
- buffer.version = sizeof(GGLSurface);
- buffer.width = this->buffer->width;
- buffer.height = this->buffer->height;
- buffer.stride = this->buffer->stride;
- buffer.data = (GGLubyte*)bits; // FIXME: hopefully is is LOCKED!!!
- buffer.format = this->buffer->format;
- gl->rasterizer.procs.readBuffer(gl, &buffer);
- return EGL_TRUE;
-}
-EGLint egl_window_surface_v2_t::getHorizontalResolution() const {
- return (nativeWindow->xdpi * EGL_DISPLAY_SCALING) * (1.0f / 25.4f);
-}
-EGLint egl_window_surface_v2_t::getVerticalResolution() const {
- return (nativeWindow->ydpi * EGL_DISPLAY_SCALING) * (1.0f / 25.4f);
-}
-EGLint egl_window_surface_v2_t::getRefreshRate() const {
- return (60 * EGL_DISPLAY_SCALING); // FIXME
-}
-EGLint egl_window_surface_v2_t::getSwapBehavior() const
-{
- /*
- * EGL_BUFFER_PRESERVED means that eglSwapBuffers() completely preserves
- * the content of the swapped buffer.
- *
- * EGL_BUFFER_DESTROYED means that the content of the buffer is lost.
- *
- * However when ANDROID_swap_retcangle is supported, EGL_BUFFER_DESTROYED
- * only applies to the area specified by eglSetSwapRectangleANDROID(), that
- * is, everything outside of this area is preserved.
- *
- * This implementation of EGL assumes the later case.
- *
- */
-
- return EGL_BUFFER_DESTROYED;
-}
-
-// ----------------------------------------------------------------------------
-
-struct egl_pixmap_surface_t : public egl_surface_t
-{
- egl_pixmap_surface_t(
- EGLDisplay dpy, EGLConfig config,
- int32_t depthFormat,
- egl_native_pixmap_t const * pixmap);
-
- virtual ~egl_pixmap_surface_t() { }
-
- virtual bool initCheck() const { return !depth.format || depth.data!=0; }
- virtual EGLBoolean bindDrawSurface(ogles_context_t* gl);
- virtual EGLBoolean bindReadSurface(ogles_context_t* gl);
- virtual EGLint getWidth() const { return nativePixmap.width; }
- virtual EGLint getHeight() const { return nativePixmap.height; }
-private:
- egl_native_pixmap_t nativePixmap;
-};
-
-egl_pixmap_surface_t::egl_pixmap_surface_t(EGLDisplay dpy,
- EGLConfig config,
- int32_t depthFormat,
- egl_native_pixmap_t const * pixmap)
- : egl_surface_t(dpy, config, depthFormat), nativePixmap(*pixmap)
-{
- if (depthFormat) {
- depth.width = pixmap->width;
- depth.height = pixmap->height;
- depth.stride = depth.width; // use the width here
- uint64_t allocSize = static_cast<uint64_t>(depth.stride) *
- static_cast<uint64_t>(depth.height) * 2;
- if (depth.stride < 0 || depth.height > INT_MAX ||
- allocSize > UINT32_MAX) {
- setError(EGL_BAD_ALLOC, EGL_NO_SURFACE);
- return;
- }
- depth.data = (GGLubyte*)malloc(allocSize);
- if (depth.data == 0) {
- setError(EGL_BAD_ALLOC, EGL_NO_SURFACE);
- }
- }
-}
-EGLBoolean egl_pixmap_surface_t::bindDrawSurface(ogles_context_t* gl)
-{
- GGLSurface buffer;
- buffer.version = sizeof(GGLSurface);
- buffer.width = nativePixmap.width;
- buffer.height = nativePixmap.height;
- buffer.stride = nativePixmap.stride;
- buffer.data = nativePixmap.data;
- buffer.format = nativePixmap.format;
-
- gl->rasterizer.procs.colorBuffer(gl, &buffer);
- if (depth.data != gl->rasterizer.state.buffers.depth.data)
- gl->rasterizer.procs.depthBuffer(gl, &depth);
- return EGL_TRUE;
-}
-EGLBoolean egl_pixmap_surface_t::bindReadSurface(ogles_context_t* gl)
-{
- GGLSurface buffer;
- buffer.version = sizeof(GGLSurface);
- buffer.width = nativePixmap.width;
- buffer.height = nativePixmap.height;
- buffer.stride = nativePixmap.stride;
- buffer.data = nativePixmap.data;
- buffer.format = nativePixmap.format;
- gl->rasterizer.procs.readBuffer(gl, &buffer);
- return EGL_TRUE;
-}
-
-// ----------------------------------------------------------------------------
-
-struct egl_pbuffer_surface_t : public egl_surface_t
-{
- egl_pbuffer_surface_t(
- EGLDisplay dpy, EGLConfig config, int32_t depthFormat,
- int32_t w, int32_t h, int32_t f);
-
- virtual ~egl_pbuffer_surface_t();
-
- virtual bool initCheck() const { return pbuffer.data != 0; }
- virtual EGLBoolean bindDrawSurface(ogles_context_t* gl);
- virtual EGLBoolean bindReadSurface(ogles_context_t* gl);
- virtual EGLint getWidth() const { return pbuffer.width; }
- virtual EGLint getHeight() const { return pbuffer.height; }
-private:
- GGLSurface pbuffer;
-};
-
-egl_pbuffer_surface_t::egl_pbuffer_surface_t(EGLDisplay dpy,
- EGLConfig config, int32_t depthFormat,
- int32_t w, int32_t h, int32_t f)
- : egl_surface_t(dpy, config, depthFormat)
-{
- size_t size = w*h;
- switch (f) {
- case GGL_PIXEL_FORMAT_A_8: size *= 1; break;
- case GGL_PIXEL_FORMAT_RGB_565: size *= 2; break;
- case GGL_PIXEL_FORMAT_RGBA_8888: size *= 4; break;
- case GGL_PIXEL_FORMAT_RGBX_8888: size *= 4; break;
- case GGL_PIXEL_FORMAT_BGRA_8888: size *= 4; break;
- default:
- ALOGE("incompatible pixel format for pbuffer (format=%d)", f);
- pbuffer.data = 0;
- break;
- }
- pbuffer.version = sizeof(GGLSurface);
- pbuffer.width = w;
- pbuffer.height = h;
- pbuffer.stride = w;
- pbuffer.data = (GGLubyte*)malloc(size);
- pbuffer.format = f;
-
- if (depthFormat) {
- depth.width = pbuffer.width;
- depth.height = pbuffer.height;
- depth.stride = depth.width; // use the width here
- uint64_t allocSize = static_cast<uint64_t>(depth.stride) *
- static_cast<uint64_t>(depth.height) * 2;
- if (depth.stride < 0 || depth.height > INT_MAX ||
- allocSize > UINT32_MAX) {
- setError(EGL_BAD_ALLOC, EGL_NO_SURFACE);
- return;
- }
- depth.data = (GGLubyte*)malloc(allocSize);
- if (depth.data == 0) {
- setError(EGL_BAD_ALLOC, EGL_NO_SURFACE);
- return;
- }
- }
-}
-egl_pbuffer_surface_t::~egl_pbuffer_surface_t() {
- free(pbuffer.data);
-}
-EGLBoolean egl_pbuffer_surface_t::bindDrawSurface(ogles_context_t* gl)
-{
- gl->rasterizer.procs.colorBuffer(gl, &pbuffer);
- if (depth.data != gl->rasterizer.state.buffers.depth.data)
- gl->rasterizer.procs.depthBuffer(gl, &depth);
- return EGL_TRUE;
-}
-EGLBoolean egl_pbuffer_surface_t::bindReadSurface(ogles_context_t* gl)
-{
- gl->rasterizer.procs.readBuffer(gl, &pbuffer);
- return EGL_TRUE;
-}
-
-// ----------------------------------------------------------------------------
-
-struct config_pair_t {
- GLint key;
- GLint value;
-};
-
-struct configs_t {
- const config_pair_t* array;
- int size;
-};
-
-struct config_management_t {
- GLint key;
- bool (*match)(GLint reqValue, GLint confValue);
- static bool atLeast(GLint reqValue, GLint confValue) {
- return (reqValue == EGL_DONT_CARE) || (confValue >= reqValue);
- }
- static bool exact(GLint reqValue, GLint confValue) {
- return (reqValue == EGL_DONT_CARE) || (confValue == reqValue);
- }
- static bool mask(GLint reqValue, GLint confValue) {
- return (confValue & reqValue) == reqValue;
- }
- static bool ignore(GLint /*reqValue*/, GLint /*confValue*/) {
- return true;
- }
-};
-
-// ----------------------------------------------------------------------------
-
-#define VERSION_MAJOR 1
-#define VERSION_MINOR 2
-static char const * const gVendorString = "Google Inc.";
-static char const * const gVersionString = "1.2 Android Driver 1.2.0";
-static char const * const gClientApiString = "OpenGL_ES";
-static char const * const gExtensionsString =
- "EGL_KHR_fence_sync "
- "EGL_KHR_image_base "
- // "KHR_image_pixmap "
- "EGL_ANDROID_image_native_buffer "
- "EGL_ANDROID_swap_rectangle "
- ;
-
-// ----------------------------------------------------------------------------
-
-struct extention_map_t {
- const char * const name;
- __eglMustCastToProperFunctionPointerType address;
-};
-
-static const extention_map_t gExtentionMap[] = {
- { "glDrawTexsOES",
- (__eglMustCastToProperFunctionPointerType)&glDrawTexsOES },
- { "glDrawTexiOES",
- (__eglMustCastToProperFunctionPointerType)&glDrawTexiOES },
- { "glDrawTexfOES",
- (__eglMustCastToProperFunctionPointerType)&glDrawTexfOES },
- { "glDrawTexxOES",
- (__eglMustCastToProperFunctionPointerType)&glDrawTexxOES },
- { "glDrawTexsvOES",
- (__eglMustCastToProperFunctionPointerType)&glDrawTexsvOES },
- { "glDrawTexivOES",
- (__eglMustCastToProperFunctionPointerType)&glDrawTexivOES },
- { "glDrawTexfvOES",
- (__eglMustCastToProperFunctionPointerType)&glDrawTexfvOES },
- { "glDrawTexxvOES",
- (__eglMustCastToProperFunctionPointerType)&glDrawTexxvOES },
- { "glQueryMatrixxOES",
- (__eglMustCastToProperFunctionPointerType)&glQueryMatrixxOES },
- { "glEGLImageTargetTexture2DOES",
- (__eglMustCastToProperFunctionPointerType)&glEGLImageTargetTexture2DOES },
- { "glEGLImageTargetRenderbufferStorageOES",
- (__eglMustCastToProperFunctionPointerType)&glEGLImageTargetRenderbufferStorageOES },
- { "glClipPlanef",
- (__eglMustCastToProperFunctionPointerType)&glClipPlanef },
- { "glClipPlanex",
- (__eglMustCastToProperFunctionPointerType)&glClipPlanex },
- { "glBindBuffer",
- (__eglMustCastToProperFunctionPointerType)&glBindBuffer },
- { "glBufferData",
- (__eglMustCastToProperFunctionPointerType)&glBufferData },
- { "glBufferSubData",
- (__eglMustCastToProperFunctionPointerType)&glBufferSubData },
- { "glDeleteBuffers",
- (__eglMustCastToProperFunctionPointerType)&glDeleteBuffers },
- { "glGenBuffers",
- (__eglMustCastToProperFunctionPointerType)&glGenBuffers },
- { "eglCreateImageKHR",
- (__eglMustCastToProperFunctionPointerType)&eglCreateImageKHR },
- { "eglDestroyImageKHR",
- (__eglMustCastToProperFunctionPointerType)&eglDestroyImageKHR },
- { "eglCreateSyncKHR",
- (__eglMustCastToProperFunctionPointerType)&eglCreateSyncKHR },
- { "eglDestroySyncKHR",
- (__eglMustCastToProperFunctionPointerType)&eglDestroySyncKHR },
- { "eglClientWaitSyncKHR",
- (__eglMustCastToProperFunctionPointerType)&eglClientWaitSyncKHR },
- { "eglGetSyncAttribKHR",
- (__eglMustCastToProperFunctionPointerType)&eglGetSyncAttribKHR },
- { "eglSetSwapRectangleANDROID",
- (__eglMustCastToProperFunctionPointerType)&eglSetSwapRectangleANDROID },
-};
-
-/*
- * In the lists below, attributes names MUST be sorted.
- * Additionally, all configs must be sorted according to
- * the EGL specification.
- */
-
-static config_pair_t const config_base_attribute_list[] = {
- { EGL_STENCIL_SIZE, 0 },
- { EGL_CONFIG_CAVEAT, EGL_SLOW_CONFIG },
- { EGL_LEVEL, 0 },
- { EGL_MAX_PBUFFER_HEIGHT, GGL_MAX_VIEWPORT_DIMS },
- { EGL_MAX_PBUFFER_PIXELS,
- GGL_MAX_VIEWPORT_DIMS*GGL_MAX_VIEWPORT_DIMS },
- { EGL_MAX_PBUFFER_WIDTH, GGL_MAX_VIEWPORT_DIMS },
- { EGL_NATIVE_RENDERABLE, EGL_TRUE },
- { EGL_NATIVE_VISUAL_ID, 0 },
- { EGL_NATIVE_VISUAL_TYPE, GGL_PIXEL_FORMAT_RGB_565 },
- { EGL_SAMPLES, 0 },
- { EGL_SAMPLE_BUFFERS, 0 },
- { EGL_TRANSPARENT_TYPE, EGL_NONE },
- { EGL_TRANSPARENT_BLUE_VALUE, 0 },
- { EGL_TRANSPARENT_GREEN_VALUE, 0 },
- { EGL_TRANSPARENT_RED_VALUE, 0 },
- { EGL_BIND_TO_TEXTURE_RGBA, EGL_FALSE },
- { EGL_BIND_TO_TEXTURE_RGB, EGL_FALSE },
- { EGL_MIN_SWAP_INTERVAL, 1 },
- { EGL_MAX_SWAP_INTERVAL, 1 },
- { EGL_LUMINANCE_SIZE, 0 },
- { EGL_ALPHA_MASK_SIZE, 0 },
- { EGL_COLOR_BUFFER_TYPE, EGL_RGB_BUFFER },
- { EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT },
- { EGL_CONFORMANT, 0 }
-};
-
-// These configs can override the base attribute list
-// NOTE: when adding a config here, don't forget to update eglCreate*Surface()
-
-// 565 configs
-static config_pair_t const config_0_attribute_list[] = {
- { EGL_BUFFER_SIZE, 16 },
- { EGL_ALPHA_SIZE, 0 },
- { EGL_BLUE_SIZE, 5 },
- { EGL_GREEN_SIZE, 6 },
- { EGL_RED_SIZE, 5 },
- { EGL_DEPTH_SIZE, 0 },
- { EGL_CONFIG_ID, 0 },
- { EGL_NATIVE_VISUAL_ID, GGL_PIXEL_FORMAT_RGB_565 },
- { EGL_SURFACE_TYPE, EGL_WINDOW_BIT|EGL_PBUFFER_BIT|EGL_PIXMAP_BIT },
-};
-
-static config_pair_t const config_1_attribute_list[] = {
- { EGL_BUFFER_SIZE, 16 },
- { EGL_ALPHA_SIZE, 0 },
- { EGL_BLUE_SIZE, 5 },
- { EGL_GREEN_SIZE, 6 },
- { EGL_RED_SIZE, 5 },
- { EGL_DEPTH_SIZE, 16 },
- { EGL_CONFIG_ID, 1 },
- { EGL_NATIVE_VISUAL_ID, GGL_PIXEL_FORMAT_RGB_565 },
- { EGL_SURFACE_TYPE, EGL_WINDOW_BIT|EGL_PBUFFER_BIT|EGL_PIXMAP_BIT },
-};
-
-// RGB 888 configs
-static config_pair_t const config_2_attribute_list[] = {
- { EGL_BUFFER_SIZE, 32 },
- { EGL_ALPHA_SIZE, 0 },
- { EGL_BLUE_SIZE, 8 },
- { EGL_GREEN_SIZE, 8 },
- { EGL_RED_SIZE, 8 },
- { EGL_DEPTH_SIZE, 0 },
- { EGL_CONFIG_ID, 6 },
- { EGL_NATIVE_VISUAL_ID, GGL_PIXEL_FORMAT_RGBX_8888 },
- { EGL_SURFACE_TYPE, EGL_WINDOW_BIT|EGL_PBUFFER_BIT|EGL_PIXMAP_BIT },
-};
-
-static config_pair_t const config_3_attribute_list[] = {
- { EGL_BUFFER_SIZE, 32 },
- { EGL_ALPHA_SIZE, 0 },
- { EGL_BLUE_SIZE, 8 },
- { EGL_GREEN_SIZE, 8 },
- { EGL_RED_SIZE, 8 },
- { EGL_DEPTH_SIZE, 16 },
- { EGL_CONFIG_ID, 7 },
- { EGL_NATIVE_VISUAL_ID, GGL_PIXEL_FORMAT_RGBX_8888 },
- { EGL_SURFACE_TYPE, EGL_WINDOW_BIT|EGL_PBUFFER_BIT|EGL_PIXMAP_BIT },
-};
-
-// 8888 configs
-static config_pair_t const config_4_attribute_list[] = {
- { EGL_BUFFER_SIZE, 32 },
- { EGL_ALPHA_SIZE, 8 },
- { EGL_BLUE_SIZE, 8 },
- { EGL_GREEN_SIZE, 8 },
- { EGL_RED_SIZE, 8 },
- { EGL_DEPTH_SIZE, 0 },
- { EGL_CONFIG_ID, 2 },
- { EGL_NATIVE_VISUAL_ID, GGL_PIXEL_FORMAT_RGBA_8888 },
- { EGL_SURFACE_TYPE, EGL_WINDOW_BIT|EGL_PBUFFER_BIT|EGL_PIXMAP_BIT },
-};
-
-static config_pair_t const config_5_attribute_list[] = {
- { EGL_BUFFER_SIZE, 32 },
- { EGL_ALPHA_SIZE, 8 },
- { EGL_BLUE_SIZE, 8 },
- { EGL_GREEN_SIZE, 8 },
- { EGL_RED_SIZE, 8 },
- { EGL_DEPTH_SIZE, 16 },
- { EGL_CONFIG_ID, 3 },
- { EGL_NATIVE_VISUAL_ID, GGL_PIXEL_FORMAT_RGBA_8888 },
- { EGL_SURFACE_TYPE, EGL_WINDOW_BIT|EGL_PBUFFER_BIT|EGL_PIXMAP_BIT },
-};
-
-// A8 configs
-static config_pair_t const config_6_attribute_list[] = {
- { EGL_BUFFER_SIZE, 8 },
- { EGL_ALPHA_SIZE, 8 },
- { EGL_BLUE_SIZE, 0 },
- { EGL_GREEN_SIZE, 0 },
- { EGL_RED_SIZE, 0 },
- { EGL_DEPTH_SIZE, 0 },
- { EGL_CONFIG_ID, 4 },
- { EGL_NATIVE_VISUAL_ID, GGL_PIXEL_FORMAT_A_8 },
- { EGL_SURFACE_TYPE, EGL_WINDOW_BIT|EGL_PBUFFER_BIT|EGL_PIXMAP_BIT },
-};
-
-static config_pair_t const config_7_attribute_list[] = {
- { EGL_BUFFER_SIZE, 8 },
- { EGL_ALPHA_SIZE, 8 },
- { EGL_BLUE_SIZE, 0 },
- { EGL_GREEN_SIZE, 0 },
- { EGL_RED_SIZE, 0 },
- { EGL_DEPTH_SIZE, 16 },
- { EGL_CONFIG_ID, 5 },
- { EGL_NATIVE_VISUAL_ID, GGL_PIXEL_FORMAT_A_8 },
- { EGL_SURFACE_TYPE, EGL_WINDOW_BIT|EGL_PBUFFER_BIT|EGL_PIXMAP_BIT },
-};
-
-// BGRA 8888 config
-static config_pair_t const config_8_attribute_list[] = {
- { EGL_BUFFER_SIZE, 32 },
- { EGL_ALPHA_SIZE, 8 },
- { EGL_BLUE_SIZE, 8 },
- { EGL_GREEN_SIZE, 8 },
- { EGL_RED_SIZE, 8 },
- { EGL_DEPTH_SIZE, 0 },
- { EGL_CONFIG_ID, 8 },
- { EGL_NATIVE_VISUAL_ID, GGL_PIXEL_FORMAT_BGRA_8888 },
- { EGL_SURFACE_TYPE, EGL_WINDOW_BIT|EGL_PBUFFER_BIT|EGL_PIXMAP_BIT },
-};
-
-static configs_t const gConfigs[] = {
- { config_0_attribute_list, NELEM(config_0_attribute_list) },
- { config_1_attribute_list, NELEM(config_1_attribute_list) },
- { config_2_attribute_list, NELEM(config_2_attribute_list) },
- { config_3_attribute_list, NELEM(config_3_attribute_list) },
- { config_4_attribute_list, NELEM(config_4_attribute_list) },
- { config_5_attribute_list, NELEM(config_5_attribute_list) },
- { config_6_attribute_list, NELEM(config_6_attribute_list) },
- { config_7_attribute_list, NELEM(config_7_attribute_list) },
- { config_8_attribute_list, NELEM(config_8_attribute_list) },
-};
-
-static config_management_t const gConfigManagement[] = {
- { EGL_BUFFER_SIZE, config_management_t::atLeast },
- { EGL_ALPHA_SIZE, config_management_t::atLeast },
- { EGL_BLUE_SIZE, config_management_t::atLeast },
- { EGL_GREEN_SIZE, config_management_t::atLeast },
- { EGL_RED_SIZE, config_management_t::atLeast },
- { EGL_DEPTH_SIZE, config_management_t::atLeast },
- { EGL_STENCIL_SIZE, config_management_t::atLeast },
- { EGL_CONFIG_CAVEAT, config_management_t::exact },
- { EGL_CONFIG_ID, config_management_t::exact },
- { EGL_LEVEL, config_management_t::exact },
- { EGL_MAX_PBUFFER_HEIGHT, config_management_t::ignore },
- { EGL_MAX_PBUFFER_PIXELS, config_management_t::ignore },
- { EGL_MAX_PBUFFER_WIDTH, config_management_t::ignore },
- { EGL_NATIVE_RENDERABLE, config_management_t::exact },
- { EGL_NATIVE_VISUAL_ID, config_management_t::ignore },
- { EGL_NATIVE_VISUAL_TYPE, config_management_t::exact },
- { EGL_SAMPLES, config_management_t::exact },
- { EGL_SAMPLE_BUFFERS, config_management_t::exact },
- { EGL_SURFACE_TYPE, config_management_t::mask },
- { EGL_TRANSPARENT_TYPE, config_management_t::exact },
- { EGL_TRANSPARENT_BLUE_VALUE, config_management_t::exact },
- { EGL_TRANSPARENT_GREEN_VALUE, config_management_t::exact },
- { EGL_TRANSPARENT_RED_VALUE, config_management_t::exact },
- { EGL_BIND_TO_TEXTURE_RGBA, config_management_t::exact },
- { EGL_BIND_TO_TEXTURE_RGB, config_management_t::exact },
- { EGL_MIN_SWAP_INTERVAL, config_management_t::exact },
- { EGL_MAX_SWAP_INTERVAL, config_management_t::exact },
- { EGL_LUMINANCE_SIZE, config_management_t::atLeast },
- { EGL_ALPHA_MASK_SIZE, config_management_t::atLeast },
- { EGL_COLOR_BUFFER_TYPE, config_management_t::exact },
- { EGL_RENDERABLE_TYPE, config_management_t::mask },
- { EGL_CONFORMANT, config_management_t::mask }
-};
-
-
-static config_pair_t const config_defaults[] = {
- // attributes that are not specified are simply ignored, if a particular
- // one needs not be ignored, it must be specified here, eg:
- // { EGL_SURFACE_TYPE, EGL_WINDOW_BIT },
-};
-
-// ----------------------------------------------------------------------------
-
-static status_t getConfigFormatInfo(EGLint configID,
- int32_t& pixelFormat, int32_t& depthFormat)
-{
- switch(configID) {
- case 0:
- pixelFormat = GGL_PIXEL_FORMAT_RGB_565;
- depthFormat = 0;
- break;
- case 1:
- pixelFormat = GGL_PIXEL_FORMAT_RGB_565;
- depthFormat = GGL_PIXEL_FORMAT_Z_16;
- break;
- case 2:
- pixelFormat = GGL_PIXEL_FORMAT_RGBX_8888;
- depthFormat = 0;
- break;
- case 3:
- pixelFormat = GGL_PIXEL_FORMAT_RGBX_8888;
- depthFormat = GGL_PIXEL_FORMAT_Z_16;
- break;
- case 4:
- pixelFormat = GGL_PIXEL_FORMAT_RGBA_8888;
- depthFormat = 0;
- break;
- case 5:
- pixelFormat = GGL_PIXEL_FORMAT_RGBA_8888;
- depthFormat = GGL_PIXEL_FORMAT_Z_16;
- break;
- case 6:
- pixelFormat = GGL_PIXEL_FORMAT_A_8;
- depthFormat = 0;
- break;
- case 7:
- pixelFormat = GGL_PIXEL_FORMAT_A_8;
- depthFormat = GGL_PIXEL_FORMAT_Z_16;
- break;
- case 8:
- pixelFormat = GGL_PIXEL_FORMAT_BGRA_8888;
- depthFormat = 0;
- break;
- default:
- return NAME_NOT_FOUND;
- }
- return NO_ERROR;
-}
-
-// ----------------------------------------------------------------------------
-
-template<typename T>
-static int binarySearch(T const sortedArray[], int first, int last, EGLint key)
-{
- while (first <= last) {
- int mid = (first + last) / 2;
- if (key > sortedArray[mid].key) {
- first = mid + 1;
- } else if (key < sortedArray[mid].key) {
- last = mid - 1;
- } else {
- return mid;
- }
- }
- return -1;
-}
-
-static int isAttributeMatching(int i, EGLint attr, EGLint val)
-{
- // look for the attribute in all of our configs
- config_pair_t const* configFound = gConfigs[i].array;
- int index = binarySearch<config_pair_t>(
- gConfigs[i].array,
- 0, gConfigs[i].size-1,
- attr);
- if (index < 0) {
- configFound = config_base_attribute_list;
- index = binarySearch<config_pair_t>(
- config_base_attribute_list,
- 0, NELEM(config_base_attribute_list)-1,
- attr);
- }
- if (index >= 0) {
- // attribute found, check if this config could match
- int cfgMgtIndex = binarySearch<config_management_t>(
- gConfigManagement,
- 0, NELEM(gConfigManagement)-1,
- attr);
- if (cfgMgtIndex >= 0) {
- bool match = gConfigManagement[cfgMgtIndex].match(
- val, configFound[index].value);
- if (match) {
- // this config matches
- return 1;
- }
- } else {
- // attribute not found. this should NEVER happen.
- }
- } else {
- // error, this attribute doesn't exist
- }
- return 0;
-}
-
-static int makeCurrent(ogles_context_t* gl)
-{
- ogles_context_t* current = (ogles_context_t*)getGlThreadSpecific();
- if (gl) {
- egl_context_t* c = egl_context_t::context(gl);
- if (c->flags & egl_context_t::IS_CURRENT) {
- if (current != gl) {
- // it is an error to set a context current, if it's already
- // current to another thread
- return -1;
- }
- } else {
- if (current) {
- // mark the current context as not current, and flush
- glFlush();
- egl_context_t::context(current)->flags &= ~egl_context_t::IS_CURRENT;
- }
- }
- if (!(c->flags & egl_context_t::IS_CURRENT)) {
- // The context is not current, make it current!
- setGlThreadSpecific(gl);
- c->flags |= egl_context_t::IS_CURRENT;
- }
- } else {
- if (current) {
- // mark the current context as not current, and flush
- glFlush();
- egl_context_t::context(current)->flags &= ~egl_context_t::IS_CURRENT;
- }
- // this thread has no context attached to it
- setGlThreadSpecific(0);
- }
- return 0;
-}
-
-static EGLBoolean getConfigAttrib(EGLDisplay /*dpy*/, EGLConfig config,
- EGLint attribute, EGLint *value)
-{
- size_t numConfigs = NELEM(gConfigs);
- int index = (int)(uintptr_t)config;
- if (uint32_t(index) >= numConfigs)
- return setError(EGL_BAD_CONFIG, EGL_FALSE);
-
- int attrIndex;
- attrIndex = binarySearch<config_pair_t>(
- gConfigs[index].array,
- 0, gConfigs[index].size-1,
- attribute);
- if (attrIndex>=0) {
- *value = gConfigs[index].array[attrIndex].value;
- return EGL_TRUE;
- }
-
- attrIndex = binarySearch<config_pair_t>(
- config_base_attribute_list,
- 0, NELEM(config_base_attribute_list)-1,
- attribute);
- if (attrIndex>=0) {
- *value = config_base_attribute_list[attrIndex].value;
- return EGL_TRUE;
- }
- return setError(EGL_BAD_ATTRIBUTE, EGL_FALSE);
-}
-
-static EGLSurface createWindowSurface(EGLDisplay dpy, EGLConfig config,
- NativeWindowType window, const EGLint* /*attrib_list*/)
-{
- if (egl_display_t::is_valid(dpy) == EGL_FALSE)
- return setError(EGL_BAD_DISPLAY, EGL_NO_SURFACE);
- if (window == 0)
- return setError(EGL_BAD_MATCH, EGL_NO_SURFACE);
-
- EGLint surfaceType;
- if (getConfigAttrib(dpy, config, EGL_SURFACE_TYPE, &surfaceType) == EGL_FALSE)
- return EGL_FALSE;
-
- if (!(surfaceType & EGL_WINDOW_BIT))
- return setError(EGL_BAD_MATCH, EGL_NO_SURFACE);
-
- if (static_cast<ANativeWindow*>(window)->common.magic !=
- ANDROID_NATIVE_WINDOW_MAGIC) {
- return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
- }
-
- EGLint configID;
- if (getConfigAttrib(dpy, config, EGL_CONFIG_ID, &configID) == EGL_FALSE)
- return EGL_FALSE;
-
- int32_t depthFormat;
- int32_t pixelFormat;
- if (getConfigFormatInfo(configID, pixelFormat, depthFormat) != NO_ERROR) {
- return setError(EGL_BAD_MATCH, EGL_NO_SURFACE);
- }
-
- // FIXME: we don't have access to the pixelFormat here just yet.
- // (it's possible that the surface is not fully initialized)
- // maybe this should be done after the page-flip
- //if (EGLint(info.format) != pixelFormat)
- // return setError(EGL_BAD_MATCH, EGL_NO_SURFACE);
-
- egl_surface_t* surface;
- surface = new egl_window_surface_v2_t(dpy, config, depthFormat,
- static_cast<ANativeWindow*>(window));
-
- if (!surface->initCheck()) {
- // there was a problem in the ctor, the error
- // flag has been set.
- delete surface;
- surface = 0;
- }
- return surface;
-}
-
-static EGLSurface createPixmapSurface(EGLDisplay dpy, EGLConfig config,
- NativePixmapType pixmap, const EGLint* /*attrib_list*/)
-{
- if (egl_display_t::is_valid(dpy) == EGL_FALSE)
- return setError(EGL_BAD_DISPLAY, EGL_NO_SURFACE);
- if (pixmap == 0)
- return setError(EGL_BAD_MATCH, EGL_NO_SURFACE);
-
- EGLint surfaceType;
- if (getConfigAttrib(dpy, config, EGL_SURFACE_TYPE, &surfaceType) == EGL_FALSE)
- return EGL_FALSE;
-
- if (!(surfaceType & EGL_PIXMAP_BIT))
- return setError(EGL_BAD_MATCH, EGL_NO_SURFACE);
-
- if (static_cast<egl_native_pixmap_t*>(pixmap)->version !=
- sizeof(egl_native_pixmap_t)) {
- return setError(EGL_BAD_NATIVE_PIXMAP, EGL_NO_SURFACE);
- }
-
- EGLint configID;
- if (getConfigAttrib(dpy, config, EGL_CONFIG_ID, &configID) == EGL_FALSE)
- return EGL_FALSE;
-
- int32_t depthFormat;
- int32_t pixelFormat;
- if (getConfigFormatInfo(configID, pixelFormat, depthFormat) != NO_ERROR) {
- return setError(EGL_BAD_MATCH, EGL_NO_SURFACE);
- }
-
- if (pixmap->format != pixelFormat)
- return setError(EGL_BAD_MATCH, EGL_NO_SURFACE);
-
- egl_surface_t* surface =
- new egl_pixmap_surface_t(dpy, config, depthFormat,
- static_cast<egl_native_pixmap_t*>(pixmap));
-
- if (!surface->initCheck()) {
- // there was a problem in the ctor, the error
- // flag has been set.
- delete surface;
- surface = 0;
- }
- return surface;
-}
-
-static EGLSurface createPbufferSurface(EGLDisplay dpy, EGLConfig config,
- const EGLint *attrib_list)
-{
- if (egl_display_t::is_valid(dpy) == EGL_FALSE)
- return setError(EGL_BAD_DISPLAY, EGL_NO_SURFACE);
-
- EGLint surfaceType;
- if (getConfigAttrib(dpy, config, EGL_SURFACE_TYPE, &surfaceType) == EGL_FALSE)
- return EGL_FALSE;
-
- if (!(surfaceType & EGL_PBUFFER_BIT))
- return setError(EGL_BAD_MATCH, EGL_NO_SURFACE);
-
- EGLint configID;
- if (getConfigAttrib(dpy, config, EGL_CONFIG_ID, &configID) == EGL_FALSE)
- return EGL_FALSE;
-
- int32_t depthFormat;
- int32_t pixelFormat;
- if (getConfigFormatInfo(configID, pixelFormat, depthFormat) != NO_ERROR) {
- return setError(EGL_BAD_MATCH, EGL_NO_SURFACE);
- }
-
- int32_t w = 0;
- int32_t h = 0;
- while (attrib_list[0] != EGL_NONE) {
- if (attrib_list[0] == EGL_WIDTH) w = attrib_list[1];
- if (attrib_list[0] == EGL_HEIGHT) h = attrib_list[1];
- attrib_list+=2;
- }
-
- egl_surface_t* surface =
- new egl_pbuffer_surface_t(dpy, config, depthFormat, w, h, pixelFormat);
-
- if (!surface->initCheck()) {
- // there was a problem in the ctor, the error
- // flag has been set.
- delete surface;
- surface = 0;
- }
- return surface;
-}
-
-// ----------------------------------------------------------------------------
-}; // namespace android
-// ----------------------------------------------------------------------------
-
-using namespace android;
-
-// ----------------------------------------------------------------------------
-// Initialization
-// ----------------------------------------------------------------------------
-
-EGLDisplay eglGetDisplay(NativeDisplayType display)
-{
-#ifndef __ANDROID__
- // this just needs to be done once
- if (gGLKey == -1) {
- pthread_mutex_lock(&gInitMutex);
- if (gGLKey == -1)
- pthread_key_create(&gGLKey, NULL);
- pthread_mutex_unlock(&gInitMutex);
- }
-#endif
- if (display == EGL_DEFAULT_DISPLAY) {
- EGLDisplay dpy = (EGLDisplay)1;
- egl_display_t& d = egl_display_t::get_display(dpy);
- d.type = display;
- return dpy;
- }
- return EGL_NO_DISPLAY;
-}
-
-EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
-{
- if (egl_display_t::is_valid(dpy) == EGL_FALSE)
- return setError(EGL_BAD_DISPLAY, EGL_FALSE);
-
- EGLBoolean res = EGL_TRUE;
- egl_display_t& d = egl_display_t::get_display(dpy);
-
- if (d.initialized.fetch_add(1, std::memory_order_acquire) == 0) {
- // initialize stuff here if needed
- //pthread_mutex_lock(&gInitMutex);
- //pthread_mutex_unlock(&gInitMutex);
- }
-
- if (res == EGL_TRUE) {
- if (major != NULL) *major = VERSION_MAJOR;
- if (minor != NULL) *minor = VERSION_MINOR;
- }
- return res;
-}
-
-EGLBoolean eglTerminate(EGLDisplay dpy)
-{
- if (egl_display_t::is_valid(dpy) == EGL_FALSE)
- return setError(EGL_BAD_DISPLAY, EGL_FALSE);
-
- EGLBoolean res = EGL_TRUE;
- egl_display_t& d = egl_display_t::get_display(dpy);
- if (d.initialized.fetch_sub(1, std::memory_order_release) == 1) {
- std::atomic_thread_fence(std::memory_order_acquire);
- // TODO: destroy all resources (surfaces, contexts, etc...)
- //pthread_mutex_lock(&gInitMutex);
- //pthread_mutex_unlock(&gInitMutex);
- }
- return res;
-}
-
-// ----------------------------------------------------------------------------
-// configuration
-// ----------------------------------------------------------------------------
-
-EGLBoolean eglGetConfigs( EGLDisplay dpy,
- EGLConfig *configs,
- EGLint config_size, EGLint *num_config)
-{
- if (egl_display_t::is_valid(dpy) == EGL_FALSE)
- return setError(EGL_BAD_DISPLAY, EGL_FALSE);
-
- if (ggl_unlikely(num_config==NULL))
- return setError(EGL_BAD_PARAMETER, EGL_FALSE);
-
- GLint numConfigs = NELEM(gConfigs);
- if (!configs) {
- *num_config = numConfigs;
- return EGL_TRUE;
- }
- GLint i;
- for (i=0 ; i<numConfigs && i<config_size ; i++) {
- *configs++ = (EGLConfig)(uintptr_t)i;
- }
- *num_config = i;
- return EGL_TRUE;
-}
-
-EGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list,
- EGLConfig *configs, EGLint config_size,
- EGLint *num_config)
-{
- if (egl_display_t::is_valid(dpy) == EGL_FALSE)
- return setError(EGL_BAD_DISPLAY, EGL_FALSE);
-
- if (ggl_unlikely(num_config==NULL)) {
- return setError(EGL_BAD_PARAMETER, EGL_FALSE);
- }
-
- if (ggl_unlikely(attrib_list==0)) {
- /*
- * A NULL attrib_list should be treated as though it was an empty
- * one (terminated with EGL_NONE) as defined in
- * section 3.4.1 "Querying Configurations" in the EGL specification.
- */
- static const EGLint dummy = EGL_NONE;
- attrib_list = &dummy;
- }
-
- int numAttributes = 0;
- int numConfigs = NELEM(gConfigs);
- uint32_t possibleMatch = (1<<numConfigs)-1;
- while(possibleMatch && *attrib_list != EGL_NONE) {
- numAttributes++;
- EGLint attr = *attrib_list++;
- EGLint val = *attrib_list++;
- for (int i=0 ; possibleMatch && i<numConfigs ; i++) {
- if (!(possibleMatch & (1<<i)))
- continue;
- if (isAttributeMatching(i, attr, val) == 0) {
- possibleMatch &= ~(1<<i);
- }
- }
- }
-
- // now, handle the attributes which have a useful default value
- for (size_t j=0 ; possibleMatch && j<NELEM(config_defaults) ; j++) {
- // see if this attribute was specified, if not, apply its
- // default value
- if (binarySearch<config_pair_t>(
- (config_pair_t const*)attrib_list,
- 0, numAttributes-1,
- config_defaults[j].key) < 0)
- {
- for (int i=0 ; possibleMatch && i<numConfigs ; i++) {
- if (!(possibleMatch & (1<<i)))
- continue;
- if (isAttributeMatching(i,
- config_defaults[j].key,
- config_defaults[j].value) == 0)
- {
- possibleMatch &= ~(1<<i);
- }
- }
- }
- }
-
- // return the configurations found
- int n=0;
- if (possibleMatch) {
- if (configs) {
- for (int i=0 ; config_size && i<numConfigs ; i++) {
- if (possibleMatch & (1<<i)) {
- *configs++ = (EGLConfig)(uintptr_t)i;
- config_size--;
- n++;
- }
- }
- } else {
- for (int i=0 ; i<numConfigs ; i++) {
- if (possibleMatch & (1<<i)) {
- n++;
- }
- }
- }
- }
- *num_config = n;
- return EGL_TRUE;
-}
-
-EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config,
- EGLint attribute, EGLint *value)
-{
- if (egl_display_t::is_valid(dpy) == EGL_FALSE)
- return setError(EGL_BAD_DISPLAY, EGL_FALSE);
-
- return getConfigAttrib(dpy, config, attribute, value);
-}
-
-// ----------------------------------------------------------------------------
-// surfaces
-// ----------------------------------------------------------------------------
-
-EGLSurface eglCreateWindowSurface( EGLDisplay dpy, EGLConfig config,
- NativeWindowType window,
- const EGLint *attrib_list)
-{
- return createWindowSurface(dpy, config, window, attrib_list);
-}
-
-EGLSurface eglCreatePixmapSurface( EGLDisplay dpy, EGLConfig config,
- NativePixmapType pixmap,
- const EGLint *attrib_list)
-{
- return createPixmapSurface(dpy, config, pixmap, attrib_list);
-}
-
-EGLSurface eglCreatePbufferSurface( EGLDisplay dpy, EGLConfig config,
- const EGLint *attrib_list)
-{
- return createPbufferSurface(dpy, config, attrib_list);
-}
-
-EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface eglSurface)
-{
- if (egl_display_t::is_valid(dpy) == EGL_FALSE)
- return setError(EGL_BAD_DISPLAY, EGL_FALSE);
- if (eglSurface != EGL_NO_SURFACE) {
- egl_surface_t* surface( static_cast<egl_surface_t*>(eglSurface) );
- if (!surface->isValid())
- return setError(EGL_BAD_SURFACE, EGL_FALSE);
- if (surface->dpy != dpy)
- return setError(EGL_BAD_DISPLAY, EGL_FALSE);
- if (surface->ctx) {
- // defer disconnect/delete until no longer current
- surface->zombie = true;
- } else {
- surface->disconnect();
- delete surface;
- }
- }
- return EGL_TRUE;
-}
-
-EGLBoolean eglQuerySurface( EGLDisplay dpy, EGLSurface eglSurface,
- EGLint attribute, EGLint *value)
-{
- if (egl_display_t::is_valid(dpy) == EGL_FALSE)
- return setError(EGL_BAD_DISPLAY, EGL_FALSE);
- egl_surface_t* surface = static_cast<egl_surface_t*>(eglSurface);
- if (!surface->isValid())
- return setError(EGL_BAD_SURFACE, EGL_FALSE);
- if (surface->dpy != dpy)
- return setError(EGL_BAD_DISPLAY, EGL_FALSE);
-
- EGLBoolean ret = EGL_TRUE;
- switch (attribute) {
- case EGL_CONFIG_ID:
- ret = getConfigAttrib(dpy, surface->config, EGL_CONFIG_ID, value);
- break;
- case EGL_WIDTH:
- *value = surface->getWidth();
- break;
- case EGL_HEIGHT:
- *value = surface->getHeight();
- break;
- case EGL_LARGEST_PBUFFER:
- // not modified for a window or pixmap surface
- break;
- case EGL_TEXTURE_FORMAT:
- *value = EGL_NO_TEXTURE;
- break;
- case EGL_TEXTURE_TARGET:
- *value = EGL_NO_TEXTURE;
- break;
- case EGL_MIPMAP_TEXTURE:
- *value = EGL_FALSE;
- break;
- case EGL_MIPMAP_LEVEL:
- *value = 0;
- break;
- case EGL_RENDER_BUFFER:
- // TODO: return the real RENDER_BUFFER here
- *value = EGL_BACK_BUFFER;
- break;
- case EGL_HORIZONTAL_RESOLUTION:
- // pixel/mm * EGL_DISPLAY_SCALING
- *value = surface->getHorizontalResolution();
- break;
- case EGL_VERTICAL_RESOLUTION:
- // pixel/mm * EGL_DISPLAY_SCALING
- *value = surface->getVerticalResolution();
- break;
- case EGL_PIXEL_ASPECT_RATIO: {
- // w/h * EGL_DISPLAY_SCALING
- int wr = surface->getHorizontalResolution();
- int hr = surface->getVerticalResolution();
- *value = (wr * EGL_DISPLAY_SCALING) / hr;
- } break;
- case EGL_SWAP_BEHAVIOR:
- *value = surface->getSwapBehavior();
- break;
- default:
- ret = setError(EGL_BAD_ATTRIBUTE, EGL_FALSE);
- }
- return ret;
-}
-
-EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config,
- EGLContext /*share_list*/, const EGLint* /*attrib_list*/)
-{
- if (egl_display_t::is_valid(dpy) == EGL_FALSE)
- return setError(EGL_BAD_DISPLAY, EGL_NO_SURFACE);
-
- ogles_context_t* gl = ogles_init(sizeof(egl_context_t));
- if (!gl) return setError(EGL_BAD_ALLOC, EGL_NO_CONTEXT);
-
- egl_context_t* c = static_cast<egl_context_t*>(gl->rasterizer.base);
- c->flags = egl_context_t::NEVER_CURRENT;
- c->dpy = dpy;
- c->config = config;
- c->read = 0;
- c->draw = 0;
- return (EGLContext)gl;
-}
-
-EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
-{
- if (egl_display_t::is_valid(dpy) == EGL_FALSE)
- return setError(EGL_BAD_DISPLAY, EGL_FALSE);
- egl_context_t* c = egl_context_t::context(ctx);
- if (c->flags & egl_context_t::IS_CURRENT)
- setGlThreadSpecific(0);
- ogles_uninit((ogles_context_t*)ctx);
- return EGL_TRUE;
-}
-
-EGLBoolean eglMakeCurrent( EGLDisplay dpy, EGLSurface draw,
- EGLSurface read, EGLContext ctx)
-{
- if (egl_display_t::is_valid(dpy) == EGL_FALSE)
- return setError(EGL_BAD_DISPLAY, EGL_FALSE);
- if (draw) {
- egl_surface_t* s = (egl_surface_t*)draw;
- if (!s->isValid())
- return setError(EGL_BAD_SURFACE, EGL_FALSE);
- if (s->dpy != dpy)
- return setError(EGL_BAD_DISPLAY, EGL_FALSE);
- // TODO: check that draw is compatible with the context
- }
- if (read && read!=draw) {
- egl_surface_t* s = (egl_surface_t*)read;
- if (!s->isValid())
- return setError(EGL_BAD_SURFACE, EGL_FALSE);
- if (s->dpy != dpy)
- return setError(EGL_BAD_DISPLAY, EGL_FALSE);
- // TODO: check that read is compatible with the context
- }
-
- EGLContext current_ctx = EGL_NO_CONTEXT;
-
- if ((read == EGL_NO_SURFACE && draw == EGL_NO_SURFACE) && (ctx != EGL_NO_CONTEXT))
- return setError(EGL_BAD_MATCH, EGL_FALSE);
-
- if ((read != EGL_NO_SURFACE || draw != EGL_NO_SURFACE) && (ctx == EGL_NO_CONTEXT))
- return setError(EGL_BAD_MATCH, EGL_FALSE);
-
- if (ctx == EGL_NO_CONTEXT) {
- // if we're detaching, we need the current context
- current_ctx = (EGLContext)getGlThreadSpecific();
- } else {
- egl_surface_t* d = (egl_surface_t*)draw;
- egl_surface_t* r = (egl_surface_t*)read;
- if ((d && d->ctx && d->ctx != ctx) ||
- (r && r->ctx && r->ctx != ctx)) {
- // one of the surface is bound to a context in another thread
- return setError(EGL_BAD_ACCESS, EGL_FALSE);
- }
- }
-
- ogles_context_t* gl = (ogles_context_t*)ctx;
- if (makeCurrent(gl) == 0) {
- if (ctx) {
- egl_context_t* c = egl_context_t::context(ctx);
- egl_surface_t* d = (egl_surface_t*)draw;
- egl_surface_t* r = (egl_surface_t*)read;
-
- if (c->draw) {
- egl_surface_t* s = reinterpret_cast<egl_surface_t*>(c->draw);
- s->disconnect();
- s->ctx = EGL_NO_CONTEXT;
- if (s->zombie)
- delete s;
- }
- if (c->read) {
- // FIXME: unlock/disconnect the read surface too
- }
-
- c->draw = draw;
- c->read = read;
-
- if (c->flags & egl_context_t::NEVER_CURRENT) {
- c->flags &= ~egl_context_t::NEVER_CURRENT;
- GLint w = 0;
- GLint h = 0;
- if (draw) {
- w = d->getWidth();
- h = d->getHeight();
- }
- ogles_surfaceport(gl, 0, 0);
- ogles_viewport(gl, 0, 0, w, h);
- ogles_scissor(gl, 0, 0, w, h);
- }
- if (d) {
- if (d->connect() == EGL_FALSE) {
- return EGL_FALSE;
- }
- d->ctx = ctx;
- d->bindDrawSurface(gl);
- }
- if (r) {
- // FIXME: lock/connect the read surface too
- r->ctx = ctx;
- r->bindReadSurface(gl);
- }
- } else {
- // if surfaces were bound to the context bound to this thread
- // mark then as unbound.
- if (current_ctx) {
- egl_context_t* c = egl_context_t::context(current_ctx);
- egl_surface_t* d = (egl_surface_t*)c->draw;
- egl_surface_t* r = (egl_surface_t*)c->read;
- if (d) {
- c->draw = 0;
- d->disconnect();
- d->ctx = EGL_NO_CONTEXT;
- if (d->zombie)
- delete d;
- }
- if (r) {
- c->read = 0;
- r->ctx = EGL_NO_CONTEXT;
- // FIXME: unlock/disconnect the read surface too
- }
- }
- }
- return EGL_TRUE;
- }
- return setError(EGL_BAD_ACCESS, EGL_FALSE);
-}
-
-EGLContext eglGetCurrentContext(void)
-{
- // eglGetCurrentContext returns the current EGL rendering context,
- // as specified by eglMakeCurrent. If no context is current,
- // EGL_NO_CONTEXT is returned.
- return (EGLContext)getGlThreadSpecific();
-}
-
-EGLSurface eglGetCurrentSurface(EGLint readdraw)
-{
- // eglGetCurrentSurface returns the read or draw surface attached
- // to the current EGL rendering context, as specified by eglMakeCurrent.
- // If no context is current, EGL_NO_SURFACE is returned.
- EGLContext ctx = (EGLContext)getGlThreadSpecific();
- if (ctx == EGL_NO_CONTEXT) return EGL_NO_SURFACE;
- egl_context_t* c = egl_context_t::context(ctx);
- if (readdraw == EGL_READ) {
- return c->read;
- } else if (readdraw == EGL_DRAW) {
- return c->draw;
- }
- return setError(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
-}
-
-EGLDisplay eglGetCurrentDisplay(void)
-{
- // eglGetCurrentDisplay returns the current EGL display connection
- // for the current EGL rendering context, as specified by eglMakeCurrent.
- // If no context is current, EGL_NO_DISPLAY is returned.
- EGLContext ctx = (EGLContext)getGlThreadSpecific();
- if (ctx == EGL_NO_CONTEXT) return EGL_NO_DISPLAY;
- egl_context_t* c = egl_context_t::context(ctx);
- return c->dpy;
-}
-
-EGLBoolean eglQueryContext( EGLDisplay dpy, EGLContext ctx,
- EGLint attribute, EGLint *value)
-{
- if (egl_display_t::is_valid(dpy) == EGL_FALSE)
- return setError(EGL_BAD_DISPLAY, EGL_FALSE);
- egl_context_t* c = egl_context_t::context(ctx);
- switch (attribute) {
- case EGL_CONFIG_ID:
- // Returns the ID of the EGL frame buffer configuration with
- // respect to which the context was created
- return getConfigAttrib(dpy, c->config, EGL_CONFIG_ID, value);
- }
- return setError(EGL_BAD_ATTRIBUTE, EGL_FALSE);
-}
-
-EGLBoolean eglWaitGL(void)
-{
- return EGL_TRUE;
-}
-
-EGLBoolean eglWaitNative(EGLint /*engine*/)
-{
- return EGL_TRUE;
-}
-
-EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface draw)
-{
- if (egl_display_t::is_valid(dpy) == EGL_FALSE)
- return setError(EGL_BAD_DISPLAY, EGL_FALSE);
-
- egl_surface_t* d = static_cast<egl_surface_t*>(draw);
- if (!d->isValid())
- return setError(EGL_BAD_SURFACE, EGL_FALSE);
- if (d->dpy != dpy)
- return setError(EGL_BAD_DISPLAY, EGL_FALSE);
-
- // post the surface
- d->swapBuffers();
-
- // if it's bound to a context, update the buffer
- if (d->ctx != EGL_NO_CONTEXT) {
- d->bindDrawSurface((ogles_context_t*)d->ctx);
- // if this surface is also the read surface of the context
- // it is bound to, make sure to update the read buffer as well.
- // The EGL spec is a little unclear about this.
- egl_context_t* c = egl_context_t::context(d->ctx);
- if (c->read == draw) {
- d->bindReadSurface((ogles_context_t*)d->ctx);
- }
- }
-
- return EGL_TRUE;
-}
-
-EGLBoolean eglCopyBuffers( EGLDisplay dpy, EGLSurface /*surface*/,
- NativePixmapType /*target*/)
-{
- if (egl_display_t::is_valid(dpy) == EGL_FALSE)
- return setError(EGL_BAD_DISPLAY, EGL_FALSE);
- // TODO: eglCopyBuffers()
- return EGL_FALSE;
-}
-
-EGLint eglGetError(void)
-{
- return getError();
-}
-
-const char* eglQueryString(EGLDisplay dpy, EGLint name)
-{
- if (egl_display_t::is_valid(dpy) == EGL_FALSE)
- return setError(EGL_BAD_DISPLAY, (const char*)0);
-
- switch (name) {
- case EGL_VENDOR:
- return gVendorString;
- case EGL_VERSION:
- return gVersionString;
- case EGL_EXTENSIONS:
- return gExtensionsString;
- case EGL_CLIENT_APIS:
- return gClientApiString;
- }
- return setError(EGL_BAD_PARAMETER, (const char *)0);
-}
-
-// ----------------------------------------------------------------------------
-// EGL 1.1
-// ----------------------------------------------------------------------------
-
-EGLBoolean eglSurfaceAttrib(
- EGLDisplay dpy, EGLSurface /*surface*/, EGLint /*attribute*/, EGLint /*value*/)
-{
- if (egl_display_t::is_valid(dpy) == EGL_FALSE)
- return setError(EGL_BAD_DISPLAY, EGL_FALSE);
- // TODO: eglSurfaceAttrib()
- return setError(EGL_BAD_PARAMETER, EGL_FALSE);
-}
-
-EGLBoolean eglBindTexImage(
- EGLDisplay dpy, EGLSurface /*surface*/, EGLint /*buffer*/)
-{
- if (egl_display_t::is_valid(dpy) == EGL_FALSE)
- return setError(EGL_BAD_DISPLAY, EGL_FALSE);
- // TODO: eglBindTexImage()
- return setError(EGL_BAD_PARAMETER, EGL_FALSE);
-}
-
-EGLBoolean eglReleaseTexImage(
- EGLDisplay dpy, EGLSurface /*surface*/, EGLint /*buffer*/)
-{
- if (egl_display_t::is_valid(dpy) == EGL_FALSE)
- return setError(EGL_BAD_DISPLAY, EGL_FALSE);
- // TODO: eglReleaseTexImage()
- return setError(EGL_BAD_PARAMETER, EGL_FALSE);
-}
-
-EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint /*interval*/)
-{
- if (egl_display_t::is_valid(dpy) == EGL_FALSE)
- return setError(EGL_BAD_DISPLAY, EGL_FALSE);
- // TODO: eglSwapInterval()
- return EGL_TRUE;
-}
-
-// ----------------------------------------------------------------------------
-// EGL 1.2
-// ----------------------------------------------------------------------------
-
-EGLBoolean eglBindAPI(EGLenum api)
-{
- if (api != EGL_OPENGL_ES_API)
- return setError(EGL_BAD_PARAMETER, EGL_FALSE);
- return EGL_TRUE;
-}
-
-EGLenum eglQueryAPI(void)
-{
- return EGL_OPENGL_ES_API;
-}
-
-EGLBoolean eglWaitClient(void)
-{
- glFinish();
- return EGL_TRUE;
-}
-
-EGLBoolean eglReleaseThread(void)
-{
- // TODO: eglReleaseThread()
- return EGL_TRUE;
-}
-
-EGLSurface eglCreatePbufferFromClientBuffer(
- EGLDisplay dpy, EGLenum /*buftype*/, EGLClientBuffer /*buffer*/,
- EGLConfig /*config*/, const EGLint* /*attrib_list*/)
-{
- if (egl_display_t::is_valid(dpy) == EGL_FALSE)
- return setError(EGL_BAD_DISPLAY, EGL_NO_SURFACE);
- // TODO: eglCreatePbufferFromClientBuffer()
- return setError(EGL_BAD_PARAMETER, EGL_NO_SURFACE);
-}
-
-// ----------------------------------------------------------------------------
-// EGL_EGLEXT_VERSION 3
-// ----------------------------------------------------------------------------
-
-void (*eglGetProcAddress (const char *procname))()
-{
- extention_map_t const * const map = gExtentionMap;
- for (uint32_t i=0 ; i<NELEM(gExtentionMap) ; i++) {
- if (!strcmp(procname, map[i].name)) {
- return map[i].address;
- }
- }
- return NULL;
-}
-
-EGLBoolean eglLockSurfaceKHR(EGLDisplay /*dpy*/, EGLSurface /*surface*/,
- const EGLint* /*attrib_list*/)
-{
- EGLBoolean result = EGL_FALSE;
- return result;
-}
-
-EGLBoolean eglUnlockSurfaceKHR(EGLDisplay /*dpy*/, EGLSurface /*surface*/)
-{
- EGLBoolean result = EGL_FALSE;
- return result;
-}
-
-EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target,
- EGLClientBuffer buffer, const EGLint* /*attrib_list*/)
-{
- if (egl_display_t::is_valid(dpy) == EGL_FALSE) {
- return setError(EGL_BAD_DISPLAY, EGL_NO_IMAGE_KHR);
- }
- if (ctx != EGL_NO_CONTEXT) {
- return setError(EGL_BAD_CONTEXT, EGL_NO_IMAGE_KHR);
- }
- if (target != EGL_NATIVE_BUFFER_ANDROID) {
- return setError(EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR);
- }
-
- ANativeWindowBuffer* native_buffer = (ANativeWindowBuffer*)buffer;
-
- if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC)
- return setError(EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR);
-
- if (native_buffer->common.version != sizeof(ANativeWindowBuffer))
- return setError(EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR);
-
- switch (native_buffer->format) {
- case HAL_PIXEL_FORMAT_RGBA_8888:
- case HAL_PIXEL_FORMAT_RGBX_8888:
- case HAL_PIXEL_FORMAT_RGB_888:
- case HAL_PIXEL_FORMAT_RGB_565:
- case HAL_PIXEL_FORMAT_BGRA_8888:
- break;
- default:
- return setError(EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR);
- }
-
- native_buffer->common.incRef(&native_buffer->common);
- return (EGLImageKHR)native_buffer;
-}
-
-EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img)
-{
- if (egl_display_t::is_valid(dpy) == EGL_FALSE) {
- return setError(EGL_BAD_DISPLAY, EGL_FALSE);
- }
-
- ANativeWindowBuffer* native_buffer = (ANativeWindowBuffer*)img;
-
- if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC)
- return setError(EGL_BAD_PARAMETER, EGL_FALSE);
-
- if (native_buffer->common.version != sizeof(ANativeWindowBuffer))
- return setError(EGL_BAD_PARAMETER, EGL_FALSE);
-
- native_buffer->common.decRef(&native_buffer->common);
-
- return EGL_TRUE;
-}
-
-// ----------------------------------------------------------------------------
-// EGL_KHR_fence_sync
-// ----------------------------------------------------------------------------
-
-#define FENCE_SYNC_HANDLE ((EGLSyncKHR)0xFE4CE)
-
-EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type,
- const EGLint *attrib_list)
-{
- if (egl_display_t::is_valid(dpy) == EGL_FALSE) {
- return setError(EGL_BAD_DISPLAY, EGL_NO_SYNC_KHR);
- }
-
- if (type != EGL_SYNC_FENCE_KHR ||
- (attrib_list != NULL && attrib_list[0] != EGL_NONE)) {
- return setError(EGL_BAD_ATTRIBUTE, EGL_NO_SYNC_KHR);
- }
-
- if (eglGetCurrentContext() == EGL_NO_CONTEXT) {
- return setError(EGL_BAD_MATCH, EGL_NO_SYNC_KHR);
- }
-
- // AGL is synchronous; nothing to do here.
-
- return FENCE_SYNC_HANDLE;
-}
-
-EGLBoolean eglDestroySyncKHR(EGLDisplay /*dpy*/, EGLSyncKHR sync)
-{
- if (sync != FENCE_SYNC_HANDLE) {
- return setError(EGL_BAD_PARAMETER, EGL_FALSE);
- }
-
- return EGL_TRUE;
-}
-
-EGLint eglClientWaitSyncKHR(EGLDisplay /*dpy*/, EGLSyncKHR sync, EGLint /*flags*/,
- EGLTimeKHR /*timeout*/)
-{
- if (sync != FENCE_SYNC_HANDLE) {
- return setError(EGL_BAD_PARAMETER, EGL_FALSE);
- }
-
- return EGL_CONDITION_SATISFIED_KHR;
-}
-
-EGLBoolean eglGetSyncAttribKHR(EGLDisplay /*dpy*/, EGLSyncKHR sync,
- EGLint attribute, EGLint *value)
-{
- if (sync != FENCE_SYNC_HANDLE) {
- return setError(EGL_BAD_PARAMETER, EGL_FALSE);
- }
-
- switch (attribute) {
- case EGL_SYNC_TYPE_KHR:
- *value = EGL_SYNC_FENCE_KHR;
- return EGL_TRUE;
- case EGL_SYNC_STATUS_KHR:
- *value = EGL_SIGNALED_KHR;
- return EGL_TRUE;
- case EGL_SYNC_CONDITION_KHR:
- *value = EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR;
- return EGL_TRUE;
- default:
- return setError(EGL_BAD_ATTRIBUTE, EGL_FALSE);
- }
-}
-
-// ----------------------------------------------------------------------------
-// ANDROID extensions
-// ----------------------------------------------------------------------------
-
-EGLBoolean eglSetSwapRectangleANDROID(EGLDisplay dpy, EGLSurface draw,
- EGLint left, EGLint top, EGLint width, EGLint height)
-{
- if (egl_display_t::is_valid(dpy) == EGL_FALSE)
- return setError(EGL_BAD_DISPLAY, EGL_FALSE);
-
- egl_surface_t* d = static_cast<egl_surface_t*>(draw);
- if (!d->isValid())
- return setError(EGL_BAD_SURFACE, EGL_FALSE);
- if (d->dpy != dpy)
- return setError(EGL_BAD_DISPLAY, EGL_FALSE);
-
- // post the surface
- d->setSwapRectangle(left, top, width, height);
-
- return EGL_TRUE;
-}
diff --git a/opengl/libagl/fixed_asm.S b/opengl/libagl/fixed_asm.S
deleted file mode 100644
index 5e08856..0000000
--- a/opengl/libagl/fixed_asm.S
+++ /dev/null
@@ -1,67 +0,0 @@
-/* libs/opengles/fixed_asm.S
-**
-** Copyright 2006, 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.
-*/
-
-
- .text
- .align 2
-
- .global gglFloatToFixed
- .type gglFloatToFixed, %function
- .global gglFloatToFixedFast
- .type gglFloatToFixedFast, %function
-
-
-/*
- * Converts a float to a s15.16 fixed-point number.
- * this doesn't handle floats out of the [-32768, +32768[ range
- * and doesn't performs round-to-nearest.
- * however, it's very fast :-)
- */
-
-gglFloatToFixedFast:
- movs r1, r0, lsl #1 /* remove bit sign */
- mov r2, #0x8E /* 127 + 15 */
- sub r1, r2, r1, lsr #24 /* compute shift */
- mov r2, r0, lsl #8 /* mantissa<<8 */
- orr r2, r2, #0x80000000 /* add the missing 1 */
- mov r0, r2, lsr r1 /* scale to 16.16 */
- rsbcs r0, r0, #0 /* negate if needed */
- bx lr
-
-/*
- * this version rounds-to-nearest and saturates numbers
- * outside the range (but not NaNs).
- */
-
-gglFloatToFixed:
- mov r1, r0, lsl #1 /* remove bit sign */
- mov r2, #0x8E /* 127 + 15 */
- subs r1, r2, r1, lsr #24 /* compute shift */
- bls 0f /* too big */
- mov r2, r0, lsl #8 /* mantissa<<8 */
- orr r2, r2, #0x80000000 /* add the missing 1 */
- mov r3, r0
- movs r0, r2, lsr r1 /* scale to 16.16 */
- addcs r0, r0, #1 /* round-to-nearest */
- tst r3, #0x80000000 /* negative? */
- rsbne r0, r0, #0 /* negate if needed */
- bx lr
-
-0: ands r0, r0, #0x80000000 /* keep only the sign bit */
- moveq r0, #0x7fffffff /* positive, maximum value */
- bx lr
-
diff --git a/opengl/libagl/fp.cpp b/opengl/libagl/fp.cpp
deleted file mode 100644
index a7a4f7b..0000000
--- a/opengl/libagl/fp.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
-/* libs/opengles/fp.cpp
-**
-** Copyright 2006, 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 "fp.h"
-
-// ----------------------------------------------------------------------------
-
-#if !(defined(__arm__) || (defined(__mips__) && !defined(__LP64__) && __mips_isa_rev < 6))
-GGLfixed gglFloatToFixed(float v) {
- return GGLfixed(floorf(v * 65536.0f + 0.5f));
-}
-#endif
-
-// ----------------------------------------------------------------------------
-
-namespace android {
-
-namespace gl {
-
-GLfloat fixedToFloat(GLfixed x)
-{
-#if DEBUG_USE_FLOATS
- return x / 65536.0f;
-#else
- if (!x) return 0;
- const uint32_t s = x & 0x80000000;
- union {
- uint32_t i;
- float f;
- };
- i = s ? -x : x;
- const int c = gglClz(i) - 8;
- i = (c>=0) ? (i<<c) : (i>>-c);
- const uint32_t e = 134 - c;
- i &= ~0x800000;
- i |= e<<23;
- i |= s;
- return f;
-#endif
-}
-
-float sinef(float x)
-{
- const float A = 1.0f / (2.0f*M_PI);
- const float B = -16.0f;
- const float C = 8.0f;
-
- // scale angle for easy argument reduction
- x *= A;
-
- if (fabsf(x) >= 0.5f) {
- // Argument reduction
- x = x - ceilf(x + 0.5f) + 1.0f;
- }
-
- const float y = B*x*fabsf(x) + C*x;
- return 0.2215f * (y*fabsf(y) - y) + y;
-}
-
-float cosinef(float x)
-{
- return sinef(x + float(M_PI/2));
-}
-
-void sincosf(GLfloat angle, GLfloat* s, GLfloat* c) {
- *s = sinef(angle);
- *c = cosinef(angle);
-}
-
-}; // namespace fp_utils
-
-// ----------------------------------------------------------------------------
-}; // namespace android
diff --git a/opengl/libagl/fp.h b/opengl/libagl/fp.h
deleted file mode 100644
index 6d0c183..0000000
--- a/opengl/libagl/fp.h
+++ /dev/null
@@ -1,243 +0,0 @@
-/* libs/opengles/fp.h
-**
-** Copyright 2006, 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.
-*/
-
-#ifndef ANDROID_OPENGLES_FP_H
-#define ANDROID_OPENGLES_FP_H
-
-#include <stdint.h>
-#include <stddef.h>
-#include <sys/types.h>
-#include <math.h>
-
-#include <private/pixelflinger/ggl_context.h>
-
-#include <GLES/gl.h>
-
-#define DEBUG_USE_FLOATS 0
-
-// ----------------------------------------------------------------------------
-
-extern "C" GLfixed gglFloatToFixed(float f) __attribute__((const));
-
-// ----------------------------------------------------------------------------
-namespace android {
-
-namespace gl {
-
- GLfloat fixedToFloat(GLfixed) CONST;
-
- void sincosf(GLfloat angle, GLfloat* s, GLfloat* c);
- float sinef(GLfloat x) CONST;
- float cosinef(GLfloat x) CONST;
-
-inline bool cmpf(GLfloat a, GLfloat b) CONST;
-inline bool isZerof(GLfloat) CONST;
-inline bool isOnef(GLfloat) CONST;
-
-inline int isZeroOrNegativef(GLfloat) CONST;
-
-inline int exponent(GLfloat) CONST;
-inline int32_t mantissa(GLfloat) CONST;
-inline GLfloat clampToZerof(GLfloat) CONST;
-inline GLfloat reciprocalf(GLfloat) CONST;
-inline GLfloat rsqrtf(GLfloat) CONST;
-inline GLfloat sqrf(GLfloat) CONST;
-inline GLfloat addExpf(GLfloat v, int e) CONST;
-inline GLfloat mul2f(GLfloat v) CONST;
-inline GLfloat div2f(GLfloat v) CONST;
-inline GLfloat absf(GLfloat v) CONST;
-
-
-/*
- * float fastexpf(float) : a fast approximation of expf(x)
- * give somewhat accurate results for -88 <= x <= 88
- *
- * exp(x) = 2^(x/ln(2))
- * we use the properties of float encoding
- * to get a fast 2^ and linear interpolation
- *
- */
-
-inline float fastexpf(float y) __attribute__((const));
-
-inline float fastexpf(float y)
-{
- union {
- float r;
- int32_t i;
- } u;
-
- // 127*ln(2) = 88
- if (y < -88.0f) {
- u.r = 0.0f;
- } else if (y > 88.0f) {
- u.r = INFINITY;
- } else {
- const float kOneOverLogTwo = (1L<<23) / M_LN2;
- const int32_t kExponentBias = 127L<<23;
- const int32_t e = int32_t(y*kOneOverLogTwo);
- u.i = e + kExponentBias;
- }
-
- return u.r;
-}
-
-
-bool cmpf(GLfloat a, GLfloat b) {
-#if DEBUG_USE_FLOATS
- return a == b;
-#else
- union {
- float f;
- uint32_t i;
- } ua, ub;
- ua.f = a;
- ub.f = b;
- return ua.i == ub.i;
-#endif
-}
-
-bool isZerof(GLfloat v) {
-#if DEBUG_USE_FLOATS
- return v == 0;
-#else
- union {
- float f;
- int32_t i;
- };
- f = v;
- return (i<<1) == 0;
-#endif
-}
-
-bool isOnef(GLfloat v) {
- return cmpf(v, 1.0f);
-}
-
-int isZeroOrNegativef(GLfloat v) {
-#if DEBUG_USE_FLOATS
- return v <= 0;
-#else
- union {
- float f;
- int32_t i;
- };
- f = v;
- return isZerof(v) | (i>>31);
-#endif
-}
-
-int exponent(GLfloat v) {
- union {
- float f;
- uint32_t i;
- };
- f = v;
- return ((i << 1) >> 24) - 127;
-}
-
-int32_t mantissa(GLfloat v) {
- union {
- float f;
- uint32_t i;
- };
- f = v;
- if (!(i&0x7F800000)) return 0;
- const int s = i >> 31;
- i |= (1L<<23);
- i &= ~0xFF000000;
- return s ? -i : i;
-}
-
-GLfloat clampToZerof(GLfloat v) {
-#if DEBUG_USE_FLOATS
- return v<0 ? 0 : (v>1 ? 1 : v);
-#else
- union {
- float f;
- int32_t i;
- };
- f = v;
- i &= ~(i>>31);
- return f;
-#endif
-}
-
-GLfloat reciprocalf(GLfloat v) {
- // XXX: do better
- return 1.0f / v;
-}
-
-GLfloat rsqrtf(GLfloat v) {
- // XXX: do better
- return 1.0f / sqrtf(v);
-}
-
-GLfloat sqrf(GLfloat v) {
- // XXX: do better
- return v*v;
-}
-
-GLfloat addExpf(GLfloat v, int e) {
- union {
- float f;
- int32_t i;
- };
- f = v;
- if (i<<1) { // XXX: deal with over/underflow
- i += int32_t(e)<<23;
- }
- return f;
-}
-
-GLfloat mul2f(GLfloat v) {
-#if DEBUG_USE_FLOATS
- return v*2;
-#else
- return addExpf(v, 1);
-#endif
-}
-
-GLfloat div2f(GLfloat v) {
-#if DEBUG_USE_FLOATS
- return v*0.5f;
-#else
- return addExpf(v, -1);
-#endif
-}
-
-GLfloat absf(GLfloat v) {
-#if DEBUG_USE_FLOATS
- return v<0 ? -v : v;
-#else
- union {
- float f;
- int32_t i;
- };
- f = v;
- i &= ~0x80000000;
- return f;
-#endif
-}
-
-}; // namespace gl
-
-// ----------------------------------------------------------------------------
-}; // namespace android
-
-#endif // ANDROID_OPENGLES_FP_H
-
diff --git a/opengl/libagl/iterators.S b/opengl/libagl/iterators.S
deleted file mode 100644
index 8fe9039..0000000
--- a/opengl/libagl/iterators.S
+++ /dev/null
@@ -1,89 +0,0 @@
-/* libs/opengles/iterators.S
-**
-** Copyright 2006, 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.
-*/
-
-
- .text
- .align 2
- .arm
-
- .global iterators0032
- .type iterators0032, %function
-
-/*
- * iterators0032
- *
- * MUST BE CALLED FROM ARM CODE
- *
- * r0: const compute_iterators_t* (this)
- * r0 + 0: m_dx01
- * r0 + 4: m_dy10
- * r0 + 8: m_dx20
- * r0 +12: m_dy02
- * r0 +16: m_x0
- * r0 +20: m_y0
- * r0 +24: m_area
- * r0 +28: m_scale
- * r0 +29: m_area_scale;
- * r1: int32_t* (out)
- * r1 + 0: c
- * r1 + 4: dcdx
- * r1 + 8: dcdy
- * r2: c0
- * r3: c1
- * [sp]: c2
- */
-
-iterators0032:
- stmfd sp!, {r4, r5, r6, r7, r8, lr}
- ldr r4, [sp, #4*6]
-
- ldrb r12, [r0, #29]
- sub r3, r3, r2
- sub r4, r4, r2
- sub r12, r12, #16
- mov r3, r3, asr r12
- mov r4, r4, asr r12
-
- ldr r5, [r0, #0]
- ldr r12, [r0, #4]
- smull r8, lr, r4, r5
- ldr r5, [r0, #8]
- smull r6, r7, r4, r12
- ldr r12, [r0, #12]
- smlal r8, lr, r3, r5
- smlal r6, r7, r3, r12
-
- ldr r3, [r0, #16] // m_x0
- ldr r4, [r0, #20] // m_x1
-
- str r6, [r1, #4]
- str r8, [r1, #8]
-
- umull r6, r5, r3, r6
- umull r8, r0, r4, r8
- mla r7, r3, r7, r5
- mla lr, r4, lr, r0
- adds r6, r6, r8
- adc r7, r7, lr
-
- movs r6, r6, lsr #4
- adc r6, r6, r7, lsl #28
- rsb r6, r6, r2, lsl #16
- str r6, [r1, #0]
-
- ldmfd sp!, {r4, r5, r6, r7, r8, pc}
-
diff --git a/opengl/libagl/light.cpp b/opengl/libagl/light.cpp
deleted file mode 100644
index 216c725..0000000
--- a/opengl/libagl/light.cpp
+++ /dev/null
@@ -1,882 +0,0 @@
-/* libs/opengles/light.cpp
-**
-** Copyright 2006, 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 <stdio.h>
-#include "context.h"
-#include "fp.h"
-#include "light.h"
-#include "state.h"
-#include "matrix.h"
-
-
-#if defined(__arm__) && defined(__thumb__)
-#warning "light.cpp should not be compiled in thumb on ARM."
-#endif
-
-namespace android {
-
-// ----------------------------------------------------------------------------
-
-static void invalidate_lighting(ogles_context_t* c);
-static void lightVertexValidate(ogles_context_t* c, vertex_t* v);
-static void lightVertexNop(ogles_context_t* c, vertex_t* v);
-static void lightVertex(ogles_context_t* c, vertex_t* v);
-static void lightVertexMaterial(ogles_context_t* c, vertex_t* v);
-
-static inline void vscale3(GLfixed* d, const GLfixed* m, GLfixed s);
-
-static __attribute__((noinline))
-void vnorm3(GLfixed* d, const GLfixed* a);
-
-static inline void vsa3(GLfixed* d,
- const GLfixed* m, GLfixed s, const GLfixed* a);
-static inline void vss3(GLfixed* d,
- const GLfixed* m, GLfixed s, const GLfixed* a);
-static inline void vmla3(GLfixed* d,
- const GLfixed* m0, const GLfixed* m1, const GLfixed* a);
-static inline void vmul3(GLfixed* d,
- const GLfixed* m0, const GLfixed* m1);
-
-static GLfixed fog_linear(ogles_context_t* c, GLfixed z);
-static GLfixed fog_exp(ogles_context_t* c, GLfixed z);
-static GLfixed fog_exp2(ogles_context_t* c, GLfixed z);
-
-
-// ----------------------------------------------------------------------------
-
-static void init_white(vec4_t& c) {
- c.r = c.g = c.b = c.a = 0x10000;
-}
-
-void ogles_init_light(ogles_context_t* c)
-{
- for (unsigned int i=0 ; i<OGLES_MAX_LIGHTS ; i++) {
- c->lighting.lights[i].ambient.a = 0x10000;
- c->lighting.lights[i].position.z = 0x10000;
- c->lighting.lights[i].spotDir.z = -0x10000;
- c->lighting.lights[i].spotCutoff = gglIntToFixed(180);
- c->lighting.lights[i].attenuation[0] = 0x10000;
- }
- init_white(c->lighting.lights[0].diffuse);
- init_white(c->lighting.lights[0].specular);
-
- c->lighting.front.ambient.r =
- c->lighting.front.ambient.g =
- c->lighting.front.ambient.b = gglFloatToFixed(0.2f);
- c->lighting.front.ambient.a = 0x10000;
- c->lighting.front.diffuse.r =
- c->lighting.front.diffuse.g =
- c->lighting.front.diffuse.b = gglFloatToFixed(0.8f);
- c->lighting.front.diffuse.a = 0x10000;
- c->lighting.front.specular.a = 0x10000;
- c->lighting.front.emission.a = 0x10000;
-
- c->lighting.lightModel.ambient.r =
- c->lighting.lightModel.ambient.g =
- c->lighting.lightModel.ambient.b = gglFloatToFixed(0.2f);
- c->lighting.lightModel.ambient.a = 0x10000;
-
- c->lighting.colorMaterial.face = GL_FRONT_AND_BACK;
- c->lighting.colorMaterial.mode = GL_AMBIENT_AND_DIFFUSE;
-
- c->fog.mode = GL_EXP;
- c->fog.fog = fog_exp;
- c->fog.density = 0x10000;
- c->fog.end = 0x10000;
- c->fog.invEndMinusStart = 0x10000;
-
- invalidate_lighting(c);
-
- c->rasterizer.procs.shadeModel(c, GL_SMOOTH);
- c->lighting.shadeModel = GL_SMOOTH;
-}
-
-void ogles_uninit_light(ogles_context_t* /*c*/)
-{
-}
-
-static inline int32_t clampF(GLfixed f) CONST;
-int32_t clampF(GLfixed f) {
- f = (f & ~(f>>31));
- if (f >= 0x10000)
- f = 0x10000;
- return f;
-}
-
-static GLfixed fog_linear(ogles_context_t* c, GLfixed z) {
- return clampF(gglMulx((c->fog.end - ((z<0)?-z:z)), c->fog.invEndMinusStart));
-}
-
-static GLfixed fog_exp(ogles_context_t* c, GLfixed z) {
- const float e = fixedToFloat(gglMulx(c->fog.density, ((z<0)?-z:z)));
- return clampF(gglFloatToFixed(fastexpf(-e)));
-}
-
-static GLfixed fog_exp2(ogles_context_t* c, GLfixed z) {
- const float e = fixedToFloat(gglMulx(c->fog.density, z));
- return clampF(gglFloatToFixed(fastexpf(-e*e)));
-}
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#pragma mark math helpers
-#endif
-
-static inline
-void vscale3(GLfixed* d, const GLfixed* m, GLfixed s) {
- d[0] = gglMulx(m[0], s);
- d[1] = gglMulx(m[1], s);
- d[2] = gglMulx(m[2], s);
-}
-
-static inline
-void vsa3(GLfixed* d, const GLfixed* m, GLfixed s, const GLfixed* a) {
- d[0] = gglMulAddx(m[0], s, a[0]);
- d[1] = gglMulAddx(m[1], s, a[1]);
- d[2] = gglMulAddx(m[2], s, a[2]);
-}
-
-static inline
-void vss3(GLfixed* d, const GLfixed* m, GLfixed s, const GLfixed* a) {
- d[0] = gglMulSubx(m[0], s, a[0]);
- d[1] = gglMulSubx(m[1], s, a[1]);
- d[2] = gglMulSubx(m[2], s, a[2]);
-}
-
-static inline
-void vmla3(GLfixed* d,
- const GLfixed* m0, const GLfixed* m1, const GLfixed* a)
-{
- d[0] = gglMulAddx(m0[0], m1[0], a[0]);
- d[1] = gglMulAddx(m0[1], m1[1], a[1]);
- d[2] = gglMulAddx(m0[2], m1[2], a[2]);
-}
-
-static inline
-void vmul3(GLfixed* d, const GLfixed* m0, const GLfixed* m1) {
- d[0] = gglMulx(m0[0], m1[0]);
- d[1] = gglMulx(m0[1], m1[1]);
- d[2] = gglMulx(m0[2], m1[2]);
-}
-
-void vnorm3(GLfixed* d, const GLfixed* a)
-{
- // we must take care of overflows when normalizing a vector
- GLfixed n;
- int32_t x = a[0]; x = x>=0 ? x : -x;
- int32_t y = a[1]; y = y>=0 ? y : -y;
- int32_t z = a[2]; z = z>=0 ? z : -z;
- if (ggl_likely(x<=0x6800 && y<=0x6800 && z<= 0x6800)) {
- // in this case this will all fit on 32 bits
- n = x*x + y*y + z*z;
- n = gglSqrtRecipx(n);
- n <<= 8;
- } else {
- // here norm^2 is at least 0x7EC00000 (>>32 == 0.495117)
- n = vsquare3(x, y, z);
- n = gglSqrtRecipx(n);
- }
- vscale3(d, a, n);
-}
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#pragma mark lighting equations
-#endif
-
-static inline void light_picker(ogles_context_t* c)
-{
- if (ggl_likely(!c->lighting.enable)) {
- c->lighting.lightVertex = lightVertexNop;
- return;
- }
- if (c->lighting.colorMaterial.enable) {
- c->lighting.lightVertex = lightVertexMaterial;
- } else {
- c->lighting.lightVertex = lightVertex;
- }
-}
-
-static inline void validate_light_mvi(ogles_context_t* c)
-{
- uint32_t en = c->lighting.enabledLights;
- // Vector from object to viewer, in eye coordinates
- while (en) {
- const int i = 31 - gglClz(en);
- en &= ~(1<<i);
- light_t& l = c->lighting.lights[i];
-#if OBJECT_SPACE_LIGHTING
- c->transforms.mvui.point4(&c->transforms.mvui,
- &l.objPosition, &l.position);
-#else
- l.objPosition = l.position;
-#endif
- vnorm3(l.normalizedObjPosition.v, l.objPosition.v);
- }
- const vec4_t eyeViewer = {{{ 0, 0, 0x10000, 0 }}};
-#if OBJECT_SPACE_LIGHTING
- c->transforms.mvui.point3(&c->transforms.mvui,
- &c->lighting.objViewer, &eyeViewer);
- vnorm3(c->lighting.objViewer.v, c->lighting.objViewer.v);
-#else
- c->lighting.objViewer = eyeViewer;
-#endif
-}
-
-static inline void validate_light(ogles_context_t* c)
-{
- // if colorMaterial is enabled, we get the color from the vertex
- if (!c->lighting.colorMaterial.enable) {
- material_t& material = c->lighting.front;
- uint32_t en = c->lighting.enabledLights;
- while (en) {
- const int i = 31 - gglClz(en);
- en &= ~(1<<i);
- light_t& l = c->lighting.lights[i];
- vmul3(l.implicitAmbient.v, material.ambient.v, l.ambient.v);
- vmul3(l.implicitDiffuse.v, material.diffuse.v, l.diffuse.v);
- vmul3(l.implicitSpecular.v, material.specular.v, l.specular.v);
-
- // this is just a flag to tell if we have a specular component
- l.implicitSpecular.v[3] =
- l.implicitSpecular.r |
- l.implicitSpecular.g |
- l.implicitSpecular.b;
-
- l.rConstAttenuation = (l.attenuation[1] | l.attenuation[2])==0;
- if (l.rConstAttenuation)
- l.rConstAttenuation = gglRecipFast(l.attenuation[0]);
- }
- // emission and ambient for the whole scene
- vmla3( c->lighting.implicitSceneEmissionAndAmbient.v,
- c->lighting.lightModel.ambient.v,
- material.ambient.v,
- material.emission.v);
- c->lighting.implicitSceneEmissionAndAmbient.a = material.diffuse.a;
- }
- validate_light_mvi(c);
-}
-
-void invalidate_lighting(ogles_context_t* c)
-{
- // TODO: pick lightVertexValidate or lightVertexValidateMVI
- // instead of systematically the heavier lightVertexValidate()
- c->lighting.lightVertex = lightVertexValidate;
-}
-
-void ogles_invalidate_lighting_mvui(ogles_context_t* c)
-{
- invalidate_lighting(c);
-}
-
-void lightVertexNop(ogles_context_t*, vertex_t* /*v*/)
-{
- // we should never end-up here
-}
-
-void lightVertexValidateMVI(ogles_context_t* c, vertex_t* v)
-{
- validate_light_mvi(c);
- light_picker(c);
- c->lighting.lightVertex(c, v);
-}
-
-void lightVertexValidate(ogles_context_t* c, vertex_t* v)
-{
- validate_light(c);
- light_picker(c);
- c->lighting.lightVertex(c, v);
-}
-
-void lightVertexMaterial(ogles_context_t* c, vertex_t* v)
-{
- // fetch the material color
- const GLvoid* cp = c->arrays.color.element(
- v->index & vertex_cache_t::INDEX_MASK);
- c->arrays.color.fetch(c, v->color.v, cp);
-
- // acquire the color-material from the vertex
- material_t& material = c->lighting.front;
- material.ambient =
- material.diffuse = v->color;
- // implicit arguments need to be computed per/vertex
- uint32_t en = c->lighting.enabledLights;
- while (en) {
- const int i = 31 - gglClz(en);
- en &= ~(1<<i);
- light_t& l = c->lighting.lights[i];
- vmul3(l.implicitAmbient.v, material.ambient.v, l.ambient.v);
- vmul3(l.implicitDiffuse.v, material.diffuse.v, l.diffuse.v);
- vmul3(l.implicitSpecular.v, material.specular.v, l.specular.v);
- // this is just a flag to tell if we have a specular component
- l.implicitSpecular.v[3] =
- l.implicitSpecular.r |
- l.implicitSpecular.g |
- l.implicitSpecular.b;
- }
- // emission and ambient for the whole scene
- vmla3( c->lighting.implicitSceneEmissionAndAmbient.v,
- c->lighting.lightModel.ambient.v,
- material.ambient.v,
- material.emission.v);
- c->lighting.implicitSceneEmissionAndAmbient.a = material.diffuse.a;
-
- // now we can light our vertex as usual
- lightVertex(c, v);
-}
-
-void lightVertex(ogles_context_t* c, vertex_t* v)
-{
- // emission and ambient for the whole scene
- vec4_t r = c->lighting.implicitSceneEmissionAndAmbient;
- const vec4_t objViewer = c->lighting.objViewer;
-
- uint32_t en = c->lighting.enabledLights;
- if (ggl_likely(en)) {
- // since we do the lighting in object-space, we don't need to
- // transform each normal. However, we might still have to normalize
- // it if GL_NORMALIZE is enabled.
- vec4_t n;
- c->arrays.normal.fetch(c, n.v,
- c->arrays.normal.element(v->index & vertex_cache_t::INDEX_MASK));
-
-#if !OBJECT_SPACE_LIGHTING
- c->transforms.mvui.point3(&c->transforms.mvui, &n, &n);
-#endif
-
- // TODO: right now we handle GL_RESCALE_NORMALS as if it were
- // GL_NORMALIZE. We could optimize this by scaling mvui
- // appropriately instead.
- if (c->transforms.rescaleNormals)
- vnorm3(n.v, n.v);
-
- const material_t& material = c->lighting.front;
- const int twoSide = c->lighting.lightModel.twoSide;
-
- while (en) {
- const int i = 31 - gglClz(en);
- en &= ~(1<<i);
- const light_t& l = c->lighting.lights[i];
-
- vec4_t d, t;
- GLfixed s;
- GLfixed sqDist = 0x10000;
-
- // compute vertex-to-light vector
- if (ggl_unlikely(l.position.w)) {
- // lightPos/1.0 - vertex/vertex.w == lightPos*vertex.w - vertex
-#if !OBJECT_SPACE_LIGHTING
- vec4_t o;
- const transform_t& mv = c->transforms.modelview.transform;
- mv.point4(&mv, &o, &v->obj);
- vss3(d.v, l.objPosition.v, o.w, o.v);
-#else
- vss3(d.v, l.objPosition.v, v->obj.w, v->obj.v);
-#endif
- sqDist = dot3(d.v, d.v);
- vscale3(d.v, d.v, gglSqrtRecipx(sqDist));
- } else {
- // TODO: avoid copy here
- d = l.normalizedObjPosition;
- }
-
- // ambient & diffuse
- s = dot3(n.v, d.v);
- s = (s<0) ? (twoSide?(-s):0) : s;
- vsa3(t.v, l.implicitDiffuse.v, s, l.implicitAmbient.v);
-
- // specular
- if (ggl_unlikely(s && l.implicitSpecular.v[3])) {
- vec4_t h;
- h.x = d.x + objViewer.x;
- h.y = d.y + objViewer.y;
- h.z = d.z + objViewer.z;
- vnorm3(h.v, h.v);
- s = dot3(n.v, h.v);
- s = (s<0) ? (twoSide?(-s):0) : s;
- if (s > 0) {
- s = gglPowx(s, material.shininess);
- vsa3(t.v, l.implicitSpecular.v, s, t.v);
- }
- }
-
- // spot
- if (ggl_unlikely(l.spotCutoff != gglIntToFixed(180))) {
- GLfixed spotAtt = -dot3(l.normalizedSpotDir.v, d.v);
- if (spotAtt >= l.spotCutoffCosine) {
- vscale3(t.v, t.v, gglPowx(spotAtt, l.spotExp));
- }
- }
-
- // attenuation
- if (ggl_unlikely(l.position.w)) {
- if (l.rConstAttenuation) {
- s = l.rConstAttenuation;
- } else {
- s = gglMulAddx(sqDist, l.attenuation[2], l.attenuation[0]);
- if (l.attenuation[1])
- s = gglMulAddx(gglSqrtx(sqDist), l.attenuation[1], s);
- s = gglRecipFast(s);
- }
- vscale3(t.v, t.v, s);
- }
-
- r.r += t.r;
- r.g += t.g;
- r.b += t.b;
- }
- }
- v->color.r = gglClampx(r.r);
- v->color.g = gglClampx(r.g);
- v->color.b = gglClampx(r.b);
- v->color.a = gglClampx(r.a);
- v->flags |= vertex_t::LIT;
-}
-
-static void lightModelx(GLenum pname, GLfixed param, ogles_context_t* c)
-{
- if (ggl_unlikely(pname != GL_LIGHT_MODEL_TWO_SIDE)) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- c->lighting.lightModel.twoSide = param ? GL_TRUE : GL_FALSE;
- invalidate_lighting(c);
-}
-
-static void lightx(GLenum i, GLenum pname, GLfixed param, ogles_context_t* c)
-{
- if (ggl_unlikely(uint32_t(i-GL_LIGHT0) >= OGLES_MAX_LIGHTS)) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
-
- light_t& light = c->lighting.lights[i-GL_LIGHT0];
- switch (pname) {
- case GL_SPOT_EXPONENT:
- if (GGLfixed(param) >= gglIntToFixed(128)) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
- light.spotExp = param;
- break;
- case GL_SPOT_CUTOFF:
- if (param!=gglIntToFixed(180) && GGLfixed(param)>=gglIntToFixed(90)) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
- light.spotCutoff = param;
- light.spotCutoffCosine =
- gglFloatToFixed(cosinef((M_PI/(180.0f*65536.0f))*param));
- break;
- case GL_CONSTANT_ATTENUATION:
- if (param < 0) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
- light.attenuation[0] = param;
- break;
- case GL_LINEAR_ATTENUATION:
- if (param < 0) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
- light.attenuation[1] = param;
- break;
- case GL_QUADRATIC_ATTENUATION:
- if (param < 0) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
- light.attenuation[2] = param;
- break;
- default:
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- invalidate_lighting(c);
-}
-
-static void lightxv(GLenum i, GLenum pname, const GLfixed *params, ogles_context_t* c)
-{
- if (ggl_unlikely(uint32_t(i-GL_LIGHT0) >= OGLES_MAX_LIGHTS)) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
-
- GLfixed* what;
- light_t& light = c->lighting.lights[i-GL_LIGHT0];
- switch (pname) {
- case GL_AMBIENT:
- what = light.ambient.v;
- break;
- case GL_DIFFUSE:
- what = light.diffuse.v;
- break;
- case GL_SPECULAR:
- what = light.specular.v;
- break;
- case GL_POSITION: {
- ogles_validate_transform(c, transform_state_t::MODELVIEW);
- transform_t& mv = c->transforms.modelview.transform;
- mv.point4(&mv, &light.position, reinterpret_cast<vec4_t const*>(params));
- invalidate_lighting(c);
- return;
- }
- case GL_SPOT_DIRECTION: {
-#if OBJECT_SPACE_LIGHTING
- ogles_validate_transform(c, transform_state_t::MVUI);
- transform_t& mvui = c->transforms.mvui;
- mvui.point3(&mvui, &light.spotDir, reinterpret_cast<vec4_t const*>(params));
-#else
- light.spotDir = *reinterpret_cast<vec4_t const*>(params);
-#endif
- vnorm3(light.normalizedSpotDir.v, light.spotDir.v);
- invalidate_lighting(c);
- return;
- }
- default:
- lightx(i, pname, params[0], c);
- return;
- }
- what[0] = params[0];
- what[1] = params[1];
- what[2] = params[2];
- what[3] = params[3];
- invalidate_lighting(c);
-}
-
-static void materialx(GLenum face, GLenum pname, GLfixed param, ogles_context_t* c)
-{
- if (ggl_unlikely(face != GL_FRONT_AND_BACK)) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- if (ggl_unlikely(pname != GL_SHININESS)) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- c->lighting.front.shininess = param;
- invalidate_lighting(c);
-}
-
-static void fogx(GLenum pname, GLfixed param, ogles_context_t* c)
-{
- switch (pname) {
- case GL_FOG_DENSITY:
- if (param >= 0) {
- c->fog.density = param;
- break;
- }
- ogles_error(c, GL_INVALID_VALUE);
- break;
- case GL_FOG_START:
- c->fog.start = param;
- c->fog.invEndMinusStart = gglRecip(c->fog.end - c->fog.start);
- break;
- case GL_FOG_END:
- c->fog.end = param;
- c->fog.invEndMinusStart = gglRecip(c->fog.end - c->fog.start);
- break;
- case GL_FOG_MODE:
- switch (param) {
- case GL_LINEAR:
- c->fog.mode = param;
- c->fog.fog = fog_linear;
- break;
- case GL_EXP:
- c->fog.mode = param;
- c->fog.fog = fog_exp;
- break;
- case GL_EXP2:
- c->fog.mode = param;
- c->fog.fog = fog_exp2;
- break;
- default:
- ogles_error(c, GL_INVALID_ENUM);
- break;
- }
- break;
- default:
- ogles_error(c, GL_INVALID_ENUM);
- break;
- }
-}
-
-// ----------------------------------------------------------------------------
-}; // namespace android
-// ----------------------------------------------------------------------------
-
-using namespace android;
-
-#if 0
-#pragma mark -
-#pragma mark lighting APIs
-#endif
-
-void glShadeModel(GLenum mode)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (ggl_unlikely(mode != GL_SMOOTH && mode != GL_FLAT)) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- c->lighting.shadeModel = mode;
-}
-
-void glLightModelf(GLenum pname, GLfloat param)
-{
- ogles_context_t* c = ogles_context_t::get();
- lightModelx(pname, gglFloatToFixed(param), c);
-}
-
-void glLightModelx(GLenum pname, GLfixed param)
-{
- ogles_context_t* c = ogles_context_t::get();
- lightModelx(pname, param, c);
-}
-
-void glLightModelfv(GLenum pname, const GLfloat *params)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (pname == GL_LIGHT_MODEL_TWO_SIDE) {
- lightModelx(pname, gglFloatToFixed(params[0]), c);
- return;
- }
-
- if (ggl_unlikely(pname != GL_LIGHT_MODEL_AMBIENT)) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
-
- c->lighting.lightModel.ambient.r = gglFloatToFixed(params[0]);
- c->lighting.lightModel.ambient.g = gglFloatToFixed(params[1]);
- c->lighting.lightModel.ambient.b = gglFloatToFixed(params[2]);
- c->lighting.lightModel.ambient.a = gglFloatToFixed(params[3]);
- invalidate_lighting(c);
-}
-
-void glLightModelxv(GLenum pname, const GLfixed *params)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (pname == GL_LIGHT_MODEL_TWO_SIDE) {
- lightModelx(pname, params[0], c);
- return;
- }
-
- if (ggl_unlikely(pname != GL_LIGHT_MODEL_AMBIENT)) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
-
- c->lighting.lightModel.ambient.r = params[0];
- c->lighting.lightModel.ambient.g = params[1];
- c->lighting.lightModel.ambient.b = params[2];
- c->lighting.lightModel.ambient.a = params[3];
- invalidate_lighting(c);
-}
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#endif
-
-void glLightf(GLenum i, GLenum pname, GLfloat param)
-{
- ogles_context_t* c = ogles_context_t::get();
- lightx(i, pname, gglFloatToFixed(param), c);
-}
-
-void glLightx(GLenum i, GLenum pname, GLfixed param)
-{
- ogles_context_t* c = ogles_context_t::get();
- lightx(i, pname, param, c);
-}
-
-void glLightfv(GLenum i, GLenum pname, const GLfloat *params)
-{
- ogles_context_t* c = ogles_context_t::get();
- switch (pname) {
- case GL_SPOT_EXPONENT:
- case GL_SPOT_CUTOFF:
- case GL_CONSTANT_ATTENUATION:
- case GL_LINEAR_ATTENUATION:
- case GL_QUADRATIC_ATTENUATION:
- lightx(i, pname, gglFloatToFixed(params[0]), c);
- return;
- }
-
- GLfixed paramsx[4];
- paramsx[0] = gglFloatToFixed(params[0]);
- paramsx[1] = gglFloatToFixed(params[1]);
- paramsx[2] = gglFloatToFixed(params[2]);
- if (pname != GL_SPOT_DIRECTION)
- paramsx[3] = gglFloatToFixed(params[3]);
-
- lightxv(i, pname, paramsx, c);
-}
-
-void glLightxv(GLenum i, GLenum pname, const GLfixed *params)
-{
- ogles_context_t* c = ogles_context_t::get();
- lightxv(i, pname, params, c);
-}
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#endif
-
-void glMaterialf(GLenum face, GLenum pname, GLfloat param)
-{
- ogles_context_t* c = ogles_context_t::get();
- materialx(face, pname, gglFloatToFixed(param), c);
-}
-
-void glMaterialx(GLenum face, GLenum pname, GLfixed param)
-{
- ogles_context_t* c = ogles_context_t::get();
- materialx(face, pname, param, c);
-}
-
-void glMaterialfv(
- GLenum face, GLenum pname, const GLfloat *params)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (ggl_unlikely(face != GL_FRONT_AND_BACK)) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- GLfixed* what=0;
- GLfixed* other=0;
- switch (pname) {
- case GL_AMBIENT: what = c->lighting.front.ambient.v; break;
- case GL_DIFFUSE: what = c->lighting.front.diffuse.v; break;
- case GL_SPECULAR: what = c->lighting.front.specular.v; break;
- case GL_EMISSION: what = c->lighting.front.emission.v; break;
- case GL_AMBIENT_AND_DIFFUSE:
- what = c->lighting.front.ambient.v;
- other = c->lighting.front.diffuse.v;
- break;
- case GL_SHININESS:
- c->lighting.front.shininess = gglFloatToFixed(params[0]);
- invalidate_lighting(c);
- return;
- default:
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- what[0] = gglFloatToFixed(params[0]);
- what[1] = gglFloatToFixed(params[1]);
- what[2] = gglFloatToFixed(params[2]);
- what[3] = gglFloatToFixed(params[3]);
- if (other) {
- other[0] = what[0];
- other[1] = what[1];
- other[2] = what[2];
- other[3] = what[3];
- }
- invalidate_lighting(c);
-}
-
-void glMaterialxv(
- GLenum face, GLenum pname, const GLfixed *params)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (ggl_unlikely(face != GL_FRONT_AND_BACK)) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- GLfixed* what=0;
- GLfixed* other=0;
- switch (pname) {
- case GL_AMBIENT: what = c->lighting.front.ambient.v; break;
- case GL_DIFFUSE: what = c->lighting.front.diffuse.v; break;
- case GL_SPECULAR: what = c->lighting.front.specular.v; break;
- case GL_EMISSION: what = c->lighting.front.emission.v; break;
- case GL_AMBIENT_AND_DIFFUSE:
- what = c->lighting.front.ambient.v;
- other = c->lighting.front.diffuse.v;
- break;
- case GL_SHININESS:
- c->lighting.front.shininess = gglFloatToFixed(params[0]);
- invalidate_lighting(c);
- return;
- default:
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- what[0] = params[0];
- what[1] = params[1];
- what[2] = params[2];
- what[3] = params[3];
- if (other) {
- other[0] = what[0];
- other[1] = what[1];
- other[2] = what[2];
- other[3] = what[3];
- }
- invalidate_lighting(c);
-}
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#pragma mark fog
-#endif
-
-void glFogf(GLenum pname, GLfloat param) {
- ogles_context_t* c = ogles_context_t::get();
- GLfixed paramx = (GLfixed)param;
- if (pname != GL_FOG_MODE)
- paramx = gglFloatToFixed(param);
- fogx(pname, paramx, c);
-}
-
-void glFogx(GLenum pname, GLfixed param) {
- ogles_context_t* c = ogles_context_t::get();
- fogx(pname, param, c);
-}
-
-void glFogfv(GLenum pname, const GLfloat *params)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (pname != GL_FOG_COLOR) {
- GLfixed paramx = (GLfixed)params[0];
- if (pname != GL_FOG_MODE)
- paramx = gglFloatToFixed(params[0]);
- fogx(pname, paramx, c);
- return;
- }
- GLfixed paramsx[4];
- paramsx[0] = gglFloatToFixed(params[0]);
- paramsx[1] = gglFloatToFixed(params[1]);
- paramsx[2] = gglFloatToFixed(params[2]);
- paramsx[3] = gglFloatToFixed(params[3]);
- c->rasterizer.procs.fogColor3xv(c, paramsx);
-}
-
-void glFogxv(GLenum pname, const GLfixed *params)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (pname != GL_FOG_COLOR) {
- fogx(pname, params[0], c);
- return;
- }
- c->rasterizer.procs.fogColor3xv(c, params);
-}
diff --git a/opengl/libagl/light.h b/opengl/libagl/light.h
deleted file mode 100644
index 39e3309..0000000
--- a/opengl/libagl/light.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/* libs/opengles/light.h
-**
-** Copyright 2006, 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.
-*/
-
-#ifndef ANDROID_OPENGLES_LIGHT_H
-#define ANDROID_OPENGLES_LIGHT_H
-
-#include <stdint.h>
-#include <stddef.h>
-#include <sys/types.h>
-
-
-// Set to 1 for object-space lighting evaluation.
-// There are still some bugs with object-space lighting,
-// especially visible in the San Angeles demo.
-#define OBJECT_SPACE_LIGHTING 0
-
-
-namespace android {
-
-namespace gl {
-struct ogles_context_t;
-};
-
-void ogles_init_light(ogles_context_t* c);
-void ogles_uninit_light(ogles_context_t* c);
-void ogles_invalidate_lighting_mvui(ogles_context_t* c);
-
-}; // namespace android
-
-#endif // ANDROID_OPENGLES_LIGHT_H
-
diff --git a/opengl/libagl/matrix.cpp b/opengl/libagl/matrix.cpp
deleted file mode 100644
index edd474d..0000000
--- a/opengl/libagl/matrix.cpp
+++ /dev/null
@@ -1,1123 +0,0 @@
-/* libs/opengles/matrix.cpp
-**
-** Copyright 2006, 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 <stdlib.h>
-#include <stdio.h>
-
-#include "context.h"
-#include "fp.h"
-#include "state.h"
-#include "matrix.h"
-#include "vertex.h"
-#include "light.h"
-
-#if defined(__arm__) && defined(__thumb__)
-#warning "matrix.cpp should not be compiled in thumb on ARM."
-#endif
-
-#define I(_i, _j) ((_j)+ 4*(_i))
-
-namespace android {
-
-// ----------------------------------------------------------------------------
-
-static const GLfloat gIdentityf[16] = { 1,0,0,0,
- 0,1,0,0,
- 0,0,1,0,
- 0,0,0,1 };
-
-static const matrixx_t gIdentityx = {
- { 0x10000,0,0,0,
- 0,0x10000,0,0,
- 0,0,0x10000,0,
- 0,0,0,0x10000
- }
- };
-
-static void point2__nop(transform_t const*, vec4_t* c, vec4_t const* o);
-static void point3__nop(transform_t const*, vec4_t* c, vec4_t const* o);
-static void point4__nop(transform_t const*, vec4_t* c, vec4_t const* o);
-static void point2__generic(transform_t const*, vec4_t* c, vec4_t const* o);
-static void point3__generic(transform_t const*, vec4_t* c, vec4_t const* o);
-static void point4__generic(transform_t const*, vec4_t* c, vec4_t const* o);
-static void point3__mvui(transform_t const*, vec4_t* c, vec4_t const* o);
-static void point4__mvui(transform_t const*, vec4_t* c, vec4_t const* o);
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#endif
-
-void ogles_init_matrix(ogles_context_t* c)
-{
- c->transforms.modelview.init(OGLES_MODELVIEW_STACK_DEPTH);
- c->transforms.projection.init(OGLES_PROJECTION_STACK_DEPTH);
- for (int i=0; i<GGL_TEXTURE_UNIT_COUNT ; i++)
- c->transforms.texture[i].init(OGLES_TEXTURE_STACK_DEPTH);
-
- c->transforms.current = &c->transforms.modelview;
- c->transforms.matrixMode = GL_MODELVIEW;
- c->transforms.dirty = transform_state_t::VIEWPORT |
- transform_state_t::MVUI |
- transform_state_t::MVIT |
- transform_state_t::MVP;
- c->transforms.mvp.loadIdentity();
- c->transforms.mvp4.loadIdentity();
- c->transforms.mvit4.loadIdentity();
- c->transforms.mvui.loadIdentity();
- c->transforms.vpt.loadIdentity();
- c->transforms.vpt.zNear = 0.0f;
- c->transforms.vpt.zFar = 1.0f;
-}
-
-void ogles_uninit_matrix(ogles_context_t* c)
-{
- c->transforms.modelview.uninit();
- c->transforms.projection.uninit();
- for (int i=0; i<GGL_TEXTURE_UNIT_COUNT ; i++)
- c->transforms.texture[i].uninit();
-}
-
-static void validate_perspective(ogles_context_t* c, vertex_t* v)
-{
- const uint32_t enables = c->rasterizer.state.enables;
- c->arrays.perspective = (c->clipPlanes.enable) ?
- ogles_vertex_clipAllPerspective3D : ogles_vertex_perspective3D;
- if (enables & (GGL_ENABLE_DEPTH_TEST|GGL_ENABLE_FOG)) {
- c->arrays.perspective = ogles_vertex_perspective3DZ;
- if (c->clipPlanes.enable || (enables&GGL_ENABLE_FOG))
- c->arrays.perspective = ogles_vertex_clipAllPerspective3DZ;
- }
- if ((c->arrays.vertex.size != 4) &&
- (c->transforms.mvp4.flags & transform_t::FLAGS_2D_PROJECTION)) {
- c->arrays.perspective = ogles_vertex_perspective2D;
- }
- c->arrays.perspective(c, v);
-}
-
-void ogles_invalidate_perspective(ogles_context_t* c)
-{
- c->arrays.perspective = validate_perspective;
-}
-
-void ogles_validate_transform_impl(ogles_context_t* c, uint32_t want)
-{
- int dirty = c->transforms.dirty & want;
-
- // Validate the modelview
- if (dirty & transform_state_t::MODELVIEW) {
- c->transforms.modelview.validate();
- }
-
- // Validate the projection stack (in fact, it's never needed)
- if (dirty & transform_state_t::PROJECTION) {
- c->transforms.projection.validate();
- }
-
- // Validate the viewport transformation
- if (dirty & transform_state_t::VIEWPORT) {
- vp_transform_t& vpt = c->transforms.vpt;
- vpt.transform.matrix.load(vpt.matrix);
- vpt.transform.picker();
- }
-
- // We need to update the mvp (used to transform each vertex)
- if (dirty & transform_state_t::MVP) {
- c->transforms.update_mvp();
- // invalidate perspective (divide by W) and view volume clipping
- ogles_invalidate_perspective(c);
- }
-
- // Validate the mvui (for normal transformation)
- if (dirty & transform_state_t::MVUI) {
- c->transforms.update_mvui();
- ogles_invalidate_lighting_mvui(c);
- }
-
- // Validate the texture stack
- if (dirty & transform_state_t::TEXTURE) {
- for (int i=0; i<GGL_TEXTURE_UNIT_COUNT ; i++)
- c->transforms.texture[i].validate();
- }
-
- // Validate the mvit4 (user-clip planes)
- if (dirty & transform_state_t::MVIT) {
- c->transforms.update_mvit();
- }
-
- c->transforms.dirty &= ~want;
-}
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#pragma mark transform_t
-#endif
-
-void transform_t::loadIdentity() {
- matrix = gIdentityx;
- flags = 0;
- ops = OP_IDENTITY;
- point2 = point2__nop;
- point3 = point3__nop;
- point4 = point4__nop;
-}
-
-
-static inline
-int notZero(GLfixed v) {
- return abs(v) & ~0x3;
-}
-
-static inline
-int notOne(GLfixed v) {
- return notZero(v - 0x10000);
-}
-
-void transform_t::picker()
-{
- const GLfixed* const m = matrix.m;
-
- // XXX: picker needs to be smarter
- flags = 0;
- ops = OP_ALL;
- point2 = point2__generic;
- point3 = point3__generic;
- point4 = point4__generic;
-
- // find out if this is a 2D projection
- if (!(notZero(m[3]) | notZero(m[7]) | notZero(m[11]) | notOne(m[15]))) {
- flags |= FLAGS_2D_PROJECTION;
- }
-}
-
-void mvui_transform_t::picker()
-{
- flags = 0;
- ops = OP_ALL;
- point3 = point3__mvui;
- point4 = point4__mvui;
-}
-
-void transform_t::dump(const char* what)
-{
- GLfixed const * const m = matrix.m;
- ALOGD("%s:", what);
- for (int i=0 ; i<4 ; i++)
- ALOGD("[%08x %08x %08x %08x] [%f %f %f %f]\n",
- m[I(0,i)], m[I(1,i)], m[I(2,i)], m[I(3,i)],
- fixedToFloat(m[I(0,i)]),
- fixedToFloat(m[I(1,i)]),
- fixedToFloat(m[I(2,i)]),
- fixedToFloat(m[I(3,i)]));
-}
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#pragma mark matrixx_t
-#endif
-
-void matrixx_t::load(const matrixf_t& rhs) {
- GLfixed* xp = m;
- GLfloat const* fp = rhs.elements();
- unsigned int i = 16;
- do {
- const GLfloat f = *fp++;
- *xp++ = isZerof(f) ? 0 : gglFloatToFixed(f);
- } while (--i);
-}
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#pragma mark matrixf_t
-#endif
-
-void matrixf_t::multiply(matrixf_t& r, const matrixf_t& lhs, const matrixf_t& rhs)
-{
- GLfloat const* const m = lhs.m;
- for (int i=0 ; i<4 ; i++) {
- const float rhs_i0 = rhs.m[ I(i,0) ];
- float ri0 = m[ I(0,0) ] * rhs_i0;
- float ri1 = m[ I(0,1) ] * rhs_i0;
- float ri2 = m[ I(0,2) ] * rhs_i0;
- float ri3 = m[ I(0,3) ] * rhs_i0;
- for (int j=1 ; j<4 ; j++) {
- const float rhs_ij = rhs.m[ I(i,j) ];
- ri0 += m[ I(j,0) ] * rhs_ij;
- ri1 += m[ I(j,1) ] * rhs_ij;
- ri2 += m[ I(j,2) ] * rhs_ij;
- ri3 += m[ I(j,3) ] * rhs_ij;
- }
- r.m[ I(i,0) ] = ri0;
- r.m[ I(i,1) ] = ri1;
- r.m[ I(i,2) ] = ri2;
- r.m[ I(i,3) ] = ri3;
- }
-}
-
-void matrixf_t::dump(const char* what) {
- ALOGD("%s", what);
- ALOGD("[ %9f %9f %9f %9f ]", m[I(0,0)], m[I(1,0)], m[I(2,0)], m[I(3,0)]);
- ALOGD("[ %9f %9f %9f %9f ]", m[I(0,1)], m[I(1,1)], m[I(2,1)], m[I(3,1)]);
- ALOGD("[ %9f %9f %9f %9f ]", m[I(0,2)], m[I(1,2)], m[I(2,2)], m[I(3,2)]);
- ALOGD("[ %9f %9f %9f %9f ]", m[I(0,3)], m[I(1,3)], m[I(2,3)], m[I(3,3)]);
-}
-
-void matrixf_t::loadIdentity() {
- memcpy(m, gIdentityf, sizeof(m));
-}
-
-void matrixf_t::set(const GLfixed* rhs) {
- load(rhs);
-}
-
-void matrixf_t::set(const GLfloat* rhs) {
- load(rhs);
-}
-
-void matrixf_t::load(const GLfixed* rhs) {
- GLfloat* fp = m;
- unsigned int i = 16;
- do {
- *fp++ = fixedToFloat(*rhs++);
- } while (--i);
-}
-
-void matrixf_t::load(const GLfloat* rhs) {
- memcpy(m, rhs, sizeof(m));
-}
-
-void matrixf_t::load(const matrixf_t& rhs) {
- operator = (rhs);
-}
-
-void matrixf_t::multiply(const matrixf_t& rhs) {
- matrixf_t r;
- multiply(r, *this, rhs);
- operator = (r);
-}
-
-void matrixf_t::translate(GLfloat x, GLfloat y, GLfloat z) {
- for (int i=0 ; i<4 ; i++) {
- m[12+i] += m[i]*x + m[4+i]*y + m[8+i]*z;
- }
-}
-
-void matrixf_t::scale(GLfloat x, GLfloat y, GLfloat z) {
- for (int i=0 ; i<4 ; i++) {
- m[ i] *= x;
- m[4+i] *= y;
- m[8+i] *= z;
- }
-}
-
-void matrixf_t::rotate(GLfloat a, GLfloat x, GLfloat y, GLfloat z)
-{
- matrixf_t rotation;
- GLfloat* r = rotation.m;
- GLfloat c, s;
- r[3] = 0; r[7] = 0; r[11]= 0;
- r[12]= 0; r[13]= 0; r[14]= 0; r[15]= 1;
- a *= GLfloat(M_PI / 180.0f);
- sincosf(a, &s, &c);
- if (isOnef(x) && isZerof(y) && isZerof(z)) {
- r[5] = c; r[10]= c;
- r[6] = s; r[9] = -s;
- r[1] = 0; r[2] = 0;
- r[4] = 0; r[8] = 0;
- r[0] = 1;
- } else if (isZerof(x) && isOnef(y) && isZerof(z)) {
- r[0] = c; r[10]= c;
- r[8] = s; r[2] = -s;
- r[1] = 0; r[4] = 0;
- r[6] = 0; r[9] = 0;
- r[5] = 1;
- } else if (isZerof(x) && isZerof(y) && isOnef(z)) {
- r[0] = c; r[5] = c;
- r[1] = s; r[4] = -s;
- r[2] = 0; r[6] = 0;
- r[8] = 0; r[9] = 0;
- r[10]= 1;
- } else {
- const GLfloat len = sqrtf(x*x + y*y + z*z);
- if (!isOnef(len)) {
- const GLfloat recipLen = reciprocalf(len);
- x *= recipLen;
- y *= recipLen;
- z *= recipLen;
- }
- const GLfloat nc = 1.0f - c;
- const GLfloat xy = x * y;
- const GLfloat yz = y * z;
- const GLfloat zx = z * x;
- const GLfloat xs = x * s;
- const GLfloat ys = y * s;
- const GLfloat zs = z * s;
- r[ 0] = x*x*nc + c; r[ 4] = xy*nc - zs; r[ 8] = zx*nc + ys;
- r[ 1] = xy*nc + zs; r[ 5] = y*y*nc + c; r[ 9] = yz*nc - xs;
- r[ 2] = zx*nc - ys; r[ 6] = yz*nc + xs; r[10] = z*z*nc + c;
- }
- multiply(rotation);
-}
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#pragma mark matrix_stack_t
-#endif
-
-void matrix_stack_t::init(int depth) {
- stack = new matrixf_t[depth];
- ops = new uint8_t[depth];
- maxDepth = depth;
- depth = 0;
- dirty = 0;
- loadIdentity();
-}
-
-void matrix_stack_t::uninit() {
- delete [] stack;
- delete [] ops;
-}
-
-void matrix_stack_t::loadIdentity() {
- transform.loadIdentity();
- stack[depth].loadIdentity();
- ops[depth] = OP_IDENTITY;
-}
-
-void matrix_stack_t::load(const GLfixed* rhs)
-{
- memcpy(transform.matrix.m, rhs, sizeof(transform.matrix.m));
- stack[depth].load(rhs);
- ops[depth] = OP_ALL; // TODO: we should look at the matrix
-}
-
-void matrix_stack_t::load(const GLfloat* rhs)
-{
- stack[depth].load(rhs);
- ops[depth] = OP_ALL; // TODO: we should look at the matrix
-}
-
-void matrix_stack_t::multiply(const matrixf_t& rhs)
-{
- stack[depth].multiply(rhs);
- ops[depth] = OP_ALL; // TODO: we should look at the matrix
-}
-
-void matrix_stack_t::translate(GLfloat x, GLfloat y, GLfloat z)
-{
- stack[depth].translate(x,y,z);
- ops[depth] |= OP_TRANSLATE;
-}
-
-void matrix_stack_t::scale(GLfloat x, GLfloat y, GLfloat z)
-{
- stack[depth].scale(x,y,z);
- if (x==y && y==z) {
- ops[depth] |= OP_UNIFORM_SCALE;
- } else {
- ops[depth] |= OP_SCALE;
- }
-}
-
-void matrix_stack_t::rotate(GLfloat a, GLfloat x, GLfloat y, GLfloat z)
-{
- stack[depth].rotate(a,x,y,z);
- ops[depth] |= OP_ROTATE;
-}
-
-void matrix_stack_t::validate()
-{
- if (dirty & DO_FLOAT_TO_FIXED) {
- transform.matrix.load(top());
- }
- if (dirty & DO_PICKER) {
- transform.picker();
- }
- dirty = 0;
-}
-
-GLint matrix_stack_t::push()
-{
- if (depth >= (maxDepth-1)) {
- return GL_STACK_OVERFLOW;
- }
- stack[depth+1] = stack[depth];
- ops[depth+1] = ops[depth];
- depth++;
- return 0;
-}
-
-GLint matrix_stack_t::pop()
-{
- if (depth == 0) {
- return GL_STACK_UNDERFLOW;
- }
- depth--;
- return 0;
-}
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#pragma mark vp_transform_t
-#endif
-
-void vp_transform_t::loadIdentity() {
- transform.loadIdentity();
- matrix.loadIdentity();
-}
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#pragma mark transform_state_t
-#endif
-
-void transform_state_t::invalidate()
-{
- switch (matrixMode) {
- case GL_MODELVIEW: dirty |= MODELVIEW | MVP | MVUI | MVIT; break;
- case GL_PROJECTION: dirty |= PROJECTION | MVP; break;
- case GL_TEXTURE: dirty |= TEXTURE | MVP; break;
- }
- current->dirty = matrix_stack_t::DO_PICKER |
- matrix_stack_t::DO_FLOAT_TO_FIXED;
-}
-
-void transform_state_t::update_mvp()
-{
- matrixf_t temp_mvp;
- matrixf_t::multiply(temp_mvp, projection.top(), modelview.top());
- mvp4.matrix.load(temp_mvp);
- mvp4.picker();
-
- if (mvp4.flags & transform_t::FLAGS_2D_PROJECTION) {
- // the mvp matrix doesn't transform W, in this case we can
- // premultiply it with the viewport transformation. In addition to
- // being more efficient, this is also much more accurate and in fact
- // is needed for 2D drawing with a resulting 1:1 mapping.
- matrixf_t mvpv;
- matrixf_t::multiply(mvpv, vpt.matrix, temp_mvp);
- mvp.matrix.load(mvpv);
- mvp.picker();
- } else {
- mvp = mvp4;
- }
-}
-
-static __attribute__((noinline))
-void invert(GLfloat* inverse, const GLfloat* src)
-{
- double t;
- int i, j, k, swap;
- GLfloat tmp[4][4];
-
- memcpy(inverse, gIdentityf, sizeof(gIdentityf));
- memcpy(tmp, src, sizeof(GLfloat)*16);
-
- for (i = 0; i < 4; i++) {
- // look for largest element in column
- swap = i;
- for (j = i + 1; j < 4; j++) {
- if (fabs(tmp[j][i]) > fabs(tmp[i][i])) {
- swap = j;
- }
- }
-
- if (swap != i) {
- /* swap rows. */
- for (k = 0; k < 4; k++) {
- t = tmp[i][k];
- tmp[i][k] = tmp[swap][k];
- tmp[swap][k] = t;
-
- t = inverse[i*4+k];
- inverse[i*4+k] = inverse[swap*4+k];
- inverse[swap*4+k] = t;
- }
- }
-
- t = 1.0f / tmp[i][i];
- for (k = 0; k < 4; k++) {
- tmp[i][k] *= t;
- inverse[i*4+k] *= t;
- }
- for (j = 0; j < 4; j++) {
- if (j != i) {
- t = tmp[j][i];
- for (k = 0; k < 4; k++) {
- tmp[j][k] -= tmp[i][k]*t;
- inverse[j*4+k] -= inverse[i*4+k]*t;
- }
- }
- }
- }
-}
-
-void transform_state_t::update_mvit()
-{
- GLfloat r[16];
- const GLfloat* const mv = modelview.top().elements();
- invert(r, mv);
- // convert to fixed-point and transpose
- GLfixed* const x = mvit4.matrix.m;
- for (int i=0 ; i<4 ; i++)
- for (int j=0 ; j<4 ; j++)
- x[I(i,j)] = gglFloatToFixed(r[I(j,i)]);
- mvit4.picker();
-}
-
-void transform_state_t::update_mvui()
-{
- GLfloat r[16];
- const GLfloat* const mv = modelview.top().elements();
-
- /*
- When evaluating the lighting equation in eye-space, normals
- are transformed by the upper 3x3 modelview inverse-transpose.
- http://www.opengl.org/documentation/specs/version1.1/glspec1.1/node26.html
-
- (note that inverse-transpose is distributive).
- Also note that:
- l(obj) = inv(modelview).l(eye) for local light
- l(obj) = tr(modelview).l(eye) for infinite light
- */
-
- invert(r, mv);
-
- GLfixed* const x = mvui.matrix.m;
-
-#if OBJECT_SPACE_LIGHTING
- for (int i=0 ; i<4 ; i++)
- for (int j=0 ; j<4 ; j++)
- x[I(i,j)] = gglFloatToFixed(r[I(i,j)]);
-#else
- for (int i=0 ; i<4 ; i++)
- for (int j=0 ; j<4 ; j++)
- x[I(i,j)] = gglFloatToFixed(r[I(j,i)]);
-#endif
-
- mvui.picker();
-}
-
-
-// ----------------------------------------------------------------------------
-// transformation and matrices API
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#pragma mark transformation and matrices API
-#endif
-
-int ogles_surfaceport(ogles_context_t* c, GLint x, GLint y)
-{
- c->viewport.surfaceport.x = x;
- c->viewport.surfaceport.y = y;
-
- ogles_viewport(c,
- c->viewport.x,
- c->viewport.y,
- c->viewport.w,
- c->viewport.h);
-
- ogles_scissor(c,
- c->viewport.scissor.x,
- c->viewport.scissor.y,
- c->viewport.scissor.w,
- c->viewport.scissor.h);
-
- return 0;
-}
-
-void ogles_scissor(ogles_context_t* c,
- GLint x, GLint y, GLsizei w, GLsizei h)
-{
- if ((w|h) < 0) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
- c->viewport.scissor.x = x;
- c->viewport.scissor.y = y;
- c->viewport.scissor.w = w;
- c->viewport.scissor.h = h;
-
- x += c->viewport.surfaceport.x;
- y += c->viewport.surfaceport.y;
-
- y = c->rasterizer.state.buffers.color.height - (y + h);
- c->rasterizer.procs.scissor(c, x, y, w, h);
-}
-
-void ogles_viewport(ogles_context_t* c,
- GLint x, GLint y, GLsizei w, GLsizei h)
-{
- if ((w|h)<0) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
-
- c->viewport.x = x;
- c->viewport.y = y;
- c->viewport.w = w;
- c->viewport.h = h;
-
- x += c->viewport.surfaceport.x;
- y += c->viewport.surfaceport.y;
-
- GLint H = c->rasterizer.state.buffers.color.height;
- GLfloat sx = div2f(w);
- GLfloat ox = sx + x;
- GLfloat sy = div2f(h);
- GLfloat oy = sy - y + (H - h);
-
- GLfloat near = c->transforms.vpt.zNear;
- GLfloat far = c->transforms.vpt.zFar;
- GLfloat A = div2f(far - near);
- GLfloat B = div2f(far + near);
-
- // compute viewport matrix
- GLfloat* const f = c->transforms.vpt.matrix.editElements();
- f[0] = sx; f[4] = 0; f[ 8] = 0; f[12] = ox;
- f[1] = 0; f[5] =-sy; f[ 9] = 0; f[13] = oy;
- f[2] = 0; f[6] = 0; f[10] = A; f[14] = B;
- f[3] = 0; f[7] = 0; f[11] = 0; f[15] = 1;
- c->transforms.dirty |= transform_state_t::VIEWPORT;
- if (c->transforms.mvp4.flags & transform_t::FLAGS_2D_PROJECTION)
- c->transforms.dirty |= transform_state_t::MVP;
-}
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#pragma mark matrix * vertex
-#endif
-
-void point2__generic(transform_t const* mx, vec4_t* lhs, vec4_t const* rhs) {
- const GLfixed* const m = mx->matrix.m;
- const GLfixed rx = rhs->x;
- const GLfixed ry = rhs->y;
- lhs->x = mla2a(rx, m[ 0], ry, m[ 4], m[12]);
- lhs->y = mla2a(rx, m[ 1], ry, m[ 5], m[13]);
- lhs->z = mla2a(rx, m[ 2], ry, m[ 6], m[14]);
- lhs->w = mla2a(rx, m[ 3], ry, m[ 7], m[15]);
-}
-
-void point3__generic(transform_t const* mx, vec4_t* lhs, vec4_t const* rhs) {
- const GLfixed* const m = mx->matrix.m;
- const GLfixed rx = rhs->x;
- const GLfixed ry = rhs->y;
- const GLfixed rz = rhs->z;
- lhs->x = mla3a(rx, m[ 0], ry, m[ 4], rz, m[ 8], m[12]);
- lhs->y = mla3a(rx, m[ 1], ry, m[ 5], rz, m[ 9], m[13]);
- lhs->z = mla3a(rx, m[ 2], ry, m[ 6], rz, m[10], m[14]);
- lhs->w = mla3a(rx, m[ 3], ry, m[ 7], rz, m[11], m[15]);
-}
-
-void point4__generic(transform_t const* mx, vec4_t* lhs, vec4_t const* rhs) {
- const GLfixed* const m = mx->matrix.m;
- const GLfixed rx = rhs->x;
- const GLfixed ry = rhs->y;
- const GLfixed rz = rhs->z;
- const GLfixed rw = rhs->w;
- lhs->x = mla4(rx, m[ 0], ry, m[ 4], rz, m[ 8], rw, m[12]);
- lhs->y = mla4(rx, m[ 1], ry, m[ 5], rz, m[ 9], rw, m[13]);
- lhs->z = mla4(rx, m[ 2], ry, m[ 6], rz, m[10], rw, m[14]);
- lhs->w = mla4(rx, m[ 3], ry, m[ 7], rz, m[11], rw, m[15]);
-}
-
-void point3__mvui(transform_t const* mx, vec4_t* lhs, vec4_t const* rhs) {
- // this is used for transforming light positions back to object space.
- // w is used as a switch for directional lights, so we need
- // to preserve it.
- const GLfixed* const m = mx->matrix.m;
- const GLfixed rx = rhs->x;
- const GLfixed ry = rhs->y;
- const GLfixed rz = rhs->z;
- lhs->x = mla3(rx, m[ 0], ry, m[ 4], rz, m[ 8]);
- lhs->y = mla3(rx, m[ 1], ry, m[ 5], rz, m[ 9]);
- lhs->z = mla3(rx, m[ 2], ry, m[ 6], rz, m[10]);
- lhs->w = 0;
-}
-
-void point4__mvui(transform_t const* mx, vec4_t* lhs, vec4_t const* rhs) {
- // this is used for transforming light positions back to object space.
- // w is used as a switch for directional lights, so we need
- // to preserve it.
- const GLfixed* const m = mx->matrix.m;
- const GLfixed rx = rhs->x;
- const GLfixed ry = rhs->y;
- const GLfixed rz = rhs->z;
- const GLfixed rw = rhs->w;
- lhs->x = mla4(rx, m[ 0], ry, m[ 4], rz, m[ 8], rw, m[12]);
- lhs->y = mla4(rx, m[ 1], ry, m[ 5], rz, m[ 9], rw, m[13]);
- lhs->z = mla4(rx, m[ 2], ry, m[ 6], rz, m[10], rw, m[14]);
- lhs->w = rw;
-}
-
-void point2__nop(transform_t const*, vec4_t* lhs, vec4_t const* rhs) {
- lhs->z = 0;
- lhs->w = 0x10000;
- if (lhs != rhs) {
- lhs->x = rhs->x;
- lhs->y = rhs->y;
- }
-}
-
-void point3__nop(transform_t const*, vec4_t* lhs, vec4_t const* rhs) {
- lhs->w = 0x10000;
- if (lhs != rhs) {
- lhs->x = rhs->x;
- lhs->y = rhs->y;
- lhs->z = rhs->z;
- }
-}
-
-void point4__nop(transform_t const*, vec4_t* lhs, vec4_t const* rhs) {
- if (lhs != rhs)
- *lhs = *rhs;
-}
-
-
-static void frustumf(
- GLfloat left, GLfloat right,
- GLfloat bottom, GLfloat top,
- GLfloat zNear, GLfloat zFar,
- ogles_context_t* c)
- {
- if (cmpf(left,right) ||
- cmpf(top, bottom) ||
- cmpf(zNear, zFar) ||
- isZeroOrNegativef(zNear) ||
- isZeroOrNegativef(zFar))
- {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
- const GLfloat r_width = reciprocalf(right - left);
- const GLfloat r_height = reciprocalf(top - bottom);
- const GLfloat r_depth = reciprocalf(zNear - zFar);
- const GLfloat x = mul2f(zNear * r_width);
- const GLfloat y = mul2f(zNear * r_height);
- const GLfloat A = mul2f((right + left) * r_width);
- const GLfloat B = (top + bottom) * r_height;
- const GLfloat C = (zFar + zNear) * r_depth;
- const GLfloat D = mul2f(zFar * zNear * r_depth);
- GLfloat f[16];
- f[ 0] = x;
- f[ 5] = y;
- f[ 8] = A;
- f[ 9] = B;
- f[10] = C;
- f[14] = D;
- f[11] = -1.0f;
- f[ 1] = f[ 2] = f[ 3] =
- f[ 4] = f[ 6] = f[ 7] =
- f[12] = f[13] = f[15] = 0.0f;
-
- matrixf_t rhs;
- rhs.set(f);
- c->transforms.current->multiply(rhs);
- c->transforms.invalidate();
-}
-
-static void orthof(
- GLfloat left, GLfloat right,
- GLfloat bottom, GLfloat top,
- GLfloat zNear, GLfloat zFar,
- ogles_context_t* c)
-{
- if (cmpf(left,right) ||
- cmpf(top, bottom) ||
- cmpf(zNear, zFar))
- {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
- const GLfloat r_width = reciprocalf(right - left);
- const GLfloat r_height = reciprocalf(top - bottom);
- const GLfloat r_depth = reciprocalf(zFar - zNear);
- const GLfloat x = mul2f(r_width);
- const GLfloat y = mul2f(r_height);
- const GLfloat z = -mul2f(r_depth);
- const GLfloat tx = -(right + left) * r_width;
- const GLfloat ty = -(top + bottom) * r_height;
- const GLfloat tz = -(zFar + zNear) * r_depth;
- GLfloat f[16];
- f[ 0] = x;
- f[ 5] = y;
- f[10] = z;
- f[12] = tx;
- f[13] = ty;
- f[14] = tz;
- f[15] = 1.0f;
- f[ 1] = f[ 2] = f[ 3] =
- f[ 4] = f[ 6] = f[ 7] =
- f[ 8] = f[ 9] = f[11] = 0.0f;
- matrixf_t rhs;
- rhs.set(f);
- c->transforms.current->multiply(rhs);
- c->transforms.invalidate();
-}
-
-static void depthRangef(GLclampf zNear, GLclampf zFar, ogles_context_t* c)
-{
- zNear = clampToZerof(zNear > 1 ? 1 : zNear);
- zFar = clampToZerof(zFar > 1 ? 1 : zFar);
- GLfloat* const f = c->transforms.vpt.matrix.editElements();
- f[10] = div2f(zFar - zNear);
- f[14] = div2f(zFar + zNear);
- c->transforms.dirty |= transform_state_t::VIEWPORT;
- c->transforms.vpt.zNear = zNear;
- c->transforms.vpt.zFar = zFar;
-}
-
-
-// ----------------------------------------------------------------------------
-}; // namespace android
-
-using namespace android;
-
-void glMatrixMode(GLenum mode)
-{
- ogles_context_t* c = ogles_context_t::get();
- matrix_stack_t* stack = 0;
- switch (mode) {
- case GL_MODELVIEW:
- stack = &c->transforms.modelview;
- break;
- case GL_PROJECTION:
- stack = &c->transforms.projection;
- break;
- case GL_TEXTURE:
- stack = &c->transforms.texture[c->textures.active];
- break;
- default:
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- c->transforms.matrixMode = mode;
- c->transforms.current = stack;
-}
-
-void glLoadIdentity()
-{
- ogles_context_t* c = ogles_context_t::get();
- c->transforms.current->loadIdentity(); // also loads the GLfixed transform
- c->transforms.invalidate();
- c->transforms.current->dirty = 0;
-}
-
-void glLoadMatrixf(const GLfloat* m)
-{
- ogles_context_t* c = ogles_context_t::get();
- c->transforms.current->load(m);
- c->transforms.invalidate();
-}
-
-void glLoadMatrixx(const GLfixed* m)
-{
- ogles_context_t* c = ogles_context_t::get();
- c->transforms.current->load(m); // also loads the GLfixed transform
- c->transforms.invalidate();
- c->transforms.current->dirty &= ~matrix_stack_t::DO_FLOAT_TO_FIXED;
-}
-
-void glMultMatrixf(const GLfloat* m)
-{
- ogles_context_t* c = ogles_context_t::get();
- matrixf_t rhs;
- rhs.set(m);
- c->transforms.current->multiply(rhs);
- c->transforms.invalidate();
-}
-
-void glMultMatrixx(const GLfixed* m)
-{
- ogles_context_t* c = ogles_context_t::get();
- matrixf_t rhs;
- rhs.set(m);
- c->transforms.current->multiply(rhs);
- c->transforms.invalidate();
-}
-
-void glPopMatrix()
-{
- ogles_context_t* c = ogles_context_t::get();
- GLint err = c->transforms.current->pop();
- if (ggl_unlikely(err)) {
- ogles_error(c, err);
- return;
- }
- c->transforms.invalidate();
-}
-
-void glPushMatrix()
-{
- ogles_context_t* c = ogles_context_t::get();
- GLint err = c->transforms.current->push();
- if (ggl_unlikely(err)) {
- ogles_error(c, err);
- return;
- }
- c->transforms.invalidate();
-}
-
-void glFrustumf(
- GLfloat left, GLfloat right,
- GLfloat bottom, GLfloat top,
- GLfloat zNear, GLfloat zFar)
-{
- ogles_context_t* c = ogles_context_t::get();
- frustumf(left, right, bottom, top, zNear, zFar, c);
-}
-
-void glFrustumx(
- GLfixed left, GLfixed right,
- GLfixed bottom, GLfixed top,
- GLfixed zNear, GLfixed zFar)
-{
- ogles_context_t* c = ogles_context_t::get();
- frustumf( fixedToFloat(left), fixedToFloat(right),
- fixedToFloat(bottom), fixedToFloat(top),
- fixedToFloat(zNear), fixedToFloat(zFar),
- c);
-}
-
-void glOrthof(
- GLfloat left, GLfloat right,
- GLfloat bottom, GLfloat top,
- GLfloat zNear, GLfloat zFar)
-{
- ogles_context_t* c = ogles_context_t::get();
- orthof(left, right, bottom, top, zNear, zFar, c);
-}
-
-void glOrthox(
- GLfixed left, GLfixed right,
- GLfixed bottom, GLfixed top,
- GLfixed zNear, GLfixed zFar)
-{
- ogles_context_t* c = ogles_context_t::get();
- orthof( fixedToFloat(left), fixedToFloat(right),
- fixedToFloat(bottom), fixedToFloat(top),
- fixedToFloat(zNear), fixedToFloat(zFar),
- c);
-}
-
-void glRotatef(GLfloat a, GLfloat x, GLfloat y, GLfloat z)
-{
- ogles_context_t* c = ogles_context_t::get();
- c->transforms.current->rotate(a, x, y, z);
- c->transforms.invalidate();
-}
-
-void glRotatex(GLfixed a, GLfixed x, GLfixed y, GLfixed z)
-{
- ogles_context_t* c = ogles_context_t::get();
- c->transforms.current->rotate(
- fixedToFloat(a), fixedToFloat(x),
- fixedToFloat(y), fixedToFloat(z));
- c->transforms.invalidate();
-}
-
-void glScalef(GLfloat x, GLfloat y, GLfloat z)
-{
- ogles_context_t* c = ogles_context_t::get();
- c->transforms.current->scale(x, y, z);
- c->transforms.invalidate();
-}
-
-void glScalex(GLfixed x, GLfixed y, GLfixed z)
-{
- ogles_context_t* c = ogles_context_t::get();
- c->transforms.current->scale(
- fixedToFloat(x), fixedToFloat(y), fixedToFloat(z));
- c->transforms.invalidate();
-}
-
-void glTranslatef(GLfloat x, GLfloat y, GLfloat z)
-{
- ogles_context_t* c = ogles_context_t::get();
- c->transforms.current->translate(x, y, z);
- c->transforms.invalidate();
-}
-
-void glTranslatex(GLfixed x, GLfixed y, GLfixed z)
-{
- ogles_context_t* c = ogles_context_t::get();
- c->transforms.current->translate(
- fixedToFloat(x), fixedToFloat(y), fixedToFloat(z));
- c->transforms.invalidate();
-}
-
-void glScissor(GLint x, GLint y, GLsizei w, GLsizei h)
-{
- ogles_context_t* c = ogles_context_t::get();
- ogles_scissor(c, x, y, w, h);
-}
-
-void glViewport(GLint x, GLint y, GLsizei w, GLsizei h)
-{
- ogles_context_t* c = ogles_context_t::get();
- ogles_viewport(c, x, y, w, h);
-}
-
-void glDepthRangef(GLclampf zNear, GLclampf zFar)
-{
- ogles_context_t* c = ogles_context_t::get();
- depthRangef(zNear, zFar, c);
-}
-
-void glDepthRangex(GLclampx zNear, GLclampx zFar)
-{
- ogles_context_t* c = ogles_context_t::get();
- depthRangef(fixedToFloat(zNear), fixedToFloat(zFar), c);
-}
-
-void glPolygonOffsetx(GLfixed factor, GLfixed units)
-{
- ogles_context_t* c = ogles_context_t::get();
- c->polygonOffset.factor = factor;
- c->polygonOffset.units = units;
-}
-
-void glPolygonOffset(GLfloat factor, GLfloat units)
-{
- ogles_context_t* c = ogles_context_t::get();
- c->polygonOffset.factor = gglFloatToFixed(factor);
- c->polygonOffset.units = gglFloatToFixed(units);
-}
-
-GLbitfield glQueryMatrixxOES(GLfixed* m, GLint* e)
-{
- ogles_context_t* c = ogles_context_t::get();
- GLbitfield status = 0;
- GLfloat const* f = c->transforms.current->top().elements();
- for (int i=0 ; i<16 ; i++) {
- if (isnan(f[i]) || isinf(f[i])) {
- status |= 1<<i;
- continue;
- }
- e[i] = exponent(f[i]) - 7;
- m[i] = mantissa(f[i]);
- }
- return status;
-}
diff --git a/opengl/libagl/matrix.h b/opengl/libagl/matrix.h
deleted file mode 100644
index cafc119..0000000
--- a/opengl/libagl/matrix.h
+++ /dev/null
@@ -1,399 +0,0 @@
-/* libs/opengles/matrix.h
-**
-** Copyright 2006, 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.
-*/
-
-#ifndef ANDROID_OPENGLES_MATRIX_H
-#define ANDROID_OPENGLES_MATRIX_H
-
-#include <stdint.h>
-#include <stddef.h>
-#include <sys/types.h>
-#include <utils/Log.h>
-
-#include <private/pixelflinger/ggl_context.h>
-
-#include <GLES/gl.h>
-
-namespace android {
-
-const int OGLES_MODELVIEW_STACK_DEPTH = 16;
-const int OGLES_PROJECTION_STACK_DEPTH = 2;
-const int OGLES_TEXTURE_STACK_DEPTH = 2;
-
-void ogles_init_matrix(ogles_context_t*);
-void ogles_uninit_matrix(ogles_context_t*);
-void ogles_invalidate_perspective(ogles_context_t* c);
-void ogles_validate_transform_impl(ogles_context_t* c, uint32_t want);
-
-int ogles_surfaceport(ogles_context_t* c, GLint x, GLint y);
-
-void ogles_scissor(ogles_context_t* c,
- GLint x, GLint y, GLsizei w, GLsizei h);
-
-void ogles_viewport(ogles_context_t* c,
- GLint x, GLint y, GLsizei w, GLsizei h);
-
-inline void ogles_validate_transform(
- ogles_context_t* c, uint32_t want)
-{
- if (c->transforms.dirty & want)
- ogles_validate_transform_impl(c, want);
-}
-
-// ----------------------------------------------------------------------------
-
-inline
-GLfixed vsquare3(GLfixed a, GLfixed b, GLfixed c)
-{
-#if defined(__arm__) && !defined(__thumb__)
-
- GLfixed r;
- int32_t t;
- asm(
- "smull %0, %1, %2, %2 \n"
- "smlal %0, %1, %3, %3 \n"
- "smlal %0, %1, %4, %4 \n"
- "movs %0, %0, lsr #16 \n"
- "adc %0, %0, %1, lsl #16 \n"
- : "=&r"(r), "=&r"(t)
- : "%r"(a), "r"(b), "r"(c)
- : "cc"
- );
- return r;
-
-#elif defined(__mips__) && !defined(__LP64__) && __mips_isa_rev < 6
-
- GLfixed res;
- int32_t t1,t2,t3;
- asm(
- "mult %[a], %[a] \r\n"
- "li %[res],0x8000 \r\n"
- "madd %[b],%[b] \r\n"
- "move %[t3],$zero \r\n"
- "madd %[c],%[c] \r\n"
- "mflo %[t1]\r\n"
- "mfhi %[t2]\r\n"
- "addu %[t1],%[res],%[t1]\r\n" /*add 0x8000*/
- "sltu %[t3],%[t1],%[res]\r\n"
- "addu %[t2],%[t2],%[t3]\r\n"
- "srl %[res],%[t1],16\r\n"
- "sll %[t2],%[t2],16\r\n"
- "or %[res],%[res],%[t2]\r\n"
- : [res]"=&r"(res),[t1]"=&r"(t1),[t2]"=&r"(t2),[t3]"=&r"(t3)
- : [a] "r" (a),[b] "r" (b),[c] "r" (c)
- : "%hi","%lo"
- );
- return res;
-
-#else
-
- return (( int64_t(a)*a +
- int64_t(b)*b +
- int64_t(c)*c + 0x8000)>>16);
-
-#endif
-}
-
-static inline GLfixed mla2a( GLfixed a0, GLfixed b0,
- GLfixed a1, GLfixed b1,
- GLfixed c)
-{
-#if defined(__arm__) && !defined(__thumb__)
-
- GLfixed r;
- int32_t t;
- asm(
- "smull %0, %1, %2, %3 \n"
- "smlal %0, %1, %4, %5 \n"
- "add %0, %6, %0, lsr #16 \n"
- "add %0, %0, %1, lsl #16 \n"
- : "=&r"(r), "=&r"(t)
- : "%r"(a0), "r"(b0),
- "%r"(a1), "r"(b1),
- "r"(c)
- :
- );
- return r;
-
-#else
-
- return (( int64_t(a0)*b0 +
- int64_t(a1)*b1)>>16) + c;
-
-#endif
-}
-
-static inline GLfixed mla3a( GLfixed a0, GLfixed b0,
- GLfixed a1, GLfixed b1,
- GLfixed a2, GLfixed b2,
- GLfixed c)
-{
-#if defined(__arm__) && !defined(__thumb__)
-
- GLfixed r;
- int32_t t;
- asm(
- "smull %0, %1, %2, %3 \n"
- "smlal %0, %1, %4, %5 \n"
- "smlal %0, %1, %6, %7 \n"
- "add %0, %8, %0, lsr #16 \n"
- "add %0, %0, %1, lsl #16 \n"
- : "=&r"(r), "=&r"(t)
- : "%r"(a0), "r"(b0),
- "%r"(a1), "r"(b1),
- "%r"(a2), "r"(b2),
- "r"(c)
- :
- );
- return r;
-
-#elif defined(__mips__) && !defined(__LP64__) && __mips_isa_rev < 6
-
- GLfixed res;
- int32_t t1,t2;
- asm(
- "mult %[a0],%[b0] \r\n"
- "madd %[a1],%[b1] \r\n"
- "madd %[a2],%[b2] \r\n"
- "mflo %[t2]\r\n"
- "mfhi %[t1]\r\n"
- "srl %[t2],%[t2],16\r\n"
- "sll %[t1],%[t1],16\r\n"
- "or %[t2],%[t2],%[t1]\r\n"
- "addu %[res],%[t2],%[c]"
- : [res]"=&r"(res),[t1]"=&r"(t1),[t2]"=&r"(t2)
- : [a0] "r" (a0),[b0] "r" (b0),[a1] "r" (a1),[b1] "r" (b1),[a2] "r" (a2),[b2] "r" (b2),[c] "r" (c)
- : "%hi","%lo"
- );
- return res;
-
-#else
-
- return (( int64_t(a0)*b0 +
- int64_t(a1)*b1 +
- int64_t(a2)*b2)>>16) + c;
-
-#endif
-}
-
-// b0, b1, b2 are signed 16-bit quanities
-// that have been shifted right by 'shift' bits relative to normal
-// S16.16 fixed point
-static inline GLfixed mla3a16( GLfixed a0, int32_t b1b0,
- GLfixed a1,
- GLfixed a2, int32_t b2,
- GLint shift,
- GLfixed c)
-{
-#if defined(__arm__) && !defined(__thumb__)
-
- GLfixed r;
- asm(
- "smulwb %0, %1, %2 \n"
- "smlawt %0, %3, %2, %0 \n"
- "smlawb %0, %4, %5, %0 \n"
- "add %0, %7, %0, lsl %6 \n"
- : "=&r"(r)
- : "r"(a0), "r"(b1b0),
- "r"(a1),
- "r"(a2), "r"(b2),
- "r"(shift),
- "r"(c)
- :
- );
- return r;
-
-#else
-
- int32_t accum;
- int16_t b0 = b1b0 & 0xffff;
- int16_t b1 = (b1b0 >> 16) & 0xffff;
- accum = int64_t(a0)*int16_t(b0) >> 16;
- accum += int64_t(a1)*int16_t(b1) >> 16;
- accum += int64_t(a2)*int16_t(b2) >> 16;
- accum = (accum << shift) + c;
- return accum;
-
-#endif
-}
-
-
-static inline GLfixed mla3a16_btb( GLfixed a0,
- GLfixed a1,
- GLfixed a2,
- int32_t b1b0, int32_t xxb2,
- GLint shift,
- GLfixed c)
-{
-#if defined(__arm__) && !defined(__thumb__)
-
- GLfixed r;
- asm(
- "smulwb %0, %1, %4 \n"
- "smlawt %0, %2, %4, %0 \n"
- "smlawb %0, %3, %5, %0 \n"
- "add %0, %7, %0, lsl %6 \n"
- : "=&r"(r)
- : "r"(a0),
- "r"(a1),
- "r"(a2),
- "r"(b1b0), "r"(xxb2),
- "r"(shift),
- "r"(c)
- :
- );
- return r;
-
-#else
-
- int32_t accum;
- int16_t b0 = b1b0 & 0xffff;
- int16_t b1 = (b1b0 >> 16) & 0xffff;
- int16_t b2 = xxb2 & 0xffff;
- accum = int64_t(a0)*int16_t(b0) >> 16;
- accum += int64_t(a1)*int16_t(b1) >> 16;
- accum += int64_t(a2)*int16_t(b2) >> 16;
- accum = (accum << shift) + c;
- return accum;
-
-#endif
-}
-
-static inline GLfixed mla3a16_btt( GLfixed a0,
- GLfixed a1,
- GLfixed a2,
- int32_t b1b0, int32_t b2xx,
- GLint shift,
- GLfixed c)
-{
-#if defined(__arm__) && !defined(__thumb__)
-
- GLfixed r;
- asm(
- "smulwb %0, %1, %4 \n"
- "smlawt %0, %2, %4, %0 \n"
- "smlawt %0, %3, %5, %0 \n"
- "add %0, %7, %0, lsl %6 \n"
- : "=&r"(r)
- : "r"(a0),
- "r"(a1),
- "r"(a2),
- "r"(b1b0), "r"(b2xx),
- "r"(shift),
- "r"(c)
- :
- );
- return r;
-
-#else
-
- int32_t accum;
- int16_t b0 = b1b0 & 0xffff;
- int16_t b1 = (b1b0 >> 16) & 0xffff;
- int16_t b2 = (b2xx >> 16) & 0xffff;
- accum = int64_t(a0)*int16_t(b0) >> 16;
- accum += int64_t(a1)*int16_t(b1) >> 16;
- accum += int64_t(a2)*int16_t(b2) >> 16;
- accum = (accum << shift) + c;
- return accum;
-
-#endif
-}
-
-static inline GLfixed mla3( GLfixed a0, GLfixed b0,
- GLfixed a1, GLfixed b1,
- GLfixed a2, GLfixed b2)
-{
-#if defined(__arm__) && !defined(__thumb__)
-
- GLfixed r;
- int32_t t;
- asm(
- "smull %0, %1, %2, %3 \n"
- "smlal %0, %1, %4, %5 \n"
- "smlal %0, %1, %6, %7 \n"
- "movs %0, %0, lsr #16 \n"
- "adc %0, %0, %1, lsl #16 \n"
- : "=&r"(r), "=&r"(t)
- : "%r"(a0), "r"(b0),
- "%r"(a1), "r"(b1),
- "%r"(a2), "r"(b2)
- : "cc"
- );
- return r;
-
-#else
-
- return (( int64_t(a0)*b0 +
- int64_t(a1)*b1 +
- int64_t(a2)*b2 + 0x8000)>>16);
-
-#endif
-}
-
-static inline GLfixed mla4( GLfixed a0, GLfixed b0,
- GLfixed a1, GLfixed b1,
- GLfixed a2, GLfixed b2,
- GLfixed a3, GLfixed b3)
-{
-#if defined(__arm__) && !defined(__thumb__)
-
- GLfixed r;
- int32_t t;
- asm(
- "smull %0, %1, %2, %3 \n"
- "smlal %0, %1, %4, %5 \n"
- "smlal %0, %1, %6, %7 \n"
- "smlal %0, %1, %8, %9 \n"
- "movs %0, %0, lsr #16 \n"
- "adc %0, %0, %1, lsl #16 \n"
- : "=&r"(r), "=&r"(t)
- : "%r"(a0), "r"(b0),
- "%r"(a1), "r"(b1),
- "%r"(a2), "r"(b2),
- "%r"(a3), "r"(b3)
- : "cc"
- );
- return r;
-
-#else
-
- return (( int64_t(a0)*b0 +
- int64_t(a1)*b1 +
- int64_t(a2)*b2 +
- int64_t(a3)*b3 + 0x8000)>>16);
-
-#endif
-}
-
-inline
-GLfixed dot4(const GLfixed* a, const GLfixed* b)
-{
- return mla4(a[0], b[0], a[1], b[1], a[2], b[2], a[3], b[3]);
-}
-
-
-inline
-GLfixed dot3(const GLfixed* a, const GLfixed* b)
-{
- return mla3(a[0], b[0], a[1], b[1], a[2], b[2]);
-}
-
-
-}; // namespace android
-
-#endif // ANDROID_OPENGLES_MATRIX_H
-
diff --git a/opengl/libagl/mipmap.cpp b/opengl/libagl/mipmap.cpp
deleted file mode 100644
index e142a58..0000000
--- a/opengl/libagl/mipmap.cpp
+++ /dev/null
@@ -1,192 +0,0 @@
-/* libs/opengles/mipmap.cpp
-**
-** Copyright 2006, 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 <stdio.h>
-#include <stdlib.h>
-
-#include "context.h"
-#include "state.h"
-#include "texture.h"
-#include "TextureObjectManager.h"
-
-namespace android {
-
-// ----------------------------------------------------------------------------
-
-status_t buildAPyramid(ogles_context_t* c, EGLTextureObject* tex)
-{
- int level = 0;
- const GGLSurface* base = &tex->surface;
- const GGLFormat& pixelFormat(c->rasterizer.formats[base->format]);
-
- int w = base->width;
- int h = base->height;
- if ((w&h) == 1)
- return NO_ERROR;
-
- w = (w>>1) ? : 1;
- h = (h>>1) ? : 1;
-
- while(true) {
- ++level;
- const int bpr = w * pixelFormat.size;
- if (tex->reallocate(level, w, h, w,
- base->format, base->compressedFormat, bpr) != NO_ERROR) {
- return NO_MEMORY;
- }
-
- int stride = w;
- int bs = base->stride;
- GGLSurface& cur = tex->editMip(level);
-
- if (base->format == GGL_PIXEL_FORMAT_RGB_565)
- {
- uint16_t const * src = (uint16_t const *)base->data;
- uint16_t* dst = (uint16_t*)cur.data;
- const uint32_t mask = 0x07E0F81F;
- for (int y=0 ; y<h ; y++) {
- size_t offset = (y*2) * bs;
- for (int x=0 ; x<w ; x++) {
- uint32_t p00 = src[offset];
- uint32_t p10 = src[offset+1];
- uint32_t p01 = src[offset+bs];
- uint32_t p11 = src[offset+bs+1];
- p00 = (p00 | (p00 << 16)) & mask;
- p01 = (p01 | (p01 << 16)) & mask;
- p10 = (p10 | (p10 << 16)) & mask;
- p11 = (p11 | (p11 << 16)) & mask;
- uint32_t grb = ((p00 + p10 + p01 + p11) >> 2) & mask;
- uint32_t rgb = (grb & 0xFFFF) | (grb >> 16);
- dst[x + y*stride] = rgb;
- offset += 2;
- }
- }
- }
- else if (base->format == GGL_PIXEL_FORMAT_RGBA_5551)
- {
- uint16_t const * src = (uint16_t const *)base->data;
- uint16_t* dst = (uint16_t*)cur.data;
- for (int y=0 ; y<h ; y++) {
- size_t offset = (y*2) * bs;
- for (int x=0 ; x<w ; x++) {
- uint32_t p00 = src[offset];
- uint32_t p10 = src[offset+1];
- uint32_t p01 = src[offset+bs];
- uint32_t p11 = src[offset+bs+1];
- uint32_t r = ((p00>>11)+(p10>>11)+(p01>>11)+(p11>>11)+2)>>2;
- uint32_t g = (((p00>>6)+(p10>>6)+(p01>>6)+(p11>>6)+2)>>2)&0x3F;
- uint32_t b = ((p00&0x3E)+(p10&0x3E)+(p01&0x3E)+(p11&0x3E)+4)>>3;
- uint32_t a = ((p00&1)+(p10&1)+(p01&1)+(p11&1)+2)>>2;
- dst[x + y*stride] = (r<<11)|(g<<6)|(b<<1)|a;
- offset += 2;
- }
- }
- }
- else if (base->format == GGL_PIXEL_FORMAT_RGBA_8888)
- {
- uint32_t const * src = (uint32_t const *)base->data;
- uint32_t* dst = (uint32_t*)cur.data;
- for (int y=0 ; y<h ; y++) {
- size_t offset = (y*2) * bs;
- for (int x=0 ; x<w ; x++) {
- uint32_t p00 = src[offset];
- uint32_t p10 = src[offset+1];
- uint32_t p01 = src[offset+bs];
- uint32_t p11 = src[offset+bs+1];
- uint32_t rb00 = p00 & 0x00FF00FF;
- uint32_t rb01 = p01 & 0x00FF00FF;
- uint32_t rb10 = p10 & 0x00FF00FF;
- uint32_t rb11 = p11 & 0x00FF00FF;
- uint32_t ga00 = (p00 >> 8) & 0x00FF00FF;
- uint32_t ga01 = (p01 >> 8) & 0x00FF00FF;
- uint32_t ga10 = (p10 >> 8) & 0x00FF00FF;
- uint32_t ga11 = (p11 >> 8) & 0x00FF00FF;
- uint32_t rb = (rb00 + rb01 + rb10 + rb11)>>2;
- uint32_t ga = (ga00 + ga01 + ga10 + ga11)>>2;
- uint32_t rgba = (rb & 0x00FF00FF) | ((ga & 0x00FF00FF)<<8);
- dst[x + y*stride] = rgba;
- offset += 2;
- }
- }
- }
- else if ((base->format == GGL_PIXEL_FORMAT_RGB_888) ||
- (base->format == GGL_PIXEL_FORMAT_LA_88) ||
- (base->format == GGL_PIXEL_FORMAT_A_8) ||
- (base->format == GGL_PIXEL_FORMAT_L_8))
- {
- int skip;
- switch (base->format) {
- case GGL_PIXEL_FORMAT_RGB_888: skip = 3; break;
- case GGL_PIXEL_FORMAT_LA_88: skip = 2; break;
- default: skip = 1; break;
- }
- uint8_t const * src = (uint8_t const *)base->data;
- uint8_t* dst = (uint8_t*)cur.data;
- bs *= skip;
- stride *= skip;
- for (int y=0 ; y<h ; y++) {
- size_t offset = (y*2) * bs;
- for (int x=0 ; x<w ; x++) {
- for (int c=0 ; c<skip ; c++) {
- uint32_t p00 = src[c+offset];
- uint32_t p10 = src[c+offset+skip];
- uint32_t p01 = src[c+offset+bs];
- uint32_t p11 = src[c+offset+bs+skip];
- dst[x + y*stride + c] = (p00 + p10 + p01 + p11) >> 2;
- }
- offset += 2*skip;
- }
- }
- }
- else if (base->format == GGL_PIXEL_FORMAT_RGBA_4444)
- {
- uint16_t const * src = (uint16_t const *)base->data;
- uint16_t* dst = (uint16_t*)cur.data;
- for (int y=0 ; y<h ; y++) {
- size_t offset = (y*2) * bs;
- for (int x=0 ; x<w ; x++) {
- uint32_t p00 = src[offset];
- uint32_t p10 = src[offset+1];
- uint32_t p01 = src[offset+bs];
- uint32_t p11 = src[offset+bs+1];
- p00 = ((p00 << 12) & 0x0F0F0000) | (p00 & 0x0F0F);
- p10 = ((p10 << 12) & 0x0F0F0000) | (p10 & 0x0F0F);
- p01 = ((p01 << 12) & 0x0F0F0000) | (p01 & 0x0F0F);
- p11 = ((p11 << 12) & 0x0F0F0000) | (p11 & 0x0F0F);
- uint32_t rbga = (p00 + p10 + p01 + p11) >> 2;
- uint32_t rgba = (rbga & 0x0F0F) | ((rbga>>12) & 0xF0F0);
- dst[x + y*stride] = rgba;
- offset += 2;
- }
- }
- } else {
- ALOGE("Unsupported format (%d)", base->format);
- return BAD_TYPE;
- }
-
- // exit condition: we just processed the 1x1 LODs
- if ((w&h) == 1)
- break;
-
- base = &cur;
- w = (w>>1) ? : 1;
- h = (h>>1) ? : 1;
- }
- return NO_ERROR;
-}
-
-}; // namespace android
diff --git a/opengl/libagl/primitives.cpp b/opengl/libagl/primitives.cpp
deleted file mode 100644
index d3b19e8..0000000
--- a/opengl/libagl/primitives.cpp
+++ /dev/null
@@ -1,1112 +0,0 @@
-/* libs/opengles/primitives.cpp
-**
-** Copyright 2006, 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 <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-
-#include "context.h"
-#include "primitives.h"
-#include "light.h"
-#include "matrix.h"
-#include "vertex.h"
-#include "fp.h"
-#include "TextureObjectManager.h"
-
-extern "C" void iterators0032(const void* that,
- int32_t* it, int32_t c0, int32_t c1, int32_t c2);
-
-namespace android {
-
-// ----------------------------------------------------------------------------
-
-static void primitive_point(ogles_context_t* c, vertex_t* v);
-static void primitive_line(ogles_context_t* c, vertex_t* v0, vertex_t* v1);
-static void primitive_clip_triangle(ogles_context_t* c,
- vertex_t* v0, vertex_t* v1, vertex_t* v2);
-
-static void primitive_nop_point(ogles_context_t* c, vertex_t* v);
-static void primitive_nop_line(ogles_context_t* c, vertex_t* v0, vertex_t* v1);
-static void primitive_nop_triangle(ogles_context_t* c,
- vertex_t* v0, vertex_t* v1, vertex_t* v2);
-
-static inline bool cull_triangle(ogles_context_t* c,
- vertex_t* v0, vertex_t* v1, vertex_t* v2);
-
-static void lerp_triangle(ogles_context_t* c,
- vertex_t* v0, vertex_t* v1, vertex_t* v2);
-
-static void lerp_texcoords(ogles_context_t* c,
- vertex_t* v0, vertex_t* v1, vertex_t* v2);
-
-static void lerp_texcoords_w(ogles_context_t* c,
- vertex_t* v0, vertex_t* v1, vertex_t* v2);
-
-static void triangle(ogles_context_t* c,
- vertex_t* v0, vertex_t* v1, vertex_t* v2);
-
-static void clip_triangle(ogles_context_t* c,
- vertex_t* v0, vertex_t* v1, vertex_t* v2);
-
-static unsigned int clip_line(ogles_context_t* c,
- vertex_t* s, vertex_t* p);
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#endif
-
-static void lightTriangleDarkSmooth(ogles_context_t* c,
- vertex_t* v0, vertex_t* v1, vertex_t* v2)
-{
- if (!(v0->flags & vertex_t::LIT)) {
- v0->flags |= vertex_t::LIT;
- const GLvoid* cp = c->arrays.color.element(
- v0->index & vertex_cache_t::INDEX_MASK);
- c->arrays.color.fetch(c, v0->color.v, cp);
- }
- if (!(v1->flags & vertex_t::LIT)) {
- v1->flags |= vertex_t::LIT;
- const GLvoid* cp = c->arrays.color.element(
- v1->index & vertex_cache_t::INDEX_MASK);
- c->arrays.color.fetch(c, v1->color.v, cp);
- }
- if(!(v2->flags & vertex_t::LIT)) {
- v2->flags |= vertex_t::LIT;
- const GLvoid* cp = c->arrays.color.element(
- v2->index & vertex_cache_t::INDEX_MASK);
- c->arrays.color.fetch(c, v2->color.v, cp);
- }
-}
-
-static void lightTriangleDarkFlat(ogles_context_t* c,
- vertex_t* /*v0*/, vertex_t* /*v1*/, vertex_t* v2)
-{
- if (!(v2->flags & vertex_t::LIT)) {
- v2->flags |= vertex_t::LIT;
- const GLvoid* cp = c->arrays.color.element(
- v2->index & vertex_cache_t::INDEX_MASK);
- c->arrays.color.fetch(c, v2->color.v, cp);
- }
- // configure the rasterizer here, before we clip
- c->rasterizer.procs.color4xv(c, v2->color.v);
-}
-
-static void lightTriangleSmooth(ogles_context_t* c,
- vertex_t* v0, vertex_t* v1, vertex_t* v2)
-{
- if (!(v0->flags & vertex_t::LIT))
- c->lighting.lightVertex(c, v0);
- if (!(v1->flags & vertex_t::LIT))
- c->lighting.lightVertex(c, v1);
- if(!(v2->flags & vertex_t::LIT))
- c->lighting.lightVertex(c, v2);
-}
-
-static void lightTriangleFlat(ogles_context_t* c,
- vertex_t* /*v0*/, vertex_t* /*v1*/, vertex_t* v2)
-{
- if (!(v2->flags & vertex_t::LIT))
- c->lighting.lightVertex(c, v2);
- // configure the rasterizer here, before we clip
- c->rasterizer.procs.color4xv(c, v2->color.v);
-}
-
-// The fog versions...
-
-static inline
-void lightVertexDarkSmoothFog(ogles_context_t* c, vertex_t* v)
-{
- if (!(v->flags & vertex_t::LIT)) {
- v->flags |= vertex_t::LIT;
- v->fog = c->fog.fog(c, v->eye.z);
- const GLvoid* cp = c->arrays.color.element(
- v->index & vertex_cache_t::INDEX_MASK);
- c->arrays.color.fetch(c, v->color.v, cp);
- }
-}
-static inline
-void lightVertexDarkFlatFog(ogles_context_t* c, vertex_t* v)
-{
- if (!(v->flags & vertex_t::LIT)) {
- v->flags |= vertex_t::LIT;
- v->fog = c->fog.fog(c, v->eye.z);
- }
-}
-static inline
-void lightVertexSmoothFog(ogles_context_t* c, vertex_t* v)
-{
- if (!(v->flags & vertex_t::LIT)) {
- v->fog = c->fog.fog(c, v->eye.z);
- c->lighting.lightVertex(c, v);
- }
-}
-
-static void lightTriangleDarkSmoothFog(ogles_context_t* c,
- vertex_t* v0, vertex_t* v1, vertex_t* v2)
-{
- lightVertexDarkSmoothFog(c, v0);
- lightVertexDarkSmoothFog(c, v1);
- lightVertexDarkSmoothFog(c, v2);
-}
-
-static void lightTriangleDarkFlatFog(ogles_context_t* c,
- vertex_t* v0, vertex_t* v1, vertex_t* v2)
-{
- lightVertexDarkFlatFog(c, v0);
- lightVertexDarkFlatFog(c, v1);
- lightVertexDarkSmoothFog(c, v2);
- // configure the rasterizer here, before we clip
- c->rasterizer.procs.color4xv(c, v2->color.v);
-}
-
-static void lightTriangleSmoothFog(ogles_context_t* c,
- vertex_t* v0, vertex_t* v1, vertex_t* v2)
-{
- lightVertexSmoothFog(c, v0);
- lightVertexSmoothFog(c, v1);
- lightVertexSmoothFog(c, v2);
-}
-
-static void lightTriangleFlatFog(ogles_context_t* c,
- vertex_t* v0, vertex_t* v1, vertex_t* v2)
-{
- lightVertexDarkFlatFog(c, v0);
- lightVertexDarkFlatFog(c, v1);
- lightVertexSmoothFog(c, v2);
- // configure the rasterizer here, before we clip
- c->rasterizer.procs.color4xv(c, v2->color.v);
-}
-
-
-
-typedef void (*light_primitive_t)(ogles_context_t*,
- vertex_t*, vertex_t*, vertex_t*);
-
-// fog 0x4, light 0x2, smooth 0x1
-static const light_primitive_t lightPrimitive[8] = {
- lightTriangleDarkFlat, // no fog | dark | flat
- lightTriangleDarkSmooth, // no fog | dark | smooth
- lightTriangleFlat, // no fog | light | flat
- lightTriangleSmooth, // no fog | light | smooth
- lightTriangleDarkFlatFog, // fog | dark | flat
- lightTriangleDarkSmoothFog, // fog | dark | smooth
- lightTriangleFlatFog, // fog | light | flat
- lightTriangleSmoothFog // fog | light | smooth
-};
-
-void ogles_validate_primitives(ogles_context_t* c)
-{
- const uint32_t enables = c->rasterizer.state.enables;
-
- // set up the lighting/shading/smoothing/fogging function
- int index = enables & GGL_ENABLE_SMOOTH ? 0x1 : 0;
- index |= c->lighting.enable ? 0x2 : 0;
- index |= enables & GGL_ENABLE_FOG ? 0x4 : 0;
- c->lighting.lightTriangle = lightPrimitive[index];
-
- // set up the primitive renderers
- if (ggl_likely(c->arrays.vertex.enable)) {
- c->prims.renderPoint = primitive_point;
- c->prims.renderLine = primitive_line;
- c->prims.renderTriangle = primitive_clip_triangle;
- } else {
- c->prims.renderPoint = primitive_nop_point;
- c->prims.renderLine = primitive_nop_line;
- c->prims.renderTriangle = primitive_nop_triangle;
- }
-}
-
-// ----------------------------------------------------------------------------
-
-void compute_iterators_t::initTriangle(
- vertex_t const* v0, vertex_t const* v1, vertex_t const* v2)
-{
- m_dx01 = v1->window.x - v0->window.x;
- m_dy10 = v0->window.y - v1->window.y;
- m_dx20 = v0->window.x - v2->window.x;
- m_dy02 = v2->window.y - v0->window.y;
- m_area = m_dx01*m_dy02 + (-m_dy10)*m_dx20;
- (void)m_reserved; // suppress unused warning
-}
-
-void compute_iterators_t::initLine(
- vertex_t const* v0, vertex_t const* v1)
-{
- m_dx01 = m_dy02 = v1->window.x - v0->window.x;
- m_dy10 = m_dx20 = v0->window.y - v1->window.y;
- m_area = m_dx01*m_dy02 + (-m_dy10)*m_dx20;
-}
-
-void compute_iterators_t::initLerp(vertex_t const* v0, uint32_t enables)
-{
- m_x0 = v0->window.x;
- m_y0 = v0->window.y;
- const GGLcoord area = (m_area + TRI_HALF) >> TRI_FRACTION_BITS;
- const GGLcoord minArea = 2; // cannot be inverted
- // triangles with an area smaller than 1.0 are not smooth-shaded
-
- int q=0, s=0, d=0;
- if (abs(area) >= minArea) {
- // Here we do some voodoo magic, to compute a suitable scale
- // factor for deltas/area:
-
- // First compute the 1/area with full 32-bits precision,
- // gglRecipQNormalized returns a number [-0.5, 0.5[ and an exponent.
- d = gglRecipQNormalized(area, &q);
-
- // Then compute the minimum left-shift to not overflow the muls
- // below.
- s = 32 - gglClz(abs(m_dy02)|abs(m_dy10)|abs(m_dx01)|abs(m_dx20));
-
- // We'll keep 16-bits of precision for deltas/area. So we need
- // to shift everything left an extra 15 bits.
- s += 15;
-
- // make sure all final shifts are not > 32, because gglMulx
- // can't handle it.
- if (s < q) s = q;
- if (s > 32) {
- d >>= 32-s;
- s = 32;
- }
- }
-
- m_dx01 = gglMulx(m_dx01, d, s);
- m_dy10 = gglMulx(m_dy10, d, s);
- m_dx20 = gglMulx(m_dx20, d, s);
- m_dy02 = gglMulx(m_dy02, d, s);
- m_area_scale = 32 + q - s;
- m_scale = 0;
-
- if (enables & GGL_ENABLE_TMUS) {
- const int A = gglClz(abs(m_dy02)|abs(m_dy10)|abs(m_dx01)|abs(m_dx20));
- const int B = gglClz(abs(m_x0)|abs(m_y0));
- m_scale = max(0, 32 - (A + 16)) +
- max(0, 32 - (B + TRI_FRACTION_BITS)) + 1;
- }
-}
-
-int compute_iterators_t::iteratorsScale(GGLfixed* it,
- int32_t c0, int32_t c1, int32_t c2) const
-{
- int32_t dc01 = c1 - c0;
- int32_t dc02 = c2 - c0;
- const int A = gglClz(abs(c0));
- const int B = gglClz(abs(dc01)|abs(dc02));
- const int scale = min(A, B - m_scale) - 2;
- if (scale >= 0) {
- c0 <<= scale;
- dc01 <<= scale;
- dc02 <<= scale;
- } else {
- c0 >>= -scale;
- dc01 >>= -scale;
- dc02 >>= -scale;
- }
- const int s = m_area_scale;
- int32_t dcdx = gglMulAddx(dc01, m_dy02, gglMulx(dc02, m_dy10, s), s);
- int32_t dcdy = gglMulAddx(dc02, m_dx01, gglMulx(dc01, m_dx20, s), s);
- int32_t c = c0 - (gglMulAddx(dcdx, m_x0,
- gglMulx(dcdy, m_y0, TRI_FRACTION_BITS), TRI_FRACTION_BITS));
- it[0] = c;
- it[1] = dcdx;
- it[2] = dcdy;
- return scale;
-}
-
-void compute_iterators_t::iterators1616(GGLfixed* it,
- GGLfixed c0, GGLfixed c1, GGLfixed c2) const
-{
- const GGLfixed dc01 = c1 - c0;
- const GGLfixed dc02 = c2 - c0;
- // 16.16 x 16.16 == 32.32 --> 16.16
- const int s = m_area_scale;
- int32_t dcdx = gglMulAddx(dc01, m_dy02, gglMulx(dc02, m_dy10, s), s);
- int32_t dcdy = gglMulAddx(dc02, m_dx01, gglMulx(dc01, m_dx20, s), s);
- int32_t c = c0 - (gglMulAddx(dcdx, m_x0,
- gglMulx(dcdy, m_y0, TRI_FRACTION_BITS), TRI_FRACTION_BITS));
- it[0] = c;
- it[1] = dcdx;
- it[2] = dcdy;
-}
-
-void compute_iterators_t::iterators0032(int64_t* it,
- int32_t c0, int32_t c1, int32_t c2) const
-{
- const int s = m_area_scale - 16;
- int32_t dc01 = (c1 - c0)>>s;
- int32_t dc02 = (c2 - c0)>>s;
- // 16.16 x 16.16 == 32.32
- int64_t dcdx = gglMulii(dc01, m_dy02) + gglMulii(dc02, m_dy10);
- int64_t dcdy = gglMulii(dc02, m_dx01) + gglMulii(dc01, m_dx20);
- it[ 0] = (c0<<16) - ((dcdx*m_x0 + dcdy*m_y0)>>4);
- it[ 1] = dcdx;
- it[ 2] = dcdy;
-}
-
-#if defined(__arm__) && !defined(__thumb__)
-inline void compute_iterators_t::iterators0032(int32_t* it,
- int32_t c0, int32_t c1, int32_t c2) const
-{
- ::iterators0032(this, it, c0, c1, c2);
-}
-#else
-void compute_iterators_t::iterators0032(int32_t* it,
- int32_t c0, int32_t c1, int32_t c2) const
-{
- int64_t it64[3];
- iterators0032(it64, c0, c1, c2);
- it[0] = it64[0];
- it[1] = it64[1];
- it[2] = it64[2];
-}
-#endif
-
-// ----------------------------------------------------------------------------
-
-static inline int32_t clampZ(GLfixed z) CONST;
-int32_t clampZ(GLfixed z) {
- z = (z & ~(z>>31));
- if (z >= 0x10000)
- z = 0xFFFF;
- return z;
-}
-
-static __attribute__((noinline))
-void fetch_texcoord_impl(ogles_context_t* c,
- vertex_t* v0, vertex_t* v1, vertex_t* v2)
-{
- vertex_t* const vtx[3] = { v0, v1, v2 };
- array_t const * const texcoordArray = c->arrays.texture;
-
- for (int i=0 ; i<GGL_TEXTURE_UNIT_COUNT ; i++) {
- if (!(c->rasterizer.state.texture[i].enable))
- continue;
-
- for (int j=0 ; j<3 ; j++) {
- vertex_t* const v = vtx[j];
- if (v->flags & vertex_t::TT)
- continue;
-
- // NOTE: here we could compute automatic texgen
- // such as sphere/cube maps, instead of fetching them
- // from the textcoord array.
-
- vec4_t& coords = v->texture[i];
- const GLubyte* tp = texcoordArray[i].element(
- v->index & vertex_cache_t::INDEX_MASK);
- texcoordArray[i].fetch(c, coords.v, tp);
-
- // transform texture coordinates...
- coords.Q = 0x10000;
- const transform_t& tr = c->transforms.texture[i].transform;
- if (ggl_unlikely(tr.ops)) {
- c->arrays.tex_transform[i](&tr, &coords, &coords);
- }
-
- // divide by Q
- const GGLfixed q = coords.Q;
- if (ggl_unlikely(q != 0x10000)) {
- const int32_t qinv = gglRecip28(q);
- coords.S = gglMulx(coords.S, qinv, 28);
- coords.T = gglMulx(coords.T, qinv, 28);
- }
- }
- }
- v0->flags |= vertex_t::TT;
- v1->flags |= vertex_t::TT;
- v2->flags |= vertex_t::TT;
-}
-
-inline void fetch_texcoord(ogles_context_t* c,
- vertex_t* v0, vertex_t* v1, vertex_t* v2)
-{
- const uint32_t enables = c->rasterizer.state.enables;
- if (!(enables & GGL_ENABLE_TMUS))
- return;
-
- // Fetch & transform texture coordinates...
- if (ggl_likely(v0->flags & v1->flags & v2->flags & vertex_t::TT)) {
- // already done for all three vertices, bail...
- return;
- }
- fetch_texcoord_impl(c, v0, v1, v2);
-}
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#pragma mark Point
-#endif
-
-void primitive_nop_point(ogles_context_t*, vertex_t*) {
-}
-
-void primitive_point(ogles_context_t* c, vertex_t* v)
-{
- // lighting & clamping...
- const uint32_t enables = c->rasterizer.state.enables;
-
- if (ggl_unlikely(!(v->flags & vertex_t::LIT))) {
- if (c->lighting.enable) {
- c->lighting.lightVertex(c, v);
- } else {
- v->flags |= vertex_t::LIT;
- const GLvoid* cp = c->arrays.color.element(
- v->index & vertex_cache_t::INDEX_MASK);
- c->arrays.color.fetch(c, v->color.v, cp);
- }
- if (enables & GGL_ENABLE_FOG) {
- v->fog = c->fog.fog(c, v->eye.z);
- }
- }
-
- // XXX: we don't need to do that each-time
- // if color array and lighting not enabled
- c->rasterizer.procs.color4xv(c, v->color.v);
-
- // XXX: look into ES point-sprite extension
- if (enables & GGL_ENABLE_TMUS) {
- fetch_texcoord(c, v,v,v);
- for (int i=0 ; i<GGL_TEXTURE_UNIT_COUNT ; i++) {
- if (!c->rasterizer.state.texture[i].enable)
- continue;
- int32_t itt[8];
- itt[1] = itt[2] = itt[4] = itt[5] = 0;
- itt[6] = itt[7] = 16; // XXX: check that
- if (c->rasterizer.state.texture[i].s_wrap == GGL_CLAMP) {
- int width = c->textures.tmu[i].texture->surface.width;
- itt[0] = v->texture[i].S * width;
- itt[6] = 0;
- }
- if (c->rasterizer.state.texture[i].t_wrap == GGL_CLAMP) {
- int height = c->textures.tmu[i].texture->surface.height;
- itt[3] = v->texture[i].T * height;
- itt[7] = 0;
- }
- c->rasterizer.procs.texCoordGradScale8xv(c, i, itt);
- }
- }
-
- if (enables & GGL_ENABLE_DEPTH_TEST) {
- int32_t itz[3];
- itz[0] = clampZ(v->window.z) * 0x00010001;
- itz[1] = itz[2] = 0;
- c->rasterizer.procs.zGrad3xv(c, itz);
- }
-
- if (enables & GGL_ENABLE_FOG) {
- GLfixed itf[3];
- itf[0] = v->fog;
- itf[1] = itf[2] = 0;
- c->rasterizer.procs.fogGrad3xv(c, itf);
- }
-
- // Render our point...
- c->rasterizer.procs.pointx(c, v->window.v, c->point.size);
-}
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#pragma mark Line
-#endif
-
-void primitive_nop_line(ogles_context_t*, vertex_t*, vertex_t*) {
-}
-
-void primitive_line(ogles_context_t* c, vertex_t* v0, vertex_t* v1)
-{
- // get texture coordinates
- fetch_texcoord(c, v0, v1, v1);
-
- // light/shade the vertices first (they're copied below)
- c->lighting.lightTriangle(c, v0, v1, v1);
-
- // clip the line if needed
- if (ggl_unlikely((v0->flags | v1->flags) & vertex_t::CLIP_ALL)) {
- unsigned int count = clip_line(c, v0, v1);
- if (ggl_unlikely(count == 0))
- return;
- }
-
- // compute iterators...
- const uint32_t enables = c->rasterizer.state.enables;
- const uint32_t mask = GGL_ENABLE_TMUS |
- GGL_ENABLE_SMOOTH |
- GGL_ENABLE_W |
- GGL_ENABLE_FOG |
- GGL_ENABLE_DEPTH_TEST;
-
- if (ggl_unlikely(enables & mask)) {
- c->lerp.initLine(v0, v1);
- lerp_triangle(c, v0, v1, v0);
- }
-
- // render our line
- c->rasterizer.procs.linex(c, v0->window.v, v1->window.v, c->line.width);
-}
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#pragma mark Triangle
-#endif
-
-void primitive_nop_triangle(ogles_context_t* /*c*/,
- vertex_t* /*v0*/, vertex_t* /*v1*/, vertex_t* /*v2*/) {
-}
-
-void primitive_clip_triangle(ogles_context_t* c,
- vertex_t* v0, vertex_t* v1, vertex_t* v2)
-{
- uint32_t cc = (v0->flags | v1->flags | v2->flags) & vertex_t::CLIP_ALL;
- if (ggl_likely(!cc)) {
- // code below must be as optimized as possible, this is the
- // common code path.
-
- // This triangle is not clipped, test if it's culled
- // unclipped triangle...
- c->lerp.initTriangle(v0, v1, v2);
- if (cull_triangle(c, v0, v1, v2))
- return; // culled!
-
- // Fetch all texture coordinates if needed
- fetch_texcoord(c, v0, v1, v2);
-
- // light (or shade) our triangle!
- c->lighting.lightTriangle(c, v0, v1, v2);
-
- triangle(c, v0, v1, v2);
- return;
- }
-
- // The assumption here is that we're not going to clip very often,
- // and even more rarely will we clip a triangle that ends up
- // being culled out. So it's okay to light the vertices here, even though
- // in a few cases we won't render the triangle (if culled).
-
- // Fetch texture coordinates...
- fetch_texcoord(c, v0, v1, v2);
-
- // light (or shade) our triangle!
- c->lighting.lightTriangle(c, v0, v1, v2);
-
- clip_triangle(c, v0, v1, v2);
-}
-
-// -----------------------------------------------------------------------
-
-void triangle(ogles_context_t* c,
- vertex_t* v0, vertex_t* v1, vertex_t* v2)
-{
- // compute iterators...
- const uint32_t enables = c->rasterizer.state.enables;
- const uint32_t mask = GGL_ENABLE_TMUS |
- GGL_ENABLE_SMOOTH |
- GGL_ENABLE_W |
- GGL_ENABLE_FOG |
- GGL_ENABLE_DEPTH_TEST;
-
- if (ggl_likely(enables & mask))
- lerp_triangle(c, v0, v1, v2);
-
- c->rasterizer.procs.trianglex(c, v0->window.v, v1->window.v, v2->window.v);
-}
-
-void lerp_triangle(ogles_context_t* c,
- vertex_t* v0, vertex_t* v1, vertex_t* v2)
-{
- const uint32_t enables = c->rasterizer.state.enables;
- c->lerp.initLerp(v0, enables);
-
- // set up texture iterators
- if (enables & GGL_ENABLE_TMUS) {
- if (enables & GGL_ENABLE_W) {
- lerp_texcoords_w(c, v0, v1, v2);
- } else {
- lerp_texcoords(c, v0, v1, v2);
- }
- }
-
- // set up the color iterators
- const compute_iterators_t& lerp = c->lerp;
- if (enables & GGL_ENABLE_SMOOTH) {
- GLfixed itc[12];
- for (int i=0 ; i<4 ; i++) {
- const GGLcolor c0 = v0->color.v[i] * 255;
- const GGLcolor c1 = v1->color.v[i] * 255;
- const GGLcolor c2 = v2->color.v[i] * 255;
- lerp.iterators1616(&itc[i*3], c0, c1, c2);
- }
- c->rasterizer.procs.colorGrad12xv(c, itc);
- }
-
- if (enables & GGL_ENABLE_DEPTH_TEST) {
- int32_t itz[3];
- const int32_t v0z = clampZ(v0->window.z);
- const int32_t v1z = clampZ(v1->window.z);
- const int32_t v2z = clampZ(v2->window.z);
- if (ggl_unlikely(c->polygonOffset.enable)) {
- const int32_t units = (c->polygonOffset.units << 16);
- const GLfixed factor = c->polygonOffset.factor;
- if (factor) {
- int64_t itz64[3];
- lerp.iterators0032(itz64, v0z, v1z, v2z);
- int64_t maxDepthSlope = max(itz64[1], itz64[2]);
- itz[0] = uint32_t(itz64[0])
- + uint32_t((maxDepthSlope*factor)>>16) + units;
- itz[1] = uint32_t(itz64[1]);
- itz[2] = uint32_t(itz64[2]);
- } else {
- lerp.iterators0032(itz, v0z, v1z, v2z);
- itz[0] += units;
- }
- } else {
- lerp.iterators0032(itz, v0z, v1z, v2z);
- }
- c->rasterizer.procs.zGrad3xv(c, itz);
- }
-
- if (ggl_unlikely(enables & GGL_ENABLE_FOG)) {
- GLfixed itf[3];
- lerp.iterators1616(itf, v0->fog, v1->fog, v2->fog);
- c->rasterizer.procs.fogGrad3xv(c, itf);
- }
-}
-
-
-static inline
-int compute_lod(ogles_context_t* c, int i,
- int32_t s0, int32_t t0, int32_t s1, int32_t t1, int32_t s2, int32_t t2)
-{
- // Compute mipmap level / primitive
- // rho = sqrt( texelArea / area )
- // lod = log2( rho )
- // lod = log2( texelArea / area ) / 2
- // lod = (log2( texelArea ) - log2( area )) / 2
- const compute_iterators_t& lerp = c->lerp;
- const GGLcoord area = abs(lerp.area());
- const int w = c->textures.tmu[i].texture->surface.width;
- const int h = c->textures.tmu[i].texture->surface.height;
- const int shift = 16 + (16 - TRI_FRACTION_BITS);
- int32_t texelArea = abs( gglMulx(s1-s0, t2-t0, shift) -
- gglMulx(s2-s0, t1-t0, shift) )*w*h;
- int log2TArea = (32-TRI_FRACTION_BITS -1) - gglClz(texelArea);
- int log2Area = (32-TRI_FRACTION_BITS*2-1) - gglClz(area);
- int lod = (log2TArea - log2Area + 1) >> 1;
- return lod;
-}
-
-void lerp_texcoords(ogles_context_t* c,
- vertex_t* v0, vertex_t* v1, vertex_t* v2)
-{
- const compute_iterators_t& lerp = c->lerp;
- int32_t itt[8] __attribute__((aligned(16)));
- for (int i=0 ; i<GGL_TEXTURE_UNIT_COUNT ; i++) {
- const texture_t& tmu = c->rasterizer.state.texture[i];
- if (!tmu.enable)
- continue;
-
- // compute the jacobians using block floating-point
- int32_t s0 = v0->texture[i].S;
- int32_t t0 = v0->texture[i].T;
- int32_t s1 = v1->texture[i].S;
- int32_t t1 = v1->texture[i].T;
- int32_t s2 = v2->texture[i].S;
- int32_t t2 = v2->texture[i].T;
-
- const GLenum min_filter = c->textures.tmu[i].texture->min_filter;
- if (ggl_unlikely(min_filter >= GL_NEAREST_MIPMAP_NEAREST)) {
- int lod = compute_lod(c, i, s0, t0, s1, t1, s2, t2);
- c->rasterizer.procs.bindTextureLod(c, i,
- &c->textures.tmu[i].texture->mip(lod));
- }
-
- // premultiply (s,t) when clampling
- if (tmu.s_wrap == GGL_CLAMP) {
- const int width = tmu.surface.width;
- s0 *= width;
- s1 *= width;
- s2 *= width;
- }
- if (tmu.t_wrap == GGL_CLAMP) {
- const int height = tmu.surface.height;
- t0 *= height;
- t1 *= height;
- t2 *= height;
- }
- itt[6] = -lerp.iteratorsScale(itt+0, s0, s1, s2);
- itt[7] = -lerp.iteratorsScale(itt+3, t0, t1, t2);
- c->rasterizer.procs.texCoordGradScale8xv(c, i, itt);
- }
-}
-
-void lerp_texcoords_w(ogles_context_t* c,
- vertex_t* v0, vertex_t* v1, vertex_t* v2)
-{
- const compute_iterators_t& lerp = c->lerp;
- int32_t itt[8] __attribute__((aligned(16)));
- int32_t itw[3];
-
- // compute W's scale to 2.30
- int32_t w0 = v0->window.w;
- int32_t w1 = v1->window.w;
- int32_t w2 = v2->window.w;
- int wscale = 32 - gglClz(w0|w1|w2);
-
- // compute the jacobian using block floating-point
- int sc = lerp.iteratorsScale(itw, w0, w1, w2);
- sc += wscale - 16;
- c->rasterizer.procs.wGrad3xv(c, itw);
-
- for (int i=0 ; i<GGL_TEXTURE_UNIT_COUNT ; i++) {
- const texture_t& tmu = c->rasterizer.state.texture[i];
- if (!tmu.enable)
- continue;
-
- // compute the jacobians using block floating-point
- int32_t s0 = v0->texture[i].S;
- int32_t t0 = v0->texture[i].T;
- int32_t s1 = v1->texture[i].S;
- int32_t t1 = v1->texture[i].T;
- int32_t s2 = v2->texture[i].S;
- int32_t t2 = v2->texture[i].T;
-
- const GLenum min_filter = c->textures.tmu[i].texture->min_filter;
- if (ggl_unlikely(min_filter >= GL_NEAREST_MIPMAP_NEAREST)) {
- int lod = compute_lod(c, i, s0, t0, s1, t1, s2, t2);
- c->rasterizer.procs.bindTextureLod(c, i,
- &c->textures.tmu[i].texture->mip(lod));
- }
-
- // premultiply (s,t) when clampling
- if (tmu.s_wrap == GGL_CLAMP) {
- const int width = tmu.surface.width;
- s0 *= width;
- s1 *= width;
- s2 *= width;
- }
- if (tmu.t_wrap == GGL_CLAMP) {
- const int height = tmu.surface.height;
- t0 *= height;
- t1 *= height;
- t2 *= height;
- }
-
- s0 = gglMulx(s0, w0, wscale);
- t0 = gglMulx(t0, w0, wscale);
- s1 = gglMulx(s1, w1, wscale);
- t1 = gglMulx(t1, w1, wscale);
- s2 = gglMulx(s2, w2, wscale);
- t2 = gglMulx(t2, w2, wscale);
-
- itt[6] = sc - lerp.iteratorsScale(itt+0, s0, s1, s2);
- itt[7] = sc - lerp.iteratorsScale(itt+3, t0, t1, t2);
- c->rasterizer.procs.texCoordGradScale8xv(c, i, itt);
- }
-}
-
-
-static inline
-bool cull_triangle(ogles_context_t* c, vertex_t* /*v0*/, vertex_t* /*v1*/, vertex_t* /*v2*/)
-{
- if (ggl_likely(c->cull.enable)) {
- const GLenum winding = (c->lerp.area() > 0) ? GL_CW : GL_CCW;
- const GLenum face = (winding == c->cull.frontFace) ? GL_FRONT : GL_BACK;
- if (face == c->cull.cullFace)
- return true; // culled!
- }
- return false;
-}
-
-static inline
-GLfixed frustumPlaneDist(int plane, const vec4_t& s)
-{
- const GLfixed d = s.v[ plane >> 1 ];
- return ((plane & 1) ? (s.w - d) : (s.w + d));
-}
-
-static inline
-int32_t clipDivide(GLfixed a, GLfixed b) {
- // returns a 4.28 fixed-point
- return gglMulDivi(1LU<<28, a, b);
-}
-
-void clip_triangle(ogles_context_t* c,
- vertex_t* v0, vertex_t* v1, vertex_t* v2)
-{
- uint32_t all_cc = (v0->flags | v1->flags | v2->flags) & vertex_t::CLIP_ALL;
-
- vertex_t *p0, *p1, *p2;
- const int MAX_CLIPPING_PLANES = 6 + OGLES_MAX_CLIP_PLANES;
- const int MAX_VERTICES = 3;
-
- // Temporary buffer to hold the new vertices. Each plane can add up to
- // two new vertices (because the polygon is convex).
- // We need one extra element, to handle an overflow case when
- // the polygon degenerates into something non convex.
- vertex_t buffer[MAX_CLIPPING_PLANES * 2 + 1]; // ~3KB
- vertex_t* buf = buffer;
-
- // original list of vertices (polygon to clip, in fact this
- // function works with an arbitrary polygon).
- vertex_t* in[3] = { v0, v1, v2 };
-
- // output lists (we need 2, which we use back and forth)
- // (maximum outpout list's size is MAX_CLIPPING_PLANES + MAX_VERTICES)
- // 2 more elements for overflow when non convex polygons.
- vertex_t* out[2][MAX_CLIPPING_PLANES + MAX_VERTICES + 2];
- unsigned int outi = 0;
-
- // current input list
- vertex_t** ivl = in;
-
- // 3 input vertices, 0 in the output list, first plane
- unsigned int ic = 3;
-
- // User clip-planes first, the clipping is always done in eye-coordinate
- // this is basically the same algorithm than for the view-volume
- // clipping, except for the computation of the distance (vertex, plane)
- // and the fact that we need to compute the eye-coordinates of each
- // new vertex we create.
-
- if (ggl_unlikely(all_cc & vertex_t::USER_CLIP_ALL))
- {
- unsigned int plane = 0;
- uint32_t cc = (all_cc & vertex_t::USER_CLIP_ALL) >> 8;
- do {
- if (cc & 1) {
- // pointers to our output list (head and current)
- vertex_t** const ovl = &out[outi][0];
- vertex_t** output = ovl;
- unsigned int oc = 0;
- unsigned int sentinel = 0;
- // previous vertex, compute distance to the plane
- vertex_t* s = ivl[ic-1];
- const vec4_t& equation = c->clipPlanes.plane[plane].equation;
- GLfixed sd = dot4(equation.v, s->eye.v);
- // clip each vertex against this plane...
- for (unsigned int i=0 ; i<ic ; i++) {
- vertex_t* p = ivl[i];
- const GLfixed pd = dot4(equation.v, p->eye.v);
- if (sd >= 0) {
- if (pd >= 0) {
- // both inside
- *output++ = p;
- oc++;
- } else {
- // s inside, p outside (exiting)
- const GLfixed t = clipDivide(sd, sd-pd);
- c->arrays.clipEye(c, buf, t, p, s);
- *output++ = buf++;
- oc++;
- if (++sentinel >= 3)
- return; // non-convex polygon!
- }
- } else {
- if (pd >= 0) {
- // s outside (entering)
- if (pd) {
- const GLfixed t = clipDivide(pd, pd-sd);
- c->arrays.clipEye(c, buf, t, s, p);
- *output++ = buf++;
- oc++;
- if (++sentinel >= 3)
- return; // non-convex polygon!
- }
- *output++ = p;
- oc++;
- } else {
- // both outside
- }
- }
- s = p;
- sd = pd;
- }
- // output list become the new input list
- if (oc<3)
- return; // less than 3 vertices left? we're done!
- ivl = ovl;
- ic = oc;
- outi = 1-outi;
- }
- cc >>= 1;
- plane++;
- } while (cc);
- }
-
- // frustum clip-planes
- if (all_cc & vertex_t::FRUSTUM_CLIP_ALL)
- {
- unsigned int plane = 0;
- uint32_t cc = all_cc & vertex_t::FRUSTUM_CLIP_ALL;
- do {
- if (cc & 1) {
- // pointers to our output list (head and current)
- vertex_t** const ovl = &out[outi][0];
- vertex_t** output = ovl;
- unsigned int oc = 0;
- unsigned int sentinel = 0;
- // previous vertex, compute distance to the plane
- vertex_t* s = ivl[ic-1];
- GLfixed sd = frustumPlaneDist(plane, s->clip);
- // clip each vertex against this plane...
- for (unsigned int i=0 ; i<ic ; i++) {
- vertex_t* p = ivl[i];
- const GLfixed pd = frustumPlaneDist(plane, p->clip);
- if (sd >= 0) {
- if (pd >= 0) {
- // both inside
- *output++ = p;
- oc++;
- } else {
- // s inside, p outside (exiting)
- const GLfixed t = clipDivide(sd, sd-pd);
- c->arrays.clipVertex(c, buf, t, p, s);
- *output++ = buf++;
- oc++;
- if (++sentinel >= 3)
- return; // non-convex polygon!
- }
- } else {
- if (pd >= 0) {
- // s outside (entering)
- if (pd) {
- const GLfixed t = clipDivide(pd, pd-sd);
- c->arrays.clipVertex(c, buf, t, s, p);
- *output++ = buf++;
- oc++;
- if (++sentinel >= 3)
- return; // non-convex polygon!
- }
- *output++ = p;
- oc++;
- } else {
- // both outside
- }
- }
- s = p;
- sd = pd;
- }
- // output list become the new input list
- if (oc<3)
- return; // less than 3 vertices left? we're done!
- ivl = ovl;
- ic = oc;
- outi = 1-outi;
- }
- cc >>= 1;
- plane++;
- } while (cc);
- }
-
- // finally we can render our triangles...
- p0 = ivl[0];
- p1 = ivl[1];
- for (unsigned int i=2 ; i<ic ; i++) {
- p2 = ivl[i];
- c->lerp.initTriangle(p0, p1, p2);
- if (cull_triangle(c, p0, p1, p2)) {
- p1 = p2;
- continue; // culled!
- }
- triangle(c, p0, p1, p2);
- p1 = p2;
- }
-}
-
-unsigned int clip_line(ogles_context_t* c, vertex_t* s, vertex_t* p)
-{
- const uint32_t all_cc = (s->flags | p->flags) & vertex_t::CLIP_ALL;
-
- if (ggl_unlikely(all_cc & vertex_t::USER_CLIP_ALL))
- {
- unsigned int plane = 0;
- uint32_t cc = (all_cc & vertex_t::USER_CLIP_ALL) >> 8;
- do {
- if (cc & 1) {
- const vec4_t& equation = c->clipPlanes.plane[plane].equation;
- const GLfixed sd = dot4(equation.v, s->eye.v);
- const GLfixed pd = dot4(equation.v, p->eye.v);
- if (sd >= 0) {
- if (pd >= 0) {
- // both inside
- } else {
- // s inside, p outside (exiting)
- const GLfixed t = clipDivide(sd, sd-pd);
- c->arrays.clipEye(c, p, t, p, s);
- }
- } else {
- if (pd >= 0) {
- // s outside (entering)
- if (pd) {
- const GLfixed t = clipDivide(pd, pd-sd);
- c->arrays.clipEye(c, s, t, s, p);
- }
- } else {
- // both outside
- return 0;
- }
- }
- }
- cc >>= 1;
- plane++;
- } while (cc);
- }
-
- // frustum clip-planes
- if (all_cc & vertex_t::FRUSTUM_CLIP_ALL)
- {
- unsigned int plane = 0;
- uint32_t cc = all_cc & vertex_t::FRUSTUM_CLIP_ALL;
- do {
- if (cc & 1) {
- const GLfixed sd = frustumPlaneDist(plane, s->clip);
- const GLfixed pd = frustumPlaneDist(plane, p->clip);
- if (sd >= 0) {
- if (pd >= 0) {
- // both inside
- } else {
- // s inside, p outside (exiting)
- const GLfixed t = clipDivide(sd, sd-pd);
- c->arrays.clipVertex(c, p, t, p, s);
- }
- } else {
- if (pd >= 0) {
- // s outside (entering)
- if (pd) {
- const GLfixed t = clipDivide(pd, pd-sd);
- c->arrays.clipVertex(c, s, t, s, p);
- }
- } else {
- // both outside
- return 0;
- }
- }
- }
- cc >>= 1;
- plane++;
- } while (cc);
- }
-
- return 2;
-}
-
-
-}; // namespace android
diff --git a/opengl/libagl/primitives.h b/opengl/libagl/primitives.h
deleted file mode 100644
index 1bef604..0000000
--- a/opengl/libagl/primitives.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/* libs/opengles/primitives.h
-**
-** Copyright 2006, 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.
-*/
-
-#ifndef ANDROID_OPENGLES_PRIMITIVES_H
-#define ANDROID_OPENGLES_PRIMITIVES_H
-
-#include <stdint.h>
-#include <stddef.h>
-#include <sys/types.h>
-
-
-namespace android {
-
-namespace gl {
-struct ogles_context_t;
-};
-
-void ogles_validate_primitives(ogles_context_t* c);
-
-}; // namespace android
-
-#endif // ANDROID_OPENGLES_PRIMITIVES_H
-
diff --git a/opengl/libagl/state.cpp b/opengl/libagl/state.cpp
deleted file mode 100644
index 8bb7e83..0000000
--- a/opengl/libagl/state.cpp
+++ /dev/null
@@ -1,598 +0,0 @@
-/* libs/opengles/state.cpp
-**
-** Copyright 2006, 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 <stdlib.h>
-
-#include "context.h"
-#include "fp.h"
-#include "state.h"
-#include "array.h"
-#include "matrix.h"
-#include "vertex.h"
-#include "light.h"
-#include "texture.h"
-#include "BufferObjectManager.h"
-#include "TextureObjectManager.h"
-
-namespace android {
-
-// ----------------------------------------------------------------------------
-
-static char const * const gVendorString = "Android";
-static char const * const gRendererString = "Android PixelFlinger 1.4";
-static char const * const gVersionString = "OpenGL ES-CM 1.0";
-static char const * const gExtensionsString =
- "GL_OES_byte_coordinates " // OK
- "GL_OES_fixed_point " // OK
- "GL_OES_single_precision " // OK
- "GL_OES_read_format " // OK
- "GL_OES_compressed_paletted_texture " // OK
- "GL_OES_draw_texture " // OK
- "GL_OES_matrix_get " // OK
- "GL_OES_query_matrix " // OK
- // "GL_OES_point_size_array " // TODO
- // "GL_OES_point_sprite " // TODO
- "GL_OES_EGL_image " // OK
- "GL_OES_EGL_sync " // OK
-#ifdef GL_OES_compressed_ETC1_RGB8_texture
- "GL_OES_compressed_ETC1_RGB8_texture " // OK
-#endif
- "GL_ARB_texture_compression " // OK
- "GL_ARB_texture_non_power_of_two " // OK
- "GL_ANDROID_user_clip_plane " // OK
- "GL_ANDROID_vertex_buffer_object " // OK
- "GL_ANDROID_generate_mipmap " // OK
- ;
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#endif
-
-ogles_context_t *ogles_init(size_t extra)
-{
- void* const base = malloc(extra + sizeof(ogles_context_t) + 32);
- if (!base) return 0;
-
- ogles_context_t *c =
- (ogles_context_t *)((ptrdiff_t(base) + extra + 31) & ~0x1FL);
- memset(c, 0, sizeof(ogles_context_t));
- ggl_init_context(&(c->rasterizer));
-
- // XXX: this should be passed as an argument
- sp<EGLSurfaceManager> smgr(new EGLSurfaceManager());
- c->surfaceManager = smgr.get();
- c->surfaceManager->incStrong(c);
-
- sp<EGLBufferObjectManager> bomgr(new EGLBufferObjectManager());
- c->bufferObjectManager = bomgr.get();
- c->bufferObjectManager->incStrong(c);
-
- ogles_init_array(c);
- ogles_init_matrix(c);
- ogles_init_vertex(c);
- ogles_init_light(c);
- ogles_init_texture(c);
-
- c->rasterizer.base = base;
- c->point.size = TRI_ONE;
- c->line.width = TRI_ONE;
-
- // in OpenGL, writing to the depth buffer is enabled by default.
- c->rasterizer.procs.depthMask(c, 1);
-
- // OpenGL enables dithering by default
- c->rasterizer.procs.enable(c, GL_DITHER);
-
- return c;
-}
-
-void ogles_uninit(ogles_context_t* c)
-{
- ogles_uninit_array(c);
- ogles_uninit_matrix(c);
- ogles_uninit_vertex(c);
- ogles_uninit_light(c);
- ogles_uninit_texture(c);
- c->surfaceManager->decStrong(c);
- c->bufferObjectManager->decStrong(c);
- ggl_uninit_context(&(c->rasterizer));
- free(c->rasterizer.base);
-}
-
-void _ogles_error(ogles_context_t* c, GLenum error)
-{
- if (c->error == GL_NO_ERROR)
- c->error = error;
-}
-
-static bool stencilop_valid(GLenum op) {
- switch (op) {
- case GL_KEEP:
- case GL_ZERO:
- case GL_REPLACE:
- case GL_INCR:
- case GL_DECR:
- case GL_INVERT:
- return true;
- }
- return false;
-}
-
-static void enable_disable(ogles_context_t* c, GLenum cap, int enabled)
-{
- if ((cap >= GL_LIGHT0) && (cap<GL_LIGHT0+OGLES_MAX_LIGHTS)) {
- c->lighting.lights[cap-GL_LIGHT0].enable = enabled;
- c->lighting.enabledLights &= ~(1<<(cap-GL_LIGHT0));
- c->lighting.enabledLights |= (enabled<<(cap-GL_LIGHT0));
- return;
- }
-
- switch (cap) {
- case GL_POINT_SMOOTH:
- c->point.smooth = enabled;
- break;
- case GL_LINE_SMOOTH:
- c->line.smooth = enabled;
- break;
- case GL_POLYGON_OFFSET_FILL:
- c->polygonOffset.enable = enabled;
- break;
- case GL_CULL_FACE:
- c->cull.enable = enabled;
- break;
- case GL_LIGHTING:
- c->lighting.enable = enabled;
- break;
- case GL_COLOR_MATERIAL:
- c->lighting.colorMaterial.enable = enabled;
- break;
- case GL_NORMALIZE:
- case GL_RESCALE_NORMAL:
- c->transforms.rescaleNormals = enabled ? cap : 0;
- // XXX: invalidate mvit
- break;
-
- case GL_CLIP_PLANE0:
- case GL_CLIP_PLANE1:
- case GL_CLIP_PLANE2:
- case GL_CLIP_PLANE3:
- case GL_CLIP_PLANE4:
- case GL_CLIP_PLANE5:
- c->clipPlanes.enable &= ~(1<<(cap-GL_CLIP_PLANE0));
- c->clipPlanes.enable |= (enabled<<(cap-GL_CLIP_PLANE0));
- ogles_invalidate_perspective(c);
- break;
-
- case GL_FOG:
- case GL_DEPTH_TEST:
- ogles_invalidate_perspective(c);
- [[fallthrough]];
- case GL_BLEND:
- case GL_SCISSOR_TEST:
- case GL_ALPHA_TEST:
- case GL_COLOR_LOGIC_OP:
- case GL_DITHER:
- case GL_STENCIL_TEST:
- case GL_TEXTURE_2D:
- // these need to fall through into the rasterizer
- c->rasterizer.procs.enableDisable(c, cap, enabled);
- break;
- case GL_TEXTURE_EXTERNAL_OES:
- c->rasterizer.procs.enableDisable(c, GL_TEXTURE_2D, enabled);
- break;
-
- case GL_MULTISAMPLE:
- case GL_SAMPLE_ALPHA_TO_COVERAGE:
- case GL_SAMPLE_ALPHA_TO_ONE:
- case GL_SAMPLE_COVERAGE:
- // not supported in this implementation
- break;
-
- default:
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
-}
-
-// ----------------------------------------------------------------------------
-}; // namespace android
-// ----------------------------------------------------------------------------
-using namespace android;
-
-#if 0
-#pragma mark -
-#endif
-
-// These ones are super-easy, we're not supporting those features!
-void glSampleCoverage(GLclampf /*value*/, GLboolean /*invert*/) {
-}
-void glSampleCoveragex(GLclampx /*value*/, GLboolean /*invert*/) {
-}
-void glStencilFunc(GLenum func, GLint /*ref*/, GLuint /*mask*/) {
- ogles_context_t* c = ogles_context_t::get();
- if (func < GL_NEVER || func > GL_ALWAYS) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- // from OpenGL|ES 1.0 sepcification:
- // If there is no stencil buffer, no stencil modification can occur
- // and it is as if the stencil test always passes.
-}
-
-void glStencilOp(GLenum fail, GLenum zfail, GLenum zpass) {
- ogles_context_t* c = ogles_context_t::get();
- if ((stencilop_valid(fail) &
- stencilop_valid(zfail) &
- stencilop_valid(zpass)) == 0) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
-}
-
-// ----------------------------------------------------------------------------
-
-void glAlphaFunc(GLenum func, GLclampf ref)
-{
- glAlphaFuncx(func, gglFloatToFixed(ref));
-}
-
-void glCullFace(GLenum mode)
-{
- ogles_context_t* c = ogles_context_t::get();
- switch (mode) {
- case GL_FRONT:
- case GL_BACK:
- case GL_FRONT_AND_BACK:
- break;
- default:
- ogles_error(c, GL_INVALID_ENUM);
- }
- c->cull.cullFace = mode;
-}
-
-void glFrontFace(GLenum mode)
-{
- ogles_context_t* c = ogles_context_t::get();
- switch (mode) {
- case GL_CW:
- case GL_CCW:
- break;
- default:
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- c->cull.frontFace = mode;
-}
-
-void glHint(GLenum target, GLenum mode)
-{
- ogles_context_t* c = ogles_context_t::get();
- switch (target) {
- case GL_FOG_HINT:
- case GL_GENERATE_MIPMAP_HINT:
- case GL_LINE_SMOOTH_HINT:
- break;
- case GL_POINT_SMOOTH_HINT:
- c->rasterizer.procs.enableDisable(c,
- GGL_POINT_SMOOTH_NICE, mode==GL_NICEST);
- break;
- case GL_PERSPECTIVE_CORRECTION_HINT:
- c->perspective = (mode == GL_NICEST) ? 1 : 0;
- break;
- default:
- ogles_error(c, GL_INVALID_ENUM);
- }
-}
-
-void glEnable(GLenum cap) {
- ogles_context_t* c = ogles_context_t::get();
- enable_disable(c, cap, 1);
-}
-void glDisable(GLenum cap) {
- ogles_context_t* c = ogles_context_t::get();
- enable_disable(c, cap, 0);
-}
-
-void glFinish()
-{ // nothing to do for our software implementation
-}
-
-void glFlush()
-{ // nothing to do for our software implementation
-}
-
-GLenum glGetError()
-{
- // From OpenGL|ES 1.0 specification:
- // If more than one flag has recorded an error, glGetError returns
- // and clears an arbitrary error flag value. Thus, glGetError should
- // always be called in a loop, until it returns GL_NO_ERROR,
- // if all error flags are to be reset.
-
- ogles_context_t* c = ogles_context_t::get();
- if (c->error) {
- const GLenum ret(c->error);
- c->error = 0;
- return ret;
- }
-
- if (c->rasterizer.error) {
- const GLenum ret(c->rasterizer.error);
- c->rasterizer.error = 0;
- return ret;
- }
-
- return GL_NO_ERROR;
-}
-
-const GLubyte* glGetString(GLenum string)
-{
- switch (string) {
- case GL_VENDOR: return (const GLubyte*)gVendorString;
- case GL_RENDERER: return (const GLubyte*)gRendererString;
- case GL_VERSION: return (const GLubyte*)gVersionString;
- case GL_EXTENSIONS: return (const GLubyte*)gExtensionsString;
- }
- ogles_context_t* c = ogles_context_t::get();
- ogles_error(c, GL_INVALID_ENUM);
- return 0;
-}
-
-void glGetIntegerv(GLenum pname, GLint *params)
-{
- int i;
- ogles_context_t* c = ogles_context_t::get();
- switch (pname) {
- case GL_ALIASED_POINT_SIZE_RANGE:
- params[0] = 0;
- params[1] = GGL_MAX_ALIASED_POINT_SIZE;
- break;
- case GL_ALIASED_LINE_WIDTH_RANGE:
- params[0] = 0;
- params[1] = GGL_MAX_ALIASED_POINT_SIZE;
- break;
- case GL_ALPHA_BITS: {
- int index = c->rasterizer.state.buffers.color.format;
- GGLFormat const * formats = gglGetPixelFormatTable();
- params[0] = formats[index].ah - formats[index].al;
- break;
- }
- case GL_RED_BITS: {
- int index = c->rasterizer.state.buffers.color.format;
- GGLFormat const * formats = gglGetPixelFormatTable();
- params[0] = formats[index].rh - formats[index].rl;
- break;
- }
- case GL_GREEN_BITS: {
- int index = c->rasterizer.state.buffers.color.format;
- GGLFormat const * formats = gglGetPixelFormatTable();
- params[0] = formats[index].gh - formats[index].gl;
- break;
- }
- case GL_BLUE_BITS: {
- int index = c->rasterizer.state.buffers.color.format;
- GGLFormat const * formats = gglGetPixelFormatTable();
- params[0] = formats[index].bh - formats[index].bl;
- break;
- }
- case GL_COMPRESSED_TEXTURE_FORMATS:
- params[ 0] = GL_PALETTE4_RGB8_OES;
- params[ 1] = GL_PALETTE4_RGBA8_OES;
- params[ 2] = GL_PALETTE4_R5_G6_B5_OES;
- params[ 3] = GL_PALETTE4_RGBA4_OES;
- params[ 4] = GL_PALETTE4_RGB5_A1_OES;
- params[ 5] = GL_PALETTE8_RGB8_OES;
- params[ 6] = GL_PALETTE8_RGBA8_OES;
- params[ 7] = GL_PALETTE8_R5_G6_B5_OES;
- params[ 8] = GL_PALETTE8_RGBA4_OES;
- params[ 9] = GL_PALETTE8_RGB5_A1_OES;
- i = 10;
-#ifdef GL_OES_compressed_ETC1_RGB8_texture
- params[i++] = GL_ETC1_RGB8_OES;
-#endif
- break;
- case GL_DEPTH_BITS:
- params[0] = c->rasterizer.state.buffers.depth.format ? 0 : 16;
- break;
- case GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES:
- params[0] = GL_RGB;
- break;
- case GL_IMPLEMENTATION_COLOR_READ_TYPE_OES:
- params[0] = GL_UNSIGNED_SHORT_5_6_5;
- break;
- case GL_MAX_LIGHTS:
- params[0] = OGLES_MAX_LIGHTS;
- break;
- case GL_MAX_CLIP_PLANES:
- params[0] = OGLES_MAX_CLIP_PLANES;
- break;
- case GL_MAX_MODELVIEW_STACK_DEPTH:
- params[0] = OGLES_MODELVIEW_STACK_DEPTH;
- break;
- case GL_MAX_PROJECTION_STACK_DEPTH:
- params[0] = OGLES_PROJECTION_STACK_DEPTH;
- break;
- case GL_MAX_TEXTURE_STACK_DEPTH:
- params[0] = OGLES_TEXTURE_STACK_DEPTH;
- break;
- case GL_MAX_TEXTURE_SIZE:
- params[0] = GGL_MAX_TEXTURE_SIZE;
- break;
- case GL_MAX_TEXTURE_UNITS:
- params[0] = GGL_TEXTURE_UNIT_COUNT;
- break;
- case GL_MAX_VIEWPORT_DIMS:
- params[0] = GGL_MAX_VIEWPORT_DIMS;
- params[1] = GGL_MAX_VIEWPORT_DIMS;
- break;
- case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
- params[0] = OGLES_NUM_COMPRESSED_TEXTURE_FORMATS;
- break;
- case GL_SMOOTH_LINE_WIDTH_RANGE:
- params[0] = 0;
- params[1] = GGL_MAX_SMOOTH_LINE_WIDTH;
- break;
- case GL_SMOOTH_POINT_SIZE_RANGE:
- params[0] = 0;
- params[1] = GGL_MAX_SMOOTH_POINT_SIZE;
- break;
- case GL_STENCIL_BITS:
- params[0] = 0;
- break;
- case GL_SUBPIXEL_BITS:
- params[0] = GGL_SUBPIXEL_BITS;
- break;
-
- case GL_MODELVIEW_MATRIX_FLOAT_AS_INT_BITS_OES:
- memcpy( params,
- c->transforms.modelview.top().elements(),
- 16*sizeof(GLint));
- break;
- case GL_PROJECTION_MATRIX_FLOAT_AS_INT_BITS_OES:
- memcpy( params,
- c->transforms.projection.top().elements(),
- 16*sizeof(GLint));
- break;
- case GL_TEXTURE_MATRIX_FLOAT_AS_INT_BITS_OES:
- memcpy( params,
- c->transforms.texture[c->textures.active].top().elements(),
- 16*sizeof(GLint));
- break;
-
- default:
- ogles_error(c, GL_INVALID_ENUM);
- break;
- }
-}
-
-// ----------------------------------------------------------------------------
-
-void glPointSize(GLfloat size)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (size <= 0) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- c->point.size = TRI_FROM_FIXED(gglFloatToFixed(size));
-}
-
-void glPointSizex(GLfixed size)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (size <= 0) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- c->point.size = TRI_FROM_FIXED(size);
-}
-
-// ----------------------------------------------------------------------------
-
-void glLineWidth(GLfloat width)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (width <= 0) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- c->line.width = TRI_FROM_FIXED(gglFloatToFixed(width));
-}
-
-void glLineWidthx(GLfixed width)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (width <= 0) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- c->line.width = TRI_FROM_FIXED(width);
-}
-
-// ----------------------------------------------------------------------------
-
-void glColorMask(GLboolean r, GLboolean g, GLboolean b, GLboolean a) {
- ogles_context_t* c = ogles_context_t::get();
- c->rasterizer.procs.colorMask(c, r, g, b, a);
-}
-
-void glDepthMask(GLboolean flag) {
- ogles_context_t* c = ogles_context_t::get();
- c->rasterizer.procs.depthMask(c, flag);
-}
-
-void glStencilMask(GLuint mask) {
- ogles_context_t* c = ogles_context_t::get();
- c->rasterizer.procs.stencilMask(c, mask);
-}
-
-void glDepthFunc(GLenum func) {
- ogles_context_t* c = ogles_context_t::get();
- c->rasterizer.procs.depthFunc(c, func);
-}
-
-void glLogicOp(GLenum opcode) {
- ogles_context_t* c = ogles_context_t::get();
- c->rasterizer.procs.logicOp(c, opcode);
-}
-
-void glAlphaFuncx(GLenum func, GLclampx ref) {
- ogles_context_t* c = ogles_context_t::get();
- c->rasterizer.procs.alphaFuncx(c, func, ref);
-}
-
-void glBlendFunc(GLenum sfactor, GLenum dfactor) {
- ogles_context_t* c = ogles_context_t::get();
- c->rasterizer.procs.blendFunc(c, sfactor, dfactor);
-}
-
-void glClear(GLbitfield mask) {
- ogles_context_t* c = ogles_context_t::get();
- c->rasterizer.procs.clear(c, mask);
-}
-
-void glClearColorx(GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha) {
- ogles_context_t* c = ogles_context_t::get();
- c->rasterizer.procs.clearColorx(c, red, green, blue, alpha);
-}
-
-void glClearColor(GLclampf r, GLclampf g, GLclampf b, GLclampf a)
-{
- ogles_context_t* c = ogles_context_t::get();
- c->rasterizer.procs.clearColorx(c,
- gglFloatToFixed(r),
- gglFloatToFixed(g),
- gglFloatToFixed(b),
- gglFloatToFixed(a));
-}
-
-void glClearDepthx(GLclampx depth) {
- ogles_context_t* c = ogles_context_t::get();
- c->rasterizer.procs.clearDepthx(c, depth);
-}
-
-void glClearDepthf(GLclampf depth)
-{
- ogles_context_t* c = ogles_context_t::get();
- c->rasterizer.procs.clearDepthx(c, gglFloatToFixed(depth));
-}
-
-void glClearStencil(GLint s) {
- ogles_context_t* c = ogles_context_t::get();
- c->rasterizer.procs.clearStencil(c, s);
-}
diff --git a/opengl/libagl/state.h b/opengl/libagl/state.h
deleted file mode 100644
index 55a5ccb..0000000
--- a/opengl/libagl/state.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/* libs/opengles/state.h
-**
-** Copyright 2006, 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.
-*/
-
-#ifndef ANDROID_OPENGLES_STATE_H
-#define ANDROID_OPENGLES_STATE_H
-
-#include <stdint.h>
-#include <stddef.h>
-#include <sys/types.h>
-
-#include <private/pixelflinger/ggl_context.h>
-
-#include <GLES/gl.h>
-
-#include <stdio.h>
-
-namespace android {
-
-ogles_context_t *ogles_init(size_t extra);
-void ogles_uninit(ogles_context_t* c);
-void _ogles_error(ogles_context_t* c, GLenum error);
-
-#ifndef TRACE_GL_ERRORS
-#define TRACE_GL_ERRORS 0
-#endif
-
-#if TRACE_GL_ERRORS
-#define ogles_error(c, error) \
-do { \
- printf("ogles_error at file %s line %d\n", __FILE__, __LINE__); \
- _ogles_error(c, error); \
-} while (0)
-#else /* !TRACE_GL_ERRORS */
-#define ogles_error(c, error) _ogles_error((c), (error))
-#endif
-
-}; // namespace android
-
-#endif // ANDROID_OPENGLES_STATE_H
-
diff --git a/opengl/libagl/texture.cpp b/opengl/libagl/texture.cpp
deleted file mode 100644
index 4c5f3e9..0000000
--- a/opengl/libagl/texture.cpp
+++ /dev/null
@@ -1,1643 +0,0 @@
-/* libs/opengles/texture.cpp
-**
-** Copyright 2006, 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 <stdio.h>
-#include <stdlib.h>
-#include "context.h"
-#include "fp.h"
-#include "state.h"
-#include "texture.h"
-#include "TextureObjectManager.h"
-
-#include <ETC1/etc1.h>
-
-#include <ui/GraphicBufferMapper.h>
-#include <ui/Rect.h>
-
-namespace android {
-
-// ----------------------------------------------------------------------------
-
-static void bindTextureTmu(
- ogles_context_t* c, int tmu, GLuint texture, const sp<EGLTextureObject>& tex);
-
-static __attribute__((noinline))
-void generateMipmap(ogles_context_t* c, GLint level);
-
-// ----------------------------------------------------------------------------
-
-#if 0
-#pragma mark -
-#pragma mark Init
-#endif
-
-void ogles_init_texture(ogles_context_t* c)
-{
- c->textures.packAlignment = 4;
- c->textures.unpackAlignment = 4;
-
- // each context has a default named (0) texture (not shared)
- c->textures.defaultTexture = new EGLTextureObject();
- c->textures.defaultTexture->incStrong(c);
-
- // bind the default texture to each texture unit
- for (int i=0; i<GGL_TEXTURE_UNIT_COUNT ; i++) {
- bindTextureTmu(c, i, 0, c->textures.defaultTexture);
- memset(c->current.texture[i].v, 0, sizeof(vec4_t));
- c->current.texture[i].Q = 0x10000;
- }
-}
-
-void ogles_uninit_texture(ogles_context_t* c)
-{
- if (c->textures.ggl)
- gglUninit(c->textures.ggl);
- c->textures.defaultTexture->decStrong(c);
- for (int i=0; i<GGL_TEXTURE_UNIT_COUNT ; i++) {
- if (c->textures.tmu[i].texture)
- c->textures.tmu[i].texture->decStrong(c);
- }
-}
-
-static __attribute__((noinline))
-void validate_tmu(ogles_context_t* c, int i)
-{
- texture_unit_t& u(c->textures.tmu[i]);
- if (u.dirty) {
- u.dirty = 0;
- c->rasterizer.procs.activeTexture(c, i);
- c->rasterizer.procs.bindTexture(c, &(u.texture->surface));
- c->rasterizer.procs.texGeni(c, GGL_S,
- GGL_TEXTURE_GEN_MODE, GGL_AUTOMATIC);
- c->rasterizer.procs.texGeni(c, GGL_T,
- GGL_TEXTURE_GEN_MODE, GGL_AUTOMATIC);
- c->rasterizer.procs.texParameteri(c, GGL_TEXTURE_2D,
- GGL_TEXTURE_WRAP_S, u.texture->wraps);
- c->rasterizer.procs.texParameteri(c, GGL_TEXTURE_2D,
- GGL_TEXTURE_WRAP_T, u.texture->wrapt);
- c->rasterizer.procs.texParameteri(c, GGL_TEXTURE_2D,
- GGL_TEXTURE_MIN_FILTER, u.texture->min_filter);
- c->rasterizer.procs.texParameteri(c, GGL_TEXTURE_2D,
- GGL_TEXTURE_MAG_FILTER, u.texture->mag_filter);
-
- // disable this texture unit if it's not complete
- if (!u.texture->isComplete()) {
- c->rasterizer.procs.disable(c, GGL_TEXTURE_2D);
- }
- }
-}
-
-void ogles_validate_texture(ogles_context_t* c)
-{
- for (int i=0 ; i<GGL_TEXTURE_UNIT_COUNT ; i++) {
- if (c->rasterizer.state.texture[i].enable)
- validate_tmu(c, i);
- }
- c->rasterizer.procs.activeTexture(c, c->textures.active);
-}
-
-static
-void invalidate_texture(ogles_context_t* c, int tmu, uint8_t flags = 0xFF) {
- c->textures.tmu[tmu].dirty = flags;
-}
-
-/*
- * If the active textures are EGLImage, they need to be locked before
- * they can be used.
- *
- * FIXME: code below is far from being optimal
- *
- */
-
-void ogles_lock_textures(ogles_context_t* c)
-{
- for (int i=0 ; i<GGL_TEXTURE_UNIT_COUNT ; i++) {
- if (c->rasterizer.state.texture[i].enable) {
- texture_unit_t& u(c->textures.tmu[i]);
- ANativeWindowBuffer* native_buffer = u.texture->buffer;
- if (native_buffer) {
- c->rasterizer.procs.activeTexture(c, i);
-
- auto& mapper = GraphicBufferMapper::get();
- void* vaddr;
- mapper.lock(native_buffer->handle, GRALLOC_USAGE_SW_READ_OFTEN,
- Rect(native_buffer->width, native_buffer->height),
- &vaddr);
-
- u.texture->setImageBits(vaddr);
- c->rasterizer.procs.bindTexture(c, &(u.texture->surface));
- }
- }
- }
-}
-
-void ogles_unlock_textures(ogles_context_t* c)
-{
- for (int i=0 ; i<GGL_TEXTURE_UNIT_COUNT ; i++) {
- if (c->rasterizer.state.texture[i].enable) {
- texture_unit_t& u(c->textures.tmu[i]);
- ANativeWindowBuffer* native_buffer = u.texture->buffer;
- if (native_buffer) {
- c->rasterizer.procs.activeTexture(c, i);
-
- auto& mapper = GraphicBufferMapper::get();
- mapper.unlock(native_buffer->handle);
-
- u.texture->setImageBits(NULL);
- c->rasterizer.procs.bindTexture(c, &(u.texture->surface));
- }
- }
- }
- c->rasterizer.procs.activeTexture(c, c->textures.active);
-}
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#pragma mark Format conversion
-#endif
-
-static uint32_t gl2format_table[6][4] = {
- // BYTE, 565, 4444, 5551
- { GGL_PIXEL_FORMAT_A_8,
- 0, 0, 0 }, // GL_ALPHA
- { GGL_PIXEL_FORMAT_RGB_888,
- GGL_PIXEL_FORMAT_RGB_565,
- 0, 0 }, // GL_RGB
- { GGL_PIXEL_FORMAT_RGBA_8888,
- 0,
- GGL_PIXEL_FORMAT_RGBA_4444,
- GGL_PIXEL_FORMAT_RGBA_5551 }, // GL_RGBA
- { GGL_PIXEL_FORMAT_L_8,
- 0, 0, 0 }, // GL_LUMINANCE
- { GGL_PIXEL_FORMAT_LA_88,
- 0, 0, 0 }, // GL_LUMINANCE_ALPHA
-};
-
-static int32_t convertGLPixelFormat(GLint format, GLenum type)
-{
- int32_t fi = -1;
- int32_t ti = -1;
- switch (format) {
- case GL_ALPHA: fi = 0; break;
- case GL_RGB: fi = 1; break;
- case GL_RGBA: fi = 2; break;
- case GL_LUMINANCE: fi = 3; break;
- case GL_LUMINANCE_ALPHA: fi = 4; break;
- }
- switch (type) {
- case GL_UNSIGNED_BYTE: ti = 0; break;
- case GL_UNSIGNED_SHORT_5_6_5: ti = 1; break;
- case GL_UNSIGNED_SHORT_4_4_4_4: ti = 2; break;
- case GL_UNSIGNED_SHORT_5_5_5_1: ti = 3; break;
- }
- if (fi==-1 || ti==-1)
- return 0;
- return gl2format_table[fi][ti];
-}
-
-// ----------------------------------------------------------------------------
-
-static GLenum validFormatType(ogles_context_t* c, GLenum format, GLenum type)
-{
- GLenum error = 0;
- if (format<GL_ALPHA || format>GL_LUMINANCE_ALPHA) {
- error = GL_INVALID_ENUM;
- }
- if (type != GL_UNSIGNED_BYTE && type != GL_UNSIGNED_SHORT_4_4_4_4 &&
- type != GL_UNSIGNED_SHORT_5_5_5_1 && type != GL_UNSIGNED_SHORT_5_6_5) {
- error = GL_INVALID_ENUM;
- }
- if (type == GL_UNSIGNED_SHORT_5_6_5 && format != GL_RGB) {
- error = GL_INVALID_OPERATION;
- }
- if ((type == GL_UNSIGNED_SHORT_4_4_4_4 ||
- type == GL_UNSIGNED_SHORT_5_5_5_1) && format != GL_RGBA) {
- error = GL_INVALID_OPERATION;
- }
- if (error) {
- ogles_error(c, error);
- }
- return error;
-}
-
-// ----------------------------------------------------------------------------
-
-GGLContext* getRasterizer(ogles_context_t* c)
-{
- GGLContext* ggl = c->textures.ggl;
- if (ggl_unlikely(!ggl)) {
- // this is quite heavy the first time...
- gglInit(&ggl);
- if (!ggl) {
- return 0;
- }
- GGLfixed colors[4] = { 0, 0, 0, 0x10000 };
- c->textures.ggl = ggl;
- ggl->activeTexture(ggl, 0);
- ggl->enable(ggl, GGL_TEXTURE_2D);
- ggl->texEnvi(ggl, GGL_TEXTURE_ENV, GGL_TEXTURE_ENV_MODE, GGL_REPLACE);
- ggl->disable(ggl, GGL_DITHER);
- ggl->shadeModel(ggl, GGL_FLAT);
- ggl->color4xv(ggl, colors);
- }
- return ggl;
-}
-
-static __attribute__((noinline))
-int copyPixels(
- ogles_context_t* c,
- const GGLSurface& dst,
- GLint xoffset, GLint yoffset,
- const GGLSurface& src,
- GLint x, GLint y, GLsizei w, GLsizei h)
-{
- if ((dst.format == src.format) &&
- (dst.stride == src.stride) &&
- (dst.width == src.width) &&
- (dst.height == src.height) &&
- (dst.stride > 0) &&
- ((x|y) == 0) &&
- ((xoffset|yoffset) == 0))
- {
- // this is a common case...
- const GGLFormat& pixelFormat(c->rasterizer.formats[src.format]);
- const size_t size = src.height * src.stride * pixelFormat.size;
- memcpy(dst.data, src.data, size);
- return 0;
- }
-
- // use pixel-flinger to handle all the conversions
- GGLContext* ggl = getRasterizer(c);
- if (!ggl) {
- // the only reason this would fail is because we ran out of memory
- return GL_OUT_OF_MEMORY;
- }
-
- ggl->colorBuffer(ggl, &dst);
- ggl->bindTexture(ggl, &src);
- ggl->texCoord2i(ggl, x-xoffset, y-yoffset);
- ggl->recti(ggl, xoffset, yoffset, xoffset+w, yoffset+h);
- return 0;
-}
-
-// ----------------------------------------------------------------------------
-
-static __attribute__((noinline))
-sp<EGLTextureObject> getAndBindActiveTextureObject(ogles_context_t* c)
-{
- sp<EGLTextureObject> tex;
- const int active = c->textures.active;
- const GLuint name = c->textures.tmu[active].name;
-
- // free the reference to the previously bound object
- texture_unit_t& u(c->textures.tmu[active]);
- if (u.texture)
- u.texture->decStrong(c);
-
- if (name == 0) {
- // 0 is our local texture object, not shared with anyone.
- // But it affects all bound TMUs immediately.
- // (we need to invalidate all units bound to this texture object)
- tex = c->textures.defaultTexture;
- for (int i=0 ; i<GGL_TEXTURE_UNIT_COUNT ; i++) {
- if (c->textures.tmu[i].texture == tex.get())
- invalidate_texture(c, i);
- }
- } else {
- // get a new texture object for that name
- tex = c->surfaceManager->replaceTexture(name);
- }
-
- // bind this texture to the current active texture unit
- // and add a reference to this texture object
- u.texture = tex.get();
- u.texture->incStrong(c);
- u.name = name;
- invalidate_texture(c, active);
- return tex;
-}
-
-void bindTextureTmu(
- ogles_context_t* c, int tmu, GLuint texture, const sp<EGLTextureObject>& tex)
-{
- if (tex.get() == c->textures.tmu[tmu].texture)
- return;
-
- // free the reference to the previously bound object
- texture_unit_t& u(c->textures.tmu[tmu]);
- if (u.texture)
- u.texture->decStrong(c);
-
- // bind this texture to the current active texture unit
- // and add a reference to this texture object
- u.texture = tex.get();
- u.texture->incStrong(c);
- u.name = texture;
- invalidate_texture(c, tmu);
-}
-
-int createTextureSurface(ogles_context_t* c,
- GGLSurface** outSurface, int32_t* outSize, GLint level,
- GLenum format, GLenum type, GLsizei width, GLsizei height,
- GLenum compressedFormat = 0)
-{
- // convert the pixelformat to one we can handle
- const int32_t formatIdx = convertGLPixelFormat(format, type);
- if (formatIdx == 0) { // we don't know what to do with this
- return GL_INVALID_OPERATION;
- }
-
- // figure out the size we need as well as the stride
- const GGLFormat& pixelFormat(c->rasterizer.formats[formatIdx]);
- const int32_t align = c->textures.unpackAlignment-1;
- const int32_t bpr = ((width * pixelFormat.size) + align) & ~align;
- const size_t size = bpr * height;
- const int32_t stride = bpr / pixelFormat.size;
-
- if (level > 0) {
- const int active = c->textures.active;
- EGLTextureObject* tex = c->textures.tmu[active].texture;
- status_t err = tex->reallocate(level,
- width, height, stride, formatIdx, compressedFormat, bpr);
- if (err != NO_ERROR)
- return GL_OUT_OF_MEMORY;
- GGLSurface& surface = tex->editMip(level);
- *outSurface = &surface;
- *outSize = size;
- return 0;
- }
-
- sp<EGLTextureObject> tex = getAndBindActiveTextureObject(c);
- status_t err = tex->reallocate(level,
- width, height, stride, formatIdx, compressedFormat, bpr);
- if (err != NO_ERROR)
- return GL_OUT_OF_MEMORY;
-
- tex->internalformat = format;
- *outSurface = &tex->surface;
- *outSize = size;
- return 0;
-}
-
-static GLsizei dataSizePalette4(int numLevels, int width, int height, int format)
-{
- int indexBits = 8;
- int entrySize = 0;
- switch (format) {
- case GL_PALETTE4_RGB8_OES:
- indexBits = 4;
- [[fallthrough]];
- case GL_PALETTE8_RGB8_OES:
- entrySize = 3;
- break;
-
- case GL_PALETTE4_RGBA8_OES:
- indexBits = 4;
- [[fallthrough]];
- case GL_PALETTE8_RGBA8_OES:
- entrySize = 4;
- break;
-
- case GL_PALETTE4_R5_G6_B5_OES:
- case GL_PALETTE4_RGBA4_OES:
- case GL_PALETTE4_RGB5_A1_OES:
- indexBits = 4;
- [[fallthrough]];
- case GL_PALETTE8_R5_G6_B5_OES:
- case GL_PALETTE8_RGBA4_OES:
- case GL_PALETTE8_RGB5_A1_OES:
- entrySize = 2;
- break;
- }
-
- size_t size = (1 << indexBits) * entrySize; // palette size
-
- for (int i=0 ; i< numLevels ; i++) {
- int w = (width >> i) ? : 1;
- int h = (height >> i) ? : 1;
- int levelSize = h * ((w * indexBits) / 8) ? : 1;
- size += levelSize;
- }
-
- return size;
-}
-
-static void decodePalette4(const GLvoid *data, int level, int width, int height,
- void *surface, int stride, int format)
-
-{
- int indexBits = 8;
- int entrySize = 0;
- switch (format) {
- case GL_PALETTE4_RGB8_OES:
- indexBits = 4;
- [[fallthrough]];
- case GL_PALETTE8_RGB8_OES:
- entrySize = 3;
- break;
-
- case GL_PALETTE4_RGBA8_OES:
- indexBits = 4;
- [[fallthrough]];
- case GL_PALETTE8_RGBA8_OES:
- entrySize = 4;
- break;
-
- case GL_PALETTE4_R5_G6_B5_OES:
- case GL_PALETTE4_RGBA4_OES:
- case GL_PALETTE4_RGB5_A1_OES:
- indexBits = 4;
- [[fallthrough]];
- case GL_PALETTE8_R5_G6_B5_OES:
- case GL_PALETTE8_RGBA4_OES:
- case GL_PALETTE8_RGB5_A1_OES:
- entrySize = 2;
- break;
- }
-
- const int paletteSize = (1 << indexBits) * entrySize;
-
- uint8_t const* pixels = (uint8_t *)data + paletteSize;
- for (int i=0 ; i<level ; i++) {
- int w = (width >> i) ? : 1;
- int h = (height >> i) ? : 1;
- pixels += h * ((w * indexBits) / 8);
- }
- width = (width >> level) ? : 1;
- height = (height >> level) ? : 1;
-
- if (entrySize == 2) {
- uint8_t const* const palette = (uint8_t*)data;
- for (int y=0 ; y<height ; y++) {
- uint8_t* p = (uint8_t*)surface + y*stride*2;
- if (indexBits == 8) {
- for (int x=0 ; x<width ; x++) {
- int index = 2 * (*pixels++);
- *p++ = palette[index + 0];
- *p++ = palette[index + 1];
- }
- } else {
- for (int x=0 ; x<width ; x+=2) {
- int v = *pixels++;
- int index = 2 * (v >> 4);
- *p++ = palette[index + 0];
- *p++ = palette[index + 1];
- if (x+1 < width) {
- index = 2 * (v & 0xF);
- *p++ = palette[index + 0];
- *p++ = palette[index + 1];
- }
- }
- }
- }
- } else if (entrySize == 3) {
- uint8_t const* const palette = (uint8_t*)data;
- for (int y=0 ; y<height ; y++) {
- uint8_t* p = (uint8_t*)surface + y*stride*3;
- if (indexBits == 8) {
- for (int x=0 ; x<width ; x++) {
- int index = 3 * (*pixels++);
- *p++ = palette[index + 0];
- *p++ = palette[index + 1];
- *p++ = palette[index + 2];
- }
- } else {
- for (int x=0 ; x<width ; x+=2) {
- int v = *pixels++;
- int index = 3 * (v >> 4);
- *p++ = palette[index + 0];
- *p++ = palette[index + 1];
- *p++ = palette[index + 2];
- if (x+1 < width) {
- index = 3 * (v & 0xF);
- *p++ = palette[index + 0];
- *p++ = palette[index + 1];
- *p++ = palette[index + 2];
- }
- }
- }
- }
- } else if (entrySize == 4) {
- uint8_t const* const palette = (uint8_t*)data;
- for (int y=0 ; y<height ; y++) {
- uint8_t* p = (uint8_t*)surface + y*stride*4;
- if (indexBits == 8) {
- for (int x=0 ; x<width ; x++) {
- int index = 4 * (*pixels++);
- *p++ = palette[index + 0];
- *p++ = palette[index + 1];
- *p++ = palette[index + 2];
- *p++ = palette[index + 3];
- }
- } else {
- for (int x=0 ; x<width ; x+=2) {
- int v = *pixels++;
- int index = 4 * (v >> 4);
- *p++ = palette[index + 0];
- *p++ = palette[index + 1];
- *p++ = palette[index + 2];
- *p++ = palette[index + 3];
- if (x+1 < width) {
- index = 4 * (v & 0xF);
- *p++ = palette[index + 0];
- *p++ = palette[index + 1];
- *p++ = palette[index + 2];
- *p++ = palette[index + 3];
- }
- }
- }
- }
- }
-}
-
-
-
-static __attribute__((noinline))
-void set_depth_and_fog(ogles_context_t* c, GGLfixed z)
-{
- const uint32_t enables = c->rasterizer.state.enables;
- // we need to compute Zw
- int32_t iterators[3];
- iterators[1] = iterators[2] = 0;
- GGLfixed Zw;
- GGLfixed n = gglFloatToFixed(c->transforms.vpt.zNear);
- GGLfixed f = gglFloatToFixed(c->transforms.vpt.zFar);
- if (z<=0) Zw = n;
- else if (z>=0x10000) Zw = f;
- else Zw = gglMulAddx(z, (f-n), n);
- if (enables & GGL_ENABLE_FOG) {
- // set up fog if needed...
- iterators[0] = c->fog.fog(c, Zw);
- c->rasterizer.procs.fogGrad3xv(c, iterators);
- }
- if (enables & GGL_ENABLE_DEPTH_TEST) {
- // set up z-test if needed...
- int32_t z = (Zw & ~(Zw>>31));
- if (z >= 0x10000)
- z = 0xFFFF;
- iterators[0] = (z << 16) | z;
- c->rasterizer.procs.zGrad3xv(c, iterators);
- }
-}
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#pragma mark Generate mimaps
-#endif
-
-extern status_t buildAPyramid(ogles_context_t* c, EGLTextureObject* tex);
-
-void generateMipmap(ogles_context_t* c, GLint level)
-{
- if (level == 0) {
- const int active = c->textures.active;
- EGLTextureObject* tex = c->textures.tmu[active].texture;
- if (tex->generate_mipmap) {
- if (buildAPyramid(c, tex) != NO_ERROR) {
- ogles_error(c, GL_OUT_OF_MEMORY);
- return;
- }
- }
- }
-}
-
-
-static void texParameterx(
- GLenum target, GLenum pname, GLfixed param, ogles_context_t* c)
-{
- if (target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
-
- EGLTextureObject* textureObject = c->textures.tmu[c->textures.active].texture;
- switch (pname) {
- case GL_TEXTURE_WRAP_S:
- if ((param == GL_REPEAT) ||
- (param == GL_CLAMP_TO_EDGE)) {
- textureObject->wraps = param;
- } else {
- goto invalid_enum;
- }
- break;
- case GL_TEXTURE_WRAP_T:
- if ((param == GL_REPEAT) ||
- (param == GL_CLAMP_TO_EDGE)) {
- textureObject->wrapt = param;
- } else {
- goto invalid_enum;
- }
- break;
- case GL_TEXTURE_MIN_FILTER:
- if ((param == GL_NEAREST) ||
- (param == GL_LINEAR) ||
- (param == GL_NEAREST_MIPMAP_NEAREST) ||
- (param == GL_LINEAR_MIPMAP_NEAREST) ||
- (param == GL_NEAREST_MIPMAP_LINEAR) ||
- (param == GL_LINEAR_MIPMAP_LINEAR)) {
- textureObject->min_filter = param;
- } else {
- goto invalid_enum;
- }
- break;
- case GL_TEXTURE_MAG_FILTER:
- if ((param == GL_NEAREST) ||
- (param == GL_LINEAR)) {
- textureObject->mag_filter = param;
- } else {
- goto invalid_enum;
- }
- break;
- case GL_GENERATE_MIPMAP:
- textureObject->generate_mipmap = param;
- break;
- default:
-invalid_enum:
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- invalidate_texture(c, c->textures.active);
-}
-
-
-
-static void drawTexxOESImp(GLfixed x, GLfixed y, GLfixed z, GLfixed w, GLfixed h,
- ogles_context_t* c)
-{
- ogles_lock_textures(c);
-
- const GGLSurface& cbSurface = c->rasterizer.state.buffers.color.s;
- y = gglIntToFixed(cbSurface.height) - (y + h);
- w >>= FIXED_BITS;
- h >>= FIXED_BITS;
-
- // set up all texture units
- for (int i=0 ; i<GGL_TEXTURE_UNIT_COUNT ; i++) {
- if (!c->rasterizer.state.texture[i].enable)
- continue;
-
- int32_t texcoords[8];
- texture_unit_t& u(c->textures.tmu[i]);
-
- // validate this tmu (bind, wrap, filter)
- validate_tmu(c, i);
- // we CLAMP here, which works with premultiplied (s,t)
- c->rasterizer.procs.texParameteri(c,
- GGL_TEXTURE_2D, GGL_TEXTURE_WRAP_S, GGL_CLAMP);
- c->rasterizer.procs.texParameteri(c,
- GGL_TEXTURE_2D, GGL_TEXTURE_WRAP_T, GGL_CLAMP);
- u.dirty = 0xFF; // XXX: should be more subtle
-
- EGLTextureObject* textureObject = u.texture;
- const GLint Ucr = textureObject->crop_rect[0] << 16;
- const GLint Vcr = textureObject->crop_rect[1] << 16;
- const GLint Wcr = textureObject->crop_rect[2] << 16;
- const GLint Hcr = textureObject->crop_rect[3] << 16;
-
- // computes texture coordinates (pre-multiplied)
- int32_t dsdx = Wcr / w; // dsdx = ((Wcr/w)/Wt)*Wt
- int32_t dtdy =-Hcr / h; // dtdy = -((Hcr/h)/Ht)*Ht
- int32_t s0 = Ucr - gglMulx(dsdx, x); // s0 = Ucr - x * dsdx
- int32_t t0 = (Vcr+Hcr) - gglMulx(dtdy, y); // t0 = (Vcr+Hcr) - y*dtdy
- texcoords[0] = s0;
- texcoords[1] = dsdx;
- texcoords[2] = 0;
- texcoords[3] = t0;
- texcoords[4] = 0;
- texcoords[5] = dtdy;
- texcoords[6] = 0;
- texcoords[7] = 0;
- c->rasterizer.procs.texCoordGradScale8xv(c, i, texcoords);
- }
-
- const uint32_t enables = c->rasterizer.state.enables;
- if (ggl_unlikely(enables & (GGL_ENABLE_DEPTH_TEST|GGL_ENABLE_FOG)))
- set_depth_and_fog(c, z);
-
- c->rasterizer.procs.activeTexture(c, c->textures.active);
- c->rasterizer.procs.color4xv(c, c->currentColorClamped.v);
- c->rasterizer.procs.disable(c, GGL_W_LERP);
- c->rasterizer.procs.disable(c, GGL_AA);
- c->rasterizer.procs.shadeModel(c, GL_FLAT);
- c->rasterizer.procs.recti(c,
- gglFixedToIntRound(x),
- gglFixedToIntRound(y),
- gglFixedToIntRound(x)+w,
- gglFixedToIntRound(y)+h);
-
- ogles_unlock_textures(c);
-}
-
-static void drawTexxOES(GLfixed x, GLfixed y, GLfixed z, GLfixed w, GLfixed h,
- ogles_context_t* c)
-{
- // quickly reject empty rects
- if ((w|h) <= 0)
- return;
-
- drawTexxOESImp(x, y, z, w, h, c);
-}
-
-static void drawTexiOES(GLint x, GLint y, GLint z, GLint w, GLint h, ogles_context_t* c)
-{
- // All coordinates are integer, so if we have only one
- // texture unit active and no scaling is required
- // THEN, we can use our special 1:1 mapping
- // which is a lot faster.
-
- if (ggl_likely(c->rasterizer.state.enabled_tmu == 1)) {
- const int tmu = 0;
- texture_unit_t& u(c->textures.tmu[tmu]);
- EGLTextureObject* textureObject = u.texture;
- const GLint Wcr = textureObject->crop_rect[2];
- const GLint Hcr = textureObject->crop_rect[3];
-
- if ((w == Wcr) && (h == -Hcr)) {
- if ((w|h) <= 0) return; // quickly reject empty rects
-
- if (u.dirty) {
- c->rasterizer.procs.activeTexture(c, tmu);
- c->rasterizer.procs.bindTexture(c, &(u.texture->surface));
- c->rasterizer.procs.texParameteri(c, GGL_TEXTURE_2D,
- GGL_TEXTURE_MIN_FILTER, u.texture->min_filter);
- c->rasterizer.procs.texParameteri(c, GGL_TEXTURE_2D,
- GGL_TEXTURE_MAG_FILTER, u.texture->mag_filter);
- }
- c->rasterizer.procs.texGeni(c, GGL_S,
- GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE);
- c->rasterizer.procs.texGeni(c, GGL_T,
- GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE);
- u.dirty = 0xFF; // XXX: should be more subtle
- c->rasterizer.procs.activeTexture(c, c->textures.active);
-
- const GGLSurface& cbSurface = c->rasterizer.state.buffers.color.s;
- y = cbSurface.height - (y + h);
- const GLint Ucr = textureObject->crop_rect[0];
- const GLint Vcr = textureObject->crop_rect[1];
- const GLint s0 = Ucr - x;
- const GLint t0 = (Vcr + Hcr) - y;
-
- const GLuint tw = textureObject->surface.width;
- const GLuint th = textureObject->surface.height;
- if ((uint32_t(s0+x+w) > tw) || (uint32_t(t0+y+h) > th)) {
- // The GL spec is unclear about what should happen
- // in this case, so we just use the slow case, which
- // at least won't crash
- goto slow_case;
- }
-
- ogles_lock_textures(c);
-
- c->rasterizer.procs.texCoord2i(c, s0, t0);
- const uint32_t enables = c->rasterizer.state.enables;
- if (ggl_unlikely(enables & (GGL_ENABLE_DEPTH_TEST|GGL_ENABLE_FOG)))
- set_depth_and_fog(c, gglIntToFixed(z));
-
- c->rasterizer.procs.color4xv(c, c->currentColorClamped.v);
- c->rasterizer.procs.disable(c, GGL_W_LERP);
- c->rasterizer.procs.disable(c, GGL_AA);
- c->rasterizer.procs.shadeModel(c, GL_FLAT);
- c->rasterizer.procs.recti(c, x, y, x+w, y+h);
-
- ogles_unlock_textures(c);
-
- return;
- }
- }
-
-slow_case:
- drawTexxOESImp(
- gglIntToFixed(x), gglIntToFixed(y), gglIntToFixed(z),
- gglIntToFixed(w), gglIntToFixed(h),
- c);
-}
-
-
-}; // namespace android
-// ----------------------------------------------------------------------------
-
-using namespace android;
-
-
-#if 0
-#pragma mark -
-#pragma mark Texture API
-#endif
-
-void glActiveTexture(GLenum texture)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (uint32_t(texture-GL_TEXTURE0) > uint32_t(GGL_TEXTURE_UNIT_COUNT)) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- c->textures.active = texture - GL_TEXTURE0;
- c->rasterizer.procs.activeTexture(c, c->textures.active);
-}
-
-void glBindTexture(GLenum target, GLuint texture)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
-
- // Bind or create a texture
- sp<EGLTextureObject> tex;
- if (texture == 0) {
- // 0 is our local texture object
- tex = c->textures.defaultTexture;
- } else {
- tex = c->surfaceManager->texture(texture);
- if (ggl_unlikely(tex == 0)) {
- tex = c->surfaceManager->createTexture(texture);
- if (tex == 0) {
- ogles_error(c, GL_OUT_OF_MEMORY);
- return;
- }
- }
- }
- bindTextureTmu(c, c->textures.active, texture, tex);
-}
-
-void glGenTextures(GLsizei n, GLuint *textures)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (n<0) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
- // generate unique (shared) texture names
- c->surfaceManager->getToken(n, textures);
-}
-
-void glDeleteTextures(GLsizei n, const GLuint *textures)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (n<0) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
-
- // If deleting a bound texture, bind this unit to 0
- for (int t=0 ; t<GGL_TEXTURE_UNIT_COUNT ; t++) {
- if (c->textures.tmu[t].name == 0)
- continue;
- for (int i=0 ; i<n ; i++) {
- if (textures[i] && (textures[i] == c->textures.tmu[t].name)) {
- // bind this tmu to texture 0
- sp<EGLTextureObject> tex(c->textures.defaultTexture);
- bindTextureTmu(c, t, 0, tex);
- }
- }
- }
- c->surfaceManager->deleteTextures(n, textures);
- c->surfaceManager->recycleTokens(n, textures);
-}
-
-void glMultiTexCoord4f(
- GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (uint32_t(target-GL_TEXTURE0) > uint32_t(GGL_TEXTURE_UNIT_COUNT)) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- const int tmu = target-GL_TEXTURE0;
- c->current.texture[tmu].S = gglFloatToFixed(s);
- c->current.texture[tmu].T = gglFloatToFixed(t);
- c->current.texture[tmu].R = gglFloatToFixed(r);
- c->current.texture[tmu].Q = gglFloatToFixed(q);
-}
-
-void glMultiTexCoord4x(
- GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (uint32_t(target-GL_TEXTURE0) > uint32_t(GGL_TEXTURE_UNIT_COUNT)) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- const int tmu = target-GL_TEXTURE0;
- c->current.texture[tmu].S = s;
- c->current.texture[tmu].T = t;
- c->current.texture[tmu].R = r;
- c->current.texture[tmu].Q = q;
-}
-
-void glPixelStorei(GLenum pname, GLint param)
-{
- ogles_context_t* c = ogles_context_t::get();
- if ((pname != GL_PACK_ALIGNMENT) && (pname != GL_UNPACK_ALIGNMENT)) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- if ((param<=0 || param>8) || (param & (param-1))) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
- if (pname == GL_PACK_ALIGNMENT)
- c->textures.packAlignment = param;
- if (pname == GL_UNPACK_ALIGNMENT)
- c->textures.unpackAlignment = param;
-}
-
-void glTexEnvf(GLenum target, GLenum pname, GLfloat param)
-{
- ogles_context_t* c = ogles_context_t::get();
- c->rasterizer.procs.texEnvi(c, target, pname, GLint(param));
-}
-
-void glTexEnvfv(
- GLenum target, GLenum pname, const GLfloat *params)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (pname == GL_TEXTURE_ENV_MODE) {
- c->rasterizer.procs.texEnvi(c, target, pname, GLint(*params));
- return;
- }
- if (pname == GL_TEXTURE_ENV_COLOR) {
- GGLfixed fixed[4];
- for (int i=0 ; i<4 ; i++)
- fixed[i] = gglFloatToFixed(params[i]);
- c->rasterizer.procs.texEnvxv(c, target, pname, fixed);
- return;
- }
- ogles_error(c, GL_INVALID_ENUM);
-}
-
-void glTexEnvx(GLenum target, GLenum pname, GLfixed param)
-{
- ogles_context_t* c = ogles_context_t::get();
- c->rasterizer.procs.texEnvi(c, target, pname, param);
-}
-
-void glTexEnvxv(
- GLenum target, GLenum pname, const GLfixed *params)
-{
- ogles_context_t* c = ogles_context_t::get();
- c->rasterizer.procs.texEnvxv(c, target, pname, params);
-}
-
-void glTexParameteriv(
- GLenum target, GLenum pname, const GLint* params)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
-
- EGLTextureObject* textureObject = c->textures.tmu[c->textures.active].texture;
- switch (pname) {
- case GL_TEXTURE_CROP_RECT_OES:
- memcpy(textureObject->crop_rect, params, 4*sizeof(GLint));
- break;
- default:
- texParameterx(target, pname, GLfixed(params[0]), c);
- return;
- }
-}
-
-void glTexParameterf(
- GLenum target, GLenum pname, GLfloat param)
-{
- ogles_context_t* c = ogles_context_t::get();
- texParameterx(target, pname, GLfixed(param), c);
-}
-
-void glTexParameterx(
- GLenum target, GLenum pname, GLfixed param)
-{
- ogles_context_t* c = ogles_context_t::get();
- texParameterx(target, pname, param, c);
-}
-
-void glTexParameteri(
- GLenum target, GLenum pname, GLint param)
-{
- ogles_context_t* c = ogles_context_t::get();
- texParameterx(target, pname, GLfixed(param), c);
-}
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#endif
-
-void glCompressedTexImage2D(
- GLenum target, GLint level, GLenum internalformat,
- GLsizei width, GLsizei height, GLint border,
- GLsizei imageSize, const GLvoid *data)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (target != GL_TEXTURE_2D) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- if (width<0 || height<0 || border!=0) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
-
- // "uncompress" the texture since pixelflinger doesn't support
- // any compressed texture format natively.
- GLenum format;
- GLenum type;
- switch (internalformat) {
- case GL_PALETTE8_RGB8_OES:
- case GL_PALETTE4_RGB8_OES:
- format = GL_RGB;
- type = GL_UNSIGNED_BYTE;
- break;
- case GL_PALETTE8_RGBA8_OES:
- case GL_PALETTE4_RGBA8_OES:
- format = GL_RGBA;
- type = GL_UNSIGNED_BYTE;
- break;
- case GL_PALETTE8_R5_G6_B5_OES:
- case GL_PALETTE4_R5_G6_B5_OES:
- format = GL_RGB;
- type = GL_UNSIGNED_SHORT_5_6_5;
- break;
- case GL_PALETTE8_RGBA4_OES:
- case GL_PALETTE4_RGBA4_OES:
- format = GL_RGBA;
- type = GL_UNSIGNED_SHORT_4_4_4_4;
- break;
- case GL_PALETTE8_RGB5_A1_OES:
- case GL_PALETTE4_RGB5_A1_OES:
- format = GL_RGBA;
- type = GL_UNSIGNED_SHORT_5_5_5_1;
- break;
-#ifdef GL_OES_compressed_ETC1_RGB8_texture
- case GL_ETC1_RGB8_OES:
- format = GL_RGB;
- type = GL_UNSIGNED_BYTE;
- break;
-#endif
- default:
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
-
- if (!data || !width || !height) {
- // unclear if this is an error or not...
- return;
- }
-
- int32_t size;
- GGLSurface* surface;
-
-#ifdef GL_OES_compressed_ETC1_RGB8_texture
- if (internalformat == GL_ETC1_RGB8_OES) {
- GLsizei compressedSize = etc1_get_encoded_data_size(width, height);
- if (compressedSize > imageSize) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
- int error = createTextureSurface(c, &surface, &size,
- level, format, type, width, height);
- if (error) {
- ogles_error(c, error);
- return;
- }
- if (etc1_decode_image(
- (const etc1_byte*)data,
- (etc1_byte*)surface->data,
- width, height, 3, surface->stride*3) != 0) {
- ogles_error(c, GL_INVALID_OPERATION);
- }
- return;
- }
-#endif
-
- // all mipmap levels are specified at once.
- const int numLevels = level<0 ? -level : 1;
-
- if (dataSizePalette4(numLevels, width, height, format) > imageSize) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
-
- for (int i=0 ; i<numLevels ; i++) {
- int lod_w = (width >> i) ? : 1;
- int lod_h = (height >> i) ? : 1;
- int error = createTextureSurface(c, &surface, &size,
- i, format, type, lod_w, lod_h);
- if (error) {
- ogles_error(c, error);
- return;
- }
- decodePalette4(data, i, width, height,
- surface->data, surface->stride, internalformat);
- }
-}
-
-
-void glTexImage2D(
- GLenum target, GLint level, GLint internalformat,
- GLsizei width, GLsizei height, GLint border,
- GLenum format, GLenum type, const GLvoid *pixels)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (target != GL_TEXTURE_2D) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- if (width<0 || height<0 || border!=0 || level < 0) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
- if (format != (GLenum)internalformat) {
- ogles_error(c, GL_INVALID_OPERATION);
- return;
- }
- if (validFormatType(c, format, type)) {
- return;
- }
-
- int32_t size = 0;
- GGLSurface* surface = 0;
- int error = createTextureSurface(c, &surface, &size,
- level, format, type, width, height);
- if (error) {
- ogles_error(c, error);
- return;
- }
-
- if (pixels) {
- const int32_t formatIdx = convertGLPixelFormat(format, type);
- const GGLFormat& pixelFormat(c->rasterizer.formats[formatIdx]);
- const int32_t align = c->textures.unpackAlignment-1;
- const int32_t bpr = ((width * pixelFormat.size) + align) & ~align;
- const int32_t stride = bpr / pixelFormat.size;
-
- GGLSurface userSurface;
- userSurface.version = sizeof(userSurface);
- userSurface.width = width;
- userSurface.height = height;
- userSurface.stride = stride;
- userSurface.format = formatIdx;
- userSurface.compressedFormat = 0;
- userSurface.data = (GLubyte*)pixels;
-
- int err = copyPixels(c, *surface, 0, 0, userSurface, 0, 0, width, height);
- if (err) {
- ogles_error(c, err);
- return;
- }
- generateMipmap(c, level);
- }
-}
-
-// ----------------------------------------------------------------------------
-
-void glCompressedTexSubImage2D(
- GLenum /*target*/, GLint /*level*/, GLint /*xoffset*/,
- GLint /*yoffset*/, GLsizei /*width*/, GLsizei /*height*/,
- GLenum /*format*/, GLsizei /*imageSize*/,
- const GLvoid* /*data*/)
-{
- ogles_context_t* c = ogles_context_t::get();
- ogles_error(c, GL_INVALID_ENUM);
-}
-
-void glTexSubImage2D(
- GLenum target, GLint level, GLint xoffset,
- GLint yoffset, GLsizei width, GLsizei height,
- GLenum format, GLenum type, const GLvoid *pixels)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (target != GL_TEXTURE_2D) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- if (xoffset<0 || yoffset<0 || width<0 || height<0 || level<0) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
- if (validFormatType(c, format, type)) {
- return;
- }
-
- // find out which texture is bound to the current unit
- const int active = c->textures.active;
- EGLTextureObject* tex = c->textures.tmu[active].texture;
- const GGLSurface& surface(tex->mip(level));
-
- if (!tex->internalformat || tex->direct) {
- ogles_error(c, GL_INVALID_OPERATION);
- return;
- }
-
- if (format != tex->internalformat) {
- ogles_error(c, GL_INVALID_OPERATION);
- return;
- }
- if ((xoffset + width > GLsizei(surface.width)) ||
- (yoffset + height > GLsizei(surface.height))) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
- if (!width || !height) {
- return; // okay, but no-op.
- }
-
- // figure out the size we need as well as the stride
- const int32_t formatIdx = convertGLPixelFormat(format, type);
- if (formatIdx == 0) { // we don't know what to do with this
- ogles_error(c, GL_INVALID_OPERATION);
- return;
- }
-
- const GGLFormat& pixelFormat(c->rasterizer.formats[formatIdx]);
- const int32_t align = c->textures.unpackAlignment-1;
- const int32_t bpr = ((width * pixelFormat.size) + align) & ~align;
- const int32_t stride = bpr / pixelFormat.size;
- GGLSurface userSurface;
- userSurface.version = sizeof(userSurface);
- userSurface.width = width;
- userSurface.height = height;
- userSurface.stride = stride;
- userSurface.format = formatIdx;
- userSurface.compressedFormat = 0;
- userSurface.data = (GLubyte*)pixels;
-
- int err = copyPixels(c,
- surface, xoffset, yoffset,
- userSurface, 0, 0, width, height);
- if (err) {
- ogles_error(c, err);
- return;
- }
-
- generateMipmap(c, level);
-
- // since we only changed the content of the texture, we don't need
- // to call bindTexture on the main rasterizer.
-}
-
-// ----------------------------------------------------------------------------
-
-void glCopyTexImage2D(
- GLenum target, GLint level, GLenum internalformat,
- GLint x, GLint y, GLsizei width, GLsizei height,
- GLint border)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (target != GL_TEXTURE_2D) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- if (internalformat<GL_ALPHA || internalformat>GL_LUMINANCE_ALPHA) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- if (width<0 || height<0 || border!=0 || level<0) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
-
- GLenum format = 0;
- GLenum type = GL_UNSIGNED_BYTE;
- const GGLSurface& cbSurface = c->rasterizer.state.buffers.color.s;
- const int cbFormatIdx = cbSurface.format;
- switch (cbFormatIdx) {
- case GGL_PIXEL_FORMAT_RGB_565:
- type = GL_UNSIGNED_SHORT_5_6_5;
- break;
- case GGL_PIXEL_FORMAT_RGBA_5551:
- type = GL_UNSIGNED_SHORT_5_5_5_1;
- break;
- case GGL_PIXEL_FORMAT_RGBA_4444:
- type = GL_UNSIGNED_SHORT_4_4_4_4;
- break;
- }
- switch (internalformat) {
- case GL_ALPHA:
- case GL_LUMINANCE_ALPHA:
- case GL_LUMINANCE:
- type = GL_UNSIGNED_BYTE;
- break;
- }
-
- // figure out the format to use for the new texture
- switch (cbFormatIdx) {
- case GGL_PIXEL_FORMAT_RGBA_8888:
- case GGL_PIXEL_FORMAT_A_8:
- case GGL_PIXEL_FORMAT_RGBA_5551:
- case GGL_PIXEL_FORMAT_RGBA_4444:
- format = internalformat;
- break;
- case GGL_PIXEL_FORMAT_RGBX_8888:
- case GGL_PIXEL_FORMAT_RGB_888:
- case GGL_PIXEL_FORMAT_RGB_565:
- case GGL_PIXEL_FORMAT_L_8:
- switch (internalformat) {
- case GL_LUMINANCE:
- case GL_RGB:
- format = internalformat;
- break;
- }
- break;
- }
-
- if (format == 0) {
- // invalid combination
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
-
- // create the new texture...
- int32_t size;
- GGLSurface* surface;
- int error = createTextureSurface(c, &surface, &size,
- level, format, type, width, height);
- if (error) {
- ogles_error(c, error);
- return;
- }
-
- // The bottom row is stored first in textures
- GGLSurface txSurface(*surface);
- txSurface.stride = -txSurface.stride;
-
- // (x,y) is the lower-left corner of colorBuffer
- y = cbSurface.height - (y + height);
-
- /* The GLES spec says:
- * If any of the pixels within the specified rectangle are outside
- * the framebuffer associated with the current rendering context,
- * then the values obtained for those pixels are undefined.
- */
- if (x+width > GLint(cbSurface.width))
- width = cbSurface.width - x;
-
- if (y+height > GLint(cbSurface.height))
- height = cbSurface.height - y;
-
- int err = copyPixels(c,
- txSurface, 0, 0,
- cbSurface, x, y, width, height);
- if (err) {
- ogles_error(c, err);
- }
-
- generateMipmap(c, level);
-}
-
-void glCopyTexSubImage2D(
- GLenum target, GLint level, GLint xoffset, GLint yoffset,
- GLint x, GLint y, GLsizei width, GLsizei height)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (target != GL_TEXTURE_2D) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- if (xoffset<0 || yoffset<0 || width<0 || height<0 || level<0) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
- if (!width || !height) {
- return; // okay, but no-op.
- }
-
- // find out which texture is bound to the current unit
- const int active = c->textures.active;
- EGLTextureObject* tex = c->textures.tmu[active].texture;
- const GGLSurface& surface(tex->mip(level));
-
- if (!tex->internalformat) {
- ogles_error(c, GL_INVALID_OPERATION);
- return;
- }
- if ((xoffset + width > GLsizei(surface.width)) ||
- (yoffset + height > GLsizei(surface.height))) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
-
- // The bottom row is stored first in textures
- GGLSurface txSurface(surface);
- txSurface.stride = -txSurface.stride;
-
- // (x,y) is the lower-left corner of colorBuffer
- const GGLSurface& cbSurface = c->rasterizer.state.buffers.color.s;
- y = cbSurface.height - (y + height);
-
- /* The GLES spec says:
- * If any of the pixels within the specified rectangle are outside
- * the framebuffer associated with the current rendering context,
- * then the values obtained for those pixels are undefined.
- */
- if (x+width > GLint(cbSurface.width))
- width = cbSurface.width - x;
-
- if (y+height > GLint(cbSurface.height))
- height = cbSurface.height - y;
-
- int err = copyPixels(c,
- txSurface, xoffset, yoffset,
- cbSurface, x, y, width, height);
- if (err) {
- ogles_error(c, err);
- return;
- }
-
- generateMipmap(c, level);
-}
-
-void glReadPixels(
- GLint x, GLint y, GLsizei width, GLsizei height,
- GLenum format, GLenum type, GLvoid *pixels)
-{
- ogles_context_t* c = ogles_context_t::get();
- if ((format != GL_RGBA) && (format != GL_RGB)) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- if ((type != GL_UNSIGNED_BYTE) && (type != GL_UNSIGNED_SHORT_5_6_5)) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
- if (width<0 || height<0) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
- if (x<0 || y<0) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
-
- int32_t formatIdx = GGL_PIXEL_FORMAT_NONE;
- if ((format == GL_RGBA) && (type == GL_UNSIGNED_BYTE)) {
- formatIdx = GGL_PIXEL_FORMAT_RGBA_8888;
- } else if ((format == GL_RGB) && (type == GL_UNSIGNED_SHORT_5_6_5)) {
- formatIdx = GGL_PIXEL_FORMAT_RGB_565;
- } else {
- ogles_error(c, GL_INVALID_OPERATION);
- return;
- }
-
- const GGLSurface& readSurface = c->rasterizer.state.buffers.read.s;
- if ((x+width > GLint(readSurface.width)) ||
- (y+height > GLint(readSurface.height))) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
-
- const GGLFormat& pixelFormat(c->rasterizer.formats[formatIdx]);
- const int32_t align = c->textures.packAlignment-1;
- const int32_t bpr = ((width * pixelFormat.size) + align) & ~align;
- const int32_t stride = bpr / pixelFormat.size;
-
- GGLSurface userSurface;
- userSurface.version = sizeof(userSurface);
- userSurface.width = width;
- userSurface.height = height;
- userSurface.stride = -stride; // bottom row is transfered first
- userSurface.format = formatIdx;
- userSurface.compressedFormat = 0;
- userSurface.data = (GLubyte*)pixels;
-
- // use pixel-flinger to handle all the conversions
- GGLContext* ggl = getRasterizer(c);
- if (!ggl) {
- // the only reason this would fail is because we ran out of memory
- ogles_error(c, GL_OUT_OF_MEMORY);
- return;
- }
-
- ggl->colorBuffer(ggl, &userSurface); // destination is user buffer
- ggl->bindTexture(ggl, &readSurface); // source is read-buffer
- ggl->texCoord2i(ggl, x, readSurface.height - (y + height));
- ggl->recti(ggl, 0, 0, width, height);
-}
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#pragma mark DrawTexture Extension
-#endif
-
-void glDrawTexsvOES(const GLshort* coords) {
- ogles_context_t* c = ogles_context_t::get();
- drawTexiOES(coords[0], coords[1], coords[2], coords[3], coords[4], c);
-}
-void glDrawTexivOES(const GLint* coords) {
- ogles_context_t* c = ogles_context_t::get();
- drawTexiOES(coords[0], coords[1], coords[2], coords[3], coords[4], c);
-}
-void glDrawTexsOES(GLshort x , GLshort y, GLshort z, GLshort w, GLshort h) {
- ogles_context_t* c = ogles_context_t::get();
- drawTexiOES(x, y, z, w, h, c);
-}
-void glDrawTexiOES(GLint x, GLint y, GLint z, GLint w, GLint h) {
- ogles_context_t* c = ogles_context_t::get();
- drawTexiOES(x, y, z, w, h, c);
-}
-
-void glDrawTexfvOES(const GLfloat* coords) {
- ogles_context_t* c = ogles_context_t::get();
- drawTexxOES(
- gglFloatToFixed(coords[0]),
- gglFloatToFixed(coords[1]),
- gglFloatToFixed(coords[2]),
- gglFloatToFixed(coords[3]),
- gglFloatToFixed(coords[4]),
- c);
-}
-void glDrawTexxvOES(const GLfixed* coords) {
- ogles_context_t* c = ogles_context_t::get();
- drawTexxOES(coords[0], coords[1], coords[2], coords[3], coords[4], c);
-}
-void glDrawTexfOES(GLfloat x, GLfloat y, GLfloat z, GLfloat w, GLfloat h){
- ogles_context_t* c = ogles_context_t::get();
- drawTexxOES(
- gglFloatToFixed(x), gglFloatToFixed(y), gglFloatToFixed(z),
- gglFloatToFixed(w), gglFloatToFixed(h),
- c);
-}
-void glDrawTexxOES(GLfixed x, GLfixed y, GLfixed z, GLfixed w, GLfixed h) {
- ogles_context_t* c = ogles_context_t::get();
- drawTexxOES(x, y, z, w, h, c);
-}
-
-// ----------------------------------------------------------------------------
-#if 0
-#pragma mark -
-#pragma mark EGL Image Extension
-#endif
-
-void glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
-
- if (image == EGL_NO_IMAGE_KHR) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
-
- ANativeWindowBuffer* native_buffer = (ANativeWindowBuffer*)image;
- if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
- if (native_buffer->common.version != sizeof(ANativeWindowBuffer)) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
-
- // bind it to the texture unit
- sp<EGLTextureObject> tex = getAndBindActiveTextureObject(c);
- tex->setImage(native_buffer);
-}
-
-void glEGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image)
-{
- ogles_context_t* c = ogles_context_t::get();
- if (target != GL_RENDERBUFFER_OES) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
-
- if (image == EGL_NO_IMAGE_KHR) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
-
- ANativeWindowBuffer* native_buffer = (ANativeWindowBuffer*)image;
- if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
- if (native_buffer->common.version != sizeof(ANativeWindowBuffer)) {
- ogles_error(c, GL_INVALID_VALUE);
- return;
- }
-
- // well, we're not supporting this extension anyways
-}
diff --git a/opengl/libagl/texture.h b/opengl/libagl/texture.h
deleted file mode 100644
index 98f7550..0000000
--- a/opengl/libagl/texture.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/* libs/opengles/texture.h
-**
-** Copyright 2006, 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.
-*/
-
-#ifndef ANDROID_OPENGLES_TEXTURE_H
-#define ANDROID_OPENGLES_TEXTURE_H
-
-#include <stdint.h>
-#include <stddef.h>
-#include <sys/types.h>
-
-#include <private/pixelflinger/ggl_context.h>
-
-#include <GLES/gl.h>
-
-#include "context.h"
-
-namespace android {
-
-void ogles_init_texture(ogles_context_t* c);
-void ogles_uninit_texture(ogles_context_t* c);
-void ogles_validate_texture(ogles_context_t* c);
-void ogles_lock_textures(ogles_context_t* c);
-void ogles_unlock_textures(ogles_context_t* c);
-
-}; // namespace android
-
-#endif // ANDROID_OPENGLES_TEXTURE_H
diff --git a/opengl/libagl/vertex.cpp b/opengl/libagl/vertex.cpp
deleted file mode 100644
index 9aacdb3..0000000
--- a/opengl/libagl/vertex.cpp
+++ /dev/null
@@ -1,247 +0,0 @@
-/* libs/opengles/vertex.cpp
-**
-** Copyright 2006, 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 <stdio.h>
-#include <stdlib.h>
-#include "context.h"
-#include "fp.h"
-#include "vertex.h"
-#include "state.h"
-#include "matrix.h"
-
-namespace android {
-
-// ----------------------------------------------------------------------------
-
-void ogles_init_vertex(ogles_context_t* c)
-{
- c->cull.enable = GL_FALSE;
- c->cull.cullFace = GL_BACK;
- c->cull.frontFace = GL_CCW;
-
- c->current.color.r = 0x10000;
- c->current.color.g = 0x10000;
- c->current.color.b = 0x10000;
- c->current.color.a = 0x10000;
-
- c->currentNormal.z = 0x10000;
-}
-
-void ogles_uninit_vertex(ogles_context_t* /*c*/)
-{
-}
-
-// ----------------------------------------------------------------------------
-// vertex processing
-// ----------------------------------------------------------------------------
-
-// Divides a vertex clip coordinates by W
-static inline
-void perspective(ogles_context_t* c, vertex_t* v, uint32_t enables)
-{
- // [x,y,z]window = vpt * ([x,y,z]clip / clip.w)
- // [w]window = 1/w
-
- // With a regular projection generated by glFrustum(),
- // we have w=-z, therefore, w is in [zNear, zFar].
- // Also, zNear and zFar are stricly positive,
- // and 1/w (window.w) is in [1/zFar, 1/zNear], usually this
- // means ]0, +inf[ -- however, it is always recommended
- // to use as large values as possible for zNear.
- // All in all, w is usually smaller than 1.0 (assuming
- // zNear is at least 1.0); and even if zNear is smaller than 1.0
- // values of w won't be too big.
-
- const int32_t rw = gglRecip28(v->clip.w);
- const GLfixed* const m = c->transforms.vpt.transform.matrix.m;
- v->window.w = rw;
- v->window.x = gglMulAddx(gglMulx(v->clip.x, rw, 16), m[ 0], m[12], 28);
- v->window.y = gglMulAddx(gglMulx(v->clip.y, rw, 16), m[ 5], m[13], 28);
- v->window.x = TRI_FROM_FIXED(v->window.x);
- v->window.y = TRI_FROM_FIXED(v->window.y);
- if (enables & GGL_ENABLE_DEPTH_TEST) {
- v->window.z = gglMulAddx(gglMulx(v->clip.z, rw, 16), m[10], m[14], 28);
- }
-}
-
-// frustum clipping and W-divide
-static inline
-void clipFrustumPerspective(ogles_context_t* c, vertex_t* v, uint32_t enables)
-{
- // ndc = clip / W
- // window = ncd * viewport
-
- // clip to the view-volume
- uint32_t clip = v->flags & vertex_t::CLIP_ALL;
- const GLfixed w = v->clip.w;
- if (v->clip.x < -w) clip |= vertex_t::CLIP_L;
- if (v->clip.x > w) clip |= vertex_t::CLIP_R;
- if (v->clip.y < -w) clip |= vertex_t::CLIP_B;
- if (v->clip.y > w) clip |= vertex_t::CLIP_T;
- if (v->clip.z < -w) clip |= vertex_t::CLIP_N;
- if (v->clip.z > w) clip |= vertex_t::CLIP_F;
-
- v->flags |= clip;
- c->arrays.cull &= clip;
-
- if (ggl_likely(!clip)) {
- // if the vertex is clipped, we don't do the perspective
- // divide, since we don't need its window coordinates.
- perspective(c, v, enables);
- }
-}
-
-// frustum clipping, user clipping and W-divide
-static inline
-void clipAllPerspective(ogles_context_t* c, vertex_t* v, uint32_t enables)
-{
- // compute eye coordinates
- c->arrays.mv_transform(
- &c->transforms.modelview.transform, &v->eye, &v->obj);
- v->flags |= vertex_t::EYE;
-
- // clip this vertex against each user clip plane
- uint32_t clip = 0;
- int planes = c->clipPlanes.enable;
- while (planes) {
- const int i = 31 - gglClz(planes);
- planes &= ~(1<<i);
- // XXX: we should have a special dot() for 2,3,4 coords vertices
- GLfixed d = dot4(c->clipPlanes.plane[i].equation.v, v->eye.v);
- if (d < 0) {
- clip |= 0x100<<i;
- }
- }
- v->flags |= clip;
-
- clipFrustumPerspective(c, v, enables);
-}
-
-// ----------------------------------------------------------------------------
-
-void ogles_vertex_project(ogles_context_t* c, vertex_t* v) {
- perspective(c, v, c->rasterizer.state.enables);
-}
-
-void ogles_vertex_perspective2D(ogles_context_t* c, vertex_t* v)
-{
- // here we assume w=1.0 and the viewport transformation
- // has been applied already.
- c->arrays.cull = 0;
- v->window.x = TRI_FROM_FIXED(v->clip.x);
- v->window.y = TRI_FROM_FIXED(v->clip.y);
- v->window.z = v->clip.z;
- v->window.w = v->clip.w << 12;
-}
-
-void ogles_vertex_perspective3DZ(ogles_context_t* c, vertex_t* v) {
- clipFrustumPerspective(c, v, GGL_ENABLE_DEPTH_TEST);
-}
-void ogles_vertex_perspective3D(ogles_context_t* c, vertex_t* v) {
- clipFrustumPerspective(c, v, 0);
-}
-void ogles_vertex_clipAllPerspective3DZ(ogles_context_t* c, vertex_t* v) {
- clipAllPerspective(c, v, GGL_ENABLE_DEPTH_TEST);
-}
-void ogles_vertex_clipAllPerspective3D(ogles_context_t* c, vertex_t* v) {
- clipAllPerspective(c, v, 0);
-}
-
-static void clipPlanex(GLenum plane, const GLfixed* equ, ogles_context_t* c)
-{
- const int p = plane - GL_CLIP_PLANE0;
- if (ggl_unlikely(uint32_t(p) > (GL_CLIP_PLANE5 - GL_CLIP_PLANE0))) {
- ogles_error(c, GL_INVALID_ENUM);
- return;
- }
-
- vec4_t& equation = c->clipPlanes.plane[p].equation;
- memcpy(equation.v, equ, sizeof(vec4_t));
-
- ogles_validate_transform(c, transform_state_t::MVIT);
- transform_t& mvit = c->transforms.mvit4;
- mvit.point4(&mvit, &equation, &equation);
-}
-
-// ----------------------------------------------------------------------------
-}; // namespace android
-// ----------------------------------------------------------------------------
-
-using namespace android;
-
-
-void glColor4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a)
-{
- ogles_context_t* c = ogles_context_t::get();
- c->current.color.r = gglFloatToFixed(r);
- c->currentColorClamped.r = gglClampx(c->current.color.r);
- c->current.color.g = gglFloatToFixed(g);
- c->currentColorClamped.g = gglClampx(c->current.color.g);
- c->current.color.b = gglFloatToFixed(b);
- c->currentColorClamped.b = gglClampx(c->current.color.b);
- c->current.color.a = gglFloatToFixed(a);
- c->currentColorClamped.a = gglClampx(c->current.color.a);
-}
-
-void glColor4x(GLfixed r, GLfixed g, GLfixed b, GLfixed a)
-{
- ogles_context_t* c = ogles_context_t::get();
- c->current.color.r = r;
- c->current.color.g = g;
- c->current.color.b = b;
- c->current.color.a = a;
- c->currentColorClamped.r = gglClampx(r);
- c->currentColorClamped.g = gglClampx(g);
- c->currentColorClamped.b = gglClampx(b);
- c->currentColorClamped.a = gglClampx(a);
-}
-
-void glNormal3f(GLfloat x, GLfloat y, GLfloat z)
-{
- ogles_context_t* c = ogles_context_t::get();
- c->currentNormal.x = gglFloatToFixed(x);
- c->currentNormal.y = gglFloatToFixed(y);
- c->currentNormal.z = gglFloatToFixed(z);
-}
-
-void glNormal3x(GLfixed x, GLfixed y, GLfixed z)
-{
- ogles_context_t* c = ogles_context_t::get();
- c->currentNormal.x = x;
- c->currentNormal.y = y;
- c->currentNormal.z = z;
-}
-
-// ----------------------------------------------------------------------------
-
-void glClipPlanef(GLenum plane, const GLfloat* equ)
-{
- const GLfixed equx[4] = {
- gglFloatToFixed(equ[0]),
- gglFloatToFixed(equ[1]),
- gglFloatToFixed(equ[2]),
- gglFloatToFixed(equ[3])
- };
- ogles_context_t* c = ogles_context_t::get();
- clipPlanex(plane, equx, c);
-}
-
-void glClipPlanex(GLenum plane, const GLfixed* equ)
-{
- ogles_context_t* c = ogles_context_t::get();
- clipPlanex(plane, equ, c);
-}
diff --git a/opengl/libagl/vertex.h b/opengl/libagl/vertex.h
deleted file mode 100644
index 55e6213..0000000
--- a/opengl/libagl/vertex.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/* libs/opengles/vertex.h
-**
-** Copyright 2006, 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.
-*/
-
-#ifndef ANDROID_OPENGLES_VERTEX_H
-#define ANDROID_OPENGLES_VERTEX_H
-
-#include <stdint.h>
-#include <stddef.h>
-#include <sys/types.h>
-
-namespace android {
-
-namespace gl {
-struct vertex_t;
-struct ogles_context_t;
-};
-
-void ogles_init_vertex(ogles_context_t* c);
-void ogles_uninit_vertex(ogles_context_t* c);
-
-void ogles_vertex_perspective2D(ogles_context_t*, vertex_t*);
-
-void ogles_vertex_perspective3D(ogles_context_t*, vertex_t*);
-void ogles_vertex_perspective3DZ(ogles_context_t*, vertex_t*);
-void ogles_vertex_clipAllPerspective3D(ogles_context_t*, vertex_t*);
-void ogles_vertex_clipAllPerspective3DZ(ogles_context_t*, vertex_t*);
-
-
-void ogles_vertex_project(ogles_context_t* c, vertex_t*);
-
-}; // namespace android
-
-#endif // ANDROID_OPENGLES_VERTEX_H
-
diff --git a/opengl/libs/EGL/Loader.cpp b/opengl/libs/EGL/Loader.cpp
index 23e11a8..e143260 100644
--- a/opengl/libs/EGL/Loader.cpp
+++ b/opengl/libs/EGL/Loader.cpp
@@ -51,12 +51,6 @@
* /vendor/lib/egl/libGLESv1_CM.so
* /vendor/lib/egl/libGLESv2.so
*
- * The software renderer for the emulator must be provided as a single
- * library at:
- *
- * /system/lib/egl/libGLES_android.so
- *
- *
* For backward compatibility and to facilitate the transition to
* this new naming scheme, the loader will additionally look for:
*
@@ -146,38 +140,6 @@
#endif
#endif
-static void setEmulatorGlesValue(void) {
- char prop[PROPERTY_VALUE_MAX];
- property_get("ro.kernel.qemu", prop, "0");
- if (atoi(prop) != 1) return;
-
- property_get("ro.kernel.qemu.gles",prop,"0");
- if (atoi(prop) == 1) {
- ALOGD("Emulator has host GPU support, qemu.gles is set to 1.");
- property_set("qemu.gles", "1");
- return;
- }
-
- // for now, checking the following
- // directory is good enough for emulator system images
- const char* vendor_lib_path =
-#if defined(__LP64__)
- "/vendor/lib64/egl";
-#else
- "/vendor/lib/egl";
-#endif
-
- const bool has_vendor_lib = (access(vendor_lib_path, R_OK) == 0);
- if (has_vendor_lib) {
- ALOGD("Emulator has vendor provided software renderer, qemu.gles is set to 2.");
- property_set("qemu.gles", "2");
- } else {
- ALOGD("Emulator without GPU support detected. "
- "Fallback to legacy software renderer, qemu.gles is set to 0.");
- property_set("qemu.gles", "0");
- }
-}
-
static const char* DRIVER_SUFFIX_PROPERTY = "ro.hardware.egl";
static const char* HAL_SUBNAME_KEY_PROPERTIES[2] = {
@@ -260,8 +222,6 @@
return cnx->dso;
}
- setEmulatorGlesValue();
-
// Check if we should use ANGLE early, so loading each driver doesn't require repeated queries.
if (android::GraphicsEnv::getInstance().shouldUseAngle()) {
cnx->shouldUseAngle = true;
diff --git a/opengl/libs/EGL/eglApi.cpp b/opengl/libs/EGL/eglApi.cpp
index 29a966d..c51a129 100644
--- a/opengl/libs/EGL/eglApi.cpp
+++ b/opengl/libs/EGL/eglApi.cpp
@@ -40,7 +40,6 @@
EGLDisplay eglGetDisplay(EGLNativeDisplayType display) {
ATRACE_CALL();
- clearError();
if (egl_init_drivers() == EGL_FALSE) {
return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY);
@@ -48,6 +47,7 @@
// Call down the chain, which usually points directly to the impl
// but may also be routed through layers
+ clearError();
egl_connection_t* const cnx = &gEGLImpl;
return cnx->platform.eglGetDisplay(display);
}
@@ -55,7 +55,6 @@
EGLDisplay eglGetPlatformDisplay(EGLenum platform, EGLNativeDisplayType display,
const EGLAttrib* attrib_list) {
ATRACE_CALL();
- clearError();
if (egl_init_drivers() == EGL_FALSE) {
return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY);
@@ -63,6 +62,7 @@
// Call down the chain, which usually points directly to the impl
// but may also be routed through layers
+ clearError();
egl_connection_t* const cnx = &gEGLImpl;
return cnx->platform.eglGetPlatformDisplay(platform, display, attrib_list);
}
@@ -239,13 +239,12 @@
// in which case we must make sure we've initialized ourselves, this
// happens the first time egl_get_display() is called.
- clearError();
-
if (egl_init_drivers() == EGL_FALSE) {
setError(EGL_BAD_PARAMETER, NULL);
return nullptr;
}
+ clearError();
egl_connection_t* const cnx = &gEGLImpl;
return cnx->platform.eglGetProcAddress(procname);
}
@@ -324,23 +323,21 @@
}
EGLBoolean eglBindAPI(EGLenum api) {
- clearError();
-
if (egl_init_drivers() == EGL_FALSE) {
return setError(EGL_BAD_PARAMETER, (EGLBoolean)EGL_FALSE);
}
+ clearError();
egl_connection_t* const cnx = &gEGLImpl;
return cnx->platform.eglBindAPI(api);
}
EGLenum eglQueryAPI(void) {
- clearError();
-
if (egl_init_drivers() == EGL_FALSE) {
return setError(EGL_BAD_PARAMETER, (EGLBoolean)EGL_FALSE);
}
+ clearError();
egl_connection_t* const cnx = &gEGLImpl;
return cnx->platform.eglQueryAPI();
}
@@ -595,23 +592,21 @@
}
EGLuint64NV eglGetSystemTimeFrequencyNV() {
- clearError();
-
if (egl_init_drivers() == EGL_FALSE) {
return setError(EGL_BAD_PARAMETER, (EGLuint64NV)EGL_FALSE);
}
+ clearError();
egl_connection_t* const cnx = &gEGLImpl;
return cnx->platform.eglGetSystemTimeFrequencyNV();
}
EGLuint64NV eglGetSystemTimeNV() {
- clearError();
-
if (egl_init_drivers() == EGL_FALSE) {
return setError(EGL_BAD_PARAMETER, (EGLuint64NV)EGL_FALSE);
}
+ clearError();
egl_connection_t* const cnx = &gEGLImpl;
return cnx->platform.eglGetSystemTimeNV();
}
diff --git a/opengl/libs/EGL/egl_platform_entries.cpp b/opengl/libs/EGL/egl_platform_entries.cpp
index e996be6..d1b4a4e 100644
--- a/opengl/libs/EGL/egl_platform_entries.cpp
+++ b/opengl/libs/EGL/egl_platform_entries.cpp
@@ -1379,6 +1379,9 @@
if (!_s.get())
return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
+ if (n_rects < 0 || (n_rects > 0 && rects == NULL))
+ return setError(EGL_BAD_PARAMETER, (EGLBoolean)EGL_FALSE);
+
egl_surface_t* const s = get_surface(draw);
if (CC_UNLIKELY(dp->traceGpuCompletion)) {
diff --git a/services/gpuservice/GpuService.cpp b/services/gpuservice/GpuService.cpp
index 42d566f..55a0c0a 100644
--- a/services/gpuservice/GpuService.cpp
+++ b/services/gpuservice/GpuService.cpp
@@ -273,7 +273,7 @@
result.append("\n");
}
if (dumpAll || dumpStats) {
- mGpuStats->dump(Vector<String16>(), &result);
+ mGpuStats->dump(args, &result);
result.append("\n");
}
if (dumpAll || dumpMemory) {
diff --git a/services/inputflinger/InputReader.cpp b/services/inputflinger/InputReader.cpp
index 4631bec..1cbf78e 100644
--- a/services/inputflinger/InputReader.cpp
+++ b/services/inputflinger/InputReader.cpp
@@ -819,14 +819,19 @@
}
InputDevice* device = mDevices.valueAt(deviceIndex);
- std::optional<int32_t> associatedDisplayId = device->getAssociatedDisplay();
+ if (!device->isEnabled()) {
+ ALOGW("Ignoring disabled device %s", device->getName().c_str());
+ return false;
+ }
+
+ std::optional<int32_t> associatedDisplayId = device->getAssociatedDisplayId();
// No associated display. By default, can dispatch to all displays.
if (!associatedDisplayId) {
return true;
}
if (*associatedDisplayId == ADISPLAY_ID_NONE) {
- ALOGW("Device has associated, but no associated display id.");
+ ALOGW("Device %s is associated with display ADISPLAY_ID_NONE.", device->getName().c_str());
return true;
}
@@ -1002,6 +1007,13 @@
}
void InputDevice::setEnabled(bool enabled, nsecs_t when) {
+ if (enabled && mAssociatedDisplayPort && !mAssociatedViewport) {
+ ALOGW("Cannot enable input device %s because it is associated with port %" PRIu8 ", "
+ "but the corresponding viewport is not found",
+ getName().c_str(), *mAssociatedDisplayPort);
+ enabled = false;
+ }
+
if (isEnabled() == enabled) {
return;
}
@@ -1103,6 +1115,7 @@
if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) {
// In most situations, no port will be specified.
mAssociatedDisplayPort = std::nullopt;
+ mAssociatedViewport = std::nullopt;
// Find the display port that corresponds to the current input port.
const std::string& inputPort = mIdentifier.location;
if (!inputPort.empty()) {
@@ -1112,6 +1125,23 @@
mAssociatedDisplayPort = std::make_optional(displayPort->second);
}
}
+
+ // If the device was explicitly disabled by the user, it would be present in the
+ // "disabledDevices" list. If it is associated with a specific display, and it was not
+ // explicitly disabled, then enable/disable the device based on whether we can find the
+ // corresponding viewport.
+ bool enabled = (config->disabledDevices.find(mId) == config->disabledDevices.end());
+ if (mAssociatedDisplayPort) {
+ mAssociatedViewport = config->getDisplayViewportByPort(*mAssociatedDisplayPort);
+ if (!mAssociatedViewport) {
+ ALOGW("Input device %s should be associated with display on port %" PRIu8 ", "
+ "but the corresponding viewport is not found.",
+ getName().c_str(), *mAssociatedDisplayPort);
+ enabled = false;
+ }
+ }
+
+ setEnabled(enabled, when);
}
for (InputMapper* mapper : mMappers) {
@@ -1276,9 +1306,15 @@
mContext->getListener()->notifyDeviceReset(&args);
}
-std::optional<int32_t> InputDevice::getAssociatedDisplay() {
+std::optional<int32_t> InputDevice::getAssociatedDisplayId() {
+ // Check if we had associated to the specific display.
+ if (mAssociatedViewport) {
+ return mAssociatedViewport->displayId;
+ }
+
+ // No associated display port, check if some InputMapper is associated.
for (InputMapper* mapper : mMappers) {
- std::optional<int32_t> associatedDisplayId = mapper->getAssociatedDisplay();
+ std::optional<int32_t> associatedDisplayId = mapper->getAssociatedDisplayId();
if (associatedDisplayId) {
return associatedDisplayId;
}
@@ -2229,6 +2265,22 @@
dump += StringPrintf(INDENT3 "DownTime: %" PRId64 "\n", mDownTime);
}
+std::optional<DisplayViewport> KeyboardInputMapper::findViewport(
+ nsecs_t when, const InputReaderConfiguration* config) {
+ const std::optional<uint8_t> displayPort = mDevice->getAssociatedDisplayPort();
+ if (displayPort) {
+ // Find the viewport that contains the same port
+ return mDevice->getAssociatedViewport();
+ }
+
+ // No associated display defined, try to find default display if orientationAware.
+ if (mParameters.orientationAware) {
+ return config->getDisplayViewportByType(ViewportType::VIEWPORT_INTERNAL);
+ }
+
+ return std::nullopt;
+}
+
void KeyboardInputMapper::configure(nsecs_t when,
const InputReaderConfiguration* config, uint32_t changes) {
InputMapper::configure(when, config, changes);
@@ -2239,9 +2291,7 @@
}
if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) {
- if (mParameters.orientationAware) {
- mViewport = config->getDisplayViewportByType(ViewportType::VIEWPORT_INTERNAL);
- }
+ mViewport = findViewport(when, config);
}
}
@@ -2521,6 +2571,12 @@
}
}
+std::optional<int32_t> KeyboardInputMapper::getAssociatedDisplayId() {
+ if (mViewport) {
+ return std::make_optional(mViewport->displayId);
+ }
+ return std::nullopt;
+}
// --- CursorInputMapper ---
@@ -2935,7 +2991,7 @@
}
}
-std::optional<int32_t> CursorInputMapper::getAssociatedDisplay() {
+std::optional<int32_t> CursorInputMapper::getAssociatedDisplayId() {
if (mParameters.hasAssociatedDisplay) {
if (mParameters.mode == Parameters::MODE_POINTER) {
return std::make_optional(mPointerController->getDisplayId());
@@ -3467,15 +3523,10 @@
const std::optional<uint8_t> displayPort = mDevice->getAssociatedDisplayPort();
if (displayPort) {
// Find the viewport that contains the same port
- std::optional<DisplayViewport> v = mConfig.getDisplayViewportByPort(*displayPort);
- if (!v) {
- ALOGW("Input device %s should be associated with display on port %" PRIu8 ", "
- "but the corresponding viewport is not found.",
- getDeviceName().c_str(), *displayPort);
- }
- return v;
+ return mDevice->getAssociatedViewport();
}
+ // Check if uniqueDisplayId is specified in idc file.
if (!mParameters.uniqueDisplayId.empty()) {
return mConfig.getDisplayViewportByUniqueId(mParameters.uniqueDisplayId);
}
@@ -3499,6 +3550,7 @@
return viewport;
}
+ // No associated display, return a non-display viewport.
DisplayViewport newViewport;
// Raw width and height in the natural orientation.
int32_t rawWidth = mRawPointerAxes.getRawWidth();
@@ -6508,7 +6560,7 @@
if (mDeviceMode == DEVICE_MODE_POINTER) {
mPointerController->getPosition(&xCursorPosition, &yCursorPosition);
}
- const int32_t displayId = getAssociatedDisplay().value_or(ADISPLAY_ID_NONE);
+ const int32_t displayId = getAssociatedDisplayId().value_or(ADISPLAY_ID_NONE);
const int32_t deviceId = getDeviceId();
std::vector<TouchVideoFrame> frames = mDevice->getEventHub()->getVideoFrames(deviceId);
std::for_each(frames.begin(), frames.end(),
@@ -6817,7 +6869,7 @@
return true;
}
-std::optional<int32_t> TouchInputMapper::getAssociatedDisplay() {
+std::optional<int32_t> TouchInputMapper::getAssociatedDisplayId() {
if (mParameters.hasAssociatedDisplay) {
if (mDeviceMode == DEVICE_MODE_POINTER) {
return std::make_optional(mPointerController->getDisplayId());
diff --git a/services/inputflinger/InputReader.h b/services/inputflinger/InputReader.h
index b7f94c1..0666ca5 100644
--- a/services/inputflinger/InputReader.h
+++ b/services/inputflinger/InputReader.h
@@ -265,7 +265,9 @@
inline std::optional<uint8_t> getAssociatedDisplayPort() const {
return mAssociatedDisplayPort;
}
-
+ inline std::optional<DisplayViewport> getAssociatedViewport() const {
+ return mAssociatedViewport;
+ }
inline void setMic(bool hasMic) { mHasMic = hasMic; }
inline bool hasMic() const { return mHasMic; }
@@ -324,7 +326,8 @@
return value;
}
- std::optional<int32_t> getAssociatedDisplay();
+ std::optional<int32_t> getAssociatedDisplayId();
+
private:
InputReaderContext* mContext;
int32_t mId;
@@ -339,6 +342,7 @@
uint32_t mSources;
bool mIsExternal;
std::optional<uint8_t> mAssociatedDisplayPort;
+ std::optional<DisplayViewport> mAssociatedViewport;
bool mHasMic;
bool mDropUntilNextSync;
@@ -718,9 +722,8 @@
virtual void updateExternalStylusState(const StylusState& state);
virtual void fadePointer();
- virtual std::optional<int32_t> getAssociatedDisplay() {
- return std::nullopt;
- }
+ virtual std::optional<int32_t> getAssociatedDisplayId() { return std::nullopt; }
+
protected:
InputDevice* mDevice;
InputReaderContext* mContext;
@@ -802,6 +805,7 @@
virtual int32_t getMetaState();
virtual void updateMetaState(int32_t keyCode);
+ virtual std::optional<int32_t> getAssociatedDisplayId();
private:
// The current viewport.
@@ -855,6 +859,8 @@
void updateLedState(bool reset);
void updateLedStateForModifier(LedState& ledState, int32_t led,
int32_t modifier, bool reset);
+ std::optional<DisplayViewport> findViewport(nsecs_t when,
+ const InputReaderConfiguration* config);
};
@@ -874,7 +880,8 @@
virtual void fadePointer();
- virtual std::optional<int32_t> getAssociatedDisplay();
+ virtual std::optional<int32_t> getAssociatedDisplayId();
+
private:
// Amount that trackball needs to move in order to generate a key event.
static const int32_t TRACKBALL_MOVEMENT_THRESHOLD = 6;
@@ -968,7 +975,8 @@
virtual void cancelTouch(nsecs_t when);
virtual void timeoutExpired(nsecs_t when);
virtual void updateExternalStylusState(const StylusState& state);
- virtual std::optional<int32_t> getAssociatedDisplay();
+ virtual std::optional<int32_t> getAssociatedDisplayId();
+
protected:
CursorButtonAccumulator mCursorButtonAccumulator;
CursorScrollAccumulator mCursorScrollAccumulator;
diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp
index d95ac96..348a12b 100644
--- a/services/inputflinger/tests/InputReader_test.cpp
+++ b/services/inputflinger/tests/InputReader_test.cpp
@@ -1556,10 +1556,14 @@
mReader->requestRefreshConfiguration(InputReaderConfiguration::CHANGE_DISPLAY_INFO);
mReader->loopOnce();
- // Check device.
+ // Device should only dispatch to the specified display.
ASSERT_EQ(deviceId, device->getId());
ASSERT_FALSE(mReader->canDispatchToDisplay(deviceId, DISPLAY_ID));
ASSERT_TRUE(mReader->canDispatchToDisplay(deviceId, SECONDARY_DISPLAY_ID));
+
+ // Can't dispatch event from a disabled device.
+ disableDevice(deviceId, device);
+ ASSERT_FALSE(mReader->canDispatchToDisplay(deviceId, SECONDARY_DISPLAY_ID));
}
@@ -1568,6 +1572,7 @@
class InputDeviceTest : public testing::Test {
protected:
static const char* DEVICE_NAME;
+ static const char* DEVICE_LOCATION;
static const int32_t DEVICE_ID;
static const int32_t DEVICE_GENERATION;
static const int32_t DEVICE_CONTROLLER_NUMBER;
@@ -1589,6 +1594,7 @@
mFakeEventHub->addDevice(DEVICE_ID, DEVICE_NAME, 0);
InputDeviceIdentifier identifier;
identifier.name = DEVICE_NAME;
+ identifier.location = DEVICE_LOCATION;
mDevice = new InputDevice(mFakeContext, DEVICE_ID, DEVICE_GENERATION,
DEVICE_CONTROLLER_NUMBER, identifier, DEVICE_CLASSES);
}
@@ -1603,6 +1609,7 @@
};
const char* InputDeviceTest::DEVICE_NAME = "device";
+const char* InputDeviceTest::DEVICE_LOCATION = "USB1";
const int32_t InputDeviceTest::DEVICE_ID = 1;
const int32_t InputDeviceTest::DEVICE_GENERATION = 2;
const int32_t InputDeviceTest::DEVICE_CONTROLLER_NUMBER = 0;
@@ -1755,6 +1762,49 @@
ASSERT_NO_FATAL_FAILURE(mapper2->assertProcessWasCalled());
}
+// A single input device is associated with a specific display. Check that:
+// 1. Device is disabled if the viewport corresponding to the associated display is not found
+// 2. Device is disabled when setEnabled API is called
+TEST_F(InputDeviceTest, Configure_AssignsDisplayPort) {
+ FakeInputMapper* mapper = new FakeInputMapper(mDevice, AINPUT_SOURCE_TOUCHSCREEN);
+ mDevice->addMapper(mapper);
+
+ // First Configuration.
+ mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), 0);
+
+ // Device should be enabled by default.
+ ASSERT_TRUE(mDevice->isEnabled());
+
+ // Prepare associated info.
+ constexpr uint8_t hdmi = 1;
+ const std::string UNIQUE_ID = "local:1";
+
+ mFakePolicy->addInputPortAssociation(DEVICE_LOCATION, hdmi);
+ mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(),
+ InputReaderConfiguration::CHANGE_DISPLAY_INFO);
+ // Device should be disabled because it is associated with a specific display via
+ // input port <-> display port association, but the corresponding display is not found
+ ASSERT_FALSE(mDevice->isEnabled());
+
+ // Prepare displays.
+ mFakePolicy->addDisplayViewport(SECONDARY_DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT,
+ DISPLAY_ORIENTATION_0, UNIQUE_ID, hdmi,
+ ViewportType::VIEWPORT_INTERNAL);
+ mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(),
+ InputReaderConfiguration::CHANGE_DISPLAY_INFO);
+ ASSERT_TRUE(mDevice->isEnabled());
+
+ // Device should be disabled after set disable.
+ mFakePolicy->addDisabledDevice(mDevice->getId());
+ mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(),
+ InputReaderConfiguration::CHANGE_ENABLED_STATE);
+ ASSERT_FALSE(mDevice->isEnabled());
+
+ // Device should still be disabled even found the associated display.
+ mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(),
+ InputReaderConfiguration::CHANGE_DISPLAY_INFO);
+ ASSERT_FALSE(mDevice->isEnabled());
+}
// --- InputMapperTest ---
@@ -1926,8 +1976,9 @@
void prepareDisplay(int32_t orientation);
- void testDPadKeyRotation(KeyboardInputMapper* mapper,
- int32_t originalScanCode, int32_t originalKeyCode, int32_t rotatedKeyCode);
+ void testDPadKeyRotation(KeyboardInputMapper* mapper, int32_t originalScanCode,
+ int32_t originalKeyCode, int32_t rotatedKeyCode,
+ int32_t displayId = ADISPLAY_ID_NONE);
};
/* Similar to setDisplayInfoAndReconfigure, but pre-populates all parameters except for the
@@ -1939,7 +1990,8 @@
}
void KeyboardInputMapperTest::testDPadKeyRotation(KeyboardInputMapper* mapper,
- int32_t originalScanCode, int32_t originalKeyCode, int32_t rotatedKeyCode) {
+ int32_t originalScanCode, int32_t originalKeyCode,
+ int32_t rotatedKeyCode, int32_t displayId) {
NotifyKeyArgs args;
process(mapper, ARBITRARY_TIME, EV_KEY, originalScanCode, 1);
@@ -1947,15 +1999,16 @@
ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action);
ASSERT_EQ(originalScanCode, args.scanCode);
ASSERT_EQ(rotatedKeyCode, args.keyCode);
+ ASSERT_EQ(displayId, args.displayId);
process(mapper, ARBITRARY_TIME, EV_KEY, originalScanCode, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action);
ASSERT_EQ(originalScanCode, args.scanCode);
ASSERT_EQ(rotatedKeyCode, args.keyCode);
+ ASSERT_EQ(displayId, args.displayId);
}
-
TEST_F(KeyboardInputMapperTest, GetSources) {
KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice,
AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC);
@@ -2136,47 +2189,47 @@
addMapperAndConfigure(mapper);
prepareDisplay(DISPLAY_ORIENTATION_0);
- ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
- KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_UP));
- ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
- KEY_RIGHT, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_RIGHT));
- ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
- KEY_DOWN, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_DOWN));
- ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
- KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_LEFT));
+ ASSERT_NO_FATAL_FAILURE(
+ testDPadKeyRotation(mapper, KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_UP, DISPLAY_ID));
+ ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, KEY_RIGHT, AKEYCODE_DPAD_RIGHT,
+ AKEYCODE_DPAD_RIGHT, DISPLAY_ID));
+ ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, KEY_DOWN, AKEYCODE_DPAD_DOWN,
+ AKEYCODE_DPAD_DOWN, DISPLAY_ID));
+ ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, KEY_LEFT, AKEYCODE_DPAD_LEFT,
+ AKEYCODE_DPAD_LEFT, DISPLAY_ID));
clearViewports();
prepareDisplay(DISPLAY_ORIENTATION_90);
- ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
- KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_LEFT));
- ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
- KEY_RIGHT, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_UP));
- ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
- KEY_DOWN, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_RIGHT));
- ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
- KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_DOWN));
+ ASSERT_NO_FATAL_FAILURE(
+ testDPadKeyRotation(mapper, KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_LEFT, DISPLAY_ID));
+ ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, KEY_RIGHT, AKEYCODE_DPAD_RIGHT,
+ AKEYCODE_DPAD_UP, DISPLAY_ID));
+ ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, KEY_DOWN, AKEYCODE_DPAD_DOWN,
+ AKEYCODE_DPAD_RIGHT, DISPLAY_ID));
+ ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, KEY_LEFT, AKEYCODE_DPAD_LEFT,
+ AKEYCODE_DPAD_DOWN, DISPLAY_ID));
clearViewports();
prepareDisplay(DISPLAY_ORIENTATION_180);
- ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
- KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_DOWN));
- ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
- KEY_RIGHT, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_LEFT));
- ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
- KEY_DOWN, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_UP));
- ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
- KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_RIGHT));
+ ASSERT_NO_FATAL_FAILURE(
+ testDPadKeyRotation(mapper, KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_DOWN, DISPLAY_ID));
+ ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, KEY_RIGHT, AKEYCODE_DPAD_RIGHT,
+ AKEYCODE_DPAD_LEFT, DISPLAY_ID));
+ ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, KEY_DOWN, AKEYCODE_DPAD_DOWN,
+ AKEYCODE_DPAD_UP, DISPLAY_ID));
+ ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, KEY_LEFT, AKEYCODE_DPAD_LEFT,
+ AKEYCODE_DPAD_RIGHT, DISPLAY_ID));
clearViewports();
prepareDisplay(DISPLAY_ORIENTATION_270);
- ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
- KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_RIGHT));
- ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
- KEY_RIGHT, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_DOWN));
- ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
- KEY_DOWN, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_LEFT));
- ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
- KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_UP));
+ ASSERT_NO_FATAL_FAILURE(
+ testDPadKeyRotation(mapper, KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_RIGHT, DISPLAY_ID));
+ ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, KEY_RIGHT, AKEYCODE_DPAD_RIGHT,
+ AKEYCODE_DPAD_DOWN, DISPLAY_ID));
+ ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, KEY_DOWN, AKEYCODE_DPAD_DOWN,
+ AKEYCODE_DPAD_LEFT, DISPLAY_ID));
+ ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, KEY_LEFT, AKEYCODE_DPAD_LEFT,
+ AKEYCODE_DPAD_UP, DISPLAY_ID));
// Special case: if orientation changes while key is down, we still emit the same keycode
// in the key up as we did in the key down.
@@ -2360,6 +2413,84 @@
ASSERT_EQ(AMETA_NONE, mapper->getMetaState());
}
+TEST_F(KeyboardInputMapperTest, Configure_AssignsDisplayPort) {
+ // keyboard 1.
+ mFakeEventHub->addKey(DEVICE_ID, KEY_UP, 0, AKEYCODE_DPAD_UP, 0);
+ mFakeEventHub->addKey(DEVICE_ID, KEY_RIGHT, 0, AKEYCODE_DPAD_RIGHT, 0);
+ mFakeEventHub->addKey(DEVICE_ID, KEY_DOWN, 0, AKEYCODE_DPAD_DOWN, 0);
+ mFakeEventHub->addKey(DEVICE_ID, KEY_LEFT, 0, AKEYCODE_DPAD_LEFT, 0);
+
+ // keyboard 2.
+ const std::string USB2 = "USB2";
+ constexpr int32_t SECOND_DEVICE_ID = DEVICE_ID + 1;
+ InputDeviceIdentifier identifier;
+ identifier.name = "KEYBOARD2";
+ identifier.location = USB2;
+ std::unique_ptr<InputDevice> device2 =
+ std::make_unique<InputDevice>(mFakeContext, SECOND_DEVICE_ID, DEVICE_GENERATION,
+ DEVICE_CONTROLLER_NUMBER, identifier, DEVICE_CLASSES);
+ mFakeEventHub->addDevice(SECOND_DEVICE_ID, DEVICE_NAME, 0 /*classes*/);
+ mFakeEventHub->addKey(SECOND_DEVICE_ID, KEY_UP, 0, AKEYCODE_DPAD_UP, 0);
+ mFakeEventHub->addKey(SECOND_DEVICE_ID, KEY_RIGHT, 0, AKEYCODE_DPAD_RIGHT, 0);
+ mFakeEventHub->addKey(SECOND_DEVICE_ID, KEY_DOWN, 0, AKEYCODE_DPAD_DOWN, 0);
+ mFakeEventHub->addKey(SECOND_DEVICE_ID, KEY_LEFT, 0, AKEYCODE_DPAD_LEFT, 0);
+
+ KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, AINPUT_SOURCE_KEYBOARD,
+ AINPUT_KEYBOARD_TYPE_ALPHABETIC);
+ addMapperAndConfigure(mapper);
+
+ KeyboardInputMapper* mapper2 = new KeyboardInputMapper(device2.get(), AINPUT_SOURCE_KEYBOARD,
+ AINPUT_KEYBOARD_TYPE_ALPHABETIC);
+ device2->addMapper(mapper2);
+ device2->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), 0 /*changes*/);
+ device2->reset(ARBITRARY_TIME);
+
+ // Prepared displays and associated info.
+ constexpr uint8_t hdmi1 = 0;
+ constexpr uint8_t hdmi2 = 1;
+ const std::string SECONDARY_UNIQUE_ID = "local:1";
+
+ mFakePolicy->addInputPortAssociation(DEVICE_LOCATION, hdmi1);
+ mFakePolicy->addInputPortAssociation(USB2, hdmi2);
+
+ // No associated display viewport found, should disable the device.
+ device2->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(),
+ InputReaderConfiguration::CHANGE_DISPLAY_INFO);
+ ASSERT_FALSE(device2->isEnabled());
+
+ // Prepare second display.
+ constexpr int32_t newDisplayId = 2;
+ setDisplayInfoAndReconfigure(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_0,
+ UNIQUE_ID, hdmi1, ViewportType::VIEWPORT_INTERNAL);
+ setDisplayInfoAndReconfigure(newDisplayId, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_0,
+ SECONDARY_UNIQUE_ID, hdmi2, ViewportType::VIEWPORT_EXTERNAL);
+ // Default device will reconfigure above, need additional reconfiguration for another device.
+ device2->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(),
+ InputReaderConfiguration::CHANGE_DISPLAY_INFO);
+
+ // Device should be enabled after the associated display is found.
+ ASSERT_TRUE(mDevice->isEnabled());
+ ASSERT_TRUE(device2->isEnabled());
+
+ // Test pad key events
+ ASSERT_NO_FATAL_FAILURE(
+ testDPadKeyRotation(mapper, KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_UP, DISPLAY_ID));
+ ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, KEY_RIGHT, AKEYCODE_DPAD_RIGHT,
+ AKEYCODE_DPAD_RIGHT, DISPLAY_ID));
+ ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, KEY_DOWN, AKEYCODE_DPAD_DOWN,
+ AKEYCODE_DPAD_DOWN, DISPLAY_ID));
+ ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, KEY_LEFT, AKEYCODE_DPAD_LEFT,
+ AKEYCODE_DPAD_LEFT, DISPLAY_ID));
+
+ ASSERT_NO_FATAL_FAILURE(
+ testDPadKeyRotation(mapper2, KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_UP, newDisplayId));
+ ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper2, KEY_RIGHT, AKEYCODE_DPAD_RIGHT,
+ AKEYCODE_DPAD_RIGHT, newDisplayId));
+ ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper2, KEY_DOWN, AKEYCODE_DPAD_DOWN,
+ AKEYCODE_DPAD_DOWN, newDisplayId));
+ ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper2, KEY_LEFT, AKEYCODE_DPAD_LEFT,
+ AKEYCODE_DPAD_LEFT, newDisplayId));
+}
// --- CursorInputMapperTest ---
@@ -6276,12 +6407,13 @@
// Create the second touch screen device, and enable multi fingers.
const std::string USB2 = "USB2";
- const int32_t SECOND_DEVICE_ID = 2;
+ constexpr int32_t SECOND_DEVICE_ID = DEVICE_ID + 1;
InputDeviceIdentifier identifier;
- identifier.name = DEVICE_NAME;
+ identifier.name = "TOUCHSCREEN2";
identifier.location = USB2;
- InputDevice* device2 = new InputDevice(mFakeContext, SECOND_DEVICE_ID, DEVICE_GENERATION,
- DEVICE_CONTROLLER_NUMBER, identifier, DEVICE_CLASSES);
+ std::unique_ptr<InputDevice> device2 =
+ std::make_unique<InputDevice>(mFakeContext, SECOND_DEVICE_ID, DEVICE_GENERATION,
+ DEVICE_CONTROLLER_NUMBER, identifier, DEVICE_CLASSES);
mFakeEventHub->addDevice(SECOND_DEVICE_ID, DEVICE_NAME, 0 /*classes*/);
mFakeEventHub->addAbsoluteAxis(SECOND_DEVICE_ID, ABS_MT_POSITION_X, RAW_X_MIN, RAW_X_MAX,
0 /*flat*/, 0 /*fuzz*/);
@@ -6296,7 +6428,7 @@
String8("touchScreen"));
// Setup the second touch screen device.
- MultiTouchInputMapper* mapper2 = new MultiTouchInputMapper(device2);
+ MultiTouchInputMapper* mapper2 = new MultiTouchInputMapper(device2.get());
device2->addMapper(mapper2);
device2->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), 0 /*changes*/);
device2->reset(ARBITRARY_TIME);
diff --git a/services/surfaceflinger/Android.bp b/services/surfaceflinger/Android.bp
index afb9cec..93c738d 100644
--- a/services/surfaceflinger/Android.bp
+++ b/services/surfaceflinger/Android.bp
@@ -19,7 +19,7 @@
"-DEGL_EGLEXT_PROTOTYPES",
],
shared_libs: [
- "android.frameworks.vr.composer@1.0",
+ "android.frameworks.vr.composer@2.0",
"android.hardware.configstore-utils",
"android.hardware.configstore@1.0",
"android.hardware.configstore@1.1",
@@ -58,13 +58,24 @@
"libutils",
"libSurfaceFlingerProp",
],
+ // VrComposer is not used when building surfaceflinger for vendors
+ target: {
+ vendor: {
+ exclude_shared_libs: [
+ "android.frameworks.vr.composer@2.0",
+ ],
+ },
+ },
static_libs: [
"libcompositionengine",
+ "libperfetto_client_experimental",
"librenderengine",
"libserviceutils",
+ "libtimestats",
"libtrace_proto",
"libvr_manager",
"libvrflinger",
+ "perfetto_src_tracing_ipc",
],
header_libs: [
"android.hardware.graphics.composer@2.1-command-buffer",
@@ -73,8 +84,10 @@
],
export_static_lib_headers: [
"libcompositionengine",
+ "libperfetto_client_experimental",
"librenderengine",
"libserviceutils",
+ "libtimestats",
],
export_shared_lib_headers: [
"android.hardware.graphics.allocator@2.0",
@@ -134,6 +147,7 @@
"DisplayHardware/VirtualDisplaySurface.cpp",
"Effects/Daltonizer.cpp",
"EventLog/EventLog.cpp",
+ "FrameTracer/FrameTracer.cpp",
"FrameTracker.cpp",
"Layer.cpp",
"LayerProtoHelper.cpp",
@@ -160,7 +174,6 @@
"SurfaceFlinger.cpp",
"SurfaceInterceptor.cpp",
"SurfaceTracing.cpp",
- "TimeStats/TimeStats.cpp",
"TransactionCompletedThread.cpp",
],
}
@@ -177,6 +190,17 @@
// can be easily replaced.
"SurfaceFlingerFactory.cpp",
],
+ cflags: [
+ "-DUSE_VR_COMPOSER=1",
+ ],
+ // VrComposer is not used when building surfaceflinger for vendors
+ target: {
+ vendor: {
+ cflags: [
+ "-DUSE_VR_COMPOSER=0",
+ ],
+ },
+ },
logtags: ["EventLog/EventLogTags.logtags"],
}
@@ -230,7 +254,6 @@
subdirs = [
"layerproto",
- "TimeStats/timestatsproto",
"tests",
]
diff --git a/services/surfaceflinger/BufferLayer.cpp b/services/surfaceflinger/BufferLayer.cpp
index e9af9e2..26abe1c 100644
--- a/services/surfaceflinger/BufferLayer.cpp
+++ b/services/surfaceflinger/BufferLayer.cpp
@@ -51,6 +51,7 @@
#include "Colorizer.h"
#include "DisplayDevice.h"
+#include "FrameTracer/FrameTracer.h"
#include "LayerRejecter.h"
#include "TimeStats/TimeStats.h"
@@ -71,7 +72,9 @@
BufferLayer::~BufferLayer() {
mFlinger->deleteTextureAsync(mTextureName);
- mFlinger->mTimeStats->onDestroy(getSequence());
+ const int32_t layerID = getSequence();
+ mFlinger->mTimeStats->onDestroy(layerID);
+ mFlinger->mFrameTracer->onDestroy(layerID);
}
void BufferLayer::useSurfaceDamage() {
@@ -158,7 +161,8 @@
finished = true;
return;
}
- under.orSelf(layer->visibleRegion);
+
+ under.orSelf(layer->getScreenBounds());
});
// if not everything below us is covered, we plug the holes!
Region holes(targetSettings.clip.subtract(under));
@@ -314,12 +318,17 @@
if (presentFence->isValid()) {
mFlinger->mTimeStats->setPresentFence(layerID, mCurrentFrameNumber, presentFence);
+ mFlinger->mFrameTracer->traceFence(layerID, getCurrentBufferId(), mCurrentFrameNumber,
+ presentFence, FrameTracer::FrameEvent::PRESENT_FENCE);
mFrameTracker.setActualPresentFence(std::shared_ptr<FenceTime>(presentFence));
} else if (displayId && mFlinger->getHwComposer().isConnected(*displayId)) {
// The HWC doesn't support present fences, so use the refresh
// timestamp instead.
const nsecs_t actualPresentTime = mFlinger->getHwComposer().getRefreshTimestamp(*displayId);
mFlinger->mTimeStats->setPresentTime(layerID, mCurrentFrameNumber, actualPresentTime);
+ mFlinger->mFrameTracer->traceTimestamp(layerID, getCurrentBufferId(), mCurrentFrameNumber,
+ actualPresentTime,
+ FrameTracer::FrameEvent::PRESENT_FENCE);
mFrameTracker.setActualPresentTime(actualPresentTime);
}
diff --git a/services/surfaceflinger/BufferQueueLayer.cpp b/services/surfaceflinger/BufferQueueLayer.cpp
index 85a00fb..16c8561 100644
--- a/services/surfaceflinger/BufferQueueLayer.cpp
+++ b/services/surfaceflinger/BufferQueueLayer.cpp
@@ -29,6 +29,7 @@
#include "LayerRejecter.h"
#include "SurfaceInterceptor.h"
+#include "FrameTracer/FrameTracer.h"
#include "TimeStats/TimeStats.h"
namespace android {
@@ -45,6 +46,14 @@
void BufferQueueLayer::onLayerDisplayed(const sp<Fence>& releaseFence) {
mConsumer->setReleaseFence(releaseFence);
+
+ // Prevent tracing the same release multiple times.
+ if (mPreviousFrameNumber != mPreviousReleasedFrameNumber) {
+ mFlinger->mFrameTracer->traceFence(getSequence(), mPreviousBufferId, mPreviousFrameNumber,
+ std::make_shared<FenceTime>(releaseFence),
+ FrameTracer::FrameEvent::RELEASE_FENCE);
+ mPreviousReleasedFrameNumber = mPreviousFrameNumber;
+ }
}
void BufferQueueLayer::setTransformHint(uint32_t orientation) const {
@@ -329,6 +338,7 @@
mQueueItems.clear();
mQueuedFrames = 0;
mFlinger->mTimeStats->onDestroy(layerID);
+ mFlinger->mFrameTracer->onDestroy(layerID);
}
// Once we have hit this state, the shadow queue may no longer
@@ -355,9 +365,15 @@
mQueuedFrames--;
}
+ uint64_t bufferID = mQueueItems[0].mGraphicBuffer->getId();
mFlinger->mTimeStats->setAcquireFence(layerID, currentFrameNumber,
mQueueItems[0].mFenceTime);
+ mFlinger->mFrameTracer->traceFence(layerID, bufferID, currentFrameNumber,
+ mQueueItems[0].mFenceTime,
+ FrameTracer::FrameEvent::ACQUIRE_FENCE);
mFlinger->mTimeStats->setLatchTime(layerID, currentFrameNumber, latchTime);
+ mFlinger->mFrameTracer->traceTimestamp(layerID, bufferID, currentFrameNumber, latchTime,
+ FrameTracer::FrameEvent::LATCH);
mQueueItems.removeAt(0);
}
@@ -373,6 +389,7 @@
status_t BufferQueueLayer::updateActiveBuffer() {
// update the active buffer
+ mPreviousBufferId = getCurrentBufferId();
mActiveBuffer = mConsumer->getCurrentBuffer(&mActiveBufferSlot, &mActiveBufferFence);
auto& layerCompositionState = getCompositionLayer()->editState().frontEnd;
layerCompositionState.buffer = mActiveBuffer;
@@ -413,6 +430,11 @@
// -----------------------------------------------------------------------
void BufferQueueLayer::onFrameAvailable(const BufferItem& item) {
+ const int32_t layerID = getSequence();
+ mFlinger->mFrameTracer->traceNewLayer(layerID, getName().c_str());
+ mFlinger->mFrameTracer->traceTimestamp(layerID, item.mGraphicBuffer->getId(), item.mFrameNumber,
+ systemTime(), FrameTracer::FrameEvent::POST);
+
ATRACE_CALL();
// Add this buffer from our internal queue tracker
{ // Autolock scope
diff --git a/services/surfaceflinger/BufferQueueLayer.h b/services/surfaceflinger/BufferQueueLayer.h
index 3bc625e..bf3f917 100644
--- a/services/surfaceflinger/BufferQueueLayer.h
+++ b/services/surfaceflinger/BufferQueueLayer.h
@@ -128,6 +128,9 @@
uint64_t mPreviousFrameNumber{0};
bool mUpdateTexImageFailed{false};
+ uint64_t mPreviousBufferId = 0;
+ uint64_t mPreviousReleasedFrameNumber = 0;
+
// Local copy of the queued contents of the incoming BufferQueue
mutable Mutex mQueueItemLock;
Condition mQueueItemCondition;
diff --git a/services/surfaceflinger/BufferStateLayer.cpp b/services/surfaceflinger/BufferStateLayer.cpp
index e0804ff..e7d1b63 100644
--- a/services/surfaceflinger/BufferStateLayer.cpp
+++ b/services/surfaceflinger/BufferStateLayer.cpp
@@ -32,6 +32,7 @@
#include "BufferStateLayer.h"
#include "ColorLayer.h"
+#include "FrameTracer/FrameTracer.h"
#include "TimeStats/TimeStats.h"
namespace android {
@@ -87,6 +88,14 @@
break;
}
}
+
+ // Prevent tracing the same release multiple times.
+ if (mPreviousFrameNumber != mPreviousReleasedFrameNumber) {
+ mFlinger->mFrameTracer->traceFence(getSequence(), mPreviousBufferId, mPreviousFrameNumber,
+ std::make_shared<FenceTime>(releaseFence),
+ FrameTracer::FrameEvent::RELEASE_FENCE);
+ mPreviousReleasedFrameNumber = mPreviousFrameNumber;
+ }
}
void BufferStateLayer::setTransformHint(uint32_t /*orientation*/) const {
@@ -226,7 +235,11 @@
mCurrentState.modified = true;
setTransactionFlags(eTransactionNeeded);
- mFlinger->mTimeStats->setPostTime(getSequence(), mFrameNumber, getName().c_str(), postTime);
+ const int32_t layerID = getSequence();
+ mFlinger->mTimeStats->setPostTime(layerID, mFrameNumber, getName().c_str(), postTime);
+ mFlinger->mFrameTracer->traceNewLayer(layerID, getName().c_str());
+ mFlinger->mFrameTracer->traceTimestamp(layerID, buffer->getId(), mFrameNumber, postTime,
+ FrameTracer::FrameEvent::POST);
mCurrentState.desiredPresentTime = desiredPresentTime;
if (mFlinger->mUseSmart90ForVideo) {
@@ -557,12 +570,18 @@
status_t err = bindTextureImage();
if (err != NO_ERROR) {
mFlinger->mTimeStats->onDestroy(layerID);
+ mFlinger->mFrameTracer->onDestroy(layerID);
return BAD_VALUE;
}
}
+ const uint64_t bufferID = getCurrentBufferId();
mFlinger->mTimeStats->setAcquireFence(layerID, mFrameNumber, getCurrentFenceTime());
+ mFlinger->mFrameTracer->traceFence(layerID, bufferID, mFrameNumber, getCurrentFenceTime(),
+ FrameTracer::FrameEvent::ACQUIRE_FENCE);
mFlinger->mTimeStats->setLatchTime(layerID, mFrameNumber, latchTime);
+ mFlinger->mFrameTracer->traceTimestamp(layerID, bufferID, mFrameNumber, latchTime,
+ FrameTracer::FrameEvent::LATCH);
mCurrentStateModified = false;
@@ -576,6 +595,7 @@
return BAD_VALUE;
}
+ mPreviousBufferId = getCurrentBufferId();
mActiveBuffer = s.buffer;
mActiveBufferFence = s.acquireFence;
auto& layerCompositionState = getCompositionLayer()->editState().frontEnd;
@@ -586,6 +606,7 @@
status_t BufferStateLayer::updateFrameNumber(nsecs_t /*latchTime*/) {
// TODO(marissaw): support frame history events
+ mPreviousFrameNumber = mCurrentFrameNumber;
mCurrentFrameNumber = mFrameNumber;
return NO_ERROR;
}
diff --git a/services/surfaceflinger/BufferStateLayer.h b/services/surfaceflinger/BufferStateLayer.h
index f2a5dff..c763f5d 100644
--- a/services/surfaceflinger/BufferStateLayer.h
+++ b/services/surfaceflinger/BufferStateLayer.h
@@ -156,6 +156,9 @@
mutable uint32_t mFrameNumber{0};
sp<Fence> mPreviousReleaseFence;
+ uint64_t mPreviousBufferId = 0;
+ uint64_t mPreviousFrameNumber = 0;
+ uint64_t mPreviousReleasedFrameNumber = 0;
mutable bool mCurrentStateModified = false;
bool mReleasePreviousBuffer = false;
diff --git a/services/surfaceflinger/CompositionEngine/Android.bp b/services/surfaceflinger/CompositionEngine/Android.bp
index 580bde8..e49b65f 100644
--- a/services/surfaceflinger/CompositionEngine/Android.bp
+++ b/services/surfaceflinger/CompositionEngine/Android.bp
@@ -5,7 +5,7 @@
"-DLOG_TAG=\"CompositionEngine\"",
],
shared_libs: [
- "android.frameworks.vr.composer@1.0",
+ "android.frameworks.vr.composer@2.0",
"android.hardware.graphics.allocator@2.0",
"android.hardware.graphics.composer@2.1",
"android.hardware.graphics.composer@2.2",
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/CompositionEngine.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/CompositionEngine.h
index 31d6365..a8e05cb 100644
--- a/services/surfaceflinger/CompositionEngine/include/compositionengine/CompositionEngine.h
+++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/CompositionEngine.h
@@ -58,6 +58,12 @@
virtual bool needsAnotherUpdate() const = 0;
virtual nsecs_t getLastFrameRefreshTimestamp() const = 0;
+ // Presents the indicated outputs
+ virtual void present(CompositionRefreshArgs&) = 0;
+
+ // Updates the cursor position for the indicated outputs.
+ virtual void updateCursorAsync(CompositionRefreshArgs&) = 0;
+
// TODO(b/121291683): These will become private/internal
virtual void preComposition(CompositionRefreshArgs&) = 0;
};
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/CompositionRefreshArgs.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/CompositionRefreshArgs.h
index 20f131e..6f689ad 100644
--- a/services/surfaceflinger/CompositionEngine/include/compositionengine/CompositionRefreshArgs.h
+++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/CompositionRefreshArgs.h
@@ -16,8 +16,13 @@
#pragma once
+#include <chrono>
+#include <optional>
+
#include <compositionengine/Display.h>
#include <compositionengine/Layer.h>
+#include <compositionengine/OutputColorSetting.h>
+#include <math/mat4.h>
namespace android::compositionengine {
@@ -35,6 +40,31 @@
// the layers is important, and should be in traversal order from back to
// front.
Layers layers;
+
+ // If true, forces the entire display to be considered dirty and repainted
+ bool repaintEverything{false};
+
+ // Controls how the color mode is chosen for an output
+ OutputColorSetting outputColorSetting{OutputColorSetting::kEnhanced};
+
+ // If not Dataspace::UNKNOWN, overrides the dataspace on each output
+ ui::Dataspace colorSpaceAgnosticDataspace{ui::Dataspace::UNKNOWN};
+
+ // Forces a color mode on the outputs being refreshed
+ ui::ColorMode forceOutputColorMode{ui::ColorMode::NATIVE};
+
+ // If true, there was a geometry update this frame
+ bool updatingGeometryThisFrame{false};
+
+ // The color matrix to use for this
+ // frame. Only set if the color transform is changing this frame.
+ std::optional<mat4> colorTransformMatrix;
+
+ // If true, client composition is always used.
+ bool devOptForceClientComposition{false};
+
+ // If set, causes the dirty regions to flash with the delay
+ std::optional<std::chrono::microseconds> devOptFlashDirtyRegionsDelay;
};
} // namespace android::compositionengine
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFE.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFE.h
index 2a901ae..db4f969 100644
--- a/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFE.h
+++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFE.h
@@ -43,6 +43,10 @@
// geometry state can be skipped.
virtual void latchCompositionState(LayerFECompositionState&, bool includeGeometry) const = 0;
+ // Latches the minimal bit of state for the cursor for a fast asynchronous
+ // update.
+ virtual void latchCursorCompositionState(LayerFECompositionState&) const = 0;
+
struct ClientCompositionTargetSettings {
// The clip region, or visible region that is being rendered to
const Region& clip;
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFECompositionState.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFECompositionState.h
index d5763d5..b066cd1 100644
--- a/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFECompositionState.h
+++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFECompositionState.h
@@ -56,10 +56,6 @@
Region geomActiveTransparentRegion;
FloatRect geomLayerBounds;
- // TODO(lpique): b/121291683 Remove this one we are sure we don't need the
- // value recomputed / set every frame.
- Region geomVisibleRegion;
-
/*
* Presentation
*/
@@ -122,6 +118,13 @@
// True if the layer has protected content
bool hasProtectedContent{false};
+
+ /*
+ * Cursor state
+ */
+
+ // The output-independent frame for the cursor
+ Rect cursorFrame;
};
} // namespace android::compositionengine
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/Output.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/Output.h
index f73304d..a509ca8 100644
--- a/services/surfaceflinger/CompositionEngine/include/compositionengine/Output.h
+++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/Output.h
@@ -21,7 +21,6 @@
#include <string>
#include <unordered_map>
-#include <math/mat4.h>
#include <renderengine/LayerSettings.h>
#include <ui/Fence.h>
#include <ui/GraphicTypes.h>
@@ -43,6 +42,9 @@
class RenderSurface;
class OutputLayer;
+struct CompositionRefreshArgs;
+struct LayerFECompositionState;
+
namespace impl {
struct OutputCompositionState;
} // namespace impl
@@ -54,6 +56,7 @@
public:
using OutputLayers = std::vector<std::unique_ptr<compositionengine::OutputLayer>>;
using ReleasedLayers = std::vector<wp<LayerFE>>;
+ using UniqueFELayerStateMap = std::unordered_map<LayerFE*, LayerFECompositionState*>;
struct FrameFences {
sp<Fence> presentFence{Fence::NO_FENCE};
@@ -61,6 +64,13 @@
std::unordered_map<HWC2::Layer*, sp<Fence>> layerFences;
};
+ struct ColorProfile {
+ ui::ColorMode mode{ui::ColorMode::NATIVE};
+ ui::Dataspace dataspace{ui::Dataspace::UNKNOWN};
+ ui::RenderIntent renderIntent{ui::RenderIntent::COLORIMETRIC};
+ ui::Dataspace colorSpaceAgnosticDataspace{ui::Dataspace::UNKNOWN};
+ };
+
virtual ~Output();
// Returns true if the output is valid. This is meant to be checked post-
@@ -81,12 +91,8 @@
// belongsInOutput for full details.
virtual void setLayerStackFilter(uint32_t layerStackId, bool isInternal) = 0;
- // Sets the color transform matrix to use
- virtual void setColorTransform(const mat4&) = 0;
-
// Sets the output color mode
- virtual void setColorMode(ui::ColorMode, ui::Dataspace, ui::RenderIntent,
- ui::Dataspace colorSpaceAgnosticDataspace) = 0;
+ virtual void setColorProfile(const ColorProfile&) = 0;
// Outputs a string with a state dump
virtual void dump(std::string&) const = 0;
@@ -151,24 +157,28 @@
// Takes (moves) the set of layers being released this frame.
virtual ReleasedLayers takeReleasedLayers() = 0;
- // Signals that a frame is beginning on the output
- virtual void beginFrame() = 0;
+ // Prepare the output, updating the OutputLayers used in the output
+ virtual void prepare(CompositionRefreshArgs&) = 0;
- // Prepares a frame for display
- virtual void prepareFrame() = 0;
+ // Presents the output, finalizing all composition details
+ virtual void present(const CompositionRefreshArgs&) = 0;
- // Performs client composition as needed for layers on the output. The
- // output fence is set to a fence to signal when client composition is
- // finished.
- // Returns false if client composition cannot be performed.
- virtual bool composeSurfaces(const Region& debugFence, base::unique_fd* outReadyFence) = 0;
-
- // Posts the new frame, and sets release fences.
- virtual void postFramebuffer() = 0;
+ // Latches the front-end layer state for each output layer
+ virtual void updateLayerStateFromFE(const CompositionRefreshArgs&) const = 0;
protected:
virtual void setDisplayColorProfile(std::unique_ptr<DisplayColorProfile>) = 0;
virtual void setRenderSurface(std::unique_ptr<RenderSurface>) = 0;
+
+ virtual void updateAndWriteCompositionState(const CompositionRefreshArgs&) = 0;
+ virtual void setColorTransform(const CompositionRefreshArgs&) = 0;
+ virtual void updateColorProfile(const CompositionRefreshArgs&) = 0;
+ virtual void beginFrame() = 0;
+ virtual void prepareFrame() = 0;
+ virtual void devOptRepaintFlash(const CompositionRefreshArgs&) = 0;
+ virtual void finishFrame(const CompositionRefreshArgs&) = 0;
+ virtual std::optional<base::unique_fd> composeSurfaces(const Region&) = 0;
+ virtual void postFramebuffer() = 0;
virtual void chooseCompositionStrategy() = 0;
virtual bool getSkipColorTransform() const = 0;
virtual FrameFences presentAndGetFrameFences() = 0;
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/OutputColorSetting.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/OutputColorSetting.h
new file mode 100644
index 0000000..6e798ce
--- /dev/null
+++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/OutputColorSetting.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright 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.
+ */
+
+#pragma once
+
+namespace android::compositionengine {
+
+enum class OutputColorSetting : int32_t {
+ kManaged = 0,
+ kUnmanaged = 1,
+ kEnhanced = 2,
+};
+
+} // namespace android::compositionengine
\ No newline at end of file
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/OutputLayer.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/OutputLayer.h
index 5f62b32c..cedd728 100644
--- a/services/surfaceflinger/CompositionEngine/include/compositionengine/OutputLayer.h
+++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/OutputLayer.h
@@ -78,12 +78,18 @@
// skipped.
virtual void writeStateToHWC(bool includeGeometry) = 0;
+ // Updates the cursor position with the HWC
+ virtual void writeCursorPositionToHWC() const = 0;
+
// Returns the HWC2::Layer associated with this layer, if it exists
virtual HWC2::Layer* getHwcLayer() const = 0;
// Returns true if the current layer state requires client composition
virtual bool requiresClientComposition() const = 0;
+ // Returns true if the current layer should be treated as a cursor layer
+ virtual bool isHardwareCursor() const = 0;
+
// Applies a HWC device requested composition type change
virtual void applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition) = 0;
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/CompositionEngine.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/CompositionEngine.h
index 96e609d..6340b14 100644
--- a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/CompositionEngine.h
+++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/CompositionEngine.h
@@ -39,8 +39,14 @@
bool needsAnotherUpdate() const override;
nsecs_t getLastFrameRefreshTimestamp() const override;
+ void present(CompositionRefreshArgs&) override;
+
+ void updateCursorAsync(CompositionRefreshArgs&) override;
+
void preComposition(CompositionRefreshArgs&) override;
+ void updateLayerStateFromFE(CompositionRefreshArgs& args);
+
// Testing
void setNeedsAnotherUpdateForTest(bool);
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Display.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Display.h
index 36e4aac..bd1aa08 100644
--- a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Display.h
+++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Display.h
@@ -40,12 +40,13 @@
// compositionengine::Output overrides
void dump(std::string&) const override;
- void setColorTransform(const mat4&) override;
- void setColorMode(ui::ColorMode, ui::Dataspace, ui::RenderIntent, ui::Dataspace) override;
+ void setColorTransform(const compositionengine::CompositionRefreshArgs&) override;
+ void setColorProfile(const ColorProfile&) override;
void chooseCompositionStrategy() override;
bool getSkipColorTransform() const override;
compositionengine::Output::FrameFences presentAndGetFrameFences() override;
void setExpensiveRenderingExpected(bool) override;
+ void finishFrame(const compositionengine::CompositionRefreshArgs&) override;
// compositionengine::Display overrides
const std::optional<DisplayId>& getId() const override;
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/LayerCompositionState.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/LayerCompositionState.h
index ab01c20..726c850 100644
--- a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/LayerCompositionState.h
+++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/LayerCompositionState.h
@@ -21,6 +21,7 @@
#include <compositionengine/LayerFECompositionState.h>
#include <renderengine/Mesh.h>
+#include <ui/Region.h>
namespace android {
@@ -28,7 +29,7 @@
struct LayerCompositionState {
/*
- * State intended to be set by LayerFE::getCompositionState
+ * State set by LayerFE::getCompositionState
*/
LayerFECompositionState frontEnd;
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Output.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Output.h
index 3972f2b..d826161 100644
--- a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Output.h
+++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Output.h
@@ -44,8 +44,8 @@
void setBounds(const ui::Size&) override;
void setLayerStackFilter(uint32_t layerStackId, bool isInternal) override;
- void setColorTransform(const mat4&) override;
- void setColorMode(ui::ColorMode, ui::Dataspace, ui::RenderIntent, ui::Dataspace) override;
+ void setColorTransform(const compositionengine::CompositionRefreshArgs&) override;
+ void setColorProfile(const ColorProfile&) override;
void dump(std::string&) const override;
@@ -75,9 +75,17 @@
void setReleasedLayers(ReleasedLayers&&) override;
ReleasedLayers takeReleasedLayers() override;
+ void prepare(compositionengine::CompositionRefreshArgs&) override;
+ void present(const compositionengine::CompositionRefreshArgs&) override;
+
+ void updateLayerStateFromFE(const CompositionRefreshArgs&) const override;
+ void updateAndWriteCompositionState(const compositionengine::CompositionRefreshArgs&) override;
+ void updateColorProfile(const compositionengine::CompositionRefreshArgs&) override;
void beginFrame() override;
void prepareFrame() override;
- bool composeSurfaces(const Region&, base::unique_fd*) override;
+ void devOptRepaintFlash(const compositionengine::CompositionRefreshArgs&) override;
+ void finishFrame(const compositionengine::CompositionRefreshArgs&) override;
+ std::optional<base::unique_fd> composeSurfaces(const Region&) override;
void postFramebuffer() override;
// Testing
@@ -98,6 +106,9 @@
private:
void dirtyEntireOutput();
+ ui::Dataspace getBestDataspace(ui::Dataspace*, bool*) const;
+ compositionengine::Output::ColorProfile pickColorProfile(
+ const compositionengine::CompositionRefreshArgs&) const;
const CompositionEngine& mCompositionEngine;
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputCompositionState.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputCompositionState.h
index 1078f11..17d3d3f 100644
--- a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputCompositionState.h
+++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputCompositionState.h
@@ -86,11 +86,8 @@
// True if the last composition frame had visible layers
bool lastCompositionHadVisibleLayers{false};
- // The color transform to apply
- android_color_transform_t colorTransform{HAL_COLOR_TRANSFORM_IDENTITY};
-
- // The color transform matrix to apply, corresponding with colorTransform.
- mat4 colorTransformMat;
+ // The color transform matrix to apply
+ mat4 colorTransformMatrix;
// Current active color mode
ui::ColorMode colorMode{ui::ColorMode::NATIVE};
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputLayer.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputLayer.h
index 4c3f935..fa4d8cd 100644
--- a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputLayer.h
+++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputLayer.h
@@ -49,9 +49,11 @@
void updateCompositionState(bool) override;
void writeStateToHWC(bool) override;
+ void writeCursorPositionToHWC() const override;
HWC2::Layer* getHwcLayer() const override;
bool requiresClientComposition() const override;
+ bool isHardwareCursor() const override;
void applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition) override;
void prepareForDeviceLayerRequests() override;
void applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest request) override;
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputLayerCompositionState.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputLayerCompositionState.h
index de0f08a..1347449 100644
--- a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputLayerCompositionState.h
+++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputLayerCompositionState.h
@@ -40,9 +40,18 @@
namespace compositionengine::impl {
struct OutputLayerCompositionState {
- // The region of this layer which is visible on this output
+ // The portion of the layer that is not obscured by opaque layers on top
Region visibleRegion;
+ // The portion of the layer that is not obscured and is also opaque
+ Region visibleNonTransparentRegion;
+
+ // The portion of the layer that is obscured by opaque layers on top
+ Region coveredRegion;
+
+ // The visibleRegion transformed to output space
+ Region outputSpaceVisibleRegion;
+
// If true, client composition will be used on this output
bool forceClientComposition{false};
@@ -62,7 +71,7 @@
ui::Dataspace dataspace{ui::Dataspace::UNKNOWN};
// The Z order index of this layer on this output
- uint32_t z;
+ uint32_t z{0};
/*
* HWC state
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/CompositionEngine.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/CompositionEngine.h
index 82ecec5..e3254ac 100644
--- a/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/CompositionEngine.h
+++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/CompositionEngine.h
@@ -44,6 +44,9 @@
MOCK_CONST_METHOD0(needsAnotherUpdate, bool());
MOCK_CONST_METHOD0(getLastFrameRefreshTimestamp, nsecs_t());
+ MOCK_METHOD1(present, void(CompositionRefreshArgs&));
+ MOCK_METHOD1(updateCursorAsync, void(CompositionRefreshArgs&));
+
MOCK_METHOD1(preComposition, void(CompositionRefreshArgs&));
};
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/LayerFE.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/LayerFE.h
index 48c2dbf..e280295 100644
--- a/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/LayerFE.h
+++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/LayerFE.h
@@ -33,6 +33,7 @@
MOCK_METHOD1(onPreComposition, bool(nsecs_t));
MOCK_CONST_METHOD2(latchCompositionState, void(LayerFECompositionState&, bool));
+ MOCK_CONST_METHOD1(latchCursorCompositionState, void(LayerFECompositionState&));
MOCK_METHOD1(prepareClientComposition,
std::optional<renderengine::LayerSettings>(
compositionengine::LayerFE::ClientCompositionTargetSettings&));
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/Output.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/Output.h
index c944bec..33925d5 100644
--- a/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/Output.h
+++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/Output.h
@@ -16,6 +16,7 @@
#pragma once
+#include <compositionengine/CompositionRefreshArgs.h>
#include <compositionengine/DisplayColorProfile.h>
#include <compositionengine/Layer.h>
#include <compositionengine/LayerFE.h>
@@ -40,8 +41,8 @@
MOCK_METHOD1(setBounds, void(const ui::Size&));
MOCK_METHOD2(setLayerStackFilter, void(uint32_t, bool));
- MOCK_METHOD1(setColorTransform, void(const mat4&));
- MOCK_METHOD4(setColorMode, void(ui::ColorMode, ui::Dataspace, ui::RenderIntent, ui::Dataspace));
+ MOCK_METHOD1(setColorTransform, void(const compositionengine::CompositionRefreshArgs&));
+ MOCK_METHOD1(setColorProfile, void(const ColorProfile&));
MOCK_CONST_METHOD1(dump, void(std::string&));
MOCK_CONST_METHOD0(getName, const std::string&());
@@ -73,11 +74,23 @@
MOCK_METHOD1(setReleasedLayers, void(ReleasedLayers&&));
MOCK_METHOD0(takeReleasedLayers, ReleasedLayers());
+ MOCK_METHOD1(prepare, void(compositionengine::CompositionRefreshArgs&));
+ MOCK_METHOD1(present, void(const compositionengine::CompositionRefreshArgs&));
+
+ MOCK_CONST_METHOD1(updateLayerStateFromFE, void(const CompositionRefreshArgs&));
+ MOCK_METHOD1(updateAndWriteCompositionState, void(const CompositionRefreshArgs&));
+ MOCK_METHOD1(updateColorProfile, void(const compositionengine::CompositionRefreshArgs&));
+
MOCK_METHOD0(beginFrame, void());
+
MOCK_METHOD0(prepareFrame, void());
MOCK_METHOD0(chooseCompositionStrategy, void());
- MOCK_METHOD2(composeSurfaces, bool(const Region&, base::unique_fd*));
+ MOCK_METHOD1(devOptRepaintFlash, void(const compositionengine::CompositionRefreshArgs&));
+
+ MOCK_METHOD1(finishFrame, void(const compositionengine::CompositionRefreshArgs&));
+
+ MOCK_METHOD1(composeSurfaces, std::optional<base::unique_fd>(const Region&));
MOCK_CONST_METHOD0(getSkipColorTransform, bool());
MOCK_METHOD0(postFramebuffer, void());
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/OutputLayer.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/OutputLayer.h
index d8d637d..6b2224a 100644
--- a/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/OutputLayer.h
+++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/OutputLayer.h
@@ -40,9 +40,11 @@
MOCK_METHOD1(updateCompositionState, void(bool));
MOCK_METHOD1(writeStateToHWC, void(bool));
+ MOCK_CONST_METHOD0(writeCursorPositionToHWC, void());
MOCK_CONST_METHOD0(getHwcLayer, HWC2::Layer*());
MOCK_CONST_METHOD0(requiresClientComposition, bool());
+ MOCK_CONST_METHOD0(isHardwareCursor, bool());
MOCK_METHOD1(applyDeviceCompositionTypeChange, void(Hwc2::IComposerClient::Composition));
MOCK_METHOD0(prepareForDeviceLayerRequests, void());
MOCK_METHOD1(applyDeviceLayerRequest, void(Hwc2::IComposerClient::LayerRequest request));
diff --git a/services/surfaceflinger/CompositionEngine/src/CompositionEngine.cpp b/services/surfaceflinger/CompositionEngine/src/CompositionEngine.cpp
index 9558266..590c596 100644
--- a/services/surfaceflinger/CompositionEngine/src/CompositionEngine.cpp
+++ b/services/surfaceflinger/CompositionEngine/src/CompositionEngine.cpp
@@ -16,6 +16,7 @@
#include <compositionengine/CompositionRefreshArgs.h>
#include <compositionengine/LayerFE.h>
+#include <compositionengine/OutputLayer.h>
#include <compositionengine/impl/CompositionEngine.h>
#include <compositionengine/impl/Display.h>
#include <compositionengine/impl/Layer.h>
@@ -70,6 +71,34 @@
return mRefreshStartTime;
}
+void CompositionEngine::present(CompositionRefreshArgs& args) {
+ for (const auto& output : args.outputs) {
+ output->prepare(args);
+ }
+
+ updateLayerStateFromFE(args);
+
+ for (const auto& output : args.outputs) {
+ output->present(args);
+ }
+}
+
+void CompositionEngine::updateCursorAsync(CompositionRefreshArgs& args) {
+ std::unordered_map<compositionengine::LayerFE*, compositionengine::LayerFECompositionState*>
+ uniqueVisibleLayers;
+
+ for (const auto& output : args.outputs) {
+ for (auto& layer : output->getOutputLayersOrderedByZ()) {
+ if (layer->isHardwareCursor()) {
+ // Latch the cursor composition state from each front-end layer.
+ layer->getLayerFE().latchCursorCompositionState(
+ layer->getLayer().editState().frontEnd);
+ layer->writeCursorPositionToHWC();
+ }
+ }
+ }
+}
+
void CompositionEngine::preComposition(CompositionRefreshArgs& args) {
ATRACE_CALL();
ALOGV(__FUNCTION__);
@@ -92,5 +121,12 @@
mNeedsAnotherUpdate = value;
}
+void CompositionEngine::updateLayerStateFromFE(CompositionRefreshArgs& args) {
+ // Update the composition state from each front-end layer
+ for (const auto& output : args.outputs) {
+ output->updateLayerStateFromFE(args);
+ }
+}
+
} // namespace impl
} // namespace android::compositionengine
diff --git a/services/surfaceflinger/CompositionEngine/src/Display.cpp b/services/surfaceflinger/CompositionEngine/src/Display.cpp
index 6cd392e..000a294 100644
--- a/services/surfaceflinger/CompositionEngine/src/Display.cpp
+++ b/services/surfaceflinger/CompositionEngine/src/Display.cpp
@@ -16,6 +16,7 @@
#include <android-base/stringprintf.h>
#include <compositionengine/CompositionEngine.h>
+#include <compositionengine/CompositionRefreshArgs.h>
#include <compositionengine/DisplayCreationArgs.h>
#include <compositionengine/DisplaySurface.h>
#include <compositionengine/impl/Display.h>
@@ -68,24 +69,28 @@
mId.reset();
}
-void Display::setColorTransform(const mat4& transform) {
- Output::setColorTransform(transform);
+void Display::setColorTransform(const compositionengine::CompositionRefreshArgs& args) {
+ Output::setColorTransform(args);
+
+ if (!mId || CC_LIKELY(!args.colorTransformMatrix)) {
+ return;
+ }
auto& hwc = getCompositionEngine().getHwComposer();
- status_t result = hwc.setColorTransform(*mId, transform);
+ status_t result = hwc.setColorTransform(*mId, *args.colorTransformMatrix);
ALOGE_IF(result != NO_ERROR, "Failed to set color transform on display \"%s\": %d",
mId ? to_string(*mId).c_str() : "", result);
}
-void Display::setColorMode(ui::ColorMode mode, ui::Dataspace dataspace,
- ui::RenderIntent renderIntent,
- ui::Dataspace colorSpaceAgnosticDataspace) {
- ui::Dataspace targetDataspace =
- getDisplayColorProfile()->getTargetDataspace(mode, dataspace,
- colorSpaceAgnosticDataspace);
+void Display::setColorProfile(const ColorProfile& colorProfile) {
+ const ui::Dataspace targetDataspace =
+ getDisplayColorProfile()->getTargetDataspace(colorProfile.mode, colorProfile.dataspace,
+ colorProfile.colorSpaceAgnosticDataspace);
- if (mode == getState().colorMode && dataspace == getState().dataspace &&
- renderIntent == getState().renderIntent && targetDataspace == getState().targetDataspace) {
+ if (colorProfile.mode == getState().colorMode &&
+ colorProfile.dataspace == getState().dataspace &&
+ colorProfile.renderIntent == getState().renderIntent &&
+ targetDataspace == getState().targetDataspace) {
return;
}
@@ -94,10 +99,10 @@
return;
}
- Output::setColorMode(mode, dataspace, renderIntent, colorSpaceAgnosticDataspace);
+ Output::setColorProfile(colorProfile);
auto& hwc = getCompositionEngine().getHwComposer();
- hwc.setActiveColorMode(*mId, mode, renderIntent);
+ hwc.setActiveColorMode(*mId, colorProfile.mode, colorProfile.renderIntent);
}
void Display::dump(std::string& out) const {
@@ -259,4 +264,19 @@
}
}
+void Display::finishFrame(const compositionengine::CompositionRefreshArgs& refreshArgs) {
+ // We only need to actually compose the display if:
+ // 1) It is being handled by hardware composer, which may need this to
+ // keep its virtual display state machine in sync, or
+ // 2) There is work to be done (the dirty region isn't empty)
+ if (!mId) {
+ if (getDirtyRegion(refreshArgs.repaintEverything).isEmpty()) {
+ ALOGV("Skipping display composition");
+ return;
+ }
+ }
+
+ impl::Output::finishFrame(refreshArgs);
+}
+
} // namespace android::compositionengine::impl
diff --git a/services/surfaceflinger/CompositionEngine/src/Output.cpp b/services/surfaceflinger/CompositionEngine/src/Output.cpp
index 55fdacd..9f4f259 100644
--- a/services/surfaceflinger/CompositionEngine/src/Output.cpp
+++ b/services/surfaceflinger/CompositionEngine/src/Output.cpp
@@ -14,8 +14,11 @@
* limitations under the License.
*/
+#include <thread>
+
#include <android-base/stringprintf.h>
#include <compositionengine/CompositionEngine.h>
+#include <compositionengine/CompositionRefreshArgs.h>
#include <compositionengine/DisplayColorProfile.h>
#include <compositionengine/Layer.h>
#include <compositionengine/LayerFE.h>
@@ -96,43 +99,37 @@
dirtyEntireOutput();
}
-void Output::setColorTransform(const mat4& transform) {
- if (mState.colorTransformMat == transform) {
+void Output::setColorTransform(const compositionengine::CompositionRefreshArgs& args) {
+ if (!args.colorTransformMatrix || mState.colorTransformMatrix == *args.colorTransformMatrix) {
return;
}
- const bool isIdentity = (transform == mat4());
- const auto newColorTransform =
- isIdentity ? HAL_COLOR_TRANSFORM_IDENTITY : HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX;
-
- mState.colorTransform = newColorTransform;
- mState.colorTransformMat = transform;
+ mState.colorTransformMatrix = *args.colorTransformMatrix;
dirtyEntireOutput();
}
-void Output::setColorMode(ui::ColorMode mode, ui::Dataspace dataspace,
- ui::RenderIntent renderIntent,
- ui::Dataspace colorSpaceAgnosticDataspace) {
- ui::Dataspace targetDataspace =
- getDisplayColorProfile()->getTargetDataspace(mode, dataspace,
- colorSpaceAgnosticDataspace);
+void Output::setColorProfile(const ColorProfile& colorProfile) {
+ const ui::Dataspace targetDataspace =
+ getDisplayColorProfile()->getTargetDataspace(colorProfile.mode, colorProfile.dataspace,
+ colorProfile.colorSpaceAgnosticDataspace);
- if (mState.colorMode == mode && mState.dataspace == dataspace &&
- mState.renderIntent == renderIntent && mState.targetDataspace == targetDataspace) {
+ if (mState.colorMode == colorProfile.mode && mState.dataspace == colorProfile.dataspace &&
+ mState.renderIntent == colorProfile.renderIntent &&
+ mState.targetDataspace == targetDataspace) {
return;
}
- mState.colorMode = mode;
- mState.dataspace = dataspace;
- mState.renderIntent = renderIntent;
+ mState.colorMode = colorProfile.mode;
+ mState.dataspace = colorProfile.dataspace;
+ mState.renderIntent = colorProfile.renderIntent;
mState.targetDataspace = targetDataspace;
- mRenderSurface->setBufferDataspace(dataspace);
+ mRenderSurface->setBufferDataspace(colorProfile.dataspace);
ALOGV("Set active color mode: %s (%d), active render intent: %s (%d)",
- decodeColorMode(mode).c_str(), mode, decodeRenderIntent(renderIntent).c_str(),
- renderIntent);
+ decodeColorMode(colorProfile.mode).c_str(), colorProfile.mode,
+ decodeRenderIntent(colorProfile.renderIntent).c_str(), colorProfile.renderIntent);
dirtyEntireOutput();
}
@@ -258,6 +255,163 @@
return std::move(mReleasedLayers);
}
+void Output::prepare(compositionengine::CompositionRefreshArgs& refreshArgs) {
+ if (CC_LIKELY(!refreshArgs.updatingGeometryThisFrame)) {
+ return;
+ }
+
+ uint32_t zOrder = 0;
+ for (auto& layer : mOutputLayersOrderedByZ) {
+ // Assign a simple Z order sequence to each visible layer.
+ layer->editState().z = zOrder++;
+ }
+}
+
+void Output::present(const compositionengine::CompositionRefreshArgs& refreshArgs) {
+ updateColorProfile(refreshArgs);
+ updateAndWriteCompositionState(refreshArgs);
+ setColorTransform(refreshArgs);
+ beginFrame();
+ prepareFrame();
+ devOptRepaintFlash(refreshArgs);
+ finishFrame(refreshArgs);
+ postFramebuffer();
+}
+
+void Output::updateLayerStateFromFE(const CompositionRefreshArgs& args) const {
+ for (auto& layer : mOutputLayersOrderedByZ) {
+ layer->getLayerFE().latchCompositionState(layer->getLayer().editState().frontEnd,
+ args.updatingGeometryThisFrame);
+ }
+}
+
+void Output::updateAndWriteCompositionState(
+ const compositionengine::CompositionRefreshArgs& refreshArgs) {
+ ATRACE_CALL();
+ ALOGV(__FUNCTION__);
+
+ for (auto& layer : mOutputLayersOrderedByZ) {
+ if (refreshArgs.devOptForceClientComposition) {
+ layer->editState().forceClientComposition = true;
+ }
+
+ layer->updateCompositionState(refreshArgs.updatingGeometryThisFrame);
+
+ // Send the updated state to the HWC, if appropriate.
+ layer->writeStateToHWC(refreshArgs.updatingGeometryThisFrame);
+ }
+}
+
+void Output::updateColorProfile(const compositionengine::CompositionRefreshArgs& refreshArgs) {
+ setColorProfile(pickColorProfile(refreshArgs));
+}
+
+// Returns a data space that fits all visible layers. The returned data space
+// can only be one of
+// - Dataspace::SRGB (use legacy dataspace and let HWC saturate when colors are enhanced)
+// - Dataspace::DISPLAY_P3
+// - Dataspace::DISPLAY_BT2020
+// The returned HDR data space is one of
+// - Dataspace::UNKNOWN
+// - Dataspace::BT2020_HLG
+// - Dataspace::BT2020_PQ
+ui::Dataspace Output::getBestDataspace(ui::Dataspace* outHdrDataSpace,
+ bool* outIsHdrClientComposition) const {
+ ui::Dataspace bestDataSpace = ui::Dataspace::V0_SRGB;
+ *outHdrDataSpace = ui::Dataspace::UNKNOWN;
+
+ for (const auto& layer : mOutputLayersOrderedByZ) {
+ switch (layer->getLayer().getState().frontEnd.dataspace) {
+ case ui::Dataspace::V0_SCRGB:
+ case ui::Dataspace::V0_SCRGB_LINEAR:
+ case ui::Dataspace::BT2020:
+ case ui::Dataspace::BT2020_ITU:
+ case ui::Dataspace::BT2020_LINEAR:
+ case ui::Dataspace::DISPLAY_BT2020:
+ bestDataSpace = ui::Dataspace::DISPLAY_BT2020;
+ break;
+ case ui::Dataspace::DISPLAY_P3:
+ bestDataSpace = ui::Dataspace::DISPLAY_P3;
+ break;
+ case ui::Dataspace::BT2020_PQ:
+ case ui::Dataspace::BT2020_ITU_PQ:
+ bestDataSpace = ui::Dataspace::DISPLAY_P3;
+ *outHdrDataSpace = ui::Dataspace::BT2020_PQ;
+ *outIsHdrClientComposition =
+ layer->getLayer().getState().frontEnd.forceClientComposition;
+ break;
+ case ui::Dataspace::BT2020_HLG:
+ case ui::Dataspace::BT2020_ITU_HLG:
+ bestDataSpace = ui::Dataspace::DISPLAY_P3;
+ // When there's mixed PQ content and HLG content, we set the HDR
+ // data space to be BT2020_PQ and convert HLG to PQ.
+ if (*outHdrDataSpace == ui::Dataspace::UNKNOWN) {
+ *outHdrDataSpace = ui::Dataspace::BT2020_HLG;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ return bestDataSpace;
+}
+
+compositionengine::Output::ColorProfile Output::pickColorProfile(
+ const compositionengine::CompositionRefreshArgs& refreshArgs) const {
+ if (refreshArgs.outputColorSetting == OutputColorSetting::kUnmanaged) {
+ return ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
+ ui::RenderIntent::COLORIMETRIC,
+ refreshArgs.colorSpaceAgnosticDataspace};
+ }
+
+ ui::Dataspace hdrDataSpace;
+ bool isHdrClientComposition = false;
+ ui::Dataspace bestDataSpace = getBestDataspace(&hdrDataSpace, &isHdrClientComposition);
+
+ switch (refreshArgs.forceOutputColorMode) {
+ case ui::ColorMode::SRGB:
+ bestDataSpace = ui::Dataspace::V0_SRGB;
+ break;
+ case ui::ColorMode::DISPLAY_P3:
+ bestDataSpace = ui::Dataspace::DISPLAY_P3;
+ break;
+ default:
+ break;
+ }
+
+ // respect hdrDataSpace only when there is no legacy HDR support
+ const bool isHdr = hdrDataSpace != ui::Dataspace::UNKNOWN &&
+ !mDisplayColorProfile->hasLegacyHdrSupport(hdrDataSpace) && !isHdrClientComposition;
+ if (isHdr) {
+ bestDataSpace = hdrDataSpace;
+ }
+
+ ui::RenderIntent intent;
+ switch (refreshArgs.outputColorSetting) {
+ case OutputColorSetting::kManaged:
+ case OutputColorSetting::kUnmanaged:
+ intent = isHdr ? ui::RenderIntent::TONE_MAP_COLORIMETRIC
+ : ui::RenderIntent::COLORIMETRIC;
+ break;
+ case OutputColorSetting::kEnhanced:
+ intent = isHdr ? ui::RenderIntent::TONE_MAP_ENHANCE : ui::RenderIntent::ENHANCE;
+ break;
+ default: // vendor display color setting
+ intent = static_cast<ui::RenderIntent>(refreshArgs.outputColorSetting);
+ break;
+ }
+
+ ui::ColorMode outMode;
+ ui::Dataspace outDataSpace;
+ ui::RenderIntent outRenderIntent;
+ mDisplayColorProfile->getBestColorMode(bestDataSpace, intent, &outDataSpace, &outMode,
+ &outRenderIntent);
+
+ return ColorProfile{outMode, outDataSpace, outRenderIntent,
+ refreshArgs.colorSpaceAgnosticDataspace};
+}
+
void Output::beginFrame() {
const bool dirty = !getDirtyRegion(false).isEmpty();
const bool empty = mOutputLayersOrderedByZ.empty();
@@ -299,14 +453,59 @@
mRenderSurface->prepareFrame(mState.usesClientComposition, mState.usesDeviceComposition);
}
-bool Output::composeSurfaces(const Region& debugRegion, base::unique_fd* readyFence) {
+void Output::devOptRepaintFlash(const compositionengine::CompositionRefreshArgs& refreshArgs) {
+ if (CC_LIKELY(!refreshArgs.devOptFlashDirtyRegionsDelay)) {
+ return;
+ }
+
+ if (mState.isEnabled) {
+ // transform the dirty region into this screen's coordinate space
+ const Region dirtyRegion = getDirtyRegion(refreshArgs.repaintEverything);
+ if (!dirtyRegion.isEmpty()) {
+ base::unique_fd readyFence;
+ // redraw the whole screen
+ static_cast<void>(composeSurfaces(dirtyRegion));
+
+ mRenderSurface->queueBuffer(std::move(readyFence));
+ }
+ }
+
+ postFramebuffer();
+
+ std::this_thread::sleep_for(*refreshArgs.devOptFlashDirtyRegionsDelay);
+
+ prepareFrame();
+}
+
+void Output::finishFrame(const compositionengine::CompositionRefreshArgs&) {
+ ATRACE_CALL();
+ ALOGV(__FUNCTION__);
+
+ if (!mState.isEnabled) {
+ return;
+ }
+
+ // Repaint the framebuffer (if needed), getting the optional fence for when
+ // the composition completes.
+ auto optReadyFence = composeSurfaces(Region::INVALID_REGION);
+ if (!optReadyFence) {
+ return;
+ }
+
+ // swap buffers (presentation)
+ mRenderSurface->queueBuffer(std::move(*optReadyFence));
+}
+
+std::optional<base::unique_fd> Output::composeSurfaces(const Region& debugRegion) {
ATRACE_CALL();
ALOGV(__FUNCTION__);
const TracedOrdinal<bool> hasClientComposition = {"hasClientComposition",
mState.usesClientComposition};
+ base::unique_fd readyFence;
+
if (!hasClientComposition) {
- return true;
+ return readyFence;
}
ALOGV("hasClientComposition");
@@ -326,7 +525,7 @@
// Compute the global color transform matrix.
if (!mState.usesDeviceComposition && !getSkipColorTransform()) {
- clientCompositionDisplay.colorTransform = mState.colorTransformMat;
+ clientCompositionDisplay.colorTransform = mState.colorTransformMatrix;
}
// Note: Updated by generateClientCompositionRequests
@@ -362,7 +561,7 @@
ALOGW("Dequeuing buffer for display [%s] failed, bailing out of "
"client composition for this frame",
mName.c_str());
- return false;
+ return std::nullopt;
}
// We boost GPU frequency here because there will be color spaces conversion
@@ -377,13 +576,13 @@
renderEngine.drawLayers(clientCompositionDisplay, clientCompositionLayers,
buf->getNativeBuffer(), /*useFramebufferCache=*/true, std::move(fd),
- readyFence);
+ &readyFence);
if (expensiveRenderingExpected) {
setExpensiveRenderingExpected(false);
}
- return true;
+ return readyFence;
}
std::vector<renderengine::LayerSettings> Output::generateClientCompositionRequests(
@@ -402,7 +601,7 @@
const auto& layerFEState = layer->getLayer().getState().frontEnd;
auto& layerFE = layer->getLayerFE();
- const Region clip(viewportRegion.intersect(layer->getState().visibleRegion));
+ const Region clip(viewportRegion.intersect(layerState.visibleRegion));
ALOGV("Layer: %s", layerFE.getDebugName());
if (clip.isEmpty()) {
ALOGV(" Skipping for empty clip");
@@ -432,7 +631,7 @@
clientComposition ? clearRegion : dummyRegion,
};
if (auto result = layerFE.prepareClientComposition(targetSettings)) {
- if (clearClientComposition) {
+ if (!clientComposition) {
auto& layerSettings = *result;
layerSettings.source.buffer.buffer = nullptr;
layerSettings.source.solidColor = half3(0.0, 0.0, 0.0);
@@ -480,6 +679,9 @@
return;
}
+ mState.dirtyRegion.clear();
+ mRenderSurface->flip();
+
auto frame = presentAndGetFrameFences();
mRenderSurface->onPresentDisplayCompleted();
diff --git a/services/surfaceflinger/CompositionEngine/src/OutputCompositionState.cpp b/services/surfaceflinger/CompositionEngine/src/OutputCompositionState.cpp
index 3e47fe2..0fcc308 100644
--- a/services/surfaceflinger/CompositionEngine/src/OutputCompositionState.cpp
+++ b/services/surfaceflinger/CompositionEngine/src/OutputCompositionState.cpp
@@ -47,7 +47,7 @@
dumpVal(out, "colorMode", toString(colorMode), colorMode);
dumpVal(out, "renderIntent", toString(renderIntent), renderIntent);
dumpVal(out, "dataspace", toString(dataspace), dataspace);
- dumpVal(out, "colorTransform", colorTransform);
+ dumpVal(out, "colorTransformMatrix", colorTransformMatrix);
dumpVal(out, "target dataspace", toString(targetDataspace), targetDataspace);
out.append("\n");
diff --git a/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp b/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp
index e721cf5..21f0ce8 100644
--- a/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp
+++ b/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp
@@ -315,11 +315,6 @@
? outputState.targetDataspace
: layerFEState.dataspace;
- // TODO(lpique): b/121291683 Remove this one we are sure we don't need the
- // value recomputed / set every frame.
- mState.visibleRegion = outputState.transform.transform(
- layerFEState.geomVisibleRegion.intersect(outputState.viewport));
-
// These are evaluated every frame as they can potentially change at any
// time.
if (layerFEState.forceClientComposition || !profile.isDataspaceSupported(mState.dataspace)) {
@@ -421,13 +416,13 @@
void OutputLayer::writeOutputDependentPerFrameStateToHWC(HWC2::Layer* hwcLayer) {
const auto& outputDependentState = getState();
- // TODO(lpique): b/121291683 visibleRegion is output-dependent geometry
+ // TODO(lpique): b/121291683 outputSpaceVisibleRegion is output-dependent geometry
// state and should not change every frame.
- if (auto error = hwcLayer->setVisibleRegion(outputDependentState.visibleRegion);
+ if (auto error = hwcLayer->setVisibleRegion(outputDependentState.outputSpaceVisibleRegion);
error != HWC2::Error::None) {
ALOGE("[%s] Failed to set visible region: %s (%d)", mLayerFE->getDebugName(),
to_string(error).c_str(), static_cast<int32_t>(error));
- outputDependentState.visibleRegion.dump(LOG_TAG);
+ outputDependentState.outputSpaceVisibleRegion.dump(LOG_TAG);
}
if (auto error = hwcLayer->setDataspace(outputDependentState.dataspace);
@@ -550,6 +545,27 @@
}
}
+void OutputLayer::writeCursorPositionToHWC() const {
+ // Skip doing this if there is no HWC interface
+ auto hwcLayer = getHwcLayer();
+ if (!hwcLayer) {
+ return;
+ }
+
+ const auto& layerFEState = mLayer->getState().frontEnd;
+ const auto& outputState = mOutput.getState();
+
+ Rect frame = layerFEState.cursorFrame;
+ frame.intersect(outputState.viewport, &frame);
+ Rect position = outputState.transform.transform(frame);
+
+ if (auto error = hwcLayer->setCursorPosition(position.left, position.top);
+ error != HWC2::Error::None) {
+ ALOGE("[%s] Failed to set cursor position to (%d, %d): %s (%d)", mLayerFE->getDebugName(),
+ position.left, position.top, to_string(error).c_str(), static_cast<int32_t>(error));
+ }
+}
+
HWC2::Layer* OutputLayer::getHwcLayer() const {
return mState.hwc ? mState.hwc->hwcLayer.get() : nullptr;
}
@@ -559,6 +575,11 @@
mState.hwc->hwcCompositionType == Hwc2::IComposerClient::Composition::CLIENT;
}
+bool OutputLayer::isHardwareCursor() const {
+ return mState.hwc &&
+ mState.hwc->hwcCompositionType == Hwc2::IComposerClient::Composition::CURSOR;
+}
+
void OutputLayer::detectDisallowedCompositionTypeChange(
Hwc2::IComposerClient::Composition from, Hwc2::IComposerClient::Composition to) const {
bool result = false;
diff --git a/services/surfaceflinger/CompositionEngine/src/OutputLayerCompositionState.cpp b/services/surfaceflinger/CompositionEngine/src/OutputLayerCompositionState.cpp
index e320bee..ad668b6 100644
--- a/services/surfaceflinger/CompositionEngine/src/OutputLayerCompositionState.cpp
+++ b/services/surfaceflinger/CompositionEngine/src/OutputLayerCompositionState.cpp
@@ -42,6 +42,15 @@
dumpVal(out, "visibleRegion", visibleRegion);
out.append(" ");
+ dumpVal(out, "visibleNonTransparentRegion", visibleNonTransparentRegion);
+
+ out.append(" ");
+ dumpVal(out, "coveredRegion", coveredRegion);
+
+ out.append(" ");
+ dumpVal(out, "output visibleRegion", outputSpaceVisibleRegion);
+
+ out.append(" ");
dumpVal(out, "forceClientComposition", forceClientComposition);
dumpVal(out, "clearClientTarget", clearClientTarget);
dumpVal(out, "displayFrame", displayFrame);
diff --git a/services/surfaceflinger/CompositionEngine/tests/DisplayTest.cpp b/services/surfaceflinger/CompositionEngine/tests/DisplayTest.cpp
index 743da82..008e631 100644
--- a/services/surfaceflinger/CompositionEngine/tests/DisplayTest.cpp
+++ b/services/surfaceflinger/CompositionEngine/tests/DisplayTest.cpp
@@ -138,23 +138,26 @@
*/
TEST_F(DisplayTest, setColorTransformSetsTransform) {
+ // No change does nothing
+ CompositionRefreshArgs refreshArgs;
+ refreshArgs.colorTransformMatrix = std::nullopt;
+ mDisplay.setColorTransform(refreshArgs);
+
// Identity matrix sets an identity state value
- const mat4 identity;
+ const mat4 kIdentity;
- EXPECT_CALL(mHwComposer, setColorTransform(DEFAULT_DISPLAY_ID, identity)).Times(1);
+ EXPECT_CALL(mHwComposer, setColorTransform(DEFAULT_DISPLAY_ID, kIdentity)).Times(1);
- mDisplay.setColorTransform(identity);
-
- EXPECT_EQ(HAL_COLOR_TRANSFORM_IDENTITY, mDisplay.getState().colorTransform);
+ refreshArgs.colorTransformMatrix = kIdentity;
+ mDisplay.setColorTransform(refreshArgs);
// Non-identity matrix sets a non-identity state value
- const mat4 nonIdentity = mat4() * 2;
+ const mat4 kNonIdentity = mat4() * 2;
- EXPECT_CALL(mHwComposer, setColorTransform(DEFAULT_DISPLAY_ID, nonIdentity)).Times(1);
+ EXPECT_CALL(mHwComposer, setColorTransform(DEFAULT_DISPLAY_ID, kNonIdentity)).Times(1);
- mDisplay.setColorTransform(nonIdentity);
-
- EXPECT_EQ(HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX, mDisplay.getState().colorTransform);
+ refreshArgs.colorTransformMatrix = kNonIdentity;
+ mDisplay.setColorTransform(refreshArgs);
}
/*
@@ -162,6 +165,8 @@
*/
TEST_F(DisplayTest, setColorModeSetsModeUnlessNoChange) {
+ using ColorProfile = Output::ColorProfile;
+
mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
mDisplay.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>();
@@ -177,8 +182,8 @@
ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay.getState().targetDataspace);
// If the set values are unchanged, nothing happens
- mDisplay.setColorMode(ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
- ui::RenderIntent::COLORIMETRIC, ui::Dataspace::UNKNOWN);
+ mDisplay.setColorProfile(ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
+ ui::RenderIntent::COLORIMETRIC, ui::Dataspace::UNKNOWN});
EXPECT_EQ(ui::ColorMode::NATIVE, mDisplay.getState().colorMode);
EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay.getState().dataspace);
@@ -192,8 +197,9 @@
ui::RenderIntent::TONE_MAP_COLORIMETRIC))
.Times(1);
- mDisplay.setColorMode(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
- ui::RenderIntent::TONE_MAP_COLORIMETRIC, ui::Dataspace::UNKNOWN);
+ mDisplay.setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
+ ui::RenderIntent::TONE_MAP_COLORIMETRIC,
+ ui::Dataspace::UNKNOWN});
EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mDisplay.getState().colorMode);
EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mDisplay.getState().dataspace);
@@ -202,6 +208,8 @@
}
TEST_F(DisplayTest, setColorModeDoesNothingForVirtualDisplay) {
+ using ColorProfile = Output::ColorProfile;
+
impl::Display virtualDisplay{mCompositionEngine,
DisplayCreationArgs{false, true, DEFAULT_DISPLAY_ID}};
@@ -214,8 +222,9 @@
ui::Dataspace::UNKNOWN))
.WillOnce(Return(ui::Dataspace::UNKNOWN));
- virtualDisplay.setColorMode(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
- ui::RenderIntent::TONE_MAP_COLORIMETRIC, ui::Dataspace::UNKNOWN);
+ virtualDisplay.setColorProfile(
+ ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
+ ui::RenderIntent::TONE_MAP_COLORIMETRIC, ui::Dataspace::UNKNOWN});
EXPECT_EQ(ui::ColorMode::NATIVE, virtualDisplay.getState().colorMode);
EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay.getState().dataspace);
@@ -537,5 +546,90 @@
mDisplay.setExpensiveRenderingExpected(false);
}
+/*
+ * Display::finishFrame()
+ */
+
+TEST_F(DisplayTest, finishFrameDoesNotSkipCompositionIfNotDirtyOnHwcDisplay) {
+ mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
+ mDisplay.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
+
+ // We expect no calls to queueBuffer if composition was skipped.
+ EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
+
+ mDisplay.editState().isEnabled = true;
+ mDisplay.editState().usesClientComposition = false;
+ mDisplay.editState().viewport = Rect(0, 0, 1, 1);
+ mDisplay.editState().dirtyRegion = Region::INVALID_REGION;
+
+ CompositionRefreshArgs refreshArgs;
+ refreshArgs.repaintEverything = false;
+
+ mDisplay.finishFrame(refreshArgs);
+}
+
+TEST_F(DisplayTest, finishFrameSkipsCompositionIfNotDirty) {
+ std::shared_ptr<impl::Display> nonHwcDisplay{
+ impl::createDisplay(mCompositionEngine, DisplayCreationArgsBuilder().build())};
+
+ mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
+ nonHwcDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
+
+ // We expect no calls to queueBuffer if composition was skipped.
+ EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(0);
+
+ nonHwcDisplay->editState().isEnabled = true;
+ nonHwcDisplay->editState().usesClientComposition = false;
+ nonHwcDisplay->editState().viewport = Rect(0, 0, 1, 1);
+ nonHwcDisplay->editState().dirtyRegion = Region::INVALID_REGION;
+
+ CompositionRefreshArgs refreshArgs;
+ refreshArgs.repaintEverything = false;
+
+ nonHwcDisplay->finishFrame(refreshArgs);
+}
+
+TEST_F(DisplayTest, finishFramePerformsCompositionIfDirty) {
+ std::shared_ptr<impl::Display> nonHwcDisplay{
+ impl::createDisplay(mCompositionEngine, DisplayCreationArgsBuilder().build())};
+
+ mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
+ nonHwcDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
+
+ // We expect a single call to queueBuffer when composition is not skipped.
+ EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
+
+ nonHwcDisplay->editState().isEnabled = true;
+ nonHwcDisplay->editState().usesClientComposition = false;
+ nonHwcDisplay->editState().viewport = Rect(0, 0, 1, 1);
+ nonHwcDisplay->editState().dirtyRegion = Region(Rect(0, 0, 1, 1));
+
+ CompositionRefreshArgs refreshArgs;
+ refreshArgs.repaintEverything = false;
+
+ nonHwcDisplay->finishFrame(refreshArgs);
+}
+
+TEST_F(DisplayTest, finishFramePerformsCompositionIfRepaintEverything) {
+ std::shared_ptr<impl::Display> nonHwcDisplay{
+ impl::createDisplay(mCompositionEngine, DisplayCreationArgsBuilder().build())};
+
+ mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
+ nonHwcDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
+
+ // We expect a single call to queueBuffer when composition is not skipped.
+ EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
+
+ nonHwcDisplay->editState().isEnabled = true;
+ nonHwcDisplay->editState().usesClientComposition = false;
+ nonHwcDisplay->editState().viewport = Rect(0, 0, 1, 1);
+ nonHwcDisplay->editState().dirtyRegion = Region::INVALID_REGION;
+
+ CompositionRefreshArgs refreshArgs;
+ refreshArgs.repaintEverything = true;
+
+ nonHwcDisplay->finishFrame(refreshArgs);
+}
+
} // namespace
} // namespace android::compositionengine
diff --git a/services/surfaceflinger/CompositionEngine/tests/OutputLayerTest.cpp b/services/surfaceflinger/CompositionEngine/tests/OutputLayerTest.cpp
index c83cae6..2276dc3 100644
--- a/services/surfaceflinger/CompositionEngine/tests/OutputLayerTest.cpp
+++ b/services/surfaceflinger/CompositionEngine/tests/OutputLayerTest.cpp
@@ -574,7 +574,7 @@
static const half4 kColor;
static const Rect kDisplayFrame;
- static const Region kVisibleRegion;
+ static const Region kOutputSpaceVisibleRegion;
static const mat4 kColorTransform;
static const Region kSurfaceDamage;
static const HdrMetadata kHdrMetadata;
@@ -590,7 +590,7 @@
outputLayerState.sourceCrop = kSourceCrop;
outputLayerState.z = kZOrder;
outputLayerState.bufferTransform = static_cast<Hwc2::Transform>(kBufferTransform);
- outputLayerState.visibleRegion = kVisibleRegion;
+ outputLayerState.outputSpaceVisibleRegion = kOutputSpaceVisibleRegion;
outputLayerState.dataspace = kDataspace;
mLayerState.frontEnd.blendMode = kBlendMode;
@@ -629,7 +629,7 @@
}
void expectPerFrameCommonCalls(SimulateUnsupported unsupported = SimulateUnsupported::None) {
- EXPECT_CALL(*mHwcLayer, setVisibleRegion(RegionEq(kVisibleRegion)))
+ EXPECT_CALL(*mHwcLayer, setVisibleRegion(RegionEq(kOutputSpaceVisibleRegion)))
.WillOnce(Return(kError));
EXPECT_CALL(*mHwcLayer, setDataspace(kDataspace)).WillOnce(Return(kError));
EXPECT_CALL(*mHwcLayer, setColorTransform(kColorTransform))
@@ -673,7 +673,8 @@
const half4 OutputLayerWriteStateToHWCTest::kColor{81.f / 255.f, 82.f / 255.f, 83.f / 255.f,
84.f / 255.f};
const Rect OutputLayerWriteStateToHWCTest::kDisplayFrame{1001, 1002, 1003, 10044};
-const Region OutputLayerWriteStateToHWCTest::kVisibleRegion{Rect{1005, 1006, 1007, 1008}};
+const Region OutputLayerWriteStateToHWCTest::kOutputSpaceVisibleRegion{
+ Rect{1005, 1006, 1007, 1008}};
const mat4 OutputLayerWriteStateToHWCTest::kColorTransform{
1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016,
1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024,
@@ -782,6 +783,61 @@
}
/*
+ * OutputLayer::writeCursorPositionToHWC()
+ */
+
+struct OutputLayerWriteCursorPositionToHWCTest : public OutputLayerTest {
+ static constexpr int kDefaultTransform = TR_IDENT;
+ static constexpr HWC2::Error kDefaultError = HWC2::Error::Unsupported;
+
+ static const Rect kDefaultDisplayViewport;
+ static const Rect kDefaultCursorFrame;
+
+ OutputLayerWriteCursorPositionToHWCTest() {
+ auto& outputLayerState = mOutputLayer.editState();
+ outputLayerState.hwc = impl::OutputLayerCompositionState::Hwc(mHwcLayer);
+
+ mLayerState.frontEnd.cursorFrame = kDefaultCursorFrame;
+
+ mOutputState.viewport = kDefaultDisplayViewport;
+ mOutputState.transform = ui::Transform{kDefaultTransform};
+ }
+
+ std::shared_ptr<HWC2::mock::Layer> mHwcLayer{std::make_shared<StrictMock<HWC2::mock::Layer>>()};
+};
+
+const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultDisplayViewport{0, 0, 1920, 1080};
+const Rect OutputLayerWriteCursorPositionToHWCTest::kDefaultCursorFrame{1, 2, 3, 4};
+
+TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCHandlesNoHwcState) {
+ mOutputLayer.editState().hwc.reset();
+
+ mOutputLayer.writeCursorPositionToHWC();
+}
+
+TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCWritesStateToHWC) {
+ EXPECT_CALL(*mHwcLayer, setCursorPosition(1, 2)).WillOnce(Return(kDefaultError));
+
+ mOutputLayer.writeCursorPositionToHWC();
+}
+
+TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCIntersectedWithViewport) {
+ mLayerState.frontEnd.cursorFrame = Rect{3000, 3000, 3016, 3016};
+
+ EXPECT_CALL(*mHwcLayer, setCursorPosition(1920, 1080)).WillOnce(Return(kDefaultError));
+
+ mOutputLayer.writeCursorPositionToHWC();
+}
+
+TEST_F(OutputLayerWriteCursorPositionToHWCTest, writeCursorPositionToHWCRotatedByTransform) {
+ mOutputState.transform = ui::Transform{TR_ROT_90};
+
+ EXPECT_CALL(*mHwcLayer, setCursorPosition(-4, 1)).WillOnce(Return(kDefaultError));
+
+ mOutputLayer.writeCursorPositionToHWC();
+}
+
+/*
* OutputLayer::getHwcLayer()
*/
@@ -829,6 +885,30 @@
}
/*
+ * OutputLayer::isHardwareCursor()
+ */
+
+TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfNoHWC2State) {
+ mOutputLayer.editState().hwc.reset();
+
+ EXPECT_FALSE(mOutputLayer.isHardwareCursor());
+}
+
+TEST_F(OutputLayerTest, isHardwareCursorReturnsTrueIfSetToCursorComposition) {
+ mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
+ mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::CURSOR;
+
+ EXPECT_TRUE(mOutputLayer.isHardwareCursor());
+}
+
+TEST_F(OutputLayerTest, isHardwareCursorReturnsFalseIfSetToDeviceComposition) {
+ mOutputLayer.editState().hwc = impl::OutputLayerCompositionState::Hwc{nullptr};
+ mOutputLayer.editState().hwc->hwcCompositionType = Hwc2::IComposerClient::Composition::DEVICE;
+
+ EXPECT_FALSE(mOutputLayer.isHardwareCursor());
+}
+
+/*
* OutputLayer::applyDeviceCompositionTypeChange()
*/
diff --git a/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp b/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp
index aa35d25..b0e8e36 100644
--- a/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp
+++ b/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp
@@ -16,8 +16,10 @@
#include <cmath>
+#include <compositionengine/impl/LayerCompositionState.h>
#include <compositionengine/impl/Output.h>
#include <compositionengine/impl/OutputCompositionState.h>
+#include <compositionengine/impl/OutputLayerCompositionState.h>
#include <compositionengine/mock/CompositionEngine.h>
#include <compositionengine/mock/DisplayColorProfile.h>
#include <compositionengine/mock/Layer.h>
@@ -25,6 +27,7 @@
#include <compositionengine/mock/OutputLayer.h>
#include <compositionengine/mock/RenderSurface.h>
#include <gtest/gtest.h>
+#include <renderengine/mock/RenderEngine.h>
#include <ui/Rect.h>
#include <ui/Region.h>
@@ -34,10 +37,18 @@
namespace android::compositionengine {
namespace {
+using testing::_;
using testing::Return;
using testing::ReturnRef;
using testing::StrictMock;
+constexpr auto TR_IDENT = 0u;
+constexpr auto TR_ROT_90 = HAL_TRANSFORM_ROT_90;
+
+const mat4 kIdentity;
+const mat4 kNonIdentityHalf = mat4() * 0.5;
+const mat4 kNonIdentityQuarter = mat4() * 0.25;
+
struct OutputTest : public testing::Test {
OutputTest() {
mOutput.setDisplayColorProfileForTest(
@@ -164,38 +175,84 @@
* Output::setColorTransform
*/
-TEST_F(OutputTest, setColorTransformSetsTransform) {
- // Identity matrix sets an identity state value
- const mat4 identity;
+TEST_F(OutputTest, setColorTransformWithNoChangeFlaggedSkipsUpdates) {
+ mOutput.editState().colorTransformMatrix = kIdentity;
- mOutput.setColorTransform(identity);
+ // If no colorTransformMatrix is set the update should be skipped.
+ CompositionRefreshArgs refreshArgs;
+ refreshArgs.colorTransformMatrix = std::nullopt;
- EXPECT_EQ(HAL_COLOR_TRANSFORM_IDENTITY, mOutput.getState().colorTransform);
- EXPECT_EQ(identity, mOutput.getState().colorTransformMat);
+ mOutput.setColorTransform(refreshArgs);
- // Since identity is the default, the dirty region should be unchanged (empty)
+ // The internal state should be unchanged
+ EXPECT_EQ(kIdentity, mOutput.getState().colorTransformMatrix);
+
+ // No dirty region should be set
EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region()));
+}
- // Non-identity matrix sets a non-identity state value
- const mat4 nonIdentityHalf = mat4() * 0.5;
+TEST_F(OutputTest, setColorTransformWithNoActualChangeSkipsUpdates) {
+ mOutput.editState().colorTransformMatrix = kIdentity;
- mOutput.setColorTransform(nonIdentityHalf);
+ // Attempting to set the same colorTransformMatrix that is already set should
+ // also skip the update.
+ CompositionRefreshArgs refreshArgs;
+ refreshArgs.colorTransformMatrix = kIdentity;
- EXPECT_EQ(HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX, mOutput.getState().colorTransform);
- EXPECT_EQ(nonIdentityHalf, mOutput.getState().colorTransformMat);
+ mOutput.setColorTransform(refreshArgs);
- // Since this is a state change, the entire output should now be dirty.
+ // The internal state should be unchanged
+ EXPECT_EQ(kIdentity, mOutput.getState().colorTransformMatrix);
+
+ // No dirty region should be set
+ EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region()));
+}
+
+TEST_F(OutputTest, setColorTransformPerformsUpdateToIdentity) {
+ mOutput.editState().colorTransformMatrix = kNonIdentityHalf;
+
+ // Setting a different colorTransformMatrix should perform the update.
+ CompositionRefreshArgs refreshArgs;
+ refreshArgs.colorTransformMatrix = kIdentity;
+
+ mOutput.setColorTransform(refreshArgs);
+
+ // The internal state should have been updated
+ EXPECT_EQ(kIdentity, mOutput.getState().colorTransformMatrix);
+
+ // The dirtyRegion should be set to the full display size
EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
+}
- // Non-identity matrix sets a non-identity state value
- const mat4 nonIdentityQuarter = mat4() * 0.25;
+TEST_F(OutputTest, setColorTransformPerformsUpdateForIdentityToHalf) {
+ mOutput.editState().colorTransformMatrix = kIdentity;
- mOutput.setColorTransform(nonIdentityQuarter);
+ // Setting a different colorTransformMatrix should perform the update.
+ CompositionRefreshArgs refreshArgs;
+ refreshArgs.colorTransformMatrix = kNonIdentityHalf;
- EXPECT_EQ(HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX, mOutput.getState().colorTransform);
- EXPECT_EQ(nonIdentityQuarter, mOutput.getState().colorTransformMat);
+ mOutput.setColorTransform(refreshArgs);
- // Since this is a state change, the entire output should now be dirty.
+ // The internal state should have been updated
+ EXPECT_EQ(kNonIdentityHalf, mOutput.getState().colorTransformMatrix);
+
+ // The dirtyRegion should be set to the full display size
+ EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
+}
+
+TEST_F(OutputTest, setColorTransformPerformsUpdateForHalfToQuarter) {
+ mOutput.editState().colorTransformMatrix = kNonIdentityHalf;
+
+ // Setting a different colorTransformMatrix should perform the update.
+ CompositionRefreshArgs refreshArgs;
+ refreshArgs.colorTransformMatrix = kNonIdentityQuarter;
+
+ mOutput.setColorTransform(refreshArgs);
+
+ // The internal state should have been updated
+ EXPECT_EQ(kNonIdentityQuarter, mOutput.getState().colorTransformMatrix);
+
+ // The dirtyRegion should be set to the full display size
EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
}
@@ -204,14 +261,17 @@
*/
TEST_F(OutputTest, setColorModeSetsStateAndDirtiesOutputIfChanged) {
+ using ColorProfile = Output::ColorProfile;
+
EXPECT_CALL(*mDisplayColorProfile,
getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
ui::Dataspace::UNKNOWN))
.WillOnce(Return(ui::Dataspace::UNKNOWN));
EXPECT_CALL(*mRenderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1);
- mOutput.setColorMode(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
- ui::RenderIntent::TONE_MAP_COLORIMETRIC, ui::Dataspace::UNKNOWN);
+ mOutput.setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
+ ui::RenderIntent::TONE_MAP_COLORIMETRIC,
+ ui::Dataspace::UNKNOWN});
EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mOutput.getState().colorMode);
EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutput.getState().dataspace);
@@ -222,6 +282,8 @@
}
TEST_F(OutputTest, setColorModeDoesNothingIfNoChange) {
+ using ColorProfile = Output::ColorProfile;
+
EXPECT_CALL(*mDisplayColorProfile,
getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
ui::Dataspace::UNKNOWN))
@@ -232,8 +294,9 @@
mOutput.editState().renderIntent = ui::RenderIntent::TONE_MAP_COLORIMETRIC;
mOutput.editState().targetDataspace = ui::Dataspace::UNKNOWN;
- mOutput.setColorMode(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
- ui::RenderIntent::TONE_MAP_COLORIMETRIC, ui::Dataspace::UNKNOWN);
+ mOutput.setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
+ ui::RenderIntent::TONE_MAP_COLORIMETRIC,
+ ui::Dataspace::UNKNOWN});
EXPECT_THAT(mOutput.getState().dirtyRegion, RegionEq(Region()));
}
@@ -446,5 +509,348 @@
EXPECT_FALSE(mOutput.getState().usesDeviceComposition);
}
+/*
+ * Output::composeSurfaces()
+ */
+
+struct OutputComposeSurfacesTest : public testing::Test {
+ static constexpr uint32_t kDefaultOutputOrientation = TR_IDENT;
+ static constexpr ui::Dataspace kDefaultOutputDataspace = ui::Dataspace::DISPLAY_P3;
+
+ static const Rect kDefaultOutputFrame;
+ static const Rect kDefaultOutputViewport;
+ static const Rect kDefaultOutputScissor;
+ static const mat4 kDefaultColorTransformMat;
+
+ struct OutputPartialMock : public impl::Output {
+ OutputPartialMock(const compositionengine::CompositionEngine& compositionEngine)
+ : impl::Output(compositionEngine) {}
+
+ // Sets up the helper functions called by composeSurfaces to use a mock
+ // implementations.
+ MOCK_CONST_METHOD0(getSkipColorTransform, bool());
+ MOCK_METHOD2(generateClientCompositionRequests,
+ std::vector<renderengine::LayerSettings>(bool, Region&));
+ MOCK_METHOD2(appendRegionFlashRequests,
+ void(const Region&, std::vector<renderengine::LayerSettings>&));
+ MOCK_METHOD1(setExpensiveRenderingExpected, void(bool));
+ };
+
+ OutputComposeSurfacesTest() {
+ mOutput.setDisplayColorProfileForTest(
+ std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
+ mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
+
+ Output::OutputLayers outputLayers;
+ outputLayers.emplace_back(std::unique_ptr<OutputLayer>(mOutputLayer1));
+ outputLayers.emplace_back(std::unique_ptr<OutputLayer>(mOutputLayer2));
+ mOutput.setOutputLayersOrderedByZ(std::move(outputLayers));
+
+ mOutput.editState().frame = kDefaultOutputFrame;
+ mOutput.editState().viewport = kDefaultOutputViewport;
+ mOutput.editState().scissor = kDefaultOutputScissor;
+ mOutput.editState().transform = ui::Transform{kDefaultOutputOrientation};
+ mOutput.editState().orientation = kDefaultOutputOrientation;
+ mOutput.editState().dataspace = kDefaultOutputDataspace;
+ mOutput.editState().colorTransformMatrix = kDefaultColorTransformMat;
+ mOutput.editState().isSecure = true;
+ mOutput.editState().needsFiltering = false;
+ mOutput.editState().usesClientComposition = true;
+ mOutput.editState().usesDeviceComposition = false;
+
+ EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine));
+ }
+
+ StrictMock<mock::CompositionEngine> mCompositionEngine;
+ StrictMock<renderengine::mock::RenderEngine> mRenderEngine;
+ mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
+ mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
+ mock::OutputLayer* mOutputLayer1 = new StrictMock<mock::OutputLayer>();
+ mock::OutputLayer* mOutputLayer2 = new StrictMock<mock::OutputLayer>();
+ StrictMock<OutputPartialMock> mOutput{mCompositionEngine};
+ sp<GraphicBuffer> mOutputBuffer = new GraphicBuffer();
+};
+
+const Rect OutputComposeSurfacesTest::kDefaultOutputFrame{1001, 1002, 1003, 1004};
+const Rect OutputComposeSurfacesTest::kDefaultOutputViewport{1005, 1006, 1007, 1008};
+const Rect OutputComposeSurfacesTest::kDefaultOutputScissor{1009, 1010, 1011, 1012};
+const mat4 OutputComposeSurfacesTest::kDefaultColorTransformMat{mat4() * 0.5};
+
+// TODO(b/121291683): Expand unit test coverage for composeSurfaces beyond these
+// basic tests.
+
+TEST_F(OutputComposeSurfacesTest, doesNothingIfNoClientComposition) {
+ mOutput.editState().usesClientComposition = false;
+
+ Region debugRegion;
+ std::optional<base::unique_fd> readyFence = mOutput.composeSurfaces(debugRegion);
+ EXPECT_TRUE(readyFence);
+}
+
+TEST_F(OutputComposeSurfacesTest, worksIfNoClientLayersQueued) {
+ const Region kDebugRegion{Rect{100, 101, 102, 103}};
+
+ constexpr float kDefaultMaxLuminance = 1.0f;
+ constexpr float kDefaultAvgLuminance = 0.7f;
+ constexpr float kDefaultMinLuminance = 0.1f;
+ HdrCapabilities HdrCapabilities{{},
+ kDefaultMaxLuminance,
+ kDefaultAvgLuminance,
+ kDefaultMinLuminance};
+
+ EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillOnce(Return(false));
+ EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, true, _, _)).Times(1);
+
+ EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillOnce(Return(true));
+ EXPECT_CALL(*mDisplayColorProfile, getHdrCapabilities()).WillOnce(ReturnRef(HdrCapabilities));
+
+ EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillOnce(Return(mOutputBuffer));
+
+ EXPECT_CALL(mOutput, getSkipColorTransform()).WillOnce(Return(false));
+ EXPECT_CALL(mOutput, generateClientCompositionRequests(false, _)).Times(1);
+ EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)).Times(1);
+ EXPECT_CALL(mOutput, setExpensiveRenderingExpected(true)).Times(1);
+ EXPECT_CALL(mOutput, setExpensiveRenderingExpected(false)).Times(1);
+
+ std::optional<base::unique_fd> readyFence = mOutput.composeSurfaces(kDebugRegion);
+ EXPECT_TRUE(readyFence);
+}
+
+/*
+ * Output::generateClientCompositionRequests()
+ */
+
+struct GenerateClientCompositionRequestsTest : public testing::Test {
+ struct OutputPartialMock : public impl::Output {
+ OutputPartialMock(const compositionengine::CompositionEngine& compositionEngine)
+ : impl::Output(compositionEngine) {}
+
+ std::vector<renderengine::LayerSettings> generateClientCompositionRequests(
+ bool supportsProtectedContent, Region& clearRegion) override {
+ return impl::Output::generateClientCompositionRequests(supportsProtectedContent,
+ clearRegion);
+ }
+ };
+
+ GenerateClientCompositionRequestsTest() {
+ mOutput.setDisplayColorProfileForTest(
+ std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
+ mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
+ }
+
+ StrictMock<mock::CompositionEngine> mCompositionEngine;
+ mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
+ mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
+ StrictMock<OutputPartialMock> mOutput{mCompositionEngine};
+};
+
+// TODO(b/121291683): Add more unit test coverage for generateClientCompositionRequests
+
+TEST_F(GenerateClientCompositionRequestsTest, worksForLandscapeModeSplitScreen) {
+ // In split-screen landscape mode, the screen is rotated 90 degrees, with
+ // one layer on the left covering the left side of the output, and one layer
+ // on the right covering that side of the output.
+
+ mock::OutputLayer* leftOutputLayer = new StrictMock<mock::OutputLayer>();
+ mock::OutputLayer* rightOutputLayer = new StrictMock<mock::OutputLayer>();
+
+ StrictMock<mock::Layer> leftLayer;
+ StrictMock<mock::LayerFE> leftLayerFE;
+ StrictMock<mock::Layer> rightLayer;
+ StrictMock<mock::LayerFE> rightLayerFE;
+
+ impl::OutputLayerCompositionState leftOutputLayerState;
+ leftOutputLayerState.clearClientTarget = false;
+ leftOutputLayerState.visibleRegion = Region{Rect{0, 0, 1000, 1000}};
+
+ impl::LayerCompositionState leftLayerState;
+ leftLayerState.frontEnd.isOpaque = true;
+
+ const half3 leftLayerColor{1.f, 0.f, 0.f};
+ renderengine::LayerSettings leftLayerRESettings;
+ leftLayerRESettings.source.solidColor = leftLayerColor;
+
+ impl::OutputLayerCompositionState rightOutputLayerState;
+ rightOutputLayerState.clearClientTarget = false;
+ rightOutputLayerState.visibleRegion = Region{Rect{1000, 0, 2000, 1000}};
+
+ impl::LayerCompositionState rightLayerState;
+ rightLayerState.frontEnd.isOpaque = true;
+
+ const half3 rightLayerColor{0.f, 1.f, 0.f};
+ renderengine::LayerSettings rightLayerRESettings;
+ rightLayerRESettings.source.solidColor = rightLayerColor;
+
+ EXPECT_CALL(*leftOutputLayer, getState()).WillRepeatedly(ReturnRef(leftOutputLayerState));
+ EXPECT_CALL(*leftOutputLayer, getLayer()).WillRepeatedly(ReturnRef(leftLayer));
+ EXPECT_CALL(*leftOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(leftLayerFE));
+ EXPECT_CALL(*leftOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true));
+ EXPECT_CALL(*leftOutputLayer, needsFiltering()).WillRepeatedly(Return(false));
+ EXPECT_CALL(leftLayer, getState()).WillRepeatedly(ReturnRef(leftLayerState));
+ EXPECT_CALL(leftLayerFE, prepareClientComposition(_)).WillOnce(Return(leftLayerRESettings));
+
+ EXPECT_CALL(*rightOutputLayer, getState()).WillRepeatedly(ReturnRef(rightOutputLayerState));
+ EXPECT_CALL(*rightOutputLayer, getLayer()).WillRepeatedly(ReturnRef(rightLayer));
+ EXPECT_CALL(*rightOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(rightLayerFE));
+ EXPECT_CALL(*rightOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true));
+ EXPECT_CALL(*rightOutputLayer, needsFiltering()).WillRepeatedly(Return(false));
+ EXPECT_CALL(rightLayer, getState()).WillRepeatedly(ReturnRef(rightLayerState));
+ EXPECT_CALL(rightLayerFE, prepareClientComposition(_)).WillOnce(Return(rightLayerRESettings));
+
+ Output::OutputLayers outputLayers;
+ outputLayers.emplace_back(std::unique_ptr<OutputLayer>(leftOutputLayer));
+ outputLayers.emplace_back(std::unique_ptr<OutputLayer>(rightOutputLayer));
+ mOutput.setOutputLayersOrderedByZ(std::move(outputLayers));
+
+ const Rect kPortraitFrame(0, 0, 1000, 2000);
+ const Rect kPortraitViewport(0, 0, 2000, 1000);
+ const Rect kPortraitScissor(0, 0, 1000, 2000);
+ const uint32_t kPortraitOrientation = TR_ROT_90;
+
+ mOutput.editState().frame = kPortraitFrame;
+ mOutput.editState().viewport = kPortraitViewport;
+ mOutput.editState().scissor = kPortraitScissor;
+ mOutput.editState().transform = ui::Transform{kPortraitOrientation};
+ mOutput.editState().orientation = kPortraitOrientation;
+ mOutput.editState().needsFiltering = true;
+ mOutput.editState().isSecure = false;
+
+ constexpr bool supportsProtectedContent = false;
+ Region clearRegion;
+ auto requests =
+ mOutput.generateClientCompositionRequests(supportsProtectedContent, clearRegion);
+
+ ASSERT_EQ(2u, requests.size());
+ EXPECT_EQ(leftLayerColor, requests[0].source.solidColor);
+ EXPECT_EQ(rightLayerColor, requests[1].source.solidColor);
+}
+
+TEST_F(GenerateClientCompositionRequestsTest, ignoresLayersThatDoNotIntersectWithViewport) {
+ // Layers whose visible region does not intersect with the viewport will be
+ // skipped when generating client composition request state.
+
+ mock::OutputLayer* outputLayer = new StrictMock<mock::OutputLayer>();
+ StrictMock<mock::Layer> layer;
+ StrictMock<mock::LayerFE> layerFE;
+
+ impl::OutputLayerCompositionState outputLayerState;
+ outputLayerState.clearClientTarget = false;
+ outputLayerState.visibleRegion = Region{Rect{3000, 0, 4000, 1000}};
+
+ impl::LayerCompositionState layerState;
+ layerState.frontEnd.isOpaque = true;
+
+ EXPECT_CALL(*outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState));
+ EXPECT_CALL(*outputLayer, getLayer()).WillRepeatedly(ReturnRef(layer));
+ EXPECT_CALL(*outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(layerFE));
+ EXPECT_CALL(*outputLayer, requiresClientComposition()).WillRepeatedly(Return(true));
+ EXPECT_CALL(*outputLayer, needsFiltering()).WillRepeatedly(Return(false));
+ EXPECT_CALL(layer, getState()).WillRepeatedly(ReturnRef(layerState));
+ EXPECT_CALL(layerFE, prepareClientComposition(_)).Times(0);
+
+ Output::OutputLayers outputLayers;
+ outputLayers.emplace_back(std::unique_ptr<OutputLayer>(outputLayer));
+ mOutput.setOutputLayersOrderedByZ(std::move(outputLayers));
+
+ const Rect kPortraitFrame(0, 0, 1000, 2000);
+ const Rect kPortraitViewport(0, 0, 2000, 1000);
+ const Rect kPortraitScissor(0, 0, 1000, 2000);
+ const uint32_t kPortraitOrientation = TR_ROT_90;
+
+ mOutput.editState().frame = kPortraitFrame;
+ mOutput.editState().viewport = kPortraitViewport;
+ mOutput.editState().scissor = kPortraitScissor;
+ mOutput.editState().transform = ui::Transform{kPortraitOrientation};
+ mOutput.editState().orientation = kPortraitOrientation;
+ mOutput.editState().needsFiltering = true;
+ mOutput.editState().isSecure = false;
+
+ constexpr bool supportsProtectedContent = false;
+ Region clearRegion;
+ auto requests =
+ mOutput.generateClientCompositionRequests(supportsProtectedContent, clearRegion);
+
+ EXPECT_EQ(0u, requests.size());
+}
+
+TEST_F(GenerateClientCompositionRequestsTest, clearsDeviceLayesAfterFirst) {
+ // If client composition is performed with some layers set to use device
+ // composition, device layers after the first layer (device or client) will
+ // clear the frame buffer if they are opaque and if that layer has a flag
+ // set to do so. The first layer is skipped as the frame buffer is already
+ // expected to be clear.
+
+ mock::OutputLayer* leftOutputLayer = new StrictMock<mock::OutputLayer>();
+ mock::OutputLayer* rightOutputLayer = new StrictMock<mock::OutputLayer>();
+
+ StrictMock<mock::Layer> leftLayer;
+ StrictMock<mock::LayerFE> leftLayerFE;
+ StrictMock<mock::Layer> rightLayer;
+ StrictMock<mock::LayerFE> rightLayerFE;
+
+ impl::OutputLayerCompositionState leftOutputLayerState;
+ leftOutputLayerState.clearClientTarget = true;
+ leftOutputLayerState.visibleRegion = Region{Rect{0, 0, 1000, 1000}};
+
+ impl::LayerCompositionState leftLayerState;
+ leftLayerState.frontEnd.isOpaque = true;
+
+ impl::OutputLayerCompositionState rightOutputLayerState;
+ rightOutputLayerState.clearClientTarget = true;
+ rightOutputLayerState.visibleRegion = Region{Rect{1000, 0, 2000, 1000}};
+
+ impl::LayerCompositionState rightLayerState;
+ rightLayerState.frontEnd.isOpaque = true;
+
+ const half3 rightLayerColor{0.f, 1.f, 0.f};
+ renderengine::LayerSettings rightLayerRESettings;
+ rightLayerRESettings.geometry.boundaries = FloatRect{456, 0, 0, 0};
+ rightLayerRESettings.source.solidColor = rightLayerColor;
+
+ EXPECT_CALL(*leftOutputLayer, getState()).WillRepeatedly(ReturnRef(leftOutputLayerState));
+ EXPECT_CALL(*leftOutputLayer, getLayer()).WillRepeatedly(ReturnRef(leftLayer));
+ EXPECT_CALL(*leftOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(leftLayerFE));
+ EXPECT_CALL(*leftOutputLayer, requiresClientComposition()).WillRepeatedly(Return(false));
+ EXPECT_CALL(*leftOutputLayer, needsFiltering()).WillRepeatedly(Return(false));
+ EXPECT_CALL(leftLayer, getState()).WillRepeatedly(ReturnRef(leftLayerState));
+
+ EXPECT_CALL(*rightOutputLayer, getState()).WillRepeatedly(ReturnRef(rightOutputLayerState));
+ EXPECT_CALL(*rightOutputLayer, getLayer()).WillRepeatedly(ReturnRef(rightLayer));
+ EXPECT_CALL(*rightOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(rightLayerFE));
+ EXPECT_CALL(*rightOutputLayer, requiresClientComposition()).WillRepeatedly(Return(false));
+ EXPECT_CALL(*rightOutputLayer, needsFiltering()).WillRepeatedly(Return(false));
+ EXPECT_CALL(rightLayer, getState()).WillRepeatedly(ReturnRef(rightLayerState));
+ EXPECT_CALL(rightLayerFE, prepareClientComposition(_)).WillOnce(Return(rightLayerRESettings));
+
+ Output::OutputLayers outputLayers;
+ outputLayers.emplace_back(std::unique_ptr<OutputLayer>(leftOutputLayer));
+ outputLayers.emplace_back(std::unique_ptr<OutputLayer>(rightOutputLayer));
+ mOutput.setOutputLayersOrderedByZ(std::move(outputLayers));
+
+ const Rect kPortraitFrame(0, 0, 1000, 2000);
+ const Rect kPortraitViewport(0, 0, 2000, 1000);
+ const Rect kPortraitScissor(0, 0, 1000, 2000);
+ const uint32_t kPortraitOrientation = TR_ROT_90;
+
+ mOutput.editState().frame = kPortraitFrame;
+ mOutput.editState().viewport = kPortraitViewport;
+ mOutput.editState().scissor = kPortraitScissor;
+ mOutput.editState().transform = ui::Transform{kPortraitOrientation};
+ mOutput.editState().orientation = kPortraitOrientation;
+ mOutput.editState().needsFiltering = true;
+ mOutput.editState().isSecure = false;
+
+ constexpr bool supportsProtectedContent = false;
+ Region clearRegion;
+ auto requests =
+ mOutput.generateClientCompositionRequests(supportsProtectedContent, clearRegion);
+
+ const half3 clearColor{0.f, 0.f, 0.f};
+
+ ASSERT_EQ(1u, requests.size());
+ EXPECT_EQ(456.f, requests[0].geometry.boundaries.left);
+ EXPECT_EQ(clearColor, requests[0].source.solidColor);
+}
+
} // namespace
} // namespace android::compositionengine
diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp
index b6d79d4..2ada86b 100644
--- a/services/surfaceflinger/DisplayDevice.cpp
+++ b/services/surfaceflinger/DisplayDevice.cpp
@@ -117,16 +117,6 @@
}
// ----------------------------------------------------------------------------
-
-void DisplayDevice::setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers) {
- mVisibleLayersSortedByZ = layers;
-}
-
-const Vector< sp<Layer> >& DisplayDevice::getVisibleLayersSortedByZ() const {
- return mVisibleLayersSortedByZ;
-}
-
-// ----------------------------------------------------------------------------
void DisplayDevice::setPowerMode(int mode) {
mPowerMode = mode;
getCompositionDisplay()->setCompositionEnabled(mPowerMode != HWC_POWER_MODE_OFF);
@@ -291,7 +281,6 @@
result.append(" ");
StringAppendF(&result, "powerMode=%d, ", mPowerMode);
StringAppendF(&result, "activeConfig=%d, ", mActiveConfig);
- StringAppendF(&result, "numLayers=%zu\n", mVisibleLayersSortedByZ.size());
getCompositionDisplay()->dump(result);
}
diff --git a/services/surfaceflinger/DisplayDevice.h b/services/surfaceflinger/DisplayDevice.h
index 4321e3d..5277320 100644
--- a/services/surfaceflinger/DisplayDevice.h
+++ b/services/surfaceflinger/DisplayDevice.h
@@ -87,9 +87,6 @@
int getHeight() const;
int getInstallOrientation() const { return mDisplayInstallOrientation; }
- void setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers);
- const Vector< sp<Layer> >& getVisibleLayersSortedByZ() const;
-
void setLayerStack(uint32_t stack);
void setDisplaySize(const int newWidth, const int newHeight);
void setProjection(int orientation, const Rect& viewport, const Rect& frame);
@@ -179,9 +176,6 @@
* don't need synchronization.
*/
- // list of visible layers on that display
- Vector< sp<Layer> > mVisibleLayersSortedByZ;
-
/*
* Transaction state
*/
diff --git a/services/surfaceflinger/DisplayHardware/ComposerHal.cpp b/services/surfaceflinger/DisplayHardware/ComposerHal.cpp
index 7f47a2e..e53d099 100644
--- a/services/surfaceflinger/DisplayHardware/ComposerHal.cpp
+++ b/services/surfaceflinger/DisplayHardware/ComposerHal.cpp
@@ -110,6 +110,7 @@
namespace impl {
+#if defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
Composer::CommandWriter::CommandWriter(uint32_t initialMaxSize)
: CommandWriterBase(initialMaxSize) {}
@@ -160,6 +161,7 @@
writeSigned(static_cast<int32_t>(metadata.format));
write64(metadata.usage);
}
+#endif // defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
Composer::Composer(const std::string& serviceName)
: mWriter(kWriterInitialSize),
@@ -198,12 +200,14 @@
LOG_ALWAYS_FATAL("failed to create composer client");
}
+#if defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
if (mIsUsingVrComposer) {
sp<IVrComposerClient> vrClient = IVrComposerClient::castFrom(mClient);
if (vrClient == nullptr) {
LOG_ALWAYS_FATAL("failed to create vr composer client");
}
}
+#endif // defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
}
Composer::~Composer() = default;
@@ -565,17 +569,20 @@
const std::vector<IComposerClient::Rect>& damage)
{
mWriter.selectDisplay(display);
+
+#if defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
if (mIsUsingVrComposer && target.get()) {
IVrComposerClient::BufferMetadata metadata = {
- .width = target->getWidth(),
- .height = target->getHeight(),
- .stride = target->getStride(),
- .layerCount = target->getLayerCount(),
- .format = static_cast<types::V1_0::PixelFormat>(target->getPixelFormat()),
- .usage = target->getUsage(),
+ .width = target->getWidth(),
+ .height = target->getHeight(),
+ .stride = target->getStride(),
+ .layerCount = target->getLayerCount(),
+ .format = static_cast<types::V1_2::PixelFormat>(target->getPixelFormat()),
+ .usage = target->getUsage(),
};
mWriter.setClientTargetMetadata(metadata);
}
+#endif // defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
const native_handle_t* handle = nullptr;
if (target.get()) {
@@ -695,17 +702,20 @@
{
mWriter.selectDisplay(display);
mWriter.selectLayer(layer);
+
+#if defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
if (mIsUsingVrComposer && buffer.get()) {
IVrComposerClient::BufferMetadata metadata = {
- .width = buffer->getWidth(),
- .height = buffer->getHeight(),
- .stride = buffer->getStride(),
- .layerCount = buffer->getLayerCount(),
- .format = static_cast<types::V1_0::PixelFormat>(buffer->getPixelFormat()),
- .usage = buffer->getUsage(),
+ .width = buffer->getWidth(),
+ .height = buffer->getHeight(),
+ .stride = buffer->getStride(),
+ .layerCount = buffer->getLayerCount(),
+ .format = static_cast<types::V1_2::PixelFormat>(buffer->getPixelFormat()),
+ .usage = buffer->getUsage(),
};
mWriter.setLayerBufferMetadata(metadata);
}
+#endif // defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
const native_handle_t* handle = nullptr;
if (buffer.get()) {
@@ -823,6 +833,7 @@
return Error::NONE;
}
+#if defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
Error Composer::setLayerInfo(Display display, Layer layer, uint32_t type,
uint32_t appId)
{
@@ -833,6 +844,15 @@
}
return Error::NONE;
}
+#else
+Error Composer::setLayerInfo(Display display, Layer layer, uint32_t, uint32_t) {
+ if (mIsUsingVrComposer) {
+ mWriter.selectDisplay(display);
+ mWriter.selectLayer(layer);
+ }
+ return Error::NONE;
+}
+#endif // defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
Error Composer::execute()
{
diff --git a/services/surfaceflinger/DisplayHardware/ComposerHal.h b/services/surfaceflinger/DisplayHardware/ComposerHal.h
index c4e952b..9f6cac2 100644
--- a/services/surfaceflinger/DisplayHardware/ComposerHal.h
+++ b/services/surfaceflinger/DisplayHardware/ComposerHal.h
@@ -23,7 +23,9 @@
#include <utility>
#include <vector>
-#include <android/frameworks/vr/composer/1.0/IVrComposerClient.h>
+#if defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
+#include <android/frameworks/vr/composer/2.0/IVrComposerClient.h>
+#endif // defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
#include <android/hardware/graphics/common/1.1/types.h>
#include <android/hardware/graphics/composer/2.3/IComposer.h>
#include <android/hardware/graphics/composer/2.3/IComposerClient.h>
@@ -38,7 +40,9 @@
namespace Hwc2 {
-using frameworks::vr::composer::V1_0::IVrComposerClient;
+#if defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
+using frameworks::vr::composer::V2_0::IVrComposerClient;
+#endif // defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
namespace types = hardware::graphics::common;
@@ -418,6 +422,7 @@
Error setDisplayBrightness(Display display, float brightness) override;
private:
+#if defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
class CommandWriter : public CommandWriterBase {
public:
explicit CommandWriter(uint32_t initialMaxSize);
@@ -433,6 +438,13 @@
void writeBufferMetadata(
const IVrComposerClient::BufferMetadata& metadata);
};
+#else
+ class CommandWriter : public CommandWriterBase {
+ public:
+ explicit CommandWriter(uint32_t initialMaxSize) : CommandWriterBase(initialMaxSize) {}
+ ~CommandWriter() override {}
+ };
+#endif // defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
// Many public functions above simply write a command into the command
// queue to batch the calls. validateDisplay and presentDisplay will call
diff --git a/services/surfaceflinger/FrameTracer/FrameTracer.cpp b/services/surfaceflinger/FrameTracer/FrameTracer.cpp
new file mode 100644
index 0000000..006dbfe
--- /dev/null
+++ b/services/surfaceflinger/FrameTracer/FrameTracer.cpp
@@ -0,0 +1,176 @@
+/*
+ * Copyright 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.
+ */
+
+#undef LOG_TAG
+#define LOG_TAG "FrameTracer"
+#define ATRACE_TAG ATRACE_TAG_GRAPHICS
+
+#include "FrameTracer.h"
+
+#include <android-base/stringprintf.h>
+
+#include <algorithm>
+#include <mutex>
+
+PERFETTO_DEFINE_DATA_SOURCE_STATIC_MEMBERS(android::FrameTracer::FrameTracerDataSource);
+
+namespace android {
+
+void FrameTracer::initialize() {
+ std::call_once(mInitializationFlag, [this]() {
+ perfetto::TracingInitArgs args;
+ args.backends = perfetto::kSystemBackend;
+ perfetto::Tracing::Initialize(args);
+ registerDataSource();
+ });
+}
+
+void FrameTracer::registerDataSource() {
+ perfetto::DataSourceDescriptor dsd;
+ dsd.set_name(kFrameTracerDataSource);
+ FrameTracerDataSource::Register(dsd);
+}
+
+void FrameTracer::traceNewLayer(int32_t layerID, const std::string& layerName) {
+ FrameTracerDataSource::Trace([this, layerID, &layerName](FrameTracerDataSource::TraceContext) {
+ if (mTraceTracker.find(layerID) == mTraceTracker.end()) {
+ std::lock_guard<std::mutex> lock(mTraceMutex);
+ mTraceTracker[layerID].layerName = layerName;
+ }
+ });
+}
+
+void FrameTracer::traceTimestamp(int32_t layerID, uint64_t bufferID, uint64_t frameNumber,
+ nsecs_t timestamp, FrameEvent::BufferEventType type,
+ nsecs_t duration) {
+ FrameTracerDataSource::Trace([this, layerID, bufferID, frameNumber, timestamp, type,
+ duration](FrameTracerDataSource::TraceContext ctx) {
+ std::lock_guard<std::mutex> lock(mTraceMutex);
+ if (mTraceTracker.find(layerID) == mTraceTracker.end()) {
+ return;
+ }
+
+ // Handle any pending fences for this buffer.
+ tracePendingFencesLocked(ctx, layerID, bufferID);
+
+ // Complete current trace.
+ traceLocked(ctx, layerID, bufferID, frameNumber, timestamp, type, duration);
+ });
+}
+
+void FrameTracer::traceFence(int32_t layerID, uint64_t bufferID, uint64_t frameNumber,
+ const std::shared_ptr<FenceTime>& fence,
+ FrameEvent::BufferEventType type, nsecs_t startTime) {
+ FrameTracerDataSource::Trace([this, layerID, bufferID, frameNumber, &fence, type,
+ startTime](FrameTracerDataSource::TraceContext ctx) {
+ const nsecs_t signalTime = fence->getSignalTime();
+ if (signalTime != Fence::SIGNAL_TIME_INVALID) {
+ std::lock_guard<std::mutex> lock(mTraceMutex);
+ if (mTraceTracker.find(layerID) == mTraceTracker.end()) {
+ return;
+ }
+
+ // Handle any pending fences for this buffer.
+ tracePendingFencesLocked(ctx, layerID, bufferID);
+
+ if (signalTime != Fence::SIGNAL_TIME_PENDING) {
+ traceSpanLocked(ctx, layerID, bufferID, frameNumber, type, startTime, signalTime);
+ } else {
+ mTraceTracker[layerID].pendingFences[bufferID].push_back(
+ {.frameNumber = frameNumber,
+ .type = type,
+ .fence = fence,
+ .startTime = startTime});
+ }
+ }
+ });
+}
+
+void FrameTracer::tracePendingFencesLocked(FrameTracerDataSource::TraceContext& ctx,
+ int32_t layerID, uint64_t bufferID) {
+ if (mTraceTracker[layerID].pendingFences.count(bufferID)) {
+ auto& pendingFences = mTraceTracker[layerID].pendingFences[bufferID];
+ for (size_t i = 0; i < pendingFences.size(); ++i) {
+ auto& pendingFence = pendingFences[i];
+
+ nsecs_t signalTime = Fence::SIGNAL_TIME_INVALID;
+ if (pendingFence.fence && pendingFence.fence->isValid()) {
+ signalTime = pendingFence.fence->getSignalTime();
+ if (signalTime == Fence::SIGNAL_TIME_PENDING) {
+ continue;
+ }
+ }
+
+ if (signalTime != Fence::SIGNAL_TIME_INVALID &&
+ systemTime() - signalTime < kFenceSignallingDeadline) {
+ traceSpanLocked(ctx, layerID, bufferID, pendingFence.frameNumber, pendingFence.type,
+ pendingFence.startTime, signalTime);
+ }
+
+ pendingFences.erase(pendingFences.begin() + i);
+ --i;
+ }
+ }
+}
+
+void FrameTracer::traceLocked(FrameTracerDataSource::TraceContext& ctx, int32_t layerID,
+ uint64_t bufferID, uint64_t frameNumber, nsecs_t timestamp,
+ FrameEvent::BufferEventType type, nsecs_t duration) {
+ auto packet = ctx.NewTracePacket();
+ packet->set_timestamp(timestamp);
+ auto* event = packet->set_graphics_frame_event()->set_buffer_event();
+ event->set_buffer_id(static_cast<uint32_t>(bufferID));
+ event->set_frame_number(frameNumber);
+ event->set_type(type);
+
+ if (mTraceTracker.find(layerID) != mTraceTracker.end() &&
+ !mTraceTracker[layerID].layerName.empty()) {
+ const std::string& layerName = mTraceTracker[layerID].layerName;
+ event->set_layer_name(layerName.c_str(), layerName.size());
+ }
+
+ if (duration > 0) {
+ event->set_duration_ns(duration);
+ }
+}
+
+void FrameTracer::traceSpanLocked(FrameTracerDataSource::TraceContext& ctx, int32_t layerID,
+ uint64_t bufferID, uint64_t frameNumber,
+ FrameEvent::BufferEventType type, nsecs_t startTime,
+ nsecs_t endTime) {
+ nsecs_t timestamp = endTime;
+ nsecs_t duration = 0;
+ if (startTime > 0 && startTime < endTime) {
+ timestamp = startTime;
+ duration = endTime - startTime;
+ }
+ traceLocked(ctx, layerID, bufferID, frameNumber, timestamp, type, duration);
+}
+
+void FrameTracer::onDestroy(int32_t layerID) {
+ std::lock_guard<std::mutex> traceLock(mTraceMutex);
+ mTraceTracker.erase(layerID);
+}
+
+std::string FrameTracer::miniDump() {
+ std::string result = "FrameTracer miniDump:\n";
+ std::lock_guard<std::mutex> lock(mTraceMutex);
+ android::base::StringAppendF(&result, "Number of layers currently being traced is %zu\n",
+ mTraceTracker.size());
+ return result;
+}
+
+} // namespace android
diff --git a/services/surfaceflinger/FrameTracer/FrameTracer.h b/services/surfaceflinger/FrameTracer/FrameTracer.h
new file mode 100644
index 0000000..d4dfab9
--- /dev/null
+++ b/services/surfaceflinger/FrameTracer/FrameTracer.h
@@ -0,0 +1,106 @@
+/*
+ * Copyright 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.
+ */
+
+#pragma once
+
+#include <perfetto/trace/android/graphics_frame_event.pbzero.h>
+#include <perfetto/tracing.h>
+#include <ui/FenceTime.h>
+
+#include <mutex>
+#include <unordered_map>
+
+namespace android {
+
+class FrameTracer {
+public:
+ class FrameTracerDataSource : public perfetto::DataSource<FrameTracerDataSource> {
+ virtual void OnSetup(const SetupArgs&) override{};
+ virtual void OnStart(const StartArgs&) override{};
+ virtual void OnStop(const StopArgs&) override{};
+ };
+
+ using FrameEvent = perfetto::protos::pbzero::GraphicsFrameEvent;
+
+ ~FrameTracer() = default;
+
+ // Sets up the perfetto tracing backend and data source.
+ void initialize();
+ // Registers the data source with the perfetto backend. Called as part of initialize()
+ // and should not be called manually outside of tests. Public to allow for substituting a
+ // perfetto::kInProcessBackend in tests.
+ void registerDataSource();
+ // Starts tracking a new layer for tracing. Needs to be called once before traceTimestamp() or
+ // traceFence() for each layer.
+ void traceNewLayer(int32_t layerID, const std::string& layerName);
+ // Creates a trace point at the timestamp provided.
+ void traceTimestamp(int32_t layerID, uint64_t bufferID, uint64_t frameNumber, nsecs_t timestamp,
+ FrameEvent::BufferEventType type, nsecs_t duration = 0);
+ // Creates a trace point after the provided fence has been signalled. If a startTime is provided
+ // the trace will have be timestamped from startTime until fence signalling time. If no
+ // startTime is provided, a durationless trace point will be created timestamped at fence
+ // signalling time. If the fence hasn't signalled yet, the trace point will be created the next
+ // time after signalling a trace call for this buffer occurs.
+ void traceFence(int32_t layerID, uint64_t bufferID, uint64_t frameNumber,
+ const std::shared_ptr<FenceTime>& fence, FrameEvent::BufferEventType type,
+ nsecs_t startTime = 0);
+
+ // Takes care of cleanup when a layer is destroyed.
+ void onDestroy(int32_t layerID);
+
+ std::string miniDump();
+
+ static constexpr char kFrameTracerDataSource[] = "android.surfaceflinger.frame";
+
+ // The maximum amount of time a fence has to signal before it is discarded.
+ // Used to avoid fences from previous traces generating new trace points in later ones.
+ // Public for testing.
+ static constexpr nsecs_t kFenceSignallingDeadline = 60'000'000'000; // 60 seconds
+
+private:
+ struct PendingFence {
+ uint64_t frameNumber;
+ FrameEvent::BufferEventType type;
+ std::shared_ptr<FenceTime> fence;
+ nsecs_t startTime;
+ };
+
+ struct TraceRecord {
+ std::string layerName;
+ using BufferID = uint64_t;
+ std::unordered_map<BufferID, std::vector<PendingFence>> pendingFences;
+ };
+
+ // Checks if any pending fences for a layer and buffer have signalled and, if they have, creates
+ // trace points for them.
+ void tracePendingFencesLocked(FrameTracerDataSource::TraceContext& ctx, int32_t layerID,
+ uint64_t bufferID);
+ // Creates a trace point by translating a start time and an end time to a timestamp and
+ // duration. If startTime is later than end time it sets end time as the timestamp and the
+ // duration to 0. Used by traceFence().
+ void traceSpanLocked(FrameTracerDataSource::TraceContext& ctx, int32_t layerID,
+ uint64_t bufferID, uint64_t frameNumber, FrameEvent::BufferEventType type,
+ nsecs_t startTime, nsecs_t endTime);
+ void traceLocked(FrameTracerDataSource::TraceContext& ctx, int32_t layerID, uint64_t bufferID,
+ uint64_t frameNumber, nsecs_t timestamp, FrameEvent::BufferEventType type,
+ nsecs_t duration = 0);
+
+ std::mutex mTraceMutex;
+ std::unordered_map<int32_t, TraceRecord> mTraceTracker;
+ std::once_flag mInitializationFlag;
+};
+
+} // namespace android
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 4c8a6bf..c1395e7 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -22,6 +22,7 @@
#include "Layer.h"
#include <android-base/stringprintf.h>
+#include <binder/IPCThreadState.h>
#include <compositionengine/Display.h>
#include <compositionengine/Layer.h>
#include <compositionengine/LayerFECompositionState.h>
@@ -57,6 +58,7 @@
#include "Colorizer.h"
#include "DisplayDevice.h"
#include "DisplayHardware/HWComposer.h"
+#include "FrameTracer/FrameTracer.h"
#include "LayerProtoHelper.h"
#include "LayerRejecter.h"
#include "MonitoredProducer.h"
@@ -121,7 +123,8 @@
mFrameTracker.setDisplayRefreshPeriod(compositorTiming.interval);
mSchedulerLayerHandle = mFlinger->mScheduler->registerLayer(mName.c_str(), mWindowType);
-
+ mCallingPid = args.callingPid;
+ mCallingUid = args.callingUid;
mFlinger->onLayerCreated();
}
@@ -135,6 +138,21 @@
mFlinger->onLayerDestroyed(this);
}
+LayerCreationArgs::LayerCreationArgs(SurfaceFlinger* flinger, const sp<Client>& client,
+ const String8& name, uint32_t w, uint32_t h, uint32_t flags,
+ LayerMetadata metadata)
+ : flinger(flinger),
+ client(client),
+ name(name),
+ w(w),
+ h(h),
+ flags(flags),
+ metadata(std::move(metadata)) {
+ IPCThreadState* ipc = IPCThreadState::self();
+ callingPid = ipc->getCallingPid();
+ callingUid = ipc->getCallingUid();
+}
+
// ---------------------------------------------------------------------------
// callbacks
// ---------------------------------------------------------------------------
@@ -443,10 +461,6 @@
const auto& drawingState{getDrawingState()};
compositionState.forceClientComposition = false;
- // TODO(lpique): b/121291683 Remove this one we are sure we don't need the
- // value recomputed / set every frame.
- compositionState.geomVisibleRegion = visibleRegion;
-
compositionState.isColorspaceAgnostic = isColorSpaceAgnostic();
compositionState.dataspace = mCurrentDataSpace;
compositionState.colorTransform = getColorTransform();
@@ -464,6 +478,21 @@
}
}
+void Layer::latchCursorCompositionState(
+ compositionengine::LayerFECompositionState& compositionState) const {
+ // This gives us only the "orientation" component of the transform
+ const State& drawingState{getDrawingState()};
+
+ // Apply the layer's transform, followed by the display's global transform
+ // Here we're guaranteed that the layer's transform preserves rects
+ Rect win = getCroppedBufferSize(drawingState);
+ // Subtract the transparent region and snap to the bounds
+ Rect bounds = reduce(win, getActiveTransparentRegion(drawingState));
+ Rect frame(getTransform().transform(bounds));
+
+ compositionState.cursorFrame = frame;
+}
+
bool Layer::onPreComposition(nsecs_t) {
return false;
}
@@ -481,38 +510,6 @@
return mName.string();
}
-void Layer::updateCursorPosition(const sp<const DisplayDevice>& display) {
- const auto outputLayer = findOutputLayerForDisplay(display);
- LOG_FATAL_IF(!outputLayer);
-
- if (!outputLayer->getState().hwc ||
- (*outputLayer->getState().hwc).hwcCompositionType !=
- Hwc2::IComposerClient::Composition::CURSOR) {
- return;
- }
-
- // This gives us only the "orientation" component of the transform
- const State& s(getDrawingState());
-
- // Apply the layer's transform, followed by the display's global transform
- // Here we're guaranteed that the layer's transform preserves rects
- Rect win = getCroppedBufferSize(s);
- // Subtract the transparent region and snap to the bounds
- Rect bounds = reduce(win, getActiveTransparentRegion(s));
- Rect frame(getTransform().transform(bounds));
- frame.intersect(display->getViewport(), &frame);
- auto& displayTransform = display->getTransform();
- auto position = displayTransform.transform(frame);
-
- auto error =
- (*outputLayer->getState().hwc).hwcLayer->setCursorPosition(position.left, position.top);
- ALOGE_IF(error != HWC2::Error::None,
- "[%s] Failed to set cursor position "
- "to (%d, %d): %s (%d)",
- mName.string(), position.left, position.top, to_string(error).c_str(),
- static_cast<int32_t>(error));
-}
-
// ---------------------------------------------------------------------------
// drawing...
// ---------------------------------------------------------------------------
@@ -584,27 +581,6 @@
return (s.flags & layer_state_t::eLayerSecure);
}
-void Layer::setVisibleRegion(const Region& visibleRegion) {
- // always called from main thread
- this->visibleRegion = visibleRegion;
-}
-
-void Layer::setCoveredRegion(const Region& coveredRegion) {
- // always called from main thread
- this->coveredRegion = coveredRegion;
-}
-
-void Layer::setVisibleNonTransparentRegion(const Region& setVisibleNonTransparentRegion) {
- // always called from main thread
- this->visibleNonTransparentRegion = setVisibleNonTransparentRegion;
-}
-
-void Layer::clearVisibilityRegions() {
- visibleRegion.clear();
- visibleNonTransparentRegion.clear();
- coveredRegion.clear();
-}
-
// ----------------------------------------------------------------------------
// transaction
// ----------------------------------------------------------------------------
@@ -1200,7 +1176,8 @@
info.mParentName = (parent == nullptr ? std::string("none") : parent->getName().string());
info.mType = getType();
info.mTransparentRegion = ds.activeTransparentRegion_legacy;
- info.mVisibleRegion = visibleRegion;
+
+ info.mVisibleRegion = debugGetVisibleRegionOnDefaultDisplay();
info.mSurfaceDamageRegion = surfaceDamageRegion;
info.mLayerStack = getLayerStack();
info.mX = ds.active_legacy.transform.tx();
@@ -1321,10 +1298,17 @@
mFrameEventHistory.dump(result);
}
+void Layer::dumpCallingUidPid(std::string& result) const {
+ StringAppendF(&result, "Layer %s (%s) pid:%d uid:%d\n", getName().string(), getType(),
+ mCallingPid, mCallingUid);
+}
+
void Layer::onDisconnect() {
Mutex::Autolock lock(mFrameEventHistoryMutex);
mFrameEventHistory.onDisconnect();
- mFlinger->mTimeStats->onDestroy(getSequence());
+ const int32_t layerID = getSequence();
+ mFlinger->mTimeStats->onDestroy(layerID);
+ mFlinger->mFrameTracer->onDestroy(layerID);
}
void Layer::addAndGetFrameTimestamps(const NewFrameEventsEntry* newTimestamps,
@@ -1824,7 +1808,7 @@
LayerProtoHelper::writePositionToProto(transform.tx(), transform.ty(),
[&]() { return layerInfo->mutable_position(); });
LayerProtoHelper::writeToProto(mBounds, [&]() { return layerInfo->mutable_bounds(); });
- LayerProtoHelper::writeToProto(visibleRegion,
+ LayerProtoHelper::writeToProto(debugGetVisibleRegionOnDefaultDisplay(),
[&]() { return layerInfo->mutable_visible_region(); });
LayerProtoHelper::writeToProto(surfaceDamageRegion,
[&]() { return layerInfo->mutable_damage_region(); });
@@ -1927,7 +1911,7 @@
InputWindowInfo info = mDrawingState.inputInfo;
if (info.displayId == ADISPLAY_ID_NONE) {
- info.displayId = mDrawingState.layerStack;
+ info.displayId = getLayerStack();
}
ui::Transform t = getTransform();
@@ -2001,6 +1985,20 @@
return display->getCompositionDisplay()->getOutputLayerForLayer(getCompositionLayer().get());
}
+Region Layer::debugGetVisibleRegionOnDefaultDisplay() const {
+ sp<DisplayDevice> displayDevice = mFlinger->getDefaultDisplayDeviceLocked();
+ if (displayDevice == nullptr) {
+ return {};
+ }
+
+ auto outputLayer = findOutputLayerForDisplay(displayDevice);
+ if (outputLayer == nullptr) {
+ return {};
+ }
+
+ return outputLayer->getState().visibleRegion;
+}
+
// ---------------------------------------------------------------------------
}; // namespace android
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index a2409e7..9d7448a 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -80,9 +80,7 @@
struct LayerCreationArgs {
LayerCreationArgs(SurfaceFlinger* flinger, const sp<Client>& client, const String8& name,
- uint32_t w, uint32_t h, uint32_t flags, LayerMetadata metadata)
- : flinger(flinger), client(client), name(name), w(w), h(h), flags(flags),
- metadata(std::move(metadata)) {}
+ uint32_t w, uint32_t h, uint32_t flags, LayerMetadata metadata);
SurfaceFlinger* flinger;
const sp<Client>& client;
@@ -91,17 +89,15 @@
uint32_t h;
uint32_t flags;
LayerMetadata metadata;
+ pid_t callingPid;
+ uid_t callingUid;
};
-class Layer : public virtual compositionengine::LayerFE {
+class Layer : public compositionengine::LayerFE {
static std::atomic<int32_t> sSequence;
public:
mutable bool contentDirty{false};
- // regions below are in window-manager space
- Region visibleRegion;
- Region coveredRegion;
- Region visibleNonTransparentRegion;
Region surfaceDamageRegion;
// Layer serial number. This gives layers an explicit ordering, so we
@@ -376,6 +372,14 @@
int32_t getSequence() const { return sequence; }
+ // For tracing.
+ // TODO: Replace with raw buffer id from buffer metadata when that becomes available.
+ // GraphicBuffer::getId() does not provide a reliable global identifier. Since the traces
+ // creates its tracks by buffer id and has no way of associating a buffer back to the process
+ // that created it, the current implementation is only sufficient for cases where a buffer is
+ // only used within a single layer.
+ uint64_t getCurrentBufferId() const { return mActiveBuffer ? mActiveBuffer->getId() : 0; }
+
// -----------------------------------------------------------------------
// Virtuals
@@ -468,6 +472,7 @@
bool onPreComposition(nsecs_t) override;
void latchCompositionState(compositionengine::LayerFECompositionState&,
bool includeGeometry) const override;
+ void latchCursorCompositionState(compositionengine::LayerFECompositionState&) const override;
std::optional<renderengine::LayerSettings> prepareClientComposition(
compositionengine::LayerFE::ClientCompositionTargetSettings&) override;
void onLayerDisplayed(const sp<Fence>& releaseFence) override;
@@ -485,7 +490,6 @@
Hwc2::IComposerClient::Composition getCompositionType(
const sp<const DisplayDevice>& display) const;
bool getClearClientTarget(const sp<const DisplayDevice>& display) const;
- void updateCursorPosition(const sp<const DisplayDevice>& display);
virtual bool shouldPresentNow(nsecs_t /*expectedPresentTime*/) const { return false; }
virtual void setTransformHint(uint32_t /*orientation*/) const { }
@@ -511,30 +515,6 @@
uint32_t doTransaction(uint32_t transactionFlags);
/*
- * setVisibleRegion - called to set the new visible region. This gives
- * a chance to update the new visible region or record the fact it changed.
- */
- void setVisibleRegion(const Region& visibleRegion);
-
- /*
- * setCoveredRegion - called when the covered region changes. The covered
- * region corresponds to any area of the surface that is covered
- * (transparently or not) by another surface.
- */
- void setCoveredRegion(const Region& coveredRegion);
-
- /*
- * setVisibleNonTransparentRegion - called when the visible and
- * non-transparent region changes.
- */
- void setVisibleNonTransparentRegion(const Region& visibleNonTransparentRegion);
-
- /*
- * Clear the visible, covered, and non-transparent regions.
- */
- void clearVisibilityRegions();
-
- /*
* latchBuffer - called each time the screen is redrawn and returns whether
* the visible regions need to be recomputed (this is a fairly heavy
* operation, so this should be set only if needed). Typically this is used
@@ -600,6 +580,7 @@
void miniDump(std::string& result, const sp<DisplayDevice>& display) const;
void dumpFrameStats(std::string& result) const;
void dumpFrameEvents(std::string& result);
+ void dumpCallingUidPid(std::string& result) const;
void clearFrameStats();
void logFrameStats();
void getFrameStats(FrameStats* outStats) const;
@@ -676,6 +657,8 @@
compositionengine::OutputLayer* findOutputLayerForDisplay(
const sp<const DisplayDevice>& display) const;
+ Region debugGetVisibleRegionOnDefaultDisplay() const;
+
protected:
// constant
sp<SurfaceFlinger> mFlinger;
@@ -922,6 +905,11 @@
bool mGetHandleCalled = false;
void removeRemoteSyncPoints();
+
+ // Tracks the process and user id of the caller when creating this layer
+ // to help debugging.
+ pid_t mCallingPid;
+ uid_t mCallingUid;
};
} // namespace android
diff --git a/services/surfaceflinger/RegionSamplingThread.cpp b/services/surfaceflinger/RegionSamplingThread.cpp
index 07fdead..1c1367c 100644
--- a/services/surfaceflinger/RegionSamplingThread.cpp
+++ b/services/surfaceflinger/RegionSamplingThread.cpp
@@ -21,15 +21,18 @@
#include "RegionSamplingThread.h"
-#include <cutils/properties.h>
-#include <gui/IRegionSamplingListener.h>
-#include <utils/Trace.h>
-#include <string>
-
#include <compositionengine/Display.h>
#include <compositionengine/impl/OutputCompositionState.h>
+#include <cutils/properties.h>
+#include <gui/IRegionSamplingListener.h>
+#include <ui/DisplayStatInfo.h>
+#include <utils/Trace.h>
+
+#include <string>
+
#include "DisplayDevice.h"
#include "Layer.h"
+#include "Scheduler/DispSync.h"
#include "SurfaceFlinger.h"
namespace android {
@@ -105,9 +108,8 @@
if (mVsyncListening) return;
mPhaseIntervalSetting = Phase::ZERO;
- mScheduler.withPrimaryDispSync([this](android::DispSync& sync) {
- sync.addEventListener("SamplingThreadDispSyncListener", 0, this, mLastCallbackTime);
- });
+ mScheduler.getPrimaryDispSync().addEventListener("SamplingThreadDispSyncListener", 0, this,
+ mLastCallbackTime);
mVsyncListening = true;
}
@@ -120,9 +122,7 @@
void stopVsyncListenerLocked() /*REQUIRES(mMutex)*/ {
if (!mVsyncListening) return;
- mScheduler.withPrimaryDispSync([this](android::DispSync& sync) {
- sync.removeEventListener(this, &mLastCallbackTime);
- });
+ mScheduler.getPrimaryDispSync().removeEventListener(this, &mLastCallbackTime);
mVsyncListening = false;
}
@@ -132,16 +132,13 @@
if (mPhaseIntervalSetting == Phase::ZERO) {
ATRACE_INT(lumaSamplingStepTag, static_cast<int>(samplingStep::waitForSamplePhase));
mPhaseIntervalSetting = Phase::SAMPLING;
- mScheduler.withPrimaryDispSync([this](android::DispSync& sync) {
- sync.changePhaseOffset(this, mTargetSamplingOffset.count());
- });
+ mScheduler.getPrimaryDispSync().changePhaseOffset(this, mTargetSamplingOffset.count());
return;
}
if (mPhaseIntervalSetting == Phase::SAMPLING) {
mPhaseIntervalSetting = Phase::ZERO;
- mScheduler.withPrimaryDispSync(
- [this](android::DispSync& sync) { sync.changePhaseOffset(this, 0); });
+ mScheduler.getPrimaryDispSync().changePhaseOffset(this, 0);
stopVsyncListenerLocked();
lock.unlock();
mRegionSamplingThread.notifySamplingOffset();
diff --git a/services/surfaceflinger/Scheduler/DispSync.cpp b/services/surfaceflinger/Scheduler/DispSync.cpp
index ad5eb33..4bdfad9 100644
--- a/services/surfaceflinger/Scheduler/DispSync.cpp
+++ b/services/surfaceflinger/Scheduler/DispSync.cpp
@@ -462,22 +462,14 @@
TracedOrdinal<bool> mParity;
};
-DispSync::DispSync(const char* name) : mName(name), mRefreshSkipCount(0) {
+DispSync::DispSync(const char* name, bool hasSyncFramework)
+ : mName(name), mIgnorePresentFences(!hasSyncFramework) {
// This flag offers the ability to turn on systrace logging from the shell.
char value[PROPERTY_VALUE_MAX];
property_get("debug.sf.dispsync_trace_detailed_info", value, "0");
mTraceDetailedInfo = atoi(value);
+
mThread = new DispSyncThread(name, mTraceDetailedInfo);
-}
-
-DispSync::~DispSync() {
- mThread->stop();
- mThread->requestExitAndWait();
-}
-
-void DispSync::init(bool hasSyncFramework, int64_t dispSyncPresentTimeOffset) {
- mIgnorePresentFences = !hasSyncFramework;
- mPresentTimeOffset = dispSyncPresentTimeOffset;
mThread->run("DispSync", PRIORITY_URGENT_DISPLAY + PRIORITY_MORE_FAVORABLE);
// set DispSync to SCHED_FIFO to minimize jitter
@@ -495,6 +487,11 @@
}
}
+DispSync::~DispSync() {
+ mThread->stop();
+ mThread->requestExitAndWait();
+}
+
void DispSync::reset() {
Mutex::Autolock lock(mMutex);
resetLocked();
@@ -620,13 +617,6 @@
return mThread->addEventListener(name, phase, callback, lastCallbackTime);
}
-void DispSync::setRefreshSkipCount(int count) {
- Mutex::Autolock lock(mMutex);
- ALOGD("setRefreshSkipCount(%d)", count);
- mRefreshSkipCount = count;
- updateModelLocked();
-}
-
status_t DispSync::removeEventListener(Callback* callback, nsecs_t* outLastCallbackTime) {
Mutex::Autolock lock(mMutex);
return mThread->removeEventListener(callback, outLastCallbackTime);
@@ -709,9 +699,6 @@
ALOGV("[%s] Adjusting mPhase -> %" PRId64, mName, ns2us(mPhase));
}
- // Artificially inflate the period if requested.
- mPeriod += mPeriod * mRefreshSkipCount;
-
mThread->updateModel(mPeriod, mPhase, mReferenceTime);
mModelUpdated = true;
}
@@ -722,10 +709,6 @@
return;
}
- // Need to compare present fences against the un-adjusted refresh period,
- // since they might arrive between two events.
- nsecs_t period = mPeriod / (1 + mRefreshSkipCount);
-
int numErrSamples = 0;
nsecs_t sqErrSum = 0;
@@ -744,9 +727,9 @@
continue;
}
- nsecs_t sampleErr = (sample - mPhase) % period;
- if (sampleErr > period / 2) {
- sampleErr -= period;
+ nsecs_t sampleErr = (sample - mPhase) % mPeriod;
+ if (sampleErr > mPeriod / 2) {
+ sampleErr -= mPeriod;
}
sqErrSum += sampleErr * sampleErr;
numErrSamples++;
@@ -801,8 +784,7 @@
void DispSync::dump(std::string& result) const {
Mutex::Autolock lock(mMutex);
StringAppendF(&result, "present fences are %s\n", mIgnorePresentFences ? "ignored" : "used");
- StringAppendF(&result, "mPeriod: %" PRId64 " ns (%.3f fps; skipCount=%d)\n", mPeriod,
- 1000000000.0 / mPeriod, mRefreshSkipCount);
+ StringAppendF(&result, "mPeriod: %" PRId64 " ns (%.3f fps)\n", mPeriod, 1000000000.0 / mPeriod);
StringAppendF(&result, "mPhase: %" PRId64 " ns\n", mPhase);
StringAppendF(&result, "mError: %" PRId64 " ns (sqrt=%.1f)\n", mError, sqrt(mError));
StringAppendF(&result, "mNumResyncSamplesSincePresent: %d (limit %d)\n",
diff --git a/services/surfaceflinger/Scheduler/DispSync.h b/services/surfaceflinger/Scheduler/DispSync.h
index 3e33c7e..c6aadbb 100644
--- a/services/surfaceflinger/Scheduler/DispSync.h
+++ b/services/surfaceflinger/Scheduler/DispSync.h
@@ -53,7 +53,6 @@
virtual void endResync() = 0;
virtual void setPeriod(nsecs_t period) = 0;
virtual nsecs_t getPeriod() = 0;
- virtual void setRefreshSkipCount(int count) = 0;
virtual status_t addEventListener(const char* name, nsecs_t phase, Callback* callback,
nsecs_t lastCallbackTime) = 0;
virtual status_t removeEventListener(Callback* callback, nsecs_t* outLastCallback) = 0;
@@ -88,11 +87,10 @@
// needed.
class DispSync : public android::DispSync {
public:
- explicit DispSync(const char* name);
+ // hasSyncFramework specifies whether the platform supports present fences.
+ DispSync(const char* name, bool hasSyncFramework);
~DispSync() override;
- void init(bool hasSyncFramework, int64_t dispSyncPresentTimeOffset);
-
// reset clears the resync samples and error value.
void reset() override;
@@ -138,12 +136,6 @@
// The getPeriod method returns the current vsync period.
nsecs_t getPeriod() override;
- // setRefreshSkipCount specifies an additional number of refresh
- // cycles to skip. For example, on a 60Hz display, a skip count of 1
- // will result in events happening at 30Hz. Default is zero. The idea
- // is to sacrifice smoothness for battery life.
- void setRefreshSkipCount(int count) override;
-
// addEventListener registers a callback to be called repeatedly at the
// given phase offset from the hardware vsync events. The callback is
// called from a separate thread and it should return reasonably quickly
@@ -252,18 +244,12 @@
std::shared_ptr<FenceTime> mPresentFences[NUM_PRESENT_SAMPLES]{FenceTime::NO_FENCE};
size_t mPresentSampleOffset;
- int mRefreshSkipCount;
-
// mThread is the thread from which all the callbacks are called.
sp<DispSyncThread> mThread;
// mMutex is used to protect access to all member variables.
mutable Mutex mMutex;
- // This is the offset from the present fence timestamps to the corresponding
- // vsync event.
- int64_t mPresentTimeOffset;
-
// Ignore present (retire) fences if the device doesn't have support for the
// sync framework
bool mIgnorePresentFences;
diff --git a/services/surfaceflinger/Scheduler/EventControlThread.cpp b/services/surfaceflinger/Scheduler/EventControlThread.cpp
index fb6cff5..85a7f82 100644
--- a/services/surfaceflinger/Scheduler/EventControlThread.cpp
+++ b/services/surfaceflinger/Scheduler/EventControlThread.cpp
@@ -31,7 +31,7 @@
namespace impl {
EventControlThread::EventControlThread(EventControlThread::SetVSyncEnabledFunction function)
- : mSetVSyncEnabled(function) {
+ : mSetVSyncEnabled(std::move(function)) {
pthread_setname_np(mThread.native_handle(), "EventControlThread");
pid_t tid = pthread_gettid_np(mThread.native_handle());
diff --git a/services/surfaceflinger/Scheduler/OneShotTimer.h b/services/surfaceflinger/Scheduler/OneShotTimer.h
index fd1aa02..921631e 100644
--- a/services/surfaceflinger/Scheduler/OneShotTimer.h
+++ b/services/surfaceflinger/Scheduler/OneShotTimer.h
@@ -39,6 +39,8 @@
const TimeoutCallback& timeoutCallback);
~OneShotTimer();
+ const Interval& interval() const { return mInterval; }
+
// Initializes and turns on the idle timer.
void start();
// Stops the idle timer and any held resources.
diff --git a/services/surfaceflinger/Scheduler/PhaseOffsets.cpp b/services/surfaceflinger/Scheduler/PhaseOffsets.cpp
index 9f8567d..04e902b 100644
--- a/services/surfaceflinger/Scheduler/PhaseOffsets.cpp
+++ b/services/surfaceflinger/Scheduler/PhaseOffsets.cpp
@@ -24,7 +24,7 @@
namespace {
-std::optional<int> getProperty(const char* name) {
+std::optional<nsecs_t> getProperty(const char* name) {
char value[PROPERTY_VALUE_MAX];
property_get(name, value, "-1");
if (const int i = atoi(value); i != -1) return i;
@@ -63,12 +63,13 @@
void PhaseOffsets::dump(std::string& result) const {
const auto [early, earlyGl, late, threshold] = getCurrentOffsets();
- base::StringAppendF(&result,
- " app phase: %9" PRId64 " ns\t SF phase: %9" PRId64 " ns\n"
- " early app phase: %9" PRId64 " ns\t early SF phase: %9" PRId64 " ns\n"
- "GL early app phase: %9" PRId64 " ns\tGL early SF phase: %9" PRId64 " ns\n"
- "threshold for next VSYNC: %" PRId64 " ns\n",
- late.app, late.sf, early.app, early.sf, earlyGl.app, earlyGl.sf, threshold);
+ using base::StringAppendF;
+ StringAppendF(&result,
+ " app phase: %9" PRId64 " ns\t SF phase: %9" PRId64 " ns\n"
+ " early app phase: %9" PRId64 " ns\t early SF phase: %9" PRId64 " ns\n"
+ " GL early app phase: %9" PRId64 " ns\tGL early SF phase: %9" PRId64 " ns\n"
+ "next VSYNC threshold: %9" PRId64 " ns\n",
+ late.app, late.sf, early.app, early.sf, earlyGl.app, earlyGl.sf, threshold);
}
PhaseOffsets::Offsets PhaseOffsets::getDefaultOffsets(nsecs_t thresholdForNextVsync) {
diff --git a/services/surfaceflinger/Scheduler/RefreshRateConfigs.h b/services/surfaceflinger/Scheduler/RefreshRateConfigs.h
index d730058..9d47749 100644
--- a/services/surfaceflinger/Scheduler/RefreshRateConfigs.h
+++ b/services/surfaceflinger/Scheduler/RefreshRateConfigs.h
@@ -16,16 +16,23 @@
#pragma once
+#include <android-base/stringprintf.h>
+
#include <algorithm>
#include <numeric>
-
-#include "android-base/stringprintf.h"
+#include <type_traits>
#include "DisplayHardware/HWComposer.h"
#include "Scheduler/SchedulerUtils.h"
-namespace android {
-namespace scheduler {
+namespace android::scheduler {
+
+enum class RefreshRateConfigEvent : unsigned { None = 0b0, Changed = 0b1 };
+
+inline RefreshRateConfigEvent operator|(RefreshRateConfigEvent lhs, RefreshRateConfigEvent rhs) {
+ using T = std::underlying_type_t<RefreshRateConfigEvent>;
+ return static_cast<RefreshRateConfigEvent>(static_cast<T>(lhs) | static_cast<T>(rhs));
+}
/**
* This class is used to encapsulate configuration for refresh rates. It holds information
@@ -134,5 +141,4 @@
std::map<RefreshRateType, std::shared_ptr<RefreshRate>> mRefreshRates;
};
-} // namespace scheduler
-} // namespace android
+} // namespace android::scheduler
diff --git a/services/surfaceflinger/Scheduler/RefreshRateStats.h b/services/surfaceflinger/Scheduler/RefreshRateStats.h
index 7e7c630..1f097db 100644
--- a/services/surfaceflinger/Scheduler/RefreshRateStats.h
+++ b/services/surfaceflinger/Scheduler/RefreshRateStats.h
@@ -94,13 +94,13 @@
// Traverses through the map of config modes and returns how long they've been running in easy
// to read format.
- std::string doDump() const {
- std::ostringstream stream;
- stream << "+ Refresh rate: running time in seconds\n";
+ void dump(std::string& result) const {
+ std::ostringstream stream("+ Refresh rate: running time in seconds\n");
+
for (const auto& [name, time] : const_cast<RefreshRateStats*>(this)->getTotalTimes()) {
stream << name << ": " << getDateFormatFromMs(time) << '\n';
}
- return stream.str();
+ result.append(stream.str());
}
private:
diff --git a/services/surfaceflinger/Scheduler/Scheduler.cpp b/services/surfaceflinger/Scheduler/Scheduler.cpp
index 3883427..eb52d3f 100644
--- a/services/surfaceflinger/Scheduler/Scheduler.cpp
+++ b/services/surfaceflinger/Scheduler/Scheduler.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#undef LOG_TAG
+#define LOG_TAG "Scheduler"
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
#include "Scheduler.h"
@@ -21,6 +23,7 @@
#include <algorithm>
#include <cinttypes>
#include <cstdint>
+#include <functional>
#include <memory>
#include <numeric>
@@ -38,80 +41,56 @@
#include "DispSyncSource.h"
#include "EventControlThread.h"
#include "EventThread.h"
-#include "InjectVSyncSource.h"
-#include "LayerInfo.h"
#include "OneShotTimer.h"
#include "SchedulerUtils.h"
#include "SurfaceFlingerProperties.h"
+#define RETURN_IF_INVALID_HANDLE(handle, ...) \
+ do { \
+ if (mConnections.count(handle) == 0) { \
+ ALOGE("Invalid connection handle %" PRIuPTR, handle.id); \
+ return __VA_ARGS__; \
+ } \
+ } while (false)
+
namespace android {
-using namespace android::hardware::configstore;
-using namespace android::hardware::configstore::V1_0;
-using namespace android::sysprop;
-
-#define RETURN_VALUE_IF_INVALID(value) \
- if (handle == nullptr || mConnections.count(handle->id) == 0) return value
-#define RETURN_IF_INVALID() \
- if (handle == nullptr || mConnections.count(handle->id) == 0) return
-
-std::atomic<int64_t> Scheduler::sNextId = 0;
-
Scheduler::Scheduler(impl::EventControlThread::SetVSyncEnabledFunction function,
const scheduler::RefreshRateConfigs& refreshRateConfig)
- : mHasSyncFramework(running_without_sync_framework(true)),
- mDispSyncPresentTimeOffset(present_time_offset_from_vsync_ns(0)),
- mPrimaryHWVsyncEnabled(false),
- mHWVsyncAvailable(false),
+ : mPrimaryDispSync(new impl::DispSync("SchedulerDispSync",
+ sysprop::running_without_sync_framework(true))),
+ mEventControlThread(new impl::EventControlThread(std::move(function))),
+ mSupportKernelTimer(sysprop::support_kernel_idle_timer(false)),
mRefreshRateConfigs(refreshRateConfig) {
- // Note: We create a local temporary with the real DispSync implementation
- // type temporarily so we can initialize it with the configured values,
- // before storing it for more generic use using the interface type.
- auto primaryDispSync = std::make_unique<impl::DispSync>("SchedulerDispSync");
- primaryDispSync->init(mHasSyncFramework, mDispSyncPresentTimeOffset);
- mPrimaryDispSync = std::move(primaryDispSync);
- mEventControlThread = std::make_unique<impl::EventControlThread>(function);
-
- mSetIdleTimerMs = set_idle_timer_ms(0);
- mSupportKernelTimer = support_kernel_idle_timer(false);
-
- mSetTouchTimerMs = set_touch_timer_ms(0);
- mSetDisplayPowerTimerMs = set_display_power_timer_ms(0);
+ using namespace sysprop;
char value[PROPERTY_VALUE_MAX];
property_get("debug.sf.set_idle_timer_ms", value, "0");
- int int_value = atoi(value);
- if (int_value) {
- mSetIdleTimerMs = atoi(value);
- }
+ const int setIdleTimerMs = atoi(value);
- if (mSetIdleTimerMs > 0) {
- if (mSupportKernelTimer) {
- mIdleTimer = std::make_unique<scheduler::OneShotTimer>(
- std::chrono::milliseconds(mSetIdleTimerMs),
- [this] { kernelIdleTimerCallback(TimerState::Reset); },
- [this] { kernelIdleTimerCallback(TimerState::Expired); });
- } else {
- mIdleTimer = std::make_unique<scheduler::OneShotTimer>(
- std::chrono::milliseconds(mSetIdleTimerMs),
- [this] { idleTimerCallback(TimerState::Reset); },
- [this] { idleTimerCallback(TimerState::Expired); });
- }
+ if (const auto millis = setIdleTimerMs ? setIdleTimerMs : set_idle_timer_ms(0); millis > 0) {
+ const auto callback = mSupportKernelTimer ? &Scheduler::kernelIdleTimerCallback
+ : &Scheduler::idleTimerCallback;
+
+ mIdleTimer.emplace(
+ std::chrono::milliseconds(millis),
+ [this, callback] { std::invoke(callback, this, TimerState::Reset); },
+ [this, callback] { std::invoke(callback, this, TimerState::Expired); });
mIdleTimer->start();
}
- if (mSetTouchTimerMs > 0) {
+ if (const int64_t millis = set_touch_timer_ms(0); millis > 0) {
// Touch events are coming to SF every 100ms, so the timer needs to be higher than that
- mTouchTimer = std::make_unique<scheduler::OneShotTimer>(
- std::chrono::milliseconds(mSetTouchTimerMs),
+ mTouchTimer.emplace(
+ std::chrono::milliseconds(millis),
[this] { touchTimerCallback(TimerState::Reset); },
[this] { touchTimerCallback(TimerState::Expired); });
mTouchTimer->start();
}
- if (mSetDisplayPowerTimerMs > 0) {
- mDisplayPowerTimer = std::make_unique<scheduler::OneShotTimer>(
- std::chrono::milliseconds(mSetDisplayPowerTimerMs),
+ if (const int64_t millis = set_display_power_timer_ms(0); millis > 0) {
+ mDisplayPowerTimer.emplace(
+ std::chrono::milliseconds(millis),
[this] { displayPowerTimerCallback(TimerState::Reset); },
[this] { displayPowerTimerCallback(TimerState::Expired); });
mDisplayPowerTimer->start();
@@ -121,9 +100,9 @@
Scheduler::Scheduler(std::unique_ptr<DispSync> primaryDispSync,
std::unique_ptr<EventControlThread> eventControlThread,
const scheduler::RefreshRateConfigs& configs)
- : mHasSyncFramework(false),
- mPrimaryDispSync(std::move(primaryDispSync)),
+ : mPrimaryDispSync(std::move(primaryDispSync)),
mEventControlThread(std::move(eventControlThread)),
+ mSupportKernelTimer(false),
mRefreshRateConfigs(configs) {}
Scheduler::~Scheduler() {
@@ -133,36 +112,39 @@
mIdleTimer.reset();
}
-sp<Scheduler::ConnectionHandle> Scheduler::createConnection(
+DispSync& Scheduler::getPrimaryDispSync() {
+ return *mPrimaryDispSync;
+}
+
+Scheduler::ConnectionHandle Scheduler::createConnection(
const char* connectionName, nsecs_t phaseOffsetNs, nsecs_t offsetThresholdForNextVsync,
ResyncCallback resyncCallback,
impl::EventThread::InterceptVSyncsCallback interceptCallback) {
- const int64_t id = sNextId++;
- ALOGV("Creating a connection handle with ID: %" PRId64 "\n", id);
+ auto eventThread = makeEventThread(connectionName, phaseOffsetNs, offsetThresholdForNextVsync,
+ std::move(interceptCallback));
+ return createConnection(std::move(eventThread), std::move(resyncCallback));
+}
- std::unique_ptr<EventThread> eventThread =
- makeEventThread(connectionName, mPrimaryDispSync.get(), phaseOffsetNs,
- offsetThresholdForNextVsync, std::move(interceptCallback));
+Scheduler::ConnectionHandle Scheduler::createConnection(std::unique_ptr<EventThread> eventThread,
+ ResyncCallback&& resyncCallback) {
+ const ConnectionHandle handle = ConnectionHandle{mNextConnectionHandleId++};
+ ALOGV("Creating a connection handle with ID %" PRIuPTR, handle.id);
- auto eventThreadConnection =
- createConnectionInternal(eventThread.get(), std::move(resyncCallback),
- ISurfaceComposer::eConfigChangedSuppress);
- mConnections.emplace(id,
- std::make_unique<Connection>(new ConnectionHandle(id),
- eventThreadConnection,
- std::move(eventThread)));
- return mConnections[id]->handle;
+ auto connection = createConnectionInternal(eventThread.get(), std::move(resyncCallback),
+ ISurfaceComposer::eConfigChangedSuppress);
+
+ mConnections.emplace(handle, Connection{connection, std::move(eventThread)});
+ return handle;
}
std::unique_ptr<EventThread> Scheduler::makeEventThread(
- const char* connectionName, DispSync* dispSync, nsecs_t phaseOffsetNs,
- nsecs_t offsetThresholdForNextVsync,
- impl::EventThread::InterceptVSyncsCallback interceptCallback) {
- std::unique_ptr<VSyncSource> eventThreadSource =
- std::make_unique<DispSyncSource>(dispSync, phaseOffsetNs, offsetThresholdForNextVsync,
- true, connectionName);
- return std::make_unique<impl::EventThread>(std::move(eventThreadSource),
- std::move(interceptCallback), connectionName);
+ const char* connectionName, nsecs_t phaseOffsetNs, nsecs_t offsetThresholdForNextVsync,
+ impl::EventThread::InterceptVSyncsCallback&& interceptCallback) {
+ auto source = std::make_unique<DispSyncSource>(mPrimaryDispSync.get(), phaseOffsetNs,
+ offsetThresholdForNextVsync,
+ true /* traceVsync */, connectionName);
+ return std::make_unique<impl::EventThread>(std::move(source), std::move(interceptCallback),
+ connectionName);
}
sp<EventThreadConnection> Scheduler::createConnectionInternal(
@@ -172,53 +154,53 @@
}
sp<IDisplayEventConnection> Scheduler::createDisplayEventConnection(
- const sp<Scheduler::ConnectionHandle>& handle, ResyncCallback resyncCallback,
+ ConnectionHandle handle, ResyncCallback resyncCallback,
ISurfaceComposer::ConfigChanged configChanged) {
- RETURN_VALUE_IF_INVALID(nullptr);
- return createConnectionInternal(mConnections[handle->id]->thread.get(),
- std::move(resyncCallback), configChanged);
+ RETURN_IF_INVALID_HANDLE(handle, nullptr);
+ return createConnectionInternal(mConnections[handle].thread.get(), std::move(resyncCallback),
+ configChanged);
}
-EventThread* Scheduler::getEventThread(const sp<Scheduler::ConnectionHandle>& handle) {
- RETURN_VALUE_IF_INVALID(nullptr);
- return mConnections[handle->id]->thread.get();
+EventThread* Scheduler::getEventThread(ConnectionHandle handle) {
+ RETURN_IF_INVALID_HANDLE(handle, nullptr);
+ return mConnections[handle].thread.get();
}
-sp<EventThreadConnection> Scheduler::getEventConnection(const sp<ConnectionHandle>& handle) {
- RETURN_VALUE_IF_INVALID(nullptr);
- return mConnections[handle->id]->eventConnection;
+sp<EventThreadConnection> Scheduler::getEventConnection(ConnectionHandle handle) {
+ RETURN_IF_INVALID_HANDLE(handle, nullptr);
+ return mConnections[handle].connection;
}
-void Scheduler::hotplugReceived(const sp<Scheduler::ConnectionHandle>& handle,
- PhysicalDisplayId displayId, bool connected) {
- RETURN_IF_INVALID();
- mConnections[handle->id]->thread->onHotplugReceived(displayId, connected);
+void Scheduler::onHotplugReceived(ConnectionHandle handle, PhysicalDisplayId displayId,
+ bool connected) {
+ RETURN_IF_INVALID_HANDLE(handle);
+ mConnections[handle].thread->onHotplugReceived(displayId, connected);
}
-void Scheduler::onScreenAcquired(const sp<Scheduler::ConnectionHandle>& handle) {
- RETURN_IF_INVALID();
- mConnections[handle->id]->thread->onScreenAcquired();
+void Scheduler::onScreenAcquired(ConnectionHandle handle) {
+ RETURN_IF_INVALID_HANDLE(handle);
+ mConnections[handle].thread->onScreenAcquired();
}
-void Scheduler::onScreenReleased(const sp<Scheduler::ConnectionHandle>& handle) {
- RETURN_IF_INVALID();
- mConnections[handle->id]->thread->onScreenReleased();
+void Scheduler::onScreenReleased(ConnectionHandle handle) {
+ RETURN_IF_INVALID_HANDLE(handle);
+ mConnections[handle].thread->onScreenReleased();
}
-void Scheduler::onConfigChanged(const sp<ConnectionHandle>& handle, PhysicalDisplayId displayId,
+void Scheduler::onConfigChanged(ConnectionHandle handle, PhysicalDisplayId displayId,
int32_t configId) {
- RETURN_IF_INVALID();
- mConnections[handle->id]->thread->onConfigChanged(displayId, configId);
+ RETURN_IF_INVALID_HANDLE(handle);
+ mConnections[handle].thread->onConfigChanged(displayId, configId);
}
-void Scheduler::dump(const sp<Scheduler::ConnectionHandle>& handle, std::string& result) const {
- RETURN_IF_INVALID();
- mConnections.at(handle->id)->thread->dump(result);
+void Scheduler::dump(ConnectionHandle handle, std::string& result) const {
+ RETURN_IF_INVALID_HANDLE(handle);
+ mConnections.at(handle).thread->dump(result);
}
-void Scheduler::setPhaseOffset(const sp<Scheduler::ConnectionHandle>& handle, nsecs_t phaseOffset) {
- RETURN_IF_INVALID();
- mConnections[handle->id]->thread->setPhaseOffset(phaseOffset);
+void Scheduler::setPhaseOffset(ConnectionHandle handle, nsecs_t phaseOffset) {
+ RETURN_IF_INVALID_HANDLE(handle);
+ mConnections[handle].thread->setPhaseOffset(phaseOffset);
}
void Scheduler::getDisplayStatInfo(DisplayStatInfo* stats) {
@@ -286,11 +268,7 @@
}
}
-void Scheduler::setRefreshSkipCount(int count) {
- mPrimaryDispSync->setRefreshSkipCount(count);
-}
-
-void Scheduler::setVsyncPeriod(const nsecs_t period) {
+void Scheduler::setVsyncPeriod(nsecs_t period) {
std::lock_guard<std::mutex> lock(mHWVsyncLock);
mPrimaryDispSync->setPeriod(period);
@@ -301,7 +279,7 @@
}
}
-void Scheduler::addResyncSample(const nsecs_t timestamp, bool* periodFlushed) {
+void Scheduler::addResyncSample(nsecs_t timestamp, bool* periodFlushed) {
bool needsHwVsync = false;
*periodFlushed = false;
{ // Scope for the lock
@@ -334,10 +312,6 @@
return mPrimaryDispSync->expectedPresentTime();
}
-void Scheduler::dumpPrimaryDispSync(std::string& result) const {
- mPrimaryDispSync->dump(result);
-}
-
std::unique_ptr<scheduler::LayerHistory::LayerHandle> Scheduler::registerLayer(
std::string const& name, int windowType) {
RefreshRateType refreshRateType = (windowType == InputWindowInfo::TYPE_WALLPAPER)
@@ -363,10 +337,6 @@
mLayerHistory.setVisibility(layerHandle, visible);
}
-void Scheduler::withPrimaryDispSync(std::function<void(DispSync&)> const& fn) {
- fn(*mPrimaryDispSync);
-}
-
void Scheduler::updateFpsBasedOnContent() {
auto [refreshRate, isHDR] = mLayerHistory.getDesiredRefreshRateAndHDR();
const uint32_t refreshRateRound = std::round(refreshRate);
@@ -393,30 +363,19 @@
changeRefreshRate(newRefreshRateType, ConfigEvent::Changed);
}
-void Scheduler::setChangeRefreshRateCallback(
- const ChangeRefreshRateCallback&& changeRefreshRateCallback) {
+void Scheduler::setChangeRefreshRateCallback(ChangeRefreshRateCallback&& callback) {
std::lock_guard<std::mutex> lock(mCallbackLock);
- mChangeRefreshRateCallback = changeRefreshRateCallback;
+ mChangeRefreshRateCallback = std::move(callback);
}
-void Scheduler::setGetCurrentRefreshRateTypeCallback(
- const GetCurrentRefreshRateTypeCallback&& getCurrentRefreshRateTypeCallback) {
+void Scheduler::setGetCurrentRefreshRateTypeCallback(GetCurrentRefreshRateTypeCallback&& callback) {
std::lock_guard<std::mutex> lock(mCallbackLock);
- mGetCurrentRefreshRateTypeCallback = getCurrentRefreshRateTypeCallback;
+ mGetCurrentRefreshRateTypeCallback = std::move(callback);
}
-void Scheduler::setGetVsyncPeriodCallback(const GetVsyncPeriod&& getVsyncPeriod) {
+void Scheduler::setGetVsyncPeriodCallback(GetVsyncPeriod&& callback) {
std::lock_guard<std::mutex> lock(mCallbackLock);
- mGetVsyncPeriod = getVsyncPeriod;
-}
-
-void Scheduler::updateFrameSkipping(const int64_t skipCount) {
- ATRACE_INT("FrameSkipCount", skipCount);
- if (mSkipCount != skipCount) {
- // Only update DispSync if it hasn't been updated yet.
- mPrimaryDispSync->setRefreshSkipCount(skipCount);
- mSkipCount = skipCount;
- }
+ mGetVsyncPeriod = std::move(callback);
}
void Scheduler::resetIdleTimer() {
@@ -430,8 +389,8 @@
mTouchTimer->reset();
}
- if (mSupportKernelTimer) {
- resetIdleTimer();
+ if (mSupportKernelTimer && mIdleTimer) {
+ mIdleTimer->reset();
}
// Touch event will boost the refresh rate to performance.
@@ -491,11 +450,16 @@
ATRACE_INT("ExpiredDisplayPowerTimer", static_cast<int>(state));
}
-std::string Scheduler::doDump() {
+void Scheduler::dump(std::string& result) const {
std::ostringstream stream;
- stream << "+ Idle timer interval: " << mSetIdleTimerMs << " ms" << std::endl;
- stream << "+ Touch timer interval: " << mSetTouchTimerMs << " ms" << std::endl;
- return stream.str();
+ if (mIdleTimer) {
+ stream << "+ Idle timer interval: " << mIdleTimer->interval().count() << " ms\n";
+ }
+ if (mTouchTimer) {
+ stream << "+ Touch timer interval: " << mTouchTimer->interval().count() << " ms\n";
+ }
+
+ result.append(stream.str());
}
template <class T>
@@ -548,6 +512,7 @@
}
// Content detection is on, find the appropriate refresh rate with minimal error
+ // TODO(b/139751853): Scan allowed refresh rates only (SurfaceFlinger::mAllowedDisplayConfigs)
const float rate = static_cast<float>(mFeatures.contentRefreshRate);
auto iter = min_element(mRefreshRateConfigs.getRefreshRates().cbegin(),
mRefreshRateConfigs.getRefreshRates().cend(),
@@ -577,6 +542,11 @@
return currRefreshRateType;
}
+Scheduler::RefreshRateType Scheduler::getPreferredRefreshRateType() {
+ std::lock_guard<std::mutex> lock(mFeatureStateLock);
+ return mFeatures.refreshRateType;
+}
+
void Scheduler::changeRefreshRate(RefreshRateType refreshRateType, ConfigEvent configEvent) {
std::lock_guard<std::mutex> lock(mCallbackLock);
if (mChangeRefreshRateCallback) {
diff --git a/services/surfaceflinger/Scheduler/Scheduler.h b/services/surfaceflinger/Scheduler/Scheduler.h
index 5905ff6..34e527c 100644
--- a/services/surfaceflinger/Scheduler/Scheduler.h
+++ b/services/surfaceflinger/Scheduler/Scheduler.h
@@ -16,17 +16,17 @@
#pragma once
-#include <cstdint>
+#include <atomic>
#include <functional>
#include <memory>
+#include <mutex>
+#include <optional>
+#include <unordered_map>
-#include <ui/DisplayStatInfo.h>
#include <ui/GraphicTypes.h>
-#include "DispSync.h"
#include "EventControlThread.h"
#include "EventThread.h"
-#include "InjectVSyncSource.h"
#include "LayerHistory.h"
#include "OneShotTimer.h"
#include "RefreshRateConfigs.h"
@@ -34,122 +34,66 @@
namespace android {
-class EventControlThread;
+class DispSync;
+class FenceTime;
+struct DisplayStateInfo;
class Scheduler {
public:
- // Enum to keep track of whether we trigger event to notify choreographer of config changes.
- enum class ConfigEvent { None, Changed };
-
- // logical or operator with the semantics of at least one of the events is Changed
- friend ConfigEvent operator|(const ConfigEvent& first, const ConfigEvent& second) {
- if (first == ConfigEvent::Changed) return ConfigEvent::Changed;
- if (second == ConfigEvent::Changed) return ConfigEvent::Changed;
- return ConfigEvent::None;
- }
-
using RefreshRateType = scheduler::RefreshRateConfigs::RefreshRateType;
+ using ConfigEvent = scheduler::RefreshRateConfigEvent;
+
using GetCurrentRefreshRateTypeCallback = std::function<RefreshRateType()>;
using ChangeRefreshRateCallback = std::function<void(RefreshRateType, ConfigEvent)>;
using GetVsyncPeriod = std::function<nsecs_t()>;
- // Enum to indicate whether to start the transaction early, or at vsync time.
+ // Indicates whether to start the transaction early, or at vsync time.
enum class TransactionStart { EARLY, NORMAL };
- /* The scheduler handle is a BBinder object passed to the client from which we can extract
- * an ID for subsequent operations.
- */
- class ConnectionHandle : public BBinder {
- public:
- ConnectionHandle(int64_t id) : id(id) {}
-
- ~ConnectionHandle() = default;
-
- const int64_t id;
- };
-
- class Connection {
- public:
- Connection(sp<ConnectionHandle> handle, sp<EventThreadConnection> eventConnection,
- std::unique_ptr<EventThread> eventThread)
- : handle(handle), eventConnection(eventConnection), thread(std::move(eventThread)) {}
-
- ~Connection() = default;
-
- sp<ConnectionHandle> handle;
- sp<EventThreadConnection> eventConnection;
- const std::unique_ptr<EventThread> thread;
- };
-
- // Stores per-display state about VSYNC.
- struct VsyncState {
- explicit VsyncState(Scheduler& scheduler) : scheduler(scheduler) {}
-
- void resync(const GetVsyncPeriod&);
-
- Scheduler& scheduler;
- std::atomic<nsecs_t> lastResyncTime = 0;
- };
-
- explicit Scheduler(impl::EventControlThread::SetVSyncEnabledFunction function,
- const scheduler::RefreshRateConfigs& refreshRateConfig);
+ Scheduler(impl::EventControlThread::SetVSyncEnabledFunction,
+ const scheduler::RefreshRateConfigs&);
virtual ~Scheduler();
- /** Creates an EventThread connection. */
- sp<ConnectionHandle> createConnection(const char* connectionName, nsecs_t phaseOffsetNs,
- nsecs_t offsetThresholdForNextVsync, ResyncCallback,
- impl::EventThread::InterceptVSyncsCallback);
+ DispSync& getPrimaryDispSync();
- sp<IDisplayEventConnection> createDisplayEventConnection(
- const sp<ConnectionHandle>& handle, ResyncCallback,
- ISurfaceComposer::ConfigChanged configChanged);
+ using ConnectionHandle = scheduler::ConnectionHandle;
+ ConnectionHandle createConnection(const char* connectionName, nsecs_t phaseOffsetNs,
+ nsecs_t offsetThresholdForNextVsync, ResyncCallback,
+ impl::EventThread::InterceptVSyncsCallback);
- // Getter methods.
- EventThread* getEventThread(const sp<ConnectionHandle>& handle);
+ sp<IDisplayEventConnection> createDisplayEventConnection(ConnectionHandle, ResyncCallback,
+ ISurfaceComposer::ConfigChanged);
- // Provides access to the DispSync object for the primary display.
- void withPrimaryDispSync(std::function<void(DispSync&)> const& fn);
+ EventThread* getEventThread(ConnectionHandle);
+ sp<EventThreadConnection> getEventConnection(ConnectionHandle);
- sp<EventThreadConnection> getEventConnection(const sp<ConnectionHandle>& handle);
+ void onHotplugReceived(ConnectionHandle, PhysicalDisplayId, bool connected);
+ void onConfigChanged(ConnectionHandle, PhysicalDisplayId, int32_t configId);
- // Should be called when receiving a hotplug event.
- void hotplugReceived(const sp<ConnectionHandle>& handle, PhysicalDisplayId displayId,
- bool connected);
+ void onScreenAcquired(ConnectionHandle);
+ void onScreenReleased(ConnectionHandle);
- // Should be called after the screen is turned on.
- void onScreenAcquired(const sp<ConnectionHandle>& handle);
-
- // Should be called before the screen is turned off.
- void onScreenReleased(const sp<ConnectionHandle>& handle);
-
- // Should be called when display config changed
- void onConfigChanged(const sp<ConnectionHandle>& handle, PhysicalDisplayId displayId,
- int32_t configId);
-
- // Should be called when dumpsys command is received.
- void dump(const sp<ConnectionHandle>& handle, std::string& result) const;
-
- // Offers ability to modify phase offset in the event thread.
- void setPhaseOffset(const sp<ConnectionHandle>& handle, nsecs_t phaseOffset);
+ // Modifies phase offset in the event thread.
+ void setPhaseOffset(ConnectionHandle, nsecs_t phaseOffset);
void getDisplayStatInfo(DisplayStatInfo* stats);
void enableHardwareVsync();
void disableHardwareVsync(bool makeUnavailable);
+
// Resyncs the scheduler to hardware vsync.
// If makeAvailable is true, then hardware vsync will be turned on.
// Otherwise, if hardware vsync is not already enabled then this method will
// no-op.
// The period is the vsync period from the current display configuration.
void resyncToHardwareVsync(bool makeAvailable, nsecs_t period);
- // Creates a callback for resyncing.
- ResyncCallback makeResyncCallback(GetVsyncPeriod&& getVsyncPeriod);
- void setRefreshSkipCount(int count);
+ ResyncCallback makeResyncCallback(GetVsyncPeriod&&);
+
// Passes a vsync sample to DispSync. periodFlushed will be true if
// DispSync detected that the vsync period changed, and false otherwise.
- void addResyncSample(const nsecs_t timestamp, bool* periodFlushed);
- void addPresentFence(const std::shared_ptr<FenceTime>& fenceTime);
+ void addResyncSample(nsecs_t timestamp, bool* periodFlushed);
+ void addPresentFence(const std::shared_ptr<FenceTime>&);
void setIgnorePresentFences(bool ignore);
nsecs_t getDispSyncExpectedPresentTime();
// Registers the layer in the scheduler, and returns the handle for future references.
@@ -165,35 +109,26 @@
const std::unique_ptr<scheduler::LayerHistory::LayerHandle>& layerHandle, bool visible);
// Updates FPS based on the most content presented.
void updateFpsBasedOnContent();
- // Callback that gets invoked when Scheduler wants to change the refresh rate.
- void setChangeRefreshRateCallback(const ChangeRefreshRateCallback&& changeRefreshRateCallback);
- void setGetCurrentRefreshRateTypeCallback(
- const GetCurrentRefreshRateTypeCallback&& getCurrentRefreshRateType);
- void setGetVsyncPeriodCallback(const GetVsyncPeriod&& getVsyncPeriod);
- // Returns whether idle timer is enabled or not
- bool isIdleTimerEnabled() { return mSetIdleTimerMs > 0; }
+ // Called by Scheduler to change refresh rate.
+ void setChangeRefreshRateCallback(ChangeRefreshRateCallback&&);
- // Function that resets the idle timer.
+ void setGetCurrentRefreshRateTypeCallback(GetCurrentRefreshRateTypeCallback&&);
+ void setGetVsyncPeriodCallback(GetVsyncPeriod&&);
+
+ bool isIdleTimerEnabled() const { return mIdleTimer.has_value(); }
void resetIdleTimer();
// Function that resets the touch timer.
void notifyTouchEvent();
- // Function that sets whether display power mode is normal or not.
void setDisplayPowerState(bool normal);
- // Returns relevant information about Scheduler for dumpsys purposes.
- std::string doDump();
+ void dump(std::string&) const;
+ void dump(ConnectionHandle, std::string&) const;
- // calls DispSync::dump() on primary disp sync
- void dumpPrimaryDispSync(std::string& result) const;
-
-protected:
- virtual std::unique_ptr<EventThread> makeEventThread(
- const char* connectionName, DispSync* dispSync, nsecs_t phaseOffsetNs,
- nsecs_t offsetThresholdForNextVsync,
- impl::EventThread::InterceptVSyncsCallback interceptCallback);
+ // Get the appropriate refresh type for current conditions.
+ RefreshRateType getPreferredRefreshRateType();
private:
friend class TestableScheduler;
@@ -209,81 +144,71 @@
const scheduler::RefreshRateConfigs&);
// Creates a connection on the given EventThread and forwards the given callbacks.
+ std::unique_ptr<EventThread> makeEventThread(const char* connectionName, nsecs_t phaseOffsetNs,
+ nsecs_t offsetThresholdForNextVsync,
+ impl::EventThread::InterceptVSyncsCallback&&);
+
+ // Create a connection on the given EventThread and forward the resync callback.
+ ConnectionHandle createConnection(std::unique_ptr<EventThread>, ResyncCallback&&);
sp<EventThreadConnection> createConnectionInternal(EventThread*, ResyncCallback&&,
ISurfaceComposer::ConfigChanged);
- nsecs_t calculateAverage() const;
- void updateFrameSkipping(const int64_t skipCount);
-
// Update feature state machine to given state when corresponding timer resets or expires.
void kernelIdleTimerCallback(TimerState);
void idleTimerCallback(TimerState);
void touchTimerCallback(TimerState);
void displayPowerTimerCallback(TimerState);
- // Sets vsync period.
- void setVsyncPeriod(const nsecs_t period);
// handles various timer features to change the refresh rate.
template <class T>
void handleTimerStateChanged(T* currentState, T newState, bool eventOnContentDetection);
- // Calculate the new refresh rate type
+
+ void setVsyncPeriod(nsecs_t period);
+
RefreshRateType calculateRefreshRateType() REQUIRES(mFeatureStateLock);
- // Acquires a lock and calls the ChangeRefreshRateCallback() with given parameters.
- void changeRefreshRate(RefreshRateType refreshRateType, ConfigEvent configEvent);
+ // Acquires a lock and calls the ChangeRefreshRateCallback with given parameters.
+ void changeRefreshRate(RefreshRateType, ConfigEvent);
- // Helper function to calculate error frames
- float getErrorFrames(float contentFps, float configFps);
+ // Stores EventThread associated with a given VSyncSource, and an initial EventThreadConnection.
+ struct Connection {
+ sp<EventThreadConnection> connection;
+ std::unique_ptr<EventThread> thread;
+ };
- // If fences from sync Framework are supported.
- const bool mHasSyncFramework;
-
- // The offset in nanoseconds to use, when DispSync timestamps present fence
- // signaling time.
- nsecs_t mDispSyncPresentTimeOffset;
-
- // Each connection has it's own ID. This variable keeps track of the count.
- static std::atomic<int64_t> sNextId;
-
- // Connections are stored in a map <connection ID, connection> for easy retrieval.
- std::unordered_map<int64_t, std::unique_ptr<Connection>> mConnections;
+ ConnectionHandle::Id mNextConnectionHandleId = 0;
+ std::unordered_map<ConnectionHandle, Connection> mConnections;
std::mutex mHWVsyncLock;
- bool mPrimaryHWVsyncEnabled GUARDED_BY(mHWVsyncLock);
- bool mHWVsyncAvailable GUARDED_BY(mHWVsyncLock);
+ bool mPrimaryHWVsyncEnabled GUARDED_BY(mHWVsyncLock) = false;
+ bool mHWVsyncAvailable GUARDED_BY(mHWVsyncLock) = false;
+
+ // Stores per-display state about VSYNC.
+ struct VsyncState {
+ explicit VsyncState(Scheduler& scheduler) : scheduler(scheduler) {}
+
+ void resync(const GetVsyncPeriod&);
+
+ Scheduler& scheduler;
+ std::atomic<nsecs_t> lastResyncTime = 0;
+ };
+
const std::shared_ptr<VsyncState> mPrimaryVsyncState{std::make_shared<VsyncState>(*this)};
std::unique_ptr<DispSync> mPrimaryDispSync;
std::unique_ptr<EventControlThread> mEventControlThread;
- // TODO(b/113612090): The following set of variables needs to be revised. For now, this is
- // a proof of concept. We turn on frame skipping if the difference between the timestamps
- // is between 32 and 34ms. We expect this currently for 30fps videos, so we render them at 30Hz.
- nsecs_t mPreviousFrameTimestamp = 0;
- // Keeping track of whether we are skipping the refresh count. If we want to
- // simulate 30Hz rendering, we skip every other frame, and this variable is set
- // to 1.
- int64_t mSkipCount = 0;
- std::array<int64_t, scheduler::ARRAY_SIZE> mTimeDifferences{};
- size_t mCounter = 0;
-
// Historical information about individual layers. Used for predicting the refresh rate.
scheduler::LayerHistory mLayerHistory;
- // Timer that records time between requests for next vsync. If the time is higher than a given
- // interval, a callback is fired. Set this variable to >0 to use this feature.
- int64_t mSetIdleTimerMs = 0;
- std::unique_ptr<scheduler::OneShotTimer> mIdleTimer;
- // Enables whether to use idle timer callbacks that support the kernel
- // timer.
- bool mSupportKernelTimer;
+ // Whether to use idle timer callbacks that support the kernel timer.
+ const bool mSupportKernelTimer;
+ // Timer that records time between requests for next vsync.
+ std::optional<scheduler::OneShotTimer> mIdleTimer;
// Timer used to monitor touch events.
- int64_t mSetTouchTimerMs = 0;
- std::unique_ptr<scheduler::OneShotTimer> mTouchTimer;
-
+ std::optional<scheduler::OneShotTimer> mTouchTimer;
// Timer used to monitor display power mode.
- int64_t mSetDisplayPowerTimerMs = 0;
- std::unique_ptr<scheduler::OneShotTimer> mDisplayPowerTimer;
+ std::optional<scheduler::OneShotTimer> mDisplayPowerTimer;
std::mutex mCallbackLock;
GetCurrentRefreshRateTypeCallback mGetCurrentRefreshRateTypeCallback GUARDED_BY(mCallbackLock);
diff --git a/services/surfaceflinger/Scheduler/SchedulerUtils.h b/services/surfaceflinger/Scheduler/SchedulerUtils.h
index ced1899..ab0c0ff 100644
--- a/services/surfaceflinger/Scheduler/SchedulerUtils.h
+++ b/services/surfaceflinger/Scheduler/SchedulerUtils.h
@@ -22,13 +22,23 @@
#include <unordered_map>
#include <vector>
-namespace android {
-namespace scheduler {
-using namespace std::chrono_literals;
+namespace android::scheduler {
-// This number is used to set the size of the arrays in scheduler that hold information
-// about layers.
-static constexpr size_t ARRAY_SIZE = 30;
+// Opaque handle to scheduler connection.
+struct ConnectionHandle {
+ using Id = std::uintptr_t;
+ static constexpr Id INVALID_ID = static_cast<Id>(-1);
+
+ Id id = INVALID_ID;
+
+ explicit operator bool() const { return id != INVALID_ID; }
+};
+
+inline bool operator==(ConnectionHandle lhs, ConnectionHandle rhs) {
+ return lhs.id == rhs.id;
+}
+
+using namespace std::chrono_literals;
// This number is used to have a place holder for when the screen is not NORMAL/ON. Currently
// the config is not visible to SF, and is completely maintained by HWC. However, we would
@@ -80,5 +90,15 @@
return static_cast<int>(std::max_element(counts.begin(), counts.end(), compareCounts)->first);
}
-} // namespace scheduler
-} // namespace android
\ No newline at end of file
+} // namespace android::scheduler
+
+namespace std {
+
+template <>
+struct hash<android::scheduler::ConnectionHandle> {
+ size_t operator()(android::scheduler::ConnectionHandle handle) const {
+ return hash<android::scheduler::ConnectionHandle::Id>()(handle.id);
+ }
+};
+
+} // namespace std
diff --git a/services/surfaceflinger/Scheduler/VSyncModulator.cpp b/services/surfaceflinger/Scheduler/VSyncModulator.cpp
index f267c99..27fd76c 100644
--- a/services/surfaceflinger/Scheduler/VSyncModulator.cpp
+++ b/services/surfaceflinger/Scheduler/VSyncModulator.cpp
@@ -27,8 +27,8 @@
namespace android::scheduler {
VSyncModulator::VSyncModulator(Scheduler& scheduler,
- const sp<Scheduler::ConnectionHandle>& appConnectionHandle,
- const sp<Scheduler::ConnectionHandle>& sfConnectionHandle,
+ Scheduler::ConnectionHandle appConnectionHandle,
+ Scheduler::ConnectionHandle sfConnectionHandle,
const OffsetsConfig& config)
: mScheduler(scheduler),
mAppConnectionHandle(appConnectionHandle),
diff --git a/services/surfaceflinger/Scheduler/VSyncModulator.h b/services/surfaceflinger/Scheduler/VSyncModulator.h
index 636c8c8..727cef2 100644
--- a/services/surfaceflinger/Scheduler/VSyncModulator.h
+++ b/services/surfaceflinger/Scheduler/VSyncModulator.h
@@ -56,8 +56,8 @@
nsecs_t thresholdForNextVsync;
};
- VSyncModulator(Scheduler&, const sp<Scheduler::ConnectionHandle>& appConnectionHandle,
- const sp<Scheduler::ConnectionHandle>& sfConnectionHandle, const OffsetsConfig&);
+ VSyncModulator(Scheduler&, ConnectionHandle appConnectionHandle,
+ ConnectionHandle sfConnectionHandle, const OffsetsConfig&);
void setPhaseOffsets(const OffsetsConfig&) EXCLUDES(mMutex);
@@ -92,8 +92,8 @@
void updateOffsetsLocked() REQUIRES(mMutex);
Scheduler& mScheduler;
- const sp<Scheduler::ConnectionHandle> mAppConnectionHandle;
- const sp<Scheduler::ConnectionHandle> mSfConnectionHandle;
+ const ConnectionHandle mAppConnectionHandle;
+ const ConnectionHandle mSfConnectionHandle;
mutable std::mutex mMutex;
OffsetsConfig mOffsetsConfig GUARDED_BY(mMutex);
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index c1a8f87..02690b0 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -98,6 +98,7 @@
#include "DisplayHardware/HWComposer.h"
#include "DisplayHardware/VirtualDisplaySurface.h"
#include "Effects/Daltonizer.h"
+#include "FrameTracer/FrameTracer.h"
#include "RegionSamplingThread.h"
#include "Scheduler/DispSync.h"
#include "Scheduler/DispSyncSource.h"
@@ -239,11 +240,11 @@
std::string decodeDisplayColorSetting(DisplayColorSetting displayColorSetting) {
switch(displayColorSetting) {
- case DisplayColorSetting::MANAGED:
+ case DisplayColorSetting::kManaged:
return std::string("Managed");
- case DisplayColorSetting::UNMANAGED:
+ case DisplayColorSetting::kUnmanaged:
return std::string("Unmanaged");
- case DisplayColorSetting::ENHANCED:
+ case DisplayColorSetting::kEnhanced:
return std::string("Enhanced");
default:
return std::string("Unknown ") +
@@ -257,6 +258,7 @@
: mFactory(factory),
mInterceptor(mFactory.createSurfaceInterceptor(this)),
mTimeStats(mFactory.createTimeStats()),
+ mFrameTracer(std::make_unique<FrameTracer>()),
mEventQueue(mFactory.createMessageQueue()),
mCompositionEngine(mFactory.createCompositionEngine()),
mPhaseOffsets(mFactory.createPhaseOffsets()) {}
@@ -513,6 +515,8 @@
const nsecs_t duration = now - mBootTime;
ALOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) );
+ mFrameTracer->initialize();
+
// wait patiently for the window manager death
const String16 name("window");
mWindowManager = defaultServiceManager()->getService(name);
@@ -1131,9 +1135,10 @@
ALOGW("Attempt to set active color mode %s (%d) for virtual display",
decodeColorMode(mode).c_str(), mode);
} else {
- display->getCompositionDisplay()->setColorMode(mode, Dataspace::UNKNOWN,
- RenderIntent::COLORIMETRIC,
- Dataspace::UNKNOWN);
+ display->getCompositionDisplay()->setColorProfile(
+ compositionengine::Output::ColorProfile{mode, Dataspace::UNKNOWN,
+ RenderIntent::COLORIMETRIC,
+ Dataspace::UNKNOWN});
}
}));
@@ -1785,18 +1790,32 @@
auto compositionLayer = layer->getCompositionLayer();
if (compositionLayer) refreshArgs.layers.push_back(compositionLayer);
});
+ refreshArgs.repaintEverything = mRepaintEverything.exchange(false);
+ refreshArgs.outputColorSetting = useColorManagement
+ ? mDisplayColorSetting
+ : compositionengine::OutputColorSetting::kUnmanaged;
+ refreshArgs.colorSpaceAgnosticDataspace = mColorSpaceAgnosticDataspace;
+ refreshArgs.forceOutputColorMode = mForceColorMode;
+ refreshArgs.updatingGeometryThisFrame = mGeometryInvalid;
- const bool repaintEverything = mRepaintEverything.exchange(false);
+ if (CC_UNLIKELY(mDrawingState.colorMatrixChanged)) {
+ refreshArgs.colorTransformMatrix = mDrawingState.colorMatrix;
+ mDrawingState.colorMatrixChanged = false;
+ }
+
+ refreshArgs.devOptForceClientComposition = mDebugDisableHWC || mDebugRegion;
+
+ if (mDebugRegion != 0) {
+ refreshArgs.devOptFlashDirtyRegionsDelay =
+ std::chrono::milliseconds(mDebugRegion > 1 ? mDebugRegion : 0);
+ }
+
mCompositionEngine->preComposition(refreshArgs);
rebuildLayerStacks();
- calculateWorkingSet();
- for (const auto& [token, displayDevice] : mDisplays) {
- auto display = displayDevice->getCompositionDisplay();
- display->beginFrame();
- display->prepareFrame();
- doDebugFlashRegions(displayDevice, repaintEverything);
- doComposition(displayDevice, repaintEverything);
- }
+ refreshArgs.updatingGeometryThisFrame = mGeometryInvalid; // Can be set by rebuildLayerStacks()
+ mCompositionEngine->present(refreshArgs);
+
+ mGeometryInvalid = false;
postFrame();
postComposition();
@@ -1845,104 +1864,6 @@
return refreshNeeded;
}
-void SurfaceFlinger::calculateWorkingSet() {
- ATRACE_CALL();
- ALOGV(__FUNCTION__);
-
- const bool updatingGeometryThisFrame = mGeometryInvalid;
- mGeometryInvalid = false;
-
- // Latch the frontend layer composition state for each layer being
- // composed.
- for (const auto& [token, displayDevice] : mDisplays) {
- auto display = displayDevice->getCompositionDisplay();
- for (auto& layer : display->getOutputLayersOrderedByZ()) {
- layer->getLayerFE().latchCompositionState(layer->getLayer().editState().frontEnd,
- updatingGeometryThisFrame);
- }
- }
-
- if (CC_UNLIKELY(updatingGeometryThisFrame)) {
- for (const auto& [token, displayDevice] : mDisplays) {
- auto display = displayDevice->getCompositionDisplay();
- uint32_t zOrder = 0;
-
- for (auto& layer : display->getOutputLayersOrderedByZ()) {
- // Assign a simple Z order sequence to each visible layer.
- layer->editState().z = zOrder++;
- }
- }
- }
-
- // Determine the color configuration of each output
- for (const auto& [token, displayDevice] : mDisplays) {
- auto display = displayDevice->getCompositionDisplay();
-
- ColorMode colorMode = ColorMode::NATIVE;
- Dataspace dataspace = Dataspace::UNKNOWN;
- RenderIntent renderIntent = RenderIntent::COLORIMETRIC;
- if (useColorManagement) {
- pickColorMode(displayDevice, &colorMode, &dataspace, &renderIntent);
- }
- display->setColorMode(colorMode, dataspace, renderIntent, mColorSpaceAgnosticDataspace);
- }
-
- for (const auto& [token, displayDevice] : mDisplays) {
- auto display = displayDevice->getCompositionDisplay();
-
- for (auto& layer : display->getOutputLayersOrderedByZ()) {
- if (mDebugDisableHWC || mDebugRegion) {
- layer->editState().forceClientComposition = true;
- }
-
- // Update the composition state of the output layer, as needed
- // recomputing it from the state given by the front-end layer.
- layer->updateCompositionState(updatingGeometryThisFrame);
-
- // Send the updated state to the HWC, if appropriate.
- layer->writeStateToHWC(updatingGeometryThisFrame);
- }
- }
-
- if (CC_UNLIKELY(mDrawingState.colorMatrixChanged)) {
- for (const auto& [token, displayDevice] : mDisplays) {
- auto display = displayDevice->getCompositionDisplay();
- display->setColorTransform(mDrawingState.colorMatrix);
- }
- mDrawingState.colorMatrixChanged = false;
- }
-}
-
-void SurfaceFlinger::doDebugFlashRegions(const sp<DisplayDevice>& displayDevice,
- bool repaintEverything) {
- auto display = displayDevice->getCompositionDisplay();
- const auto& displayState = display->getState();
-
- // is debugging enabled
- if (CC_LIKELY(!mDebugRegion))
- return;
-
- if (displayState.isEnabled) {
- // transform the dirty region into this screen's coordinate space
- const Region dirtyRegion = display->getDirtyRegion(repaintEverything);
- if (!dirtyRegion.isEmpty()) {
- base::unique_fd readyFence;
- // redraw the whole screen
- display->composeSurfaces(dirtyRegion, &readyFence);
-
- display->getRenderSurface()->queueBuffer(std::move(readyFence));
- }
- }
-
- displayDevice->getCompositionDisplay()->postFramebuffer();
-
- if (mDebugRegion > 1) {
- usleep(mDebugRegion * 1000);
- }
-
- displayDevice->getCompositionDisplay()->prepareFrame();
-}
-
void SurfaceFlinger::updateCompositorTiming(const DisplayStatInfo& stats, nsecs_t compositeTime,
std::shared_ptr<FenceTime>& presentFenceTime) {
// Update queue of past composite+present times and determine the
@@ -2166,6 +2087,12 @@
ATRACE_NAME("rebuildLayerStacks VR Dirty");
invalidateHwcGeometry();
+ std::vector<sp<compositionengine::LayerFE>> layersWithQueuedFrames;
+ layersWithQueuedFrames.reserve(mLayersWithQueuedFrames.size());
+ for (sp<Layer> layer : mLayersWithQueuedFrames) {
+ layersWithQueuedFrames.push_back(layer);
+ }
+
for (const auto& pair : mDisplays) {
const auto& displayDevice = pair.second;
auto display = displayDevice->getCompositionDisplay();
@@ -2173,65 +2100,45 @@
Region opaqueRegion;
Region dirtyRegion;
compositionengine::Output::OutputLayers layersSortedByZ;
- compositionengine::Output::ReleasedLayers releasedLayers;
- Vector<sp<Layer>> deprecated_layersSortedByZ;
const ui::Transform& tr = displayState.transform;
const Rect bounds = displayState.bounds;
- if (displayState.isEnabled) {
- computeVisibleRegions(displayDevice, dirtyRegion, opaqueRegion);
-
- mDrawingState.traverseInZOrder([&](Layer* layer) {
- auto compositionLayer = layer->getCompositionLayer();
- if (compositionLayer == nullptr) {
- return;
- }
-
- const auto displayId = displayDevice->getId();
- sp<compositionengine::LayerFE> layerFE = compositionLayer->getLayerFE();
- LOG_ALWAYS_FATAL_IF(layerFE.get() == nullptr);
-
- bool needsOutputLayer = false;
-
- if (display->belongsInOutput(layer->getLayerStack(),
- layer->getPrimaryDisplayOnly())) {
- Region drawRegion(tr.transform(
- layer->visibleNonTransparentRegion));
- drawRegion.andSelf(bounds);
- if (!drawRegion.isEmpty()) {
- needsOutputLayer = true;
- }
- }
-
- if (needsOutputLayer) {
- layersSortedByZ.emplace_back(
- display->getOrCreateOutputLayer(displayId, compositionLayer,
- layerFE));
- deprecated_layersSortedByZ.add(layer);
-
- auto& outputLayerState = layersSortedByZ.back()->editState();
- outputLayerState.visibleRegion =
- tr.transform(layer->visibleRegion.intersect(displayState.viewport));
- } else if (displayId) {
- // For layers that are being removed from a HWC display,
- // and that have queued frames, add them to a a list of
- // released layers so we can properly set a fence.
- bool hasExistingOutputLayer =
- display->getOutputLayerForLayer(compositionLayer.get()) != nullptr;
- bool hasQueuedFrames = std::find(mLayersWithQueuedFrames.cbegin(),
- mLayersWithQueuedFrames.cend(),
- layer) != mLayersWithQueuedFrames.cend();
-
- if (hasExistingOutputLayer && hasQueuedFrames) {
- releasedLayers.push_back(layer);
- }
- }
- });
+ if (!displayState.isEnabled) {
+ continue;
}
- display->setOutputLayersOrderedByZ(std::move(layersSortedByZ));
- display->setReleasedLayers(std::move(releasedLayers));
+ computeVisibleRegions(displayDevice, dirtyRegion, opaqueRegion, layersSortedByZ);
- displayDevice->setVisibleLayersSortedByZ(deprecated_layersSortedByZ);
+ // computeVisibleRegions walks the layers in reverse-Z order. Reverse
+ // to get a back-to-front ordering.
+ std::reverse(layersSortedByZ.begin(), layersSortedByZ.end());
+
+ display->setOutputLayersOrderedByZ(std::move(layersSortedByZ));
+
+ compositionengine::Output::ReleasedLayers releasedLayers;
+ if (displayDevice->getId() && !layersWithQueuedFrames.empty()) {
+ // For layers that are being removed from a HWC display,
+ // and that have queued frames, add them to a a list of
+ // released layers so we can properly set a fence.
+
+ // Any non-null entries in the current list of layers are layers
+ // that are no longer going to be visible
+ for (auto& layer : display->getOutputLayersOrderedByZ()) {
+ if (!layer) {
+ continue;
+ }
+
+ sp<compositionengine::LayerFE> layerFE(&layer->getLayerFE());
+ const bool hasQueuedFrames =
+ std::find(layersWithQueuedFrames.cbegin(),
+ layersWithQueuedFrames.cend(),
+ layerFE) != layersWithQueuedFrames.cend();
+
+ if (hasQueuedFrames) {
+ releasedLayers.emplace_back(layerFE);
+ }
+ }
+ }
+ display->setReleasedLayers(std::move(releasedLayers));
Region undefinedRegion{bounds};
undefinedRegion.subtractSelf(tr.transform(opaqueRegion));
@@ -2242,129 +2149,6 @@
}
}
-// Returns a data space that fits all visible layers. The returned data space
-// can only be one of
-// - Dataspace::SRGB (use legacy dataspace and let HWC saturate when colors are enhanced)
-// - Dataspace::DISPLAY_P3
-// - Dataspace::DISPLAY_BT2020
-// The returned HDR data space is one of
-// - Dataspace::UNKNOWN
-// - Dataspace::BT2020_HLG
-// - Dataspace::BT2020_PQ
-Dataspace SurfaceFlinger::getBestDataspace(const sp<DisplayDevice>& display,
- Dataspace* outHdrDataSpace,
- bool* outIsHdrClientComposition) const {
- Dataspace bestDataSpace = Dataspace::V0_SRGB;
- *outHdrDataSpace = Dataspace::UNKNOWN;
-
- for (const auto& layer : display->getVisibleLayersSortedByZ()) {
- switch (layer->getDataSpace()) {
- case Dataspace::V0_SCRGB:
- case Dataspace::V0_SCRGB_LINEAR:
- case Dataspace::BT2020:
- case Dataspace::BT2020_ITU:
- case Dataspace::BT2020_LINEAR:
- case Dataspace::DISPLAY_BT2020:
- bestDataSpace = Dataspace::DISPLAY_BT2020;
- break;
- case Dataspace::DISPLAY_P3:
- bestDataSpace = Dataspace::DISPLAY_P3;
- break;
- case Dataspace::BT2020_PQ:
- case Dataspace::BT2020_ITU_PQ:
- bestDataSpace = Dataspace::DISPLAY_P3;
- *outHdrDataSpace = Dataspace::BT2020_PQ;
- *outIsHdrClientComposition =
- layer->getCompositionLayer()->getState().frontEnd.forceClientComposition;
- break;
- case Dataspace::BT2020_HLG:
- case Dataspace::BT2020_ITU_HLG:
- bestDataSpace = Dataspace::DISPLAY_P3;
- // When there's mixed PQ content and HLG content, we set the HDR
- // data space to be BT2020_PQ and convert HLG to PQ.
- if (*outHdrDataSpace == Dataspace::UNKNOWN) {
- *outHdrDataSpace = Dataspace::BT2020_HLG;
- }
- break;
- default:
- break;
- }
- }
-
- return bestDataSpace;
-}
-
-// Pick the ColorMode / Dataspace for the display device.
-void SurfaceFlinger::pickColorMode(const sp<DisplayDevice>& display, ColorMode* outMode,
- Dataspace* outDataSpace, RenderIntent* outRenderIntent) const {
- if (mDisplayColorSetting == DisplayColorSetting::UNMANAGED) {
- *outMode = ColorMode::NATIVE;
- *outDataSpace = Dataspace::UNKNOWN;
- *outRenderIntent = RenderIntent::COLORIMETRIC;
- return;
- }
-
- Dataspace hdrDataSpace;
- bool isHdrClientComposition = false;
- Dataspace bestDataSpace = getBestDataspace(display, &hdrDataSpace, &isHdrClientComposition);
-
- auto* profile = display->getCompositionDisplay()->getDisplayColorProfile();
-
- switch (mForceColorMode) {
- case ColorMode::SRGB:
- bestDataSpace = Dataspace::V0_SRGB;
- break;
- case ColorMode::DISPLAY_P3:
- bestDataSpace = Dataspace::DISPLAY_P3;
- break;
- default:
- break;
- }
-
- // respect hdrDataSpace only when there is no legacy HDR support
- const bool isHdr = hdrDataSpace != Dataspace::UNKNOWN &&
- !profile->hasLegacyHdrSupport(hdrDataSpace) && !isHdrClientComposition;
- if (isHdr) {
- bestDataSpace = hdrDataSpace;
- }
-
- RenderIntent intent;
- switch (mDisplayColorSetting) {
- case DisplayColorSetting::MANAGED:
- case DisplayColorSetting::UNMANAGED:
- intent = isHdr ? RenderIntent::TONE_MAP_COLORIMETRIC : RenderIntent::COLORIMETRIC;
- break;
- case DisplayColorSetting::ENHANCED:
- intent = isHdr ? RenderIntent::TONE_MAP_ENHANCE : RenderIntent::ENHANCE;
- break;
- default: // vendor display color setting
- intent = static_cast<RenderIntent>(mDisplayColorSetting);
- break;
- }
-
- profile->getBestColorMode(bestDataSpace, intent, outDataSpace, outMode, outRenderIntent);
-}
-
-void SurfaceFlinger::doComposition(const sp<DisplayDevice>& displayDevice, bool repaintEverything) {
- ATRACE_CALL();
- ALOGV("doComposition");
-
- auto display = displayDevice->getCompositionDisplay();
- const auto& displayState = display->getState();
-
- if (displayState.isEnabled) {
- // transform the dirty region into this screen's coordinate space
- const Region dirtyRegion = display->getDirtyRegion(repaintEverything);
-
- // repaint the framebuffer (if needed)
- doDisplayComposition(displayDevice, dirtyRegion);
-
- display->editState().dirtyRegion.clear();
- display->getRenderSurface()->flip();
- }
- displayDevice->getCompositionDisplay()->postFramebuffer();
-}
-
void SurfaceFlinger::postFrame()
{
// |mStateLock| not needed as we are on the main thread
@@ -2444,8 +2228,8 @@
}
void SurfaceFlinger::dispatchDisplayHotplugEvent(PhysicalDisplayId displayId, bool connected) {
- mScheduler->hotplugReceived(mAppConnectionHandle, displayId, connected);
- mScheduler->hotplugReceived(mSfConnectionHandle, displayId, connected);
+ mScheduler->onHotplugReceived(mAppConnectionHandle, displayId, connected);
+ mScheduler->onHotplugReceived(mSfConnectionHandle, displayId, connected);
}
sp<DisplayDevice> SurfaceFlinger::setupNewDisplayDeviceInternal(
@@ -2512,8 +2296,10 @@
defaultColorMode = ColorMode::SRGB;
defaultDataSpace = Dataspace::V0_SRGB;
}
- display->getCompositionDisplay()->setColorMode(defaultColorMode, defaultDataSpace,
- RenderIntent::COLORIMETRIC, Dataspace::UNKNOWN);
+ display->getCompositionDisplay()->setColorProfile(
+ compositionengine::Output::ColorProfile{defaultColorMode, defaultDataSpace,
+ RenderIntent::COLORIMETRIC,
+ Dataspace::UNKNOWN});
if (!state.isVirtual()) {
LOG_ALWAYS_FATAL_IF(!displayId);
display->setActiveConfig(getHwComposer().getActiveConfigIndex(*displayId));
@@ -2859,45 +2645,43 @@
void SurfaceFlinger::updateCursorAsync()
{
- for (const auto& [token, display] : mDisplays) {
- if (!display->getId()) {
- continue;
- }
-
- for (auto& layer : display->getVisibleLayersSortedByZ()) {
- layer->updateCursorPosition(display);
+ compositionengine::CompositionRefreshArgs refreshArgs;
+ for (const auto& [_, display] : mDisplays) {
+ if (display->getId()) {
+ refreshArgs.outputs.push_back(display->getCompositionDisplay());
}
}
+
+ mCompositionEngine->updateCursorAsync(refreshArgs);
}
void SurfaceFlinger::commitTransaction()
{
- if (!mLayersPendingRemoval.isEmpty()) {
- // Notify removed layers now that they can't be drawn from
- for (const auto& l : mLayersPendingRemoval) {
- recordBufferingStats(l->getName().string(),
- l->getOccupancyHistory(true));
-
- // Ensure any buffers set to display on any children are released.
- if (l->isRemovedFromCurrentState()) {
- l->latchAndReleaseBuffer();
- }
-
- // If the layer has been removed and has no parent, then it will not be reachable
- // when traversing layers on screen. Add the layer to the offscreenLayers set to
- // ensure we can copy its current to drawing state.
- if (!l->getParent()) {
- mOffscreenLayers.emplace(l.get());
- }
- }
- mLayersPendingRemoval.clear();
- }
-
- // If this transaction is part of a window animation then the next frame
- // we composite should be considered an animation as well.
- mAnimCompositionPending = mAnimTransactionPending;
-
withTracingLock([&]() {
+ if (!mLayersPendingRemoval.isEmpty()) {
+ // Notify removed layers now that they can't be drawn from
+ for (const auto& l : mLayersPendingRemoval) {
+ recordBufferingStats(l->getName().string(), l->getOccupancyHistory(true));
+
+ // Ensure any buffers set to display on any children are released.
+ if (l->isRemovedFromCurrentState()) {
+ l->latchAndReleaseBuffer();
+ }
+
+ // If the layer has been removed and has no parent, then it will not be reachable
+ // when traversing layers on screen. Add the layer to the offscreenLayers set to
+ // ensure we can copy its current to drawing state.
+ if (!l->getParent()) {
+ mOffscreenLayers.emplace(l.get());
+ }
+ }
+ mLayersPendingRemoval.clear();
+ }
+
+ // If this transaction is part of a window animation then the next frame
+ // we composite should be considered an animation as well.
+ mAnimCompositionPending = mAnimTransactionPending;
+
mDrawingState = mCurrentState;
// clear the "changed" flags in current state
mCurrentState.colorMatrixChanged = false;
@@ -2952,8 +2736,10 @@
}
}
-void SurfaceFlinger::computeVisibleRegions(const sp<const DisplayDevice>& displayDevice,
- Region& outDirtyRegion, Region& outOpaqueRegion) {
+void SurfaceFlinger::computeVisibleRegions(
+ const sp<const DisplayDevice>& displayDevice, Region& outDirtyRegion,
+ Region& outOpaqueRegion,
+ std::vector<std::unique_ptr<compositionengine::OutputLayer>>& outLayersSortedByZ) {
ATRACE_CALL();
ALOGV("computeVisibleRegions");
@@ -2966,6 +2752,11 @@
outDirtyRegion.clear();
mDrawingState.traverseInReverseZOrder([&](Layer* layer) {
+ auto compositionLayer = layer->getCompositionLayer();
+ if (compositionLayer == nullptr) {
+ return;
+ }
+
// start with the whole surface at its current location
const Layer::State& s(layer->getDrawingState());
@@ -3003,7 +2794,6 @@
*/
Region transparentRegion;
-
// handle hidden surfaces by setting the visible region to empty
if (CC_LIKELY(layer->isVisible())) {
const bool translucent = !layer->isOpaque(s);
@@ -3036,7 +2826,6 @@
}
if (visibleRegion.isEmpty()) {
- layer->clearVisibilityRegions();
return;
}
@@ -3049,12 +2838,21 @@
// subtract the opaque region covered by the layers above us
visibleRegion.subtractSelf(aboveOpaqueLayers);
+ // Get coverage information for the layer as previously displayed
+ auto prevOutputLayer = display->getOutputLayerForLayer(compositionLayer.get());
+ // TODO(b/121291683): Define this as a constant in Region.h
+ const Region kEmptyRegion;
+ const Region& oldVisibleRegion =
+ prevOutputLayer ? prevOutputLayer->getState().visibleRegion : kEmptyRegion;
+ const Region& oldCoveredRegion =
+ prevOutputLayer ? prevOutputLayer->getState().coveredRegion : kEmptyRegion;
+
// compute this layer's dirty region
if (layer->contentDirty) {
// we need to invalidate the whole region
dirty = visibleRegion;
// as well, as the old visible region
- dirty.orSelf(layer->visibleRegion);
+ dirty.orSelf(oldVisibleRegion);
layer->contentDirty = false;
} else {
/* compute the exposed region:
@@ -3070,8 +2868,6 @@
* exposed because of a resize.
*/
const Region newExposed = visibleRegion - coveredRegion;
- const Region oldVisibleRegion = layer->visibleRegion;
- const Region oldCoveredRegion = layer->coveredRegion;
const Region oldExposed = oldVisibleRegion - oldCoveredRegion;
dirty = (visibleRegion&oldCoveredRegion) | (newExposed-oldExposed);
}
@@ -3083,11 +2879,30 @@
// Update aboveOpaqueLayers for next (lower) layer
aboveOpaqueLayers.orSelf(opaqueRegion);
- // Store the visible region in screen space
- layer->setVisibleRegion(visibleRegion);
- layer->setCoveredRegion(coveredRegion);
- layer->setVisibleNonTransparentRegion(
- visibleRegion.subtract(transparentRegion));
+ // Compute the visible non-transparent region
+ Region visibleNonTransparentRegion = visibleRegion.subtract(transparentRegion);
+
+ // Setup an output layer for this output if the layer is visible on this
+ // output
+ const auto& displayState = display->getState();
+ Region drawRegion(displayState.transform.transform(visibleNonTransparentRegion));
+ drawRegion.andSelf(displayState.bounds);
+ if (drawRegion.isEmpty()) {
+ return;
+ }
+
+ const auto displayId = displayDevice->getId();
+ sp<compositionengine::LayerFE> layerFE = compositionLayer->getLayerFE();
+ LOG_ALWAYS_FATAL_IF(layerFE.get() == nullptr);
+
+ outLayersSortedByZ.emplace_back(
+ display->getOrCreateOutputLayer(displayId, compositionLayer, layerFE));
+ auto& outputLayerState = outLayersSortedByZ.back()->editState();
+ outputLayerState.visibleRegion = std::move(visibleRegion);
+ outputLayerState.visibleNonTransparentRegion = std::move(visibleNonTransparentRegion);
+ outputLayerState.coveredRegion = std::move(coveredRegion);
+ outputLayerState.outputSpaceVisibleRegion = displayState.transform.transform(
+ outputLayerState.visibleRegion.intersect(displayState.viewport));
});
outOpaqueRegion = aboveOpaqueLayers;
@@ -3186,26 +3001,6 @@
mGeometryInvalid = true;
}
-void SurfaceFlinger::doDisplayComposition(const sp<DisplayDevice>& displayDevice,
- const Region& inDirtyRegion) {
- auto display = displayDevice->getCompositionDisplay();
- // We only need to actually compose the display if:
- // 1) It is being handled by hardware composer, which may need this to
- // keep its virtual display state machine in sync, or
- // 2) There is work to be done (the dirty region isn't empty)
- if (!displayDevice->getId() && inDirtyRegion.isEmpty()) {
- ALOGV("Skipping display composition");
- return;
- }
-
- ALOGV("doDisplayComposition");
- base::unique_fd readyFence;
- if (!display->composeSurfaces(Region::INVALID_REGION, &readyFence)) return;
-
- // swap buffers (presentation)
- display->getRenderSurface()->queueBuffer(std::move(readyFence));
-}
-
status_t SurfaceFlinger::addClientLayer(const sp<Client>& client, const sp<IBinder>& handle,
const sp<IGraphicBufferProducer>& gbc, const sp<Layer>& lbc,
const sp<IBinder>& parentHandle,
@@ -4253,9 +4048,8 @@
static const std::unordered_map<std::string, Dumper> dumpers = {
{"--display-id"s, dumper(&SurfaceFlinger::dumpDisplayIdentificationData)},
- {"--dispsync"s, dumper([this](std::string& s) {
- mScheduler->dumpPrimaryDispSync(s);
- })},
+ {"--dispsync"s,
+ dumper([this](std::string& s) { mScheduler->getPrimaryDispSync().dump(s); })},
{"--frame-events"s, dumper(&SurfaceFlinger::dumpFrameEventsLocked)},
{"--latency"s, argsDumper(&SurfaceFlinger::dumpStatsLocked)},
{"--latency-clear"s, argsDumper(&SurfaceFlinger::clearStatsLocked)},
@@ -4284,9 +4078,11 @@
if (asProto) {
result.append(layersProto.SerializeAsString());
} else {
+ // Dump info that we need to access from the main thread
const auto layerTree = LayerProtoParser::generateLayerTree(layersProto);
result.append(LayerProtoParser::layerTreeToString(layerTree));
result.append("\n");
+ dumpOffscreenLayers(result);
}
}
}
@@ -4362,22 +4158,26 @@
}
void SurfaceFlinger::dumpVSync(std::string& result) const {
+ mScheduler->dump(result);
+ StringAppendF(&result, "+ Smart video mode: %s\n\n", mUseSmart90ForVideo ? "on" : "off");
+
+ mRefreshRateStats.dump(result);
+ result.append("\n");
+
mPhaseOffsets->dump(result);
StringAppendF(&result,
- " present offset: %9" PRId64 " ns\t VSYNC period: %9" PRId64 " ns\n\n",
+ " present offset: %9" PRId64 " ns\t VSYNC period: %9" PRId64 " ns\n\n",
dispSyncPresentTimeOffset, getVsyncPeriod());
- StringAppendF(&result, "Scheduler enabled.");
- StringAppendF(&result, "+ Smart 90 for video detection: %s\n\n",
- mUseSmart90ForVideo ? "on" : "off");
StringAppendF(&result, "Allowed Display Configs: ");
- for (auto refresh : mRefreshRateConfigs.getRefreshRates()) {
- if (refresh.second && isDisplayConfigAllowed(refresh.second->configId)) {
- StringAppendF(&result, "%dHz, ", refresh.second->fps);
+ for (const auto& [type, rate] : mRefreshRateConfigs.getRefreshRates()) {
+ if (rate && isDisplayConfigAllowed(rate->configId)) {
+ StringAppendF(&result, "%" PRIu32 " Hz, ", rate->fps);
}
}
StringAppendF(&result, "(config override by backdoor: %s)\n\n",
mDebugDisplayConfigSetByBackdoor ? "yes" : "no");
+
mScheduler->dump(mAppConnectionHandle, result);
}
@@ -4540,12 +4340,54 @@
return layersProto;
}
+void SurfaceFlinger::dumpOffscreenLayersProto(LayersProto& layersProto, uint32_t traceFlags) const {
+ // Add a fake invisible root layer to the proto output and parent all the offscreen layers to
+ // it.
+ LayerProto* rootProto = layersProto.add_layers();
+ const int32_t offscreenRootLayerId = INT32_MAX - 2;
+ rootProto->set_id(offscreenRootLayerId);
+ rootProto->set_name("Offscreen Root");
+
+ for (Layer* offscreenLayer : mOffscreenLayers) {
+ // Add layer as child of the fake root
+ rootProto->add_children(offscreenLayer->sequence);
+
+ // Add layer
+ LayerProto* layerProto = layersProto.add_layers();
+ offscreenLayer->writeToProtoDrawingState(layerProto, traceFlags);
+ offscreenLayer->writeToProtoCommonState(layerProto, LayerVector::StateSet::Drawing,
+ traceFlags);
+ layerProto->set_parent(offscreenRootLayerId);
+
+ // Add children
+ offscreenLayer->traverseInZOrder(LayerVector::StateSet::Drawing, [&](Layer* layer) {
+ if (layer == offscreenLayer) {
+ return;
+ }
+ LayerProto* childProto = layersProto.add_layers();
+ layer->writeToProtoDrawingState(childProto, traceFlags);
+ layer->writeToProtoCommonState(childProto, LayerVector::StateSet::Drawing, traceFlags);
+ });
+ }
+}
+
LayersProto SurfaceFlinger::dumpProtoFromMainThread(uint32_t traceFlags) {
LayersProto layersProto;
postMessageSync(new LambdaMessage([&]() { layersProto = dumpDrawingStateProto(traceFlags); }));
return layersProto;
}
+void SurfaceFlinger::dumpOffscreenLayers(std::string& result) {
+ result.append("Offscreen Layers:\n");
+ postMessageSync(new LambdaMessage([&]() {
+ for (Layer* offscreenLayer : mOffscreenLayers) {
+ offscreenLayer->traverseInZOrder(LayerVector::StateSet::Drawing, [&](Layer* layer) {
+ layer->dumpCallingUidPid(result);
+ });
+ }
+ }));
+}
+
void SurfaceFlinger::dumpAllLocked(const DumpArgs& args, std::string& result) const {
const bool colorize = !args.empty() && args[0] == String16("--color");
Colorizer colorizer(colorize);
@@ -4580,7 +4422,7 @@
result.append("\n\n");
colorizer.bold(result);
- result.append("VSYNC configuration:\n");
+ result.append("Scheduler:\n");
colorizer.reset(result);
dumpVSync(result);
result.append("\n");
@@ -4707,14 +4549,6 @@
result.append("\n");
}
- /**
- * Scheduler dump state.
- */
- result.append("\nScheduler state:\n");
- result.append(mScheduler->doDump() + "\n");
- StringAppendF(&result, "+ Smart video mode: %s\n\n", mUseSmart90ForVideo ? "on" : "off");
- result.append(mRefreshRateStats.doDump() + "\n");
-
result.append(mTimeStats->miniDump());
result.append("\n");
}
@@ -4998,13 +4832,8 @@
updateColorMatrixLocked();
return NO_ERROR;
}
- // This is an experimental interface
- // Needs to be shifted to proper binder interface when we productize
- case 1016: {
- n = data.readInt32();
- // TODO(b/113612090): Evaluate if this can be removed.
- mScheduler->setRefreshSkipCount(n);
- return NO_ERROR;
+ case 1016: { // Unused.
+ return NAME_NOT_FOUND;
}
case 1017: {
n = data.readInt32();
@@ -5098,13 +4927,13 @@
DisplayColorSetting setting = static_cast<DisplayColorSetting>(data.readInt32());
switch (setting) {
- case DisplayColorSetting::MANAGED:
+ case DisplayColorSetting::kManaged:
reply->writeBool(useColorManagement);
break;
- case DisplayColorSetting::UNMANAGED:
+ case DisplayColorSetting::kUnmanaged:
reply->writeBool(true);
break;
- case DisplayColorSetting::ENHANCED:
+ case DisplayColorSetting::kEnhanced:
reply->writeBool(display->hasRenderIntent(RenderIntent::ENHANCE));
break;
default: // vendor display color setting
@@ -5768,25 +5597,47 @@
}
}
+void SurfaceFlinger::setPreferredDisplayConfig() {
+ const auto& type = mScheduler->getPreferredRefreshRateType();
+ const auto& config = mRefreshRateConfigs.getRefreshRate(type);
+ if (config && isDisplayConfigAllowed(config->configId)) {
+ ALOGV("switching to Scheduler preferred config %d", config->configId);
+ setDesiredActiveConfig({type, config->configId, Scheduler::ConfigEvent::Changed});
+ } else {
+ // Set the highest allowed config by iterating backwards on available refresh rates
+ const auto& refreshRates = mRefreshRateConfigs.getRefreshRates();
+ for (auto iter = refreshRates.crbegin(); iter != refreshRates.crend(); ++iter) {
+ if (iter->second && isDisplayConfigAllowed(iter->second->configId)) {
+ ALOGV("switching to allowed config %d", iter->second->configId);
+ setDesiredActiveConfig({iter->first, iter->second->configId,
+ Scheduler::ConfigEvent::Changed});
+ }
+ }
+ }
+}
+
void SurfaceFlinger::setAllowedDisplayConfigsInternal(const sp<DisplayDevice>& display,
const std::vector<int32_t>& allowedConfigs) {
if (!display->isPrimary()) {
return;
}
- ALOGV("Updating allowed configs");
- mAllowedDisplayConfigs = DisplayConfigs(allowedConfigs.begin(), allowedConfigs.end());
-
- // Set the highest allowed config by iterating backwards on available refresh rates
- const auto& refreshRates = mRefreshRateConfigs.getRefreshRates();
- for (auto iter = refreshRates.crbegin(); iter != refreshRates.crend(); ++iter) {
- if (iter->second && isDisplayConfigAllowed(iter->second->configId)) {
- ALOGV("switching to config %d", iter->second->configId);
- setDesiredActiveConfig(
- {iter->first, iter->second->configId, Scheduler::ConfigEvent::Changed});
- break;
- }
+ const auto allowedDisplayConfigs = DisplayConfigs(allowedConfigs.begin(),
+ allowedConfigs.end());
+ if (allowedDisplayConfigs == mAllowedDisplayConfigs) {
+ return;
}
+
+ ALOGV("Updating allowed configs");
+ mAllowedDisplayConfigs = std::move(allowedDisplayConfigs);
+
+ // TODO(b/140204874): This hack triggers a notification that something has changed, so
+ // that listeners that care about a change in allowed configs can get the notification.
+ // Giving current ActiveConfig so that most other listeners would just drop the event
+ mScheduler->onConfigChanged(mAppConnectionHandle, display->getId()->value,
+ display->getActiveConfig());
+
+ setPreferredDisplayConfig();
}
status_t SurfaceFlinger::setAllowedDisplayConfigs(const sp<IBinder>& displayToken,
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 05ba234..f220c26 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -23,6 +23,7 @@
*/
#include <android-base/thread_annotations.h>
+#include <compositionengine/OutputColorSetting.h>
#include <cutils/atomic.h>
#include <cutils/compiler.h>
#include <gui/BufferQueue.h>
@@ -94,9 +95,13 @@
class RefreshRateOverlay;
class RegionSamplingThread;
class TimeStats;
+class FrameTracer;
namespace compositionengine {
class DisplaySurface;
+class OutputLayer;
+
+struct CompositionRefreshArgs;
} // namespace compositionengine
namespace renderengine {
@@ -116,11 +121,7 @@
eTransactionMask = 0x1f,
};
-enum class DisplayColorSetting : int32_t {
- MANAGED = 0,
- UNMANAGED = 1,
- ENHANCED = 2,
-};
+using DisplayColorSetting = compositionengine::OutputColorSetting;
class SurfaceFlingerBE
{
@@ -528,6 +529,9 @@
// called on the main thread in response to setPowerMode()
void setPowerModeInternal(const sp<DisplayDevice>& display, int mode) REQUIRES(mStateLock);
+ // Query the Scheduler or allowed display configs list for a matching config, and set it
+ void setPreferredDisplayConfig() REQUIRES(mStateLock);
+
// called on the main thread in response to setAllowedDisplayConfigs()
void setAllowedDisplayConfigsInternal(const sp<DisplayDevice>& display,
const std::vector<int32_t>& allowedConfigs)
@@ -741,8 +745,9 @@
* Compositing
*/
void invalidateHwcGeometry();
- void computeVisibleRegions(const sp<const DisplayDevice>& display, Region& dirtyRegion,
- Region& opaqueRegion);
+ void computeVisibleRegions(
+ const sp<const DisplayDevice>& display, Region& dirtyRegion, Region& opaqueRegion,
+ std::vector<std::unique_ptr<compositionengine::OutputLayer>>& outputLayers);
void postComposition();
void getCompositorTiming(CompositorTiming* compositorTiming);
@@ -752,20 +757,6 @@
nsecs_t compositeToPresentLatency);
void rebuildLayerStacks();
- ui::Dataspace getBestDataspace(const sp<DisplayDevice>& display, ui::Dataspace* outHdrDataSpace,
- bool* outIsHdrClientComposition) const;
-
- // Returns the appropriate ColorMode, Dataspace and RenderIntent for the
- // DisplayDevice. The function only returns the supported ColorMode,
- // Dataspace and RenderIntent.
- void pickColorMode(const sp<DisplayDevice>& display, ui::ColorMode* outMode,
- ui::Dataspace* outDataSpace, ui::RenderIntent* outRenderIntent) const;
-
- void calculateWorkingSet();
- void doComposition(const sp<DisplayDevice>& display, bool repainEverything);
- void doDebugFlashRegions(const sp<DisplayDevice>& display, bool repaintEverything);
- void doDisplayComposition(const sp<DisplayDevice>& display, const Region& dirtyRegion);
-
void postFrame();
/* ------------------------------------------------------------------------
@@ -876,8 +867,11 @@
void dumpDisplayIdentificationData(std::string& result) const;
void dumpWideColorInfo(std::string& result) const;
LayersProto dumpDrawingStateProto(uint32_t traceFlags = SurfaceTracing::TRACE_ALL) const;
+ void dumpOffscreenLayersProto(LayersProto& layersProto,
+ uint32_t traceFlags = SurfaceTracing::TRACE_ALL) const;
LayersProto dumpProtoFromMainThread(uint32_t traceFlags = SurfaceTracing::TRACE_ALL)
EXCLUDES(mStateLock);
+ void dumpOffscreenLayers(std::string& result) EXCLUDES(mStateLock);
void withTracingLock(std::function<void()> operation) REQUIRES(mStateLock);
bool isLayerTripleBufferingDisabled() const {
@@ -996,6 +990,7 @@
bool mTracingEnabled = false;
bool mTracingEnabledChanged GUARDED_BY(mStateLock) = false;
const std::shared_ptr<TimeStats> mTimeStats;
+ const std::unique_ptr<FrameTracer> mFrameTracer;
bool mUseHwcVirtualDisplays = false;
std::atomic<uint32_t> mFrameMissedCount = 0;
std::atomic<uint32_t> mHwcFrameMissedCount = 0;
@@ -1074,7 +1069,7 @@
static bool useVrFlinger;
std::thread::id mMainThreadId = std::this_thread::get_id();
- DisplayColorSetting mDisplayColorSetting = DisplayColorSetting::ENHANCED;
+ DisplayColorSetting mDisplayColorSetting = DisplayColorSetting::kEnhanced;
// Color mode forced by setting persist.sys.sf.color_mode, it must:
// 1. not be NATIVE color mode, NATIVE color mode means no forced color mode;
@@ -1097,8 +1092,8 @@
*/
bool mUseSmart90ForVideo = false;
std::unique_ptr<Scheduler> mScheduler;
- sp<Scheduler::ConnectionHandle> mAppConnectionHandle;
- sp<Scheduler::ConnectionHandle> mSfConnectionHandle;
+ scheduler::ConnectionHandle mAppConnectionHandle;
+ scheduler::ConnectionHandle mSfConnectionHandle;
// Stores phase offsets configured per refresh rate.
const std::unique_ptr<scheduler::PhaseOffsets> mPhaseOffsets;
diff --git a/services/surfaceflinger/SurfaceFlingerFactory.cpp b/services/surfaceflinger/SurfaceFlingerFactory.cpp
index e425b2a..041ff8d 100644
--- a/services/surfaceflinger/SurfaceFlingerFactory.cpp
+++ b/services/surfaceflinger/SurfaceFlingerFactory.cpp
@@ -45,19 +45,13 @@
Factory() = default;
~Factory() = default;
- std::unique_ptr<DispSync> createDispSync(const char* name, bool hasSyncFramework,
- int64_t dispSyncPresentTimeOffset) override {
- // Note: We create a local temporary with the real DispSync implementation
- // type temporarily so we can initialize it with the configured values,
- // before storing it for more generic use using the interface type.
- auto primaryDispSync = std::make_unique<android::impl::DispSync>(name);
- primaryDispSync->init(hasSyncFramework, dispSyncPresentTimeOffset);
- return primaryDispSync;
+ std::unique_ptr<DispSync> createDispSync(const char* name, bool hasSyncFramework) override {
+ return std::make_unique<android::impl::DispSync>(name, hasSyncFramework);
}
std::unique_ptr<EventControlThread> createEventControlThread(
- std::function<void(bool)> setVSyncEnabled) override {
- return std::make_unique<android::impl::EventControlThread>(setVSyncEnabled);
+ SetVSyncEnabled setVSyncEnabled) override {
+ return std::make_unique<android::impl::EventControlThread>(std::move(setVSyncEnabled));
}
std::unique_ptr<HWComposer> createHWComposer(const std::string& serviceName) override {
@@ -74,9 +68,9 @@
}
std::unique_ptr<Scheduler> createScheduler(
- std::function<void(bool)> callback,
- const scheduler::RefreshRateConfigs& refreshRateConfig) override {
- return std::make_unique<Scheduler>(callback, refreshRateConfig);
+ SetVSyncEnabled setVSyncEnabled,
+ const scheduler::RefreshRateConfigs& configs) override {
+ return std::make_unique<Scheduler>(std::move(setVSyncEnabled), configs);
}
std::unique_ptr<SurfaceInterceptor> createSurfaceInterceptor(
diff --git a/services/surfaceflinger/SurfaceFlingerFactory.h b/services/surfaceflinger/SurfaceFlingerFactory.h
index c2bc808..5d487e6 100644
--- a/services/surfaceflinger/SurfaceFlingerFactory.h
+++ b/services/surfaceflinger/SurfaceFlingerFactory.h
@@ -64,16 +64,15 @@
// of each interface.
class Factory {
public:
- virtual std::unique_ptr<DispSync> createDispSync(const char* name, bool hasSyncFramework,
- int64_t dispSyncPresentTimeOffset) = 0;
- virtual std::unique_ptr<EventControlThread> createEventControlThread(
- std::function<void(bool)> setVSyncEnabled) = 0;
+ using SetVSyncEnabled = std::function<void(bool)>;
+
+ virtual std::unique_ptr<DispSync> createDispSync(const char* name, bool hasSyncFramework) = 0;
+ virtual std::unique_ptr<EventControlThread> createEventControlThread(SetVSyncEnabled) = 0;
virtual std::unique_ptr<HWComposer> createHWComposer(const std::string& serviceName) = 0;
virtual std::unique_ptr<MessageQueue> createMessageQueue() = 0;
virtual std::unique_ptr<scheduler::PhaseOffsets> createPhaseOffsets() = 0;
- virtual std::unique_ptr<Scheduler> createScheduler(
- std::function<void(bool)> callback,
- const scheduler::RefreshRateConfigs& refreshRateConfig) = 0;
+ virtual std::unique_ptr<Scheduler> createScheduler(SetVSyncEnabled,
+ const scheduler::RefreshRateConfigs&) = 0;
virtual std::unique_ptr<SurfaceInterceptor> createSurfaceInterceptor(SurfaceFlinger*) = 0;
virtual sp<StartPropertySetThread> createStartPropertySetThread(
diff --git a/services/surfaceflinger/SurfaceTracing.cpp b/services/surfaceflinger/SurfaceTracing.cpp
index 9053f2c..eb26cd0 100644
--- a/services/surfaceflinger/SurfaceTracing.cpp
+++ b/services/surfaceflinger/SurfaceTracing.cpp
@@ -163,6 +163,7 @@
entry.set_elapsed_realtime_nanos(elapsedRealtimeNano());
entry.set_where(where);
LayersProto layers(mFlinger.dumpDrawingStateProto(mTraceFlags));
+ mFlinger.dumpOffscreenLayersProto(layers);
entry.mutable_layers()->Swap(&layers);
return entry;
diff --git a/services/surfaceflinger/TimeStats/Android.bp b/services/surfaceflinger/TimeStats/Android.bp
new file mode 100644
index 0000000..2080a38
--- /dev/null
+++ b/services/surfaceflinger/TimeStats/Android.bp
@@ -0,0 +1,12 @@
+cc_library_static {
+ name: "libtimestats",
+ defaults: ["surfaceflinger_defaults"],
+ srcs: [
+ "TimeStats.cpp",
+ ],
+ export_include_dirs: ["."],
+ shared_libs: [
+ "libtimestats_proto",
+ "libui",
+ ],
+}
diff --git a/services/surfaceflinger/TimeStats/TimeStats.cpp b/services/surfaceflinger/TimeStats/TimeStats.cpp
index 3e3ab18..b01fa81 100644
--- a/services/surfaceflinger/TimeStats/TimeStats.cpp
+++ b/services/surfaceflinger/TimeStats/TimeStats.cpp
@@ -407,13 +407,9 @@
}
void TimeStats::onDestroy(int32_t layerID) {
- if (!mEnabled.load()) return;
-
ATRACE_CALL();
ALOGV("[%d]-onDestroy", layerID);
-
std::lock_guard<std::mutex> lock(mMutex);
- if (!mTimeStatsTracker.count(layerID)) return;
mTimeStatsTracker.erase(layerID);
}
diff --git a/services/surfaceflinger/TimeStats/TimeStats.h b/services/surfaceflinger/TimeStats/TimeStats.h
index eed7111..9ebc1ad 100644
--- a/services/surfaceflinger/TimeStats/TimeStats.h
+++ b/services/surfaceflinger/TimeStats/TimeStats.h
@@ -16,13 +16,10 @@
#pragma once
+#include <hardware/hwcomposer_defs.h>
#include <timestatsproto/TimeStatsHelper.h>
#include <timestatsproto/TimeStatsProtoHeader.h>
-
-#include <hardware/hwcomposer_defs.h>
-
#include <ui/FenceTime.h>
-
#include <utils/String16.h>
#include <utils/Vector.h>
diff --git a/services/surfaceflinger/tests/Android.bp b/services/surfaceflinger/tests/Android.bp
index 53a3611..159c2a4 100644
--- a/services/surfaceflinger/tests/Android.bp
+++ b/services/surfaceflinger/tests/Android.bp
@@ -50,6 +50,7 @@
"fakehwc",
"hwc2",
"unittests",
+ "utils",
"vsync",
"waitforvsync",
]
diff --git a/services/surfaceflinger/tests/Transaction_test.cpp b/services/surfaceflinger/tests/Transaction_test.cpp
index 03c646b..4fff268 100644
--- a/services/surfaceflinger/tests/Transaction_test.cpp
+++ b/services/surfaceflinger/tests/Transaction_test.cpp
@@ -20,7 +20,6 @@
#include <functional>
#include <limits>
#include <ostream>
-#include <thread>
#include <gtest/gtest.h>
@@ -37,10 +36,7 @@
#include <private/android_filesystem_config.h>
#include <private/gui/ComposerService.h>
-#include <ui/ColorSpace.h>
#include <ui/DisplayInfo.h>
-#include <ui/Rect.h>
-#include <utils/String8.h>
#include <math.h>
#include <math/vec3.h>
@@ -48,293 +44,14 @@
#include <unistd.h>
#include "BufferGenerator.h"
+#include "utils/CallbackUtils.h"
+#include "utils/ColorUtils.h"
+#include "utils/ScreenshotUtils.h"
+#include "utils/TransactionUtils.h"
namespace android {
-namespace {
-
-struct Color {
- uint8_t r;
- uint8_t g;
- uint8_t b;
- uint8_t a;
-
- static const Color RED;
- static const Color GREEN;
- static const Color BLUE;
- static const Color WHITE;
- static const Color BLACK;
- static const Color TRANSPARENT;
-};
-
-const Color Color::RED{255, 0, 0, 255};
-const Color Color::GREEN{0, 255, 0, 255};
-const Color Color::BLUE{0, 0, 255, 255};
-const Color Color::WHITE{255, 255, 255, 255};
-const Color Color::BLACK{0, 0, 0, 255};
-const Color Color::TRANSPARENT{0, 0, 0, 0};
-
using android::hardware::graphics::common::V1_1::BufferUsage;
-using namespace std::chrono_literals;
-
-std::ostream& operator<<(std::ostream& os, const Color& color) {
- os << int(color.r) << ", " << int(color.g) << ", " << int(color.b) << ", " << int(color.a);
- return os;
-}
-
-// Fill a region with the specified color.
-void fillANativeWindowBufferColor(const ANativeWindow_Buffer& buffer, const Rect& rect,
- const Color& color) {
- Rect r(0, 0, buffer.width, buffer.height);
- if (!r.intersect(rect, &r)) {
- return;
- }
-
- int32_t width = r.right - r.left;
- int32_t height = r.bottom - r.top;
-
- for (int32_t row = 0; row < height; row++) {
- uint8_t* dst =
- static_cast<uint8_t*>(buffer.bits) + (buffer.stride * (r.top + row) + r.left) * 4;
- for (int32_t column = 0; column < width; column++) {
- dst[0] = color.r;
- dst[1] = color.g;
- dst[2] = color.b;
- dst[3] = color.a;
- dst += 4;
- }
- }
-}
-
-// Fill a region with the specified color.
-void fillGraphicBufferColor(const sp<GraphicBuffer>& buffer, const Rect& rect, const Color& color) {
- Rect r(0, 0, buffer->width, buffer->height);
- if (!r.intersect(rect, &r)) {
- return;
- }
-
- int32_t width = r.right - r.left;
- int32_t height = r.bottom - r.top;
-
- uint8_t* pixels;
- buffer->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
- reinterpret_cast<void**>(&pixels));
-
- for (int32_t row = 0; row < height; row++) {
- uint8_t* dst = pixels + (buffer->getStride() * (r.top + row) + r.left) * 4;
- for (int32_t column = 0; column < width; column++) {
- dst[0] = color.r;
- dst[1] = color.g;
- dst[2] = color.b;
- dst[3] = color.a;
- dst += 4;
- }
- }
- buffer->unlock();
-}
-
-// Check if a region has the specified color.
-void expectBufferColor(const sp<GraphicBuffer>& outBuffer, uint8_t* pixels, const Rect& rect,
- const Color& color, uint8_t tolerance) {
- int32_t x = rect.left;
- int32_t y = rect.top;
- int32_t width = rect.right - rect.left;
- int32_t height = rect.bottom - rect.top;
-
- int32_t bufferWidth = int32_t(outBuffer->getWidth());
- int32_t bufferHeight = int32_t(outBuffer->getHeight());
- if (x + width > bufferWidth) {
- x = std::min(x, bufferWidth);
- width = bufferWidth - x;
- }
- if (y + height > bufferHeight) {
- y = std::min(y, bufferHeight);
- height = bufferHeight - y;
- }
-
- auto colorCompare = [tolerance](uint8_t a, uint8_t b) {
- uint8_t tmp = a >= b ? a - b : b - a;
- return tmp <= tolerance;
- };
- for (int32_t j = 0; j < height; j++) {
- const uint8_t* src = pixels + (outBuffer->getStride() * (y + j) + x) * 4;
- for (int32_t i = 0; i < width; i++) {
- const uint8_t expected[4] = {color.r, color.g, color.b, color.a};
- EXPECT_TRUE(std::equal(src, src + 4, expected, colorCompare))
- << "pixel @ (" << x + i << ", " << y + j << "): "
- << "expected (" << color << "), "
- << "got (" << Color{src[0], src[1], src[2], src[3]} << ")";
- src += 4;
- }
- }
-}
-
-} // anonymous namespace
-
-using Transaction = SurfaceComposerClient::Transaction;
-
-// Fill an RGBA_8888 formatted surface with a single color.
-static void fillSurfaceRGBA8(const sp<SurfaceControl>& sc, uint8_t r, uint8_t g, uint8_t b,
- bool unlock = true) {
- ANativeWindow_Buffer outBuffer;
- sp<Surface> s = sc->getSurface();
- ASSERT_TRUE(s != nullptr);
- ASSERT_EQ(NO_ERROR, s->lock(&outBuffer, nullptr));
- uint8_t* img = reinterpret_cast<uint8_t*>(outBuffer.bits);
- for (int y = 0; y < outBuffer.height; y++) {
- for (int x = 0; x < outBuffer.width; x++) {
- uint8_t* pixel = img + (4 * (y * outBuffer.stride + x));
- pixel[0] = r;
- pixel[1] = g;
- pixel[2] = b;
- pixel[3] = 255;
- }
- }
- if (unlock) {
- ASSERT_EQ(NO_ERROR, s->unlockAndPost());
- }
-}
-
-// A ScreenCapture is a screenshot from SurfaceFlinger that can be used to check
-// individual pixel values for testing purposes.
-class ScreenCapture : public RefBase {
-public:
- static void captureScreen(std::unique_ptr<ScreenCapture>* sc) {
- captureScreen(sc, SurfaceComposerClient::getInternalDisplayToken());
- }
-
- static void captureScreen(std::unique_ptr<ScreenCapture>* sc, sp<IBinder> displayToken) {
- const auto sf = ComposerService::getComposerService();
- SurfaceComposerClient::Transaction().apply(true);
-
- sp<GraphicBuffer> outBuffer;
- ASSERT_EQ(NO_ERROR, sf->captureScreen(displayToken, &outBuffer, Rect(), 0, 0, false));
- *sc = std::make_unique<ScreenCapture>(outBuffer);
- }
-
- static void captureLayers(std::unique_ptr<ScreenCapture>* sc, sp<IBinder>& parentHandle,
- Rect crop = Rect::EMPTY_RECT, float frameScale = 1.0) {
- sp<ISurfaceComposer> sf(ComposerService::getComposerService());
- SurfaceComposerClient::Transaction().apply(true);
-
- sp<GraphicBuffer> outBuffer;
- ASSERT_EQ(NO_ERROR, sf->captureLayers(parentHandle, &outBuffer, crop, frameScale));
- *sc = std::make_unique<ScreenCapture>(outBuffer);
- }
-
- static void captureChildLayers(std::unique_ptr<ScreenCapture>* sc, sp<IBinder>& parentHandle,
- Rect crop = Rect::EMPTY_RECT, float frameScale = 1.0) {
- sp<ISurfaceComposer> sf(ComposerService::getComposerService());
- SurfaceComposerClient::Transaction().apply(true);
-
- sp<GraphicBuffer> outBuffer;
- ASSERT_EQ(NO_ERROR, sf->captureLayers(parentHandle, &outBuffer, crop, frameScale, true));
- *sc = std::make_unique<ScreenCapture>(outBuffer);
- }
-
- static void captureChildLayersExcluding(
- std::unique_ptr<ScreenCapture>* sc, sp<IBinder>& parentHandle,
- std::unordered_set<sp<IBinder>, ISurfaceComposer::SpHash<IBinder>> excludeLayers) {
- sp<ISurfaceComposer> sf(ComposerService::getComposerService());
- SurfaceComposerClient::Transaction().apply(true);
-
- sp<GraphicBuffer> outBuffer;
- ASSERT_EQ(NO_ERROR,
- sf->captureLayers(parentHandle, &outBuffer, ui::Dataspace::V0_SRGB,
- ui::PixelFormat::RGBA_8888, Rect::EMPTY_RECT, excludeLayers,
- 1.0f, true));
- *sc = std::make_unique<ScreenCapture>(outBuffer);
- }
-
- void expectColor(const Rect& rect, const Color& color, uint8_t tolerance = 0) {
- ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mOutBuffer->getPixelFormat());
- expectBufferColor(mOutBuffer, mPixels, rect, color, tolerance);
- }
-
- void expectBorder(const Rect& rect, const Color& color, uint8_t tolerance = 0) {
- ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mOutBuffer->getPixelFormat());
- const bool leftBorder = rect.left > 0;
- const bool topBorder = rect.top > 0;
- const bool rightBorder = rect.right < int32_t(mOutBuffer->getWidth());
- const bool bottomBorder = rect.bottom < int32_t(mOutBuffer->getHeight());
-
- if (topBorder) {
- Rect top(rect.left, rect.top - 1, rect.right, rect.top);
- if (leftBorder) {
- top.left -= 1;
- }
- if (rightBorder) {
- top.right += 1;
- }
- expectColor(top, color, tolerance);
- }
- if (leftBorder) {
- Rect left(rect.left - 1, rect.top, rect.left, rect.bottom);
- expectColor(left, color, tolerance);
- }
- if (rightBorder) {
- Rect right(rect.right, rect.top, rect.right + 1, rect.bottom);
- expectColor(right, color, tolerance);
- }
- if (bottomBorder) {
- Rect bottom(rect.left, rect.bottom, rect.right, rect.bottom + 1);
- if (leftBorder) {
- bottom.left -= 1;
- }
- if (rightBorder) {
- bottom.right += 1;
- }
- expectColor(bottom, color, tolerance);
- }
- }
-
- void expectQuadrant(const Rect& rect, const Color& topLeft, const Color& topRight,
- const Color& bottomLeft, const Color& bottomRight, bool filtered = false,
- uint8_t tolerance = 0) {
- ASSERT_TRUE((rect.right - rect.left) % 2 == 0 && (rect.bottom - rect.top) % 2 == 0);
-
- const int32_t centerX = rect.left + (rect.right - rect.left) / 2;
- const int32_t centerY = rect.top + (rect.bottom - rect.top) / 2;
- // avoid checking borders due to unspecified filtering behavior
- const int32_t offsetX = filtered ? 2 : 0;
- const int32_t offsetY = filtered ? 2 : 0;
- expectColor(Rect(rect.left, rect.top, centerX - offsetX, centerY - offsetY), topLeft,
- tolerance);
- expectColor(Rect(centerX + offsetX, rect.top, rect.right, centerY - offsetY), topRight,
- tolerance);
- expectColor(Rect(rect.left, centerY + offsetY, centerX - offsetX, rect.bottom), bottomLeft,
- tolerance);
- expectColor(Rect(centerX + offsetX, centerY + offsetY, rect.right, rect.bottom),
- bottomRight, tolerance);
- }
-
- void checkPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b) {
- ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mOutBuffer->getPixelFormat());
- const uint8_t* pixel = mPixels + (4 * (y * mOutBuffer->getStride() + x));
- if (r != pixel[0] || g != pixel[1] || b != pixel[2]) {
- String8 err(String8::format("pixel @ (%3d, %3d): "
- "expected [%3d, %3d, %3d], got [%3d, %3d, %3d]",
- x, y, r, g, b, pixel[0], pixel[1], pixel[2]));
- EXPECT_EQ(String8(), err) << err.string();
- }
- }
-
- void expectFGColor(uint32_t x, uint32_t y) { checkPixel(x, y, 195, 63, 63); }
-
- void expectBGColor(uint32_t x, uint32_t y) { checkPixel(x, y, 63, 63, 195); }
-
- void expectChildColor(uint32_t x, uint32_t y) { checkPixel(x, y, 200, 200, 200); }
-
- explicit ScreenCapture(const sp<GraphicBuffer>& outBuffer) : mOutBuffer(outBuffer) {
- mOutBuffer->lock(GRALLOC_USAGE_SW_READ_OFTEN, reinterpret_cast<void**>(&mPixels));
- }
-
- ~ScreenCapture() { mOutBuffer->unlock(); }
-
-private:
- sp<GraphicBuffer> mOutBuffer;
- uint8_t* mPixels = nullptr;
-};
class LayerTransactionTest : public ::testing::Test {
protected:
@@ -583,7 +300,6 @@
friend class LayerRenderPathTestHarness;
};
-enum class RenderPath { SCREENSHOT, VIRTUAL_DISPLAY };
class LayerRenderPathTestHarness {
public:
@@ -693,13 +409,6 @@
LayerRenderPathTestHarness mRenderPathHarness;
};
-// Environment for starting up binder threads. This is required for testing
-// virtual displays, as BufferQueue parameters may be queried over binder.
-class BinderEnvironment : public ::testing::Environment {
-public:
- void SetUp() override { ProcessState::self()->startThreadPool(); }
-};
-
::testing::Environment* const binderEnv =
::testing::AddGlobalTestEnvironment(new BinderEnvironment());
@@ -1282,19 +991,6 @@
composer->captureScreen(mDisplay, &outBuffer, Rect(), 0, 0, false));
}
-/** RAII Wrapper around get/seteuid */
-class UIDFaker {
- uid_t oldId;
-public:
- UIDFaker(uid_t uid) {
- oldId = geteuid();
- seteuid(uid);
- }
- ~UIDFaker() {
- seteuid(oldId);
- }
-};
-
TEST_F(LayerTransactionTest, SetFlagsSecureEUidSystem) {
sp<SurfaceControl> layer;
ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
@@ -1539,6 +1235,7 @@
Transaction()
.setCornerRadius(layer, cornerRadius)
+ .setCrop_legacy(layer, Rect(0, 0, size, size))
.apply();
{
const uint8_t bottom = size - 1;
@@ -1565,6 +1262,7 @@
Transaction()
.setCornerRadius(parent, cornerRadius)
+ .setCrop_legacy(parent, Rect(0, 0, size, size))
.reparent(child, parent->getHandle())
.setPosition(child, 0, size / 2)
.apply();
@@ -2810,47 +2508,6 @@
}
}
-class ColorTransformHelper {
-public:
- static void DegammaColorSingle(half& s) {
- if (s <= 0.03928f)
- s = s / 12.92f;
- else
- s = pow((s + 0.055f) / 1.055f, 2.4f);
- }
-
- static void DegammaColor(half3& color) {
- DegammaColorSingle(color.r);
- DegammaColorSingle(color.g);
- DegammaColorSingle(color.b);
- }
-
- static void GammaColorSingle(half& s) {
- if (s <= 0.0031308f) {
- s = s * 12.92f;
- } else {
- s = 1.055f * pow(s, (1.0f / 2.4f)) - 0.055f;
- }
- }
-
- static void GammaColor(half3& color) {
- GammaColorSingle(color.r);
- GammaColorSingle(color.g);
- GammaColorSingle(color.b);
- }
-
- static void applyMatrix(half3& color, const mat3& mat) {
- half3 ret = half3(0);
-
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- ret[i] = ret[i] + color[j] * mat[j][i];
- }
- }
- color = ret;
- }
-};
-
TEST_P(LayerRenderTypeTransactionTest, SetColorTransformBasic) {
sp<SurfaceControl> colorLayer;
ASSERT_NO_FATAL_FAILURE(colorLayer =
@@ -3014,173 +2671,6 @@
}
}
-struct CallbackData {
- CallbackData() = default;
- CallbackData(nsecs_t time, const sp<Fence>& fence,
- const std::vector<SurfaceControlStats>& stats)
- : latchTime(time), presentFence(fence), surfaceControlStats(stats) {}
-
- nsecs_t latchTime;
- sp<Fence> presentFence;
- std::vector<SurfaceControlStats> surfaceControlStats;
-};
-
-class ExpectedResult {
-public:
- enum Transaction {
- NOT_PRESENTED = 0,
- PRESENTED,
- };
-
- enum Buffer {
- NOT_ACQUIRED = 0,
- ACQUIRED,
- };
-
- enum PreviousBuffer {
- NOT_RELEASED = 0,
- RELEASED,
- UNKNOWN,
- };
-
- void reset() {
- mTransactionResult = ExpectedResult::Transaction::NOT_PRESENTED;
- mExpectedSurfaceResults.clear();
- }
-
- void addSurface(ExpectedResult::Transaction transactionResult, const sp<SurfaceControl>& layer,
- ExpectedResult::Buffer bufferResult = ACQUIRED,
- ExpectedResult::PreviousBuffer previousBufferResult = NOT_RELEASED) {
- mTransactionResult = transactionResult;
- mExpectedSurfaceResults.emplace(std::piecewise_construct, std::forward_as_tuple(layer),
- std::forward_as_tuple(bufferResult, previousBufferResult));
- }
-
- void addSurfaces(ExpectedResult::Transaction transactionResult,
- const std::vector<sp<SurfaceControl>>& layers,
- ExpectedResult::Buffer bufferResult = ACQUIRED,
- ExpectedResult::PreviousBuffer previousBufferResult = NOT_RELEASED) {
- for (const auto& layer : layers) {
- addSurface(transactionResult, layer, bufferResult, previousBufferResult);
- }
- }
-
- void addExpectedPresentTime(nsecs_t expectedPresentTime) {
- mExpectedPresentTime = expectedPresentTime;
- }
-
- void verifyCallbackData(const CallbackData& callbackData) const {
- const auto& [latchTime, presentFence, surfaceControlStats] = callbackData;
- if (mTransactionResult == ExpectedResult::Transaction::PRESENTED) {
- ASSERT_GE(latchTime, 0) << "bad latch time";
- ASSERT_NE(presentFence, nullptr);
- if (mExpectedPresentTime >= 0) {
- ASSERT_EQ(presentFence->wait(3000), NO_ERROR);
- ASSERT_GE(presentFence->getSignalTime(), mExpectedPresentTime - nsecs_t(5 * 1e6));
- // if the panel is running at 30 hz, at the worst case, our expected time just
- // misses vsync and we have to wait another 33.3ms
- ASSERT_LE(presentFence->getSignalTime(),
- mExpectedPresentTime + nsecs_t(66.666666 * 1e6));
- }
- } else {
- ASSERT_EQ(presentFence, nullptr) << "transaction shouldn't have been presented";
- ASSERT_EQ(latchTime, -1) << "unpresented transactions shouldn't be latched";
- }
-
- ASSERT_EQ(surfaceControlStats.size(), mExpectedSurfaceResults.size())
- << "wrong number of surfaces";
-
- for (const auto& stats : surfaceControlStats) {
- ASSERT_NE(stats.surfaceControl, nullptr) << "returned null surface control";
-
- const auto& expectedSurfaceResult = mExpectedSurfaceResults.find(stats.surfaceControl);
- ASSERT_NE(expectedSurfaceResult, mExpectedSurfaceResults.end())
- << "unexpected surface control";
- expectedSurfaceResult->second.verifySurfaceControlStats(stats, latchTime);
- }
- }
-
-private:
- class ExpectedSurfaceResult {
- public:
- ExpectedSurfaceResult(ExpectedResult::Buffer bufferResult,
- ExpectedResult::PreviousBuffer previousBufferResult)
- : mBufferResult(bufferResult), mPreviousBufferResult(previousBufferResult) {}
-
- void verifySurfaceControlStats(const SurfaceControlStats& surfaceControlStats,
- nsecs_t latchTime) const {
- const auto& [surfaceControl, acquireTime, previousReleaseFence] = surfaceControlStats;
-
- ASSERT_EQ(acquireTime > 0, mBufferResult == ExpectedResult::Buffer::ACQUIRED)
- << "bad acquire time";
- ASSERT_LE(acquireTime, latchTime) << "acquire time should be <= latch time";
-
- if (mPreviousBufferResult == ExpectedResult::PreviousBuffer::RELEASED) {
- ASSERT_NE(previousReleaseFence, nullptr)
- << "failed to set release prev buffer fence";
- } else if (mPreviousBufferResult == ExpectedResult::PreviousBuffer::NOT_RELEASED) {
- ASSERT_EQ(previousReleaseFence, nullptr)
- << "should not have set released prev buffer fence";
- }
- }
-
- private:
- ExpectedResult::Buffer mBufferResult;
- ExpectedResult::PreviousBuffer mPreviousBufferResult;
- };
-
- struct SCHash {
- std::size_t operator()(const sp<SurfaceControl>& sc) const {
- return std::hash<IBinder*>{}(sc->getHandle().get());
- }
- };
- ExpectedResult::Transaction mTransactionResult = ExpectedResult::Transaction::NOT_PRESENTED;
- nsecs_t mExpectedPresentTime = -1;
- std::unordered_map<sp<SurfaceControl>, ExpectedSurfaceResult, SCHash> mExpectedSurfaceResults;
-};
-
-class CallbackHelper {
-public:
- static void function(void* callbackContext, nsecs_t latchTime, const sp<Fence>& presentFence,
- const std::vector<SurfaceControlStats>& stats) {
- if (!callbackContext) {
- ALOGE("failed to get callback context");
- }
- CallbackHelper* helper = static_cast<CallbackHelper*>(callbackContext);
- std::lock_guard lock(helper->mMutex);
- helper->mCallbackDataQueue.emplace(latchTime, presentFence, stats);
- helper->mConditionVariable.notify_all();
- }
-
- void getCallbackData(CallbackData* outData) {
- std::unique_lock lock(mMutex);
-
- if (mCallbackDataQueue.empty()) {
- ASSERT_NE(mConditionVariable.wait_for(lock, std::chrono::seconds(3)),
- std::cv_status::timeout)
- << "did not receive callback";
- }
-
- *outData = std::move(mCallbackDataQueue.front());
- mCallbackDataQueue.pop();
- }
-
- void verifyFinalState() {
- // Wait to see if there are extra callbacks
- std::this_thread::sleep_for(500ms);
-
- std::lock_guard lock(mMutex);
- EXPECT_EQ(mCallbackDataQueue.size(), 0) << "extra callbacks received";
- mCallbackDataQueue = {};
- }
-
- void* getContext() { return static_cast<void*>(this); }
-
- std::mutex mMutex;
- std::condition_variable mConditionVariable;
- std::queue<CallbackData> mCallbackDataQueue;
-};
-
class LayerCallbackTest : public LayerTransactionTest {
public:
virtual sp<SurfaceControl> createBufferStateLayer() {
diff --git a/services/surfaceflinger/tests/fakehwc/Android.bp b/services/surfaceflinger/tests/fakehwc/Android.bp
index f359550..3e29016 100644
--- a/services/surfaceflinger/tests/fakehwc/Android.bp
+++ b/services/surfaceflinger/tests/fakehwc/Android.bp
@@ -13,6 +13,7 @@
"android.hardware.graphics.composer@2.1-resources",
"android.hardware.graphics.mapper@2.0",
"android.hardware.graphics.mapper@3.0",
+ "android.hardware.graphics.mapper@4.0",
"android.hardware.power@1.3",
"libbase",
"libbinder",
@@ -32,8 +33,11 @@
"libutils",
],
static_libs: [
+ "libcompositionengine",
"libgmock",
+ "libperfetto_client_experimental",
"librenderengine",
+ "libtimestats",
"libtrace_proto",
],
header_libs: [
diff --git a/services/surfaceflinger/tests/unittests/Android.bp b/services/surfaceflinger/tests/unittests/Android.bp
index 4917bc2..8d98af6 100644
--- a/services/surfaceflinger/tests/unittests/Android.bp
+++ b/services/surfaceflinger/tests/unittests/Android.bp
@@ -36,7 +36,7 @@
":libsurfaceflinger_sources",
"libsurfaceflinger_unittest_main.cpp",
"CachingTest.cpp",
- "CompositionTest.cpp",
+ "CompositionTest.cpp",
"DispSyncSourceTest.cpp",
"DisplayIdentificationTest.cpp",
"DisplayTransactionTest.cpp",
@@ -51,6 +51,7 @@
"RefreshRateStatsTest.cpp",
"RegionSamplingTest.cpp",
"TimeStatsTest.cpp",
+ "FrameTracerTest.cpp",
"mock/DisplayHardware/MockComposer.cpp",
"mock/DisplayHardware/MockDisplay.cpp",
"mock/DisplayHardware/MockPowerAdvisor.cpp",
@@ -63,13 +64,20 @@
"mock/MockNativeWindowSurface.cpp",
"mock/MockSurfaceInterceptor.cpp",
"mock/MockTimeStats.cpp",
+ "mock/MockFrameTracer.cpp",
"mock/system/window/MockNativeWindow.cpp",
],
static_libs: [
"libgmock",
"libcompositionengine",
"libcompositionengine_mocks",
+ "libperfetto_client_experimental",
"librenderengine_mocks",
+ "libtimestats",
+ "perfetto_trace_protos",
+ ],
+ shared_libs: [
+ "libsurfaceflinger",
],
header_libs: [
"libsurfaceflinger_headers",
diff --git a/services/surfaceflinger/tests/unittests/CompositionTest.cpp b/services/surfaceflinger/tests/unittests/CompositionTest.cpp
index 82dd3c7..9e4d57e 100644
--- a/services/surfaceflinger/tests/unittests/CompositionTest.cpp
+++ b/services/surfaceflinger/tests/unittests/CompositionTest.cpp
@@ -124,7 +124,16 @@
auto sfEventThread = std::make_unique<mock::EventThread>();
EXPECT_CALL(*eventThread, registerDisplayEventConnection(_));
+ EXPECT_CALL(*eventThread, createEventConnection(_, _))
+ .WillOnce(Return(
+ new EventThreadConnection(eventThread.get(), ResyncCallback(),
+ ISurfaceComposer::eConfigChangedSuppress)));
+
EXPECT_CALL(*sfEventThread, registerDisplayEventConnection(_));
+ EXPECT_CALL(*sfEventThread, createEventConnection(_, _))
+ .WillOnce(Return(
+ new EventThreadConnection(sfEventThread.get(), ResyncCallback(),
+ ISurfaceComposer::eConfigChangedSuppress)));
auto primaryDispSync = std::make_unique<mock::DispSync>();
@@ -605,6 +614,12 @@
displaySettings.clip);
// screen capture adds an additional color layer as an alpha
// prefill, so gtet the back layer.
+ if (layerSettings.empty()) {
+ ADD_FAILURE() << "layerSettings was not expected to be empty in "
+ "setupREBufferCompositionCommonCallExpectations "
+ "verification lambda";
+ return NO_ERROR;
+ }
renderengine::LayerSettings layer = layerSettings.back();
EXPECT_THAT(layer.source.buffer.buffer, Not(IsNull()));
EXPECT_THAT(layer.source.buffer.fence, Not(IsNull()));
@@ -648,6 +663,12 @@
displaySettings.clip);
// screen capture adds an additional color layer as an alpha
// prefill, so get the back layer.
+ if (layerSettings.empty()) {
+ ADD_FAILURE()
+ << "layerSettings was not expected to be empty in "
+ "setupREColorCompositionCallExpectations verification lambda";
+ return NO_ERROR;
+ }
renderengine::LayerSettings layer = layerSettings.back();
EXPECT_THAT(layer.source.buffer.buffer, IsNull());
EXPECT_EQ(half3(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
@@ -718,6 +739,12 @@
displaySettings.clip);
// screen capture adds an additional color layer as an alpha
// prefill, so get the back layer.
+ if (layerSettings.empty()) {
+ ADD_FAILURE() << "layerSettings was not expected to be empty in "
+ "setupInsecureREBufferCompositionCommonCallExpectations "
+ "verification lambda";
+ return NO_ERROR;
+ }
renderengine::LayerSettings layer = layerSettings.back();
EXPECT_THAT(layer.source.buffer.buffer, IsNull());
EXPECT_EQ(half3(0.0f, 0.0f, 0.0f), layer.source.solidColor);
@@ -777,7 +804,6 @@
layerDrawingState.color = half4(LayerProperties::COLOR[0], LayerProperties::COLOR[1],
LayerProperties::COLOR[2], LayerProperties::COLOR[3]);
layer->computeBounds(FloatRect(0, 0, 100, 100), ui::Transform());
- layer->setVisibleRegion(Region(Rect(0, 0, 100, 100)));
return layer;
}
@@ -792,13 +818,13 @@
layer->getCompositionLayer(),
layer));
+ outputLayers.back()->editState().visibleRegion = Region(Rect(0, 0, 100, 100));
+ outputLayers.back()->editState().outputSpaceVisibleRegion = Region(Rect(0, 0, 100, 100));
+
test->mDisplay->getCompositionDisplay()->setOutputLayersOrderedByZ(std::move(outputLayers));
Mock::VerifyAndClear(test->mComposer);
- Vector<sp<Layer>> layers;
- layers.add(layer);
- test->mDisplay->setVisibleLayersSortedByZ(layers);
test->mFlinger.mutableDrawingState().layersSortedByZ.add(layer);
}
@@ -1087,8 +1113,6 @@
for (auto& hwcDisplay : test->mFlinger.mFakeHwcDisplays) {
hwcDisplay->mutableLayers().clear();
}
-
- test->mDisplay->setVisibleLayersSortedByZ(Vector<sp<android::Layer>>());
}
};
diff --git a/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp b/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp
index 8f6f3ec..fcce57b 100644
--- a/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp
+++ b/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp
@@ -149,7 +149,7 @@
// Default to no wide color display support configured
mFlinger.mutableHasWideColorDisplay() = false;
mFlinger.mutableUseColorManagement() = false;
- mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
+ mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::kUnmanaged;
// Default to using HWC virtual displays
mFlinger.mutableUseHwcVirtualDisplays() = true;
@@ -179,7 +179,14 @@
void DisplayTransactionTest::injectMockScheduler() {
EXPECT_CALL(*mEventThread, registerDisplayEventConnection(_));
+ EXPECT_CALL(*mEventThread, createEventConnection(_, _))
+ .WillOnce(Return(new EventThreadConnection(mEventThread, ResyncCallback(),
+ ISurfaceComposer::eConfigChangedSuppress)));
+
EXPECT_CALL(*mSFEventThread, registerDisplayEventConnection(_));
+ EXPECT_CALL(*mSFEventThread, createEventConnection(_, _))
+ .WillOnce(Return(new EventThreadConnection(mSFEventThread, ResyncCallback(),
+ ISurfaceComposer::eConfigChangedSuppress)));
mFlinger.setupScheduler(std::unique_ptr<DispSync>(mPrimaryDispSync),
std::unique_ptr<EventControlThread>(mEventControlThread),
@@ -591,7 +598,7 @@
static void injectConfigChange(DisplayTransactionTest* test) {
test->mFlinger.mutableHasWideColorDisplay() = false;
test->mFlinger.mutableUseColorManagement() = false;
- test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
+ test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::kUnmanaged;
}
static void setupComposerCallExpectations(DisplayTransactionTest* test) {
@@ -611,7 +618,7 @@
static void injectConfigChange(DisplayTransactionTest* test) {
test->mFlinger.mutableUseColorManagement() = true;
test->mFlinger.mutableHasWideColorDisplay() = true;
- test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::UNMANAGED;
+ test->mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::kUnmanaged;
}
static void setupComposerCallExpectations(DisplayTransactionTest* test) {
diff --git a/services/surfaceflinger/tests/unittests/FrameTracerTest.cpp b/services/surfaceflinger/tests/unittests/FrameTracerTest.cpp
new file mode 100644
index 0000000..b5af591
--- /dev/null
+++ b/services/surfaceflinger/tests/unittests/FrameTracerTest.cpp
@@ -0,0 +1,396 @@
+/*
+ * Copyright 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.
+ */
+
+#undef LOG_TAG
+#define LOG_TAG "LibSurfaceFlingerUnittests"
+
+#include <FrameTracer/FrameTracer.h>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <log/log.h>
+#include <perfetto/trace/trace.pb.h>
+
+#include "libsurfaceflinger_unittest_main.h"
+
+using namespace google::protobuf;
+
+namespace android {
+namespace {
+
+class FrameTracerTest : public testing::Test {
+public:
+ FrameTracerTest() {
+ const ::testing::TestInfo* const test_info =
+ ::testing::UnitTest::GetInstance()->current_test_info();
+ ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
+
+ // Need to initialize tracing in process for testing, and only once per test suite.
+ static bool wasInitialized = false;
+ if (!wasInitialized) {
+ perfetto::TracingInitArgs args;
+ args.backends = perfetto::kInProcessBackend;
+ perfetto::Tracing::Initialize(args);
+ wasInitialized = true;
+ }
+ }
+
+ ~FrameTracerTest() {
+ const ::testing::TestInfo* const test_info =
+ ::testing::UnitTest::GetInstance()->current_test_info();
+ ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
+ }
+
+ void SetUp() override {
+ mFrameTracer = std::make_unique<FrameTracer>();
+ mFrameTracer->registerDataSource();
+ }
+
+ void TearDown() override { mFrameTracer.reset(); }
+
+ // Each tracing session can be used for a single block of Start -> Stop.
+ static std::unique_ptr<perfetto::TracingSession> getTracingSessionForTest() {
+ perfetto::TraceConfig cfg;
+ cfg.set_duration_ms(500);
+ cfg.add_buffers()->set_size_kb(1024);
+ auto* ds_cfg = cfg.add_data_sources()->mutable_config();
+ ds_cfg->set_name(FrameTracer::kFrameTracerDataSource);
+
+ auto tracingSession = perfetto::Tracing::NewTrace(perfetto::kInProcessBackend);
+ tracingSession->Setup(cfg);
+ return tracingSession;
+ }
+
+ std::unique_ptr<FrameTracer> mFrameTracer;
+ FenceToFenceTimeMap fenceFactory;
+};
+
+TEST_F(FrameTracerTest, traceNewLayerStartsTrackingLayerWhenTracing) {
+ EXPECT_EQ(mFrameTracer->miniDump(),
+ "FrameTracer miniDump:\nNumber of layers currently being traced is 0\n");
+
+ const std::string layerName = "co.layername#0";
+ const int32_t layerID = 5;
+ mFrameTracer->traceNewLayer(layerID, layerName);
+
+ EXPECT_EQ(mFrameTracer->miniDump(),
+ "FrameTracer miniDump:\nNumber of layers currently being traced is 0\n");
+
+ auto tracingSession = getTracingSessionForTest();
+ tracingSession->StartBlocking();
+ EXPECT_EQ(mFrameTracer->miniDump(),
+ "FrameTracer miniDump:\nNumber of layers currently being traced is 0\n");
+ mFrameTracer->traceNewLayer(layerID, layerName);
+ EXPECT_EQ(mFrameTracer->miniDump(),
+ "FrameTracer miniDump:\nNumber of layers currently being traced is 1\n");
+ tracingSession->StopBlocking();
+}
+
+TEST_F(FrameTracerTest, onDestroyRemovesTheTrackedLayer) {
+ EXPECT_EQ(mFrameTracer->miniDump(),
+ "FrameTracer miniDump:\nNumber of layers currently being traced is 0\n");
+
+ const std::string layerName = "co.layername#0";
+ const int32_t layerID = 5;
+ const int32_t secondLayerID = 6;
+
+ auto tracingSession = getTracingSessionForTest();
+ tracingSession->StartBlocking();
+ mFrameTracer->traceNewLayer(layerID, layerName);
+ mFrameTracer->traceNewLayer(secondLayerID, layerName);
+ EXPECT_EQ(mFrameTracer->miniDump(),
+ "FrameTracer miniDump:\nNumber of layers currently being traced is 2\n");
+ tracingSession->StopBlocking();
+
+ mFrameTracer->onDestroy(layerID);
+ EXPECT_EQ(mFrameTracer->miniDump(),
+ "FrameTracer miniDump:\nNumber of layers currently being traced is 1\n");
+ mFrameTracer->onDestroy(layerID);
+ EXPECT_EQ(mFrameTracer->miniDump(),
+ "FrameTracer miniDump:\nNumber of layers currently being traced is 1\n");
+ mFrameTracer->onDestroy(secondLayerID);
+ EXPECT_EQ(mFrameTracer->miniDump(),
+ "FrameTracer miniDump:\nNumber of layers currently being traced is 0\n");
+}
+
+TEST_F(FrameTracerTest, canTraceAfterAddingLayer) {
+ const std::string layerName = "co.layername#0";
+ const int32_t layerID = 1;
+ const uint32_t bufferID = 2;
+ const uint64_t frameNumber = 3;
+ const nsecs_t timestamp = 4;
+ const nsecs_t duration = 5;
+ const auto type = FrameTracer::FrameEvent::POST;
+
+ {
+ auto tracingSession = getTracingSessionForTest();
+
+ tracingSession->StartBlocking();
+ // Clean up irrelevant traces.
+ tracingSession->ReadTraceBlocking();
+
+ mFrameTracer->traceTimestamp(layerID, bufferID, frameNumber, timestamp, type, duration);
+ // Create second trace packet to finalize the previous one.
+ mFrameTracer->traceTimestamp(layerID, 0, 0, 0, FrameTracer::FrameEvent::UNSPECIFIED);
+ tracingSession->StopBlocking();
+
+ std::vector<char> raw_trace = tracingSession->ReadTraceBlocking();
+ EXPECT_EQ(raw_trace.size(), 0);
+ }
+
+ {
+ auto tracingSession = getTracingSessionForTest();
+
+ tracingSession->StartBlocking();
+ // Clean up irrelevant traces.
+ tracingSession->ReadTraceBlocking();
+
+ mFrameTracer->traceNewLayer(layerID, layerName);
+ mFrameTracer->traceTimestamp(layerID, bufferID, frameNumber, timestamp, type, duration);
+ // Create second trace packet to finalize the previous one.
+ mFrameTracer->traceTimestamp(layerID, 0, 0, 0, FrameTracer::FrameEvent::UNSPECIFIED);
+ tracingSession->StopBlocking();
+
+ std::vector<char> raw_trace = tracingSession->ReadTraceBlocking();
+ ASSERT_GT(raw_trace.size(), 0);
+
+ perfetto::protos::Trace trace;
+ ASSERT_TRUE(trace.ParseFromArray(raw_trace.data(), int(raw_trace.size())));
+ ASSERT_FALSE(trace.packet().empty());
+ EXPECT_EQ(trace.packet().size(), 1);
+
+ const auto& packet = trace.packet().Get(0);
+ ASSERT_TRUE(packet.has_timestamp());
+ EXPECT_EQ(packet.timestamp(), timestamp);
+ ASSERT_TRUE(packet.has_graphics_frame_event());
+ const auto& frame_event = packet.graphics_frame_event();
+ ASSERT_TRUE(frame_event.has_buffer_event());
+ const auto& buffer_event = frame_event.buffer_event();
+ ASSERT_TRUE(buffer_event.has_buffer_id());
+ EXPECT_EQ(buffer_event.buffer_id(), bufferID);
+ ASSERT_TRUE(buffer_event.has_frame_number());
+ EXPECT_EQ(buffer_event.frame_number(), frameNumber);
+ ASSERT_TRUE(buffer_event.has_type());
+ EXPECT_EQ(buffer_event.type(), perfetto::protos::GraphicsFrameEvent_BufferEventType(type));
+ ASSERT_TRUE(buffer_event.has_duration_ns());
+ EXPECT_EQ(buffer_event.duration_ns(), duration);
+ }
+}
+
+TEST_F(FrameTracerTest, traceFenceTriggersOnNextTraceAfterFenceFired) {
+ const std::string layerName = "co.layername#0";
+ const int32_t layerID = 5;
+ const uint32_t bufferID = 4;
+ const uint64_t frameNumber = 3;
+ const auto type = FrameTracer::FrameEvent::ACQUIRE_FENCE;
+
+ {
+ auto fenceTime = fenceFactory.createFenceTimeForTest(Fence::NO_FENCE);
+ fenceFactory.signalAllForTest(Fence::NO_FENCE, Fence::SIGNAL_TIME_PENDING);
+ auto tracingSession = getTracingSessionForTest();
+ tracingSession->StartBlocking();
+ // Clean up irrelevant traces.
+ tracingSession->ReadTraceBlocking();
+ // Trace.
+ mFrameTracer->traceNewLayer(layerID, layerName);
+ mFrameTracer->traceFence(layerID, bufferID, frameNumber, fenceTime, type);
+ // Create extra trace packet to (hopefully not) trigger and finalize the fence packet.
+ mFrameTracer->traceTimestamp(layerID, bufferID, 0, 0, FrameTracer::FrameEvent::UNSPECIFIED);
+ tracingSession->StopBlocking();
+ std::vector<char> raw_trace = tracingSession->ReadTraceBlocking();
+ EXPECT_EQ(raw_trace.size(), 0);
+ }
+
+ {
+ auto fenceTime = fenceFactory.createFenceTimeForTest(Fence::NO_FENCE);
+ auto tracingSession = getTracingSessionForTest();
+ tracingSession->StartBlocking();
+ // Clean up irrelevant traces.
+ tracingSession->ReadTraceBlocking();
+ mFrameTracer->traceNewLayer(layerID, layerName);
+ mFrameTracer->traceFence(layerID, bufferID, frameNumber, fenceTime, type);
+ const nsecs_t timestamp = systemTime();
+ fenceFactory.signalAllForTest(Fence::NO_FENCE, timestamp);
+ // Create extra trace packet to trigger and finalize fence trace packets.
+ mFrameTracer->traceTimestamp(layerID, bufferID, 0, 0, FrameTracer::FrameEvent::UNSPECIFIED);
+ tracingSession->StopBlocking();
+
+ std::vector<char> raw_trace = tracingSession->ReadTraceBlocking();
+ ASSERT_GT(raw_trace.size(), 0);
+
+ perfetto::protos::Trace trace;
+ ASSERT_TRUE(trace.ParseFromArray(raw_trace.data(), int(raw_trace.size())));
+ ASSERT_FALSE(trace.packet().empty());
+ EXPECT_EQ(trace.packet().size(), 2); // Two packets because of the extra trace made above.
+
+ const auto& packet = trace.packet().Get(1);
+ ASSERT_TRUE(packet.has_timestamp());
+ EXPECT_EQ(packet.timestamp(), timestamp);
+ ASSERT_TRUE(packet.has_graphics_frame_event());
+ const auto& frame_event = packet.graphics_frame_event();
+ ASSERT_TRUE(frame_event.has_buffer_event());
+ const auto& buffer_event = frame_event.buffer_event();
+ ASSERT_TRUE(buffer_event.has_buffer_id());
+ EXPECT_EQ(buffer_event.buffer_id(), bufferID);
+ ASSERT_TRUE(buffer_event.has_frame_number());
+ EXPECT_EQ(buffer_event.frame_number(), frameNumber);
+ ASSERT_TRUE(buffer_event.has_type());
+ EXPECT_EQ(buffer_event.type(), perfetto::protos::GraphicsFrameEvent_BufferEventType(type));
+ EXPECT_FALSE(buffer_event.has_duration_ns());
+ }
+}
+
+TEST_F(FrameTracerTest, traceFenceWithStartTimeAfterSignalTime_ShouldHaveNoDuration) {
+ const std::string layerName = "co.layername#0";
+ const int32_t layerID = 5;
+ const uint32_t bufferID = 4;
+ const uint64_t frameNumber = 3;
+ const auto type = FrameTracer::FrameEvent::ACQUIRE_FENCE;
+
+ auto tracingSession = getTracingSessionForTest();
+
+ tracingSession->StartBlocking();
+ // Clean up irrelevant traces.
+ tracingSession->ReadTraceBlocking();
+ mFrameTracer->traceNewLayer(layerID, layerName);
+
+ // traceFence called after fence signalled.
+ const nsecs_t signalTime1 = systemTime();
+ const nsecs_t startTime1 = signalTime1 + 100000;
+ auto fence1 = fenceFactory.createFenceTimeForTest(Fence::NO_FENCE);
+ fenceFactory.signalAllForTest(Fence::NO_FENCE, signalTime1);
+ mFrameTracer->traceFence(layerID, bufferID, frameNumber, fence1, type, startTime1);
+
+ // traceFence called before fence signalled.
+ const nsecs_t signalTime2 = systemTime();
+ const nsecs_t startTime2 = signalTime2 + 100000;
+ auto fence2 = fenceFactory.createFenceTimeForTest(Fence::NO_FENCE);
+ mFrameTracer->traceFence(layerID, bufferID, frameNumber, fence2, type, startTime2);
+ fenceFactory.signalAllForTest(Fence::NO_FENCE, signalTime2);
+
+ // Create extra trace packet to trigger and finalize fence trace packets.
+ mFrameTracer->traceTimestamp(layerID, bufferID, 0, 0, FrameTracer::FrameEvent::UNSPECIFIED);
+ tracingSession->StopBlocking();
+
+ std::vector<char> raw_trace = tracingSession->ReadTraceBlocking();
+ ASSERT_GT(raw_trace.size(), 0);
+
+ perfetto::protos::Trace trace;
+ ASSERT_TRUE(trace.ParseFromArray(raw_trace.data(), int(raw_trace.size())));
+ ASSERT_FALSE(trace.packet().empty());
+ EXPECT_EQ(trace.packet().size(), 2);
+
+ const auto& packet1 = trace.packet().Get(0);
+ ASSERT_TRUE(packet1.has_timestamp());
+ EXPECT_EQ(packet1.timestamp(), signalTime1);
+ ASSERT_TRUE(packet1.has_graphics_frame_event());
+ ASSERT_TRUE(packet1.graphics_frame_event().has_buffer_event());
+ ASSERT_FALSE(packet1.graphics_frame_event().buffer_event().has_duration_ns());
+
+ const auto& packet2 = trace.packet().Get(1);
+ ASSERT_TRUE(packet2.has_timestamp());
+ EXPECT_EQ(packet2.timestamp(), signalTime2);
+ ASSERT_TRUE(packet2.has_graphics_frame_event());
+ ASSERT_TRUE(packet2.graphics_frame_event().has_buffer_event());
+ ASSERT_FALSE(packet2.graphics_frame_event().buffer_event().has_duration_ns());
+}
+
+TEST_F(FrameTracerTest, traceFenceOlderThanDeadline_ShouldBeIgnored) {
+ const std::string layerName = "co.layername#0";
+ const int32_t layerID = 5;
+ const uint32_t bufferID = 4;
+ const uint64_t frameNumber = 3;
+ const auto type = FrameTracer::FrameEvent::ACQUIRE_FENCE;
+ const nsecs_t signalTime = systemTime() - FrameTracer::kFenceSignallingDeadline;
+
+ auto tracingSession = getTracingSessionForTest();
+ auto fence = fenceFactory.createFenceTimeForTest(Fence::NO_FENCE);
+
+ tracingSession->StartBlocking();
+ // Clean up irrelevant traces.
+ tracingSession->ReadTraceBlocking();
+ mFrameTracer->traceNewLayer(layerID, layerName);
+ mFrameTracer->traceFence(layerID, bufferID, frameNumber, fence, type);
+ fenceFactory.signalAllForTest(Fence::NO_FENCE, signalTime);
+ // Create extra trace packet to trigger and finalize any previous fence packets.
+ mFrameTracer->traceTimestamp(layerID, bufferID, 0, 0, FrameTracer::FrameEvent::UNSPECIFIED);
+ tracingSession->StopBlocking();
+
+ std::vector<char> raw_trace = tracingSession->ReadTraceBlocking();
+ EXPECT_EQ(raw_trace.size(), 0);
+}
+
+TEST_F(FrameTracerTest, traceFenceWithValidStartTime_ShouldHaveCorrectDuration) {
+ const std::string layerName = "co.layername#0";
+ const int32_t layerID = 5;
+ const uint32_t bufferID = 4;
+ const uint64_t frameNumber = 3;
+ const auto type = FrameTracer::FrameEvent::ACQUIRE_FENCE;
+ const nsecs_t duration = 1234;
+
+ auto tracingSession = getTracingSessionForTest();
+
+ tracingSession->StartBlocking();
+ // Clean up irrelevant traces.
+ tracingSession->ReadTraceBlocking();
+ mFrameTracer->traceNewLayer(layerID, layerName);
+
+ // traceFence called after fence signalled.
+ const nsecs_t signalTime1 = systemTime();
+ const nsecs_t startTime1 = signalTime1 - duration;
+ auto fence1 = fenceFactory.createFenceTimeForTest(Fence::NO_FENCE);
+ fenceFactory.signalAllForTest(Fence::NO_FENCE, signalTime1);
+ mFrameTracer->traceFence(layerID, bufferID, frameNumber, fence1, type, startTime1);
+
+ // traceFence called before fence signalled.
+ const nsecs_t signalTime2 = systemTime();
+ const nsecs_t startTime2 = signalTime2 - duration;
+ auto fence2 = fenceFactory.createFenceTimeForTest(Fence::NO_FENCE);
+ mFrameTracer->traceFence(layerID, bufferID, frameNumber, fence2, type, startTime2);
+ fenceFactory.signalAllForTest(Fence::NO_FENCE, signalTime2);
+
+ // Create extra trace packet to trigger and finalize fence trace packets.
+ mFrameTracer->traceTimestamp(layerID, bufferID, 0, 0, FrameTracer::FrameEvent::UNSPECIFIED);
+ tracingSession->StopBlocking();
+
+ std::vector<char> raw_trace = tracingSession->ReadTraceBlocking();
+ ASSERT_GT(raw_trace.size(), 0);
+
+ perfetto::protos::Trace trace;
+ ASSERT_TRUE(trace.ParseFromArray(raw_trace.data(), int(raw_trace.size())));
+ ASSERT_FALSE(trace.packet().empty());
+ EXPECT_EQ(trace.packet().size(), 2);
+
+ const auto& packet1 = trace.packet().Get(0);
+ ASSERT_TRUE(packet1.has_timestamp());
+ EXPECT_EQ(packet1.timestamp(), startTime1);
+ ASSERT_TRUE(packet1.has_graphics_frame_event());
+ ASSERT_TRUE(packet1.graphics_frame_event().has_buffer_event());
+ ASSERT_TRUE(packet1.graphics_frame_event().buffer_event().has_duration_ns());
+ const auto& buffer_event1 = packet1.graphics_frame_event().buffer_event();
+ EXPECT_EQ(buffer_event1.duration_ns(), duration);
+
+ const auto& packet2 = trace.packet().Get(1);
+ ASSERT_TRUE(packet2.has_timestamp());
+ EXPECT_EQ(packet2.timestamp(), startTime2);
+ ASSERT_TRUE(packet2.has_graphics_frame_event());
+ ASSERT_TRUE(packet2.graphics_frame_event().has_buffer_event());
+ ASSERT_TRUE(packet2.graphics_frame_event().buffer_event().has_duration_ns());
+ const auto& buffer_event2 = packet2.graphics_frame_event().buffer_event();
+ EXPECT_EQ(buffer_event2.duration_ns(), duration);
+}
+
+} // namespace
+} // namespace android
diff --git a/services/surfaceflinger/tests/unittests/SchedulerTest.cpp b/services/surfaceflinger/tests/unittests/SchedulerTest.cpp
index 740115e..ebcb9d8 100644
--- a/services/surfaceflinger/tests/unittests/SchedulerTest.cpp
+++ b/services/surfaceflinger/tests/unittests/SchedulerTest.cpp
@@ -3,14 +3,13 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
-
#include <log/log.h>
#include <mutex>
#include "Scheduler/EventControlThread.h"
#include "Scheduler/EventThread.h"
-#include "Scheduler/Scheduler.h"
+#include "TestableScheduler.h"
#include "mock/MockEventThread.h"
using testing::_;
@@ -34,37 +33,14 @@
MOCK_METHOD0(requestNextVsync, void());
};
- scheduler::RefreshRateConfigs mRefreshRateConfigs;
-
- /**
- * This mock Scheduler class uses implementation of mock::EventThread but keeps everything else
- * the same.
- */
- class MockScheduler : public android::Scheduler {
- public:
- MockScheduler(const scheduler::RefreshRateConfigs& refreshRateConfigs,
- std::unique_ptr<EventThread> eventThread)
- : Scheduler([](bool) {}, refreshRateConfigs), mEventThread(std::move(eventThread)) {}
-
- std::unique_ptr<EventThread> makeEventThread(
- const char* /* connectionName */, DispSync* /* dispSync */,
- nsecs_t /* phaseOffsetNs */, nsecs_t /* offsetThresholdForNextVsync */,
- impl::EventThread::InterceptVSyncsCallback /* interceptCallback */) override {
- return std::move(mEventThread);
- }
-
- MockScheduler() = default;
- ~MockScheduler() override = default;
-
- std::unique_ptr<EventThread> mEventThread;
- };
-
SchedulerTest();
~SchedulerTest() override;
- sp<Scheduler::ConnectionHandle> mConnectionHandle;
+ scheduler::RefreshRateConfigs mRefreshRateConfigs;
+ TestableScheduler mScheduler{mRefreshRateConfigs};
+
+ Scheduler::ConnectionHandle mConnectionHandle;
mock::EventThread* mEventThread;
- std::unique_ptr<MockScheduler> mScheduler;
sp<MockEventThreadConnection> mEventThreadConnection;
};
@@ -73,9 +49,8 @@
::testing::UnitTest::GetInstance()->current_test_info();
ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
- std::unique_ptr<mock::EventThread> eventThread = std::make_unique<mock::EventThread>();
+ auto eventThread = std::make_unique<mock::EventThread>();
mEventThread = eventThread.get();
- mScheduler = std::make_unique<MockScheduler>(mRefreshRateConfigs, std::move(eventThread));
EXPECT_CALL(*mEventThread, registerDisplayEventConnection(_)).WillOnce(Return(0));
mEventThreadConnection = new MockEventThreadConnection(mEventThread);
@@ -85,9 +60,8 @@
EXPECT_CALL(*mEventThread, createEventConnection(_, _))
.WillRepeatedly(Return(mEventThreadConnection));
- mConnectionHandle = mScheduler->createConnection("appConnection", 16, 16, ResyncCallback(),
- impl::EventThread::InterceptVSyncsCallback());
- EXPECT_TRUE(mConnectionHandle != nullptr);
+ mConnectionHandle = mScheduler.createConnection(std::move(eventThread));
+ EXPECT_TRUE(mConnectionHandle);
}
SchedulerTest::~SchedulerTest() {
@@ -101,92 +75,67 @@
* Test cases
*/
-TEST_F(SchedulerTest, testNullPtr) {
- // Passing a null pointer for ConnectionHandle is a valid argument. The code doesn't throw any
- // exceptions, just gracefully continues.
- sp<IDisplayEventConnection> returnedValue;
- ASSERT_NO_FATAL_FAILURE(
- returnedValue =
- mScheduler->createDisplayEventConnection(nullptr, ResyncCallback(),
- ISurfaceComposer::
- eConfigChangedSuppress));
- EXPECT_TRUE(returnedValue == nullptr);
- EXPECT_TRUE(mScheduler->getEventThread(nullptr) == nullptr);
- EXPECT_TRUE(mScheduler->getEventConnection(nullptr) == nullptr);
- ASSERT_NO_FATAL_FAILURE(mScheduler->hotplugReceived(nullptr, PHYSICAL_DISPLAY_ID, false));
- ASSERT_NO_FATAL_FAILURE(mScheduler->onScreenAcquired(nullptr));
- ASSERT_NO_FATAL_FAILURE(mScheduler->onScreenReleased(nullptr));
- std::string testString;
- ASSERT_NO_FATAL_FAILURE(mScheduler->dump(nullptr, testString));
- EXPECT_TRUE(testString == "");
- ASSERT_NO_FATAL_FAILURE(mScheduler->setPhaseOffset(nullptr, 10));
-}
-
TEST_F(SchedulerTest, invalidConnectionHandle) {
- // Passing an invalid ConnectionHandle is a valid argument. The code doesn't throw any
- // exceptions, just gracefully continues.
- sp<Scheduler::ConnectionHandle> connectionHandle = new Scheduler::ConnectionHandle(20);
+ Scheduler::ConnectionHandle handle;
- sp<IDisplayEventConnection> returnedValue;
+ sp<IDisplayEventConnection> connection;
ASSERT_NO_FATAL_FAILURE(
- returnedValue =
- mScheduler->createDisplayEventConnection(connectionHandle, ResyncCallback(),
- ISurfaceComposer::
- eConfigChangedSuppress));
- EXPECT_TRUE(returnedValue == nullptr);
- EXPECT_TRUE(mScheduler->getEventThread(connectionHandle) == nullptr);
- EXPECT_TRUE(mScheduler->getEventConnection(connectionHandle) == nullptr);
+ connection = mScheduler.createDisplayEventConnection(handle, ResyncCallback(),
+ ISurfaceComposer::
+ eConfigChangedSuppress));
+ EXPECT_FALSE(connection);
+ EXPECT_FALSE(mScheduler.getEventThread(handle));
+ EXPECT_FALSE(mScheduler.getEventConnection(handle));
// The EXPECT_CALLS make sure we don't call the functions on the subsequent event threads.
EXPECT_CALL(*mEventThread, onHotplugReceived(_, _)).Times(0);
- ASSERT_NO_FATAL_FAILURE(
- mScheduler->hotplugReceived(connectionHandle, PHYSICAL_DISPLAY_ID, false));
+ ASSERT_NO_FATAL_FAILURE(mScheduler.onHotplugReceived(handle, PHYSICAL_DISPLAY_ID, false));
EXPECT_CALL(*mEventThread, onScreenAcquired()).Times(0);
- ASSERT_NO_FATAL_FAILURE(mScheduler->onScreenAcquired(connectionHandle));
+ ASSERT_NO_FATAL_FAILURE(mScheduler.onScreenAcquired(handle));
EXPECT_CALL(*mEventThread, onScreenReleased()).Times(0);
- ASSERT_NO_FATAL_FAILURE(mScheduler->onScreenReleased(connectionHandle));
+ ASSERT_NO_FATAL_FAILURE(mScheduler.onScreenReleased(handle));
- std::string testString;
+ std::string output;
EXPECT_CALL(*mEventThread, dump(_)).Times(0);
- ASSERT_NO_FATAL_FAILURE(mScheduler->dump(connectionHandle, testString));
- EXPECT_TRUE(testString == "");
+ ASSERT_NO_FATAL_FAILURE(mScheduler.dump(handle, output));
+ EXPECT_TRUE(output.empty());
EXPECT_CALL(*mEventThread, setPhaseOffset(_)).Times(0);
- ASSERT_NO_FATAL_FAILURE(mScheduler->setPhaseOffset(connectionHandle, 10));
+ ASSERT_NO_FATAL_FAILURE(mScheduler.setPhaseOffset(handle, 10));
}
TEST_F(SchedulerTest, validConnectionHandle) {
- sp<IDisplayEventConnection> returnedValue;
+ sp<IDisplayEventConnection> connection;
ASSERT_NO_FATAL_FAILURE(
- returnedValue =
- mScheduler->createDisplayEventConnection(mConnectionHandle, ResyncCallback(),
- ISurfaceComposer::
- eConfigChangedSuppress));
- EXPECT_TRUE(returnedValue != nullptr);
- ASSERT_EQ(returnedValue, mEventThreadConnection);
+ connection =
+ mScheduler.createDisplayEventConnection(mConnectionHandle, ResyncCallback(),
+ ISurfaceComposer::
+ eConfigChangedSuppress));
+ ASSERT_EQ(mEventThreadConnection, connection);
- EXPECT_TRUE(mScheduler->getEventThread(mConnectionHandle) != nullptr);
- EXPECT_TRUE(mScheduler->getEventConnection(mConnectionHandle) != nullptr);
+ EXPECT_TRUE(mScheduler.getEventThread(mConnectionHandle));
+ EXPECT_TRUE(mScheduler.getEventConnection(mConnectionHandle));
EXPECT_CALL(*mEventThread, onHotplugReceived(PHYSICAL_DISPLAY_ID, false)).Times(1);
ASSERT_NO_FATAL_FAILURE(
- mScheduler->hotplugReceived(mConnectionHandle, PHYSICAL_DISPLAY_ID, false));
+ mScheduler.onHotplugReceived(mConnectionHandle, PHYSICAL_DISPLAY_ID, false));
EXPECT_CALL(*mEventThread, onScreenAcquired()).Times(1);
- ASSERT_NO_FATAL_FAILURE(mScheduler->onScreenAcquired(mConnectionHandle));
+ ASSERT_NO_FATAL_FAILURE(mScheduler.onScreenAcquired(mConnectionHandle));
EXPECT_CALL(*mEventThread, onScreenReleased()).Times(1);
- ASSERT_NO_FATAL_FAILURE(mScheduler->onScreenReleased(mConnectionHandle));
+ ASSERT_NO_FATAL_FAILURE(mScheduler.onScreenReleased(mConnectionHandle));
- std::string testString("dump");
- EXPECT_CALL(*mEventThread, dump(testString)).Times(1);
- ASSERT_NO_FATAL_FAILURE(mScheduler->dump(mConnectionHandle, testString));
- EXPECT_TRUE(testString != "");
+ std::string output("dump");
+ EXPECT_CALL(*mEventThread, dump(output)).Times(1);
+ ASSERT_NO_FATAL_FAILURE(mScheduler.dump(mConnectionHandle, output));
+ EXPECT_FALSE(output.empty());
EXPECT_CALL(*mEventThread, setPhaseOffset(10)).Times(1);
- ASSERT_NO_FATAL_FAILURE(mScheduler->setPhaseOffset(mConnectionHandle, 10));
+ ASSERT_NO_FATAL_FAILURE(mScheduler.setPhaseOffset(mConnectionHandle, 10));
}
+
} // namespace
} // namespace android
diff --git a/services/surfaceflinger/tests/unittests/TestableScheduler.h b/services/surfaceflinger/tests/unittests/TestableScheduler.h
index 5157cc4..780b608 100644
--- a/services/surfaceflinger/tests/unittests/TestableScheduler.h
+++ b/services/surfaceflinger/tests/unittests/TestableScheduler.h
@@ -19,6 +19,7 @@
#include <gmock/gmock.h>
#include <gui/ISurfaceComposer.h>
+#include "Scheduler/DispSync.h"
#include "Scheduler/EventThread.h"
#include "Scheduler/Scheduler.h"
@@ -26,24 +27,17 @@
class TestableScheduler : public Scheduler {
public:
+ explicit TestableScheduler(const scheduler::RefreshRateConfigs& configs)
+ : Scheduler([](bool) {}, configs) {}
+
TestableScheduler(std::unique_ptr<DispSync> primaryDispSync,
std::unique_ptr<EventControlThread> eventControlThread,
const scheduler::RefreshRateConfigs& configs)
: Scheduler(std::move(primaryDispSync), std::move(eventControlThread), configs) {}
- // Creates EventThreadConnection with the given eventThread. Creates Scheduler::Connection
- // and adds it to the list of connectins. Returns the ConnectionHandle for the
- // Scheduler::Connection. This allows plugging in mock::EventThread.
- sp<Scheduler::ConnectionHandle> addConnection(std::unique_ptr<EventThread> eventThread) {
- sp<EventThreadConnection> eventThreadConnection =
- new EventThreadConnection(eventThread.get(), ResyncCallback(),
- ISurfaceComposer::eConfigChangedSuppress);
- const int64_t id = sNextId++;
- mConnections.emplace(id,
- std::make_unique<Scheduler::Connection>(new ConnectionHandle(id),
- eventThreadConnection,
- std::move(eventThread)));
- return mConnections[id]->handle;
+ // Used to inject mock event thread.
+ ConnectionHandle createConnection(std::unique_ptr<EventThread> eventThread) {
+ return Scheduler::createConnection(std::move(eventThread), ResyncCallback());
}
/* ------------------------------------------------------------------------
diff --git a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
index 27a119b..9536dd1 100644
--- a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
+++ b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
@@ -61,7 +61,7 @@
public:
~Factory() = default;
- std::unique_ptr<DispSync> createDispSync(const char*, bool, int64_t) override {
+ std::unique_ptr<DispSync> createDispSync(const char*, bool) override {
// TODO: Use test-fixture controlled factory
return nullptr;
}
@@ -198,8 +198,8 @@
new TestableScheduler(std::move(primaryDispSync), std::move(eventControlThread),
mFlinger->mRefreshRateConfigs);
- mFlinger->mAppConnectionHandle = mScheduler->addConnection(std::move(appEventThread));
- mFlinger->mSfConnectionHandle = mScheduler->addConnection(std::move(sfEventThread));
+ mFlinger->mAppConnectionHandle = mScheduler->createConnection(std::move(appEventThread));
+ mFlinger->mSfConnectionHandle = mScheduler->createConnection(std::move(sfEventThread));
mFlinger->mScheduler.reset(mScheduler);
mFlinger->mVSyncModulator.emplace(*mScheduler, mFlinger->mAppConnectionHandle,
diff --git a/services/surfaceflinger/tests/unittests/TimeStatsTest.cpp b/services/surfaceflinger/tests/unittests/TimeStatsTest.cpp
index f35758d..ffacbfe 100644
--- a/services/surfaceflinger/tests/unittests/TimeStatsTest.cpp
+++ b/services/surfaceflinger/tests/unittests/TimeStatsTest.cpp
@@ -17,6 +17,7 @@
#undef LOG_TAG
#define LOG_TAG "LibSurfaceFlingerUnittests"
+#include <TimeStats/TimeStats.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
@@ -27,8 +28,6 @@
#include <random>
#include <unordered_set>
-#include "TimeStats/TimeStats.h"
-
#include "libsurfaceflinger_unittest_main.h"
using namespace android::surfaceflinger;
diff --git a/services/surfaceflinger/tests/unittests/mock/MockFrameTracer.cpp b/services/surfaceflinger/tests/unittests/mock/MockFrameTracer.cpp
new file mode 100644
index 0000000..358dfdb
--- /dev/null
+++ b/services/surfaceflinger/tests/unittests/mock/MockFrameTracer.cpp
@@ -0,0 +1,27 @@
+/*
+ * Copyright 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.
+ */
+
+#include "mock/MockFrameTracer.h"
+
+namespace android {
+namespace mock {
+
+// Explicit default instantiation is recommended.
+FrameTracer::FrameTracer() = default;
+FrameTracer::~FrameTracer() = default;
+
+} // namespace mock
+} // namespace android
diff --git a/services/surfaceflinger/tests/unittests/mock/MockFrameTracer.h b/services/surfaceflinger/tests/unittests/mock/MockFrameTracer.h
new file mode 100644
index 0000000..f768b81
--- /dev/null
+++ b/services/surfaceflinger/tests/unittests/mock/MockFrameTracer.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright 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.
+ */
+
+#pragma once
+
+#include <gmock/gmock.h>
+
+#include "FrameTracer/FrameTracer.h"
+
+namespace android {
+namespace mock {
+
+class FrameTracer : public android::FrameTracer {
+public:
+ FrameTracer();
+ ~FrameTracer();
+
+ MOCK_METHOD0(initialize, void());
+ MOCK_METHOD0(registerDataSource, void());
+ MOCK_METHOD2(traceNewLayer, void(int32_t, const std::string&));
+ MOCK_METHOD6(traceTimestamp,
+ void(int32_t, uint64_t, uint64_t, nsecs_t, FrameEvent::BufferEventType, nsecs_t));
+ MOCK_METHOD6(traceFence,
+ void(int32_t, uint64_t, uint64_t, const std::shared_ptr<FenceTime>&,
+ FrameEvent::BufferEventType, nsecs_t));
+ MOCK_METHOD0(miniDump, std::string());
+};
+
+} // namespace mock
+} // namespace android
diff --git a/services/surfaceflinger/tests/utils/CallbackUtils.h b/services/surfaceflinger/tests/utils/CallbackUtils.h
new file mode 100644
index 0000000..51ae8c4
--- /dev/null
+++ b/services/surfaceflinger/tests/utils/CallbackUtils.h
@@ -0,0 +1,196 @@
+/*
+ * 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.
+ */
+#pragma once
+
+#include <gtest/gtest.h>
+#include <gui/SurfaceComposerClient.h>
+#include <gui/SurfaceControl.h>
+#include <ui/Fence.h>
+#include <utils/Timers.h>
+#include <thread>
+
+namespace android {
+
+namespace {
+
+struct CallbackData {
+ CallbackData() = default;
+ CallbackData(nsecs_t time, const sp<Fence>& fence,
+ const std::vector<SurfaceControlStats>& stats)
+ : latchTime(time), presentFence(fence), surfaceControlStats(stats) {}
+
+ nsecs_t latchTime;
+ sp<Fence> presentFence;
+ std::vector<SurfaceControlStats> surfaceControlStats;
+};
+
+class ExpectedResult {
+public:
+ enum Transaction {
+ NOT_PRESENTED = 0,
+ PRESENTED,
+ };
+
+ enum Buffer {
+ NOT_ACQUIRED = 0,
+ ACQUIRED,
+ };
+
+ enum PreviousBuffer {
+ NOT_RELEASED = 0,
+ RELEASED,
+ UNKNOWN,
+ };
+
+ void reset() {
+ mTransactionResult = ExpectedResult::Transaction::NOT_PRESENTED;
+ mExpectedSurfaceResults.clear();
+ }
+
+ void addSurface(ExpectedResult::Transaction transactionResult, const sp<SurfaceControl>& layer,
+ ExpectedResult::Buffer bufferResult = ACQUIRED,
+ ExpectedResult::PreviousBuffer previousBufferResult = NOT_RELEASED) {
+ mTransactionResult = transactionResult;
+ mExpectedSurfaceResults.emplace(std::piecewise_construct, std::forward_as_tuple(layer),
+ std::forward_as_tuple(bufferResult, previousBufferResult));
+ }
+
+ void addSurfaces(ExpectedResult::Transaction transactionResult,
+ const std::vector<sp<SurfaceControl>>& layers,
+ ExpectedResult::Buffer bufferResult = ACQUIRED,
+ ExpectedResult::PreviousBuffer previousBufferResult = NOT_RELEASED) {
+ for (const auto& layer : layers) {
+ addSurface(transactionResult, layer, bufferResult, previousBufferResult);
+ }
+ }
+
+ void addExpectedPresentTime(nsecs_t expectedPresentTime) {
+ mExpectedPresentTime = expectedPresentTime;
+ }
+
+ void verifyCallbackData(const CallbackData& callbackData) const {
+ const auto& [latchTime, presentFence, surfaceControlStats] = callbackData;
+ if (mTransactionResult == ExpectedResult::Transaction::PRESENTED) {
+ ASSERT_GE(latchTime, 0) << "bad latch time";
+ ASSERT_NE(presentFence, nullptr);
+ if (mExpectedPresentTime >= 0) {
+ ASSERT_EQ(presentFence->wait(3000), NO_ERROR);
+ ASSERT_GE(presentFence->getSignalTime(), mExpectedPresentTime - nsecs_t(5 * 1e6));
+ // if the panel is running at 30 hz, at the worst case, our expected time just
+ // misses vsync and we have to wait another 33.3ms
+ ASSERT_LE(presentFence->getSignalTime(),
+ mExpectedPresentTime + nsecs_t(66.666666 * 1e6));
+ }
+ } else {
+ ASSERT_EQ(presentFence, nullptr) << "transaction shouldn't have been presented";
+ ASSERT_EQ(latchTime, -1) << "unpresented transactions shouldn't be latched";
+ }
+
+ ASSERT_EQ(surfaceControlStats.size(), mExpectedSurfaceResults.size())
+ << "wrong number of surfaces";
+
+ for (const auto& stats : surfaceControlStats) {
+ ASSERT_NE(stats.surfaceControl, nullptr) << "returned null surface control";
+
+ const auto& expectedSurfaceResult = mExpectedSurfaceResults.find(stats.surfaceControl);
+ ASSERT_NE(expectedSurfaceResult, mExpectedSurfaceResults.end())
+ << "unexpected surface control";
+ expectedSurfaceResult->second.verifySurfaceControlStats(stats, latchTime);
+ }
+ }
+
+private:
+ class ExpectedSurfaceResult {
+ public:
+ ExpectedSurfaceResult(ExpectedResult::Buffer bufferResult,
+ ExpectedResult::PreviousBuffer previousBufferResult)
+ : mBufferResult(bufferResult), mPreviousBufferResult(previousBufferResult) {}
+
+ void verifySurfaceControlStats(const SurfaceControlStats& surfaceControlStats,
+ nsecs_t latchTime) const {
+ const auto& [surfaceControl, acquireTime, previousReleaseFence] = surfaceControlStats;
+
+ ASSERT_EQ(acquireTime > 0, mBufferResult == ExpectedResult::Buffer::ACQUIRED)
+ << "bad acquire time";
+ ASSERT_LE(acquireTime, latchTime) << "acquire time should be <= latch time";
+
+ if (mPreviousBufferResult == ExpectedResult::PreviousBuffer::RELEASED) {
+ ASSERT_NE(previousReleaseFence, nullptr)
+ << "failed to set release prev buffer fence";
+ } else if (mPreviousBufferResult == ExpectedResult::PreviousBuffer::NOT_RELEASED) {
+ ASSERT_EQ(previousReleaseFence, nullptr)
+ << "should not have set released prev buffer fence";
+ }
+ }
+
+ private:
+ ExpectedResult::Buffer mBufferResult;
+ ExpectedResult::PreviousBuffer mPreviousBufferResult;
+ };
+
+ struct SCHash {
+ std::size_t operator()(const sp<SurfaceControl>& sc) const {
+ return std::hash<IBinder*>{}(sc->getHandle().get());
+ }
+ };
+ ExpectedResult::Transaction mTransactionResult = ExpectedResult::Transaction::NOT_PRESENTED;
+ nsecs_t mExpectedPresentTime = -1;
+ std::unordered_map<sp<SurfaceControl>, ExpectedSurfaceResult, SCHash> mExpectedSurfaceResults;
+};
+
+class CallbackHelper {
+public:
+ static void function(void* callbackContext, nsecs_t latchTime, const sp<Fence>& presentFence,
+ const std::vector<SurfaceControlStats>& stats) {
+ if (!callbackContext) {
+ ALOGE("failed to get callback context");
+ }
+ CallbackHelper* helper = static_cast<CallbackHelper*>(callbackContext);
+ std::lock_guard lock(helper->mMutex);
+ helper->mCallbackDataQueue.emplace(latchTime, presentFence, stats);
+ helper->mConditionVariable.notify_all();
+ }
+
+ void getCallbackData(CallbackData* outData) {
+ std::unique_lock lock(mMutex);
+
+ if (mCallbackDataQueue.empty()) {
+ ASSERT_NE(mConditionVariable.wait_for(lock, std::chrono::seconds(3)),
+ std::cv_status::timeout)
+ << "did not receive callback";
+ }
+
+ *outData = std::move(mCallbackDataQueue.front());
+ mCallbackDataQueue.pop();
+ }
+
+ void verifyFinalState() {
+ // Wait to see if there are extra callbacks
+ std::this_thread::sleep_for(500ms);
+
+ std::lock_guard lock(mMutex);
+ EXPECT_EQ(mCallbackDataQueue.size(), 0) << "extra callbacks received";
+ mCallbackDataQueue = {};
+ }
+
+ void* getContext() { return static_cast<void*>(this); }
+
+ std::mutex mMutex;
+ std::condition_variable mConditionVariable;
+ std::queue<CallbackData> mCallbackDataQueue;
+};
+}
+} // namespace android
diff --git a/services/surfaceflinger/tests/utils/ColorUtils.h b/services/surfaceflinger/tests/utils/ColorUtils.h
new file mode 100644
index 0000000..07916b6
--- /dev/null
+++ b/services/surfaceflinger/tests/utils/ColorUtils.h
@@ -0,0 +1,86 @@
+/*
+ * 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.
+ */
+#pragma once
+
+#include <ui/ColorSpace.h>
+
+namespace android {
+
+namespace {
+
+struct Color {
+ uint8_t r;
+ uint8_t g;
+ uint8_t b;
+ uint8_t a;
+
+ static const Color RED;
+ static const Color GREEN;
+ static const Color BLUE;
+ static const Color WHITE;
+ static const Color BLACK;
+ static const Color TRANSPARENT;
+};
+
+const Color Color::RED{255, 0, 0, 255};
+const Color Color::GREEN{0, 255, 0, 255};
+const Color Color::BLUE{0, 0, 255, 255};
+const Color Color::WHITE{255, 255, 255, 255};
+const Color Color::BLACK{0, 0, 0, 255};
+const Color Color::TRANSPARENT{0, 0, 0, 0};
+
+class ColorTransformHelper {
+public:
+ static void DegammaColorSingle(half& s) {
+ if (s <= 0.03928f)
+ s = s / 12.92f;
+ else
+ s = pow((s + 0.055f) / 1.055f, 2.4f);
+ }
+
+ static void DegammaColor(half3& color) {
+ DegammaColorSingle(color.r);
+ DegammaColorSingle(color.g);
+ DegammaColorSingle(color.b);
+ }
+
+ static void GammaColorSingle(half& s) {
+ if (s <= 0.0031308f) {
+ s = s * 12.92f;
+ } else {
+ s = 1.055f * pow(s, (1.0f / 2.4f)) - 0.055f;
+ }
+ }
+
+ static void GammaColor(half3& color) {
+ GammaColorSingle(color.r);
+ GammaColorSingle(color.g);
+ GammaColorSingle(color.b);
+ }
+
+ static void applyMatrix(half3& color, const mat3& mat) {
+ half3 ret = half3(0);
+
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 3; j++) {
+ ret[i] = ret[i] + color[j] * mat[j][i];
+ }
+ }
+ color = ret;
+ }
+};
+} // namespace
+} // namespace android
diff --git a/services/surfaceflinger/tests/utils/ScreenshotUtils.h b/services/surfaceflinger/tests/utils/ScreenshotUtils.h
new file mode 100644
index 0000000..02e7623
--- /dev/null
+++ b/services/surfaceflinger/tests/utils/ScreenshotUtils.h
@@ -0,0 +1,167 @@
+/*
+ * 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.
+ */
+#pragma once
+
+#include <ui/Rect.h>
+#include <utils/String8.h>
+#include "TransactionUtils.h"
+
+namespace android {
+
+namespace {
+
+// A ScreenCapture is a screenshot from SurfaceFlinger that can be used to check
+// individual pixel values for testing purposes.
+class ScreenCapture : public RefBase {
+public:
+ static void captureScreen(std::unique_ptr<ScreenCapture>* sc) {
+ captureScreen(sc, SurfaceComposerClient::getInternalDisplayToken());
+ }
+
+ static void captureScreen(std::unique_ptr<ScreenCapture>* sc, sp<IBinder> displayToken) {
+ const auto sf = ComposerService::getComposerService();
+ SurfaceComposerClient::Transaction().apply(true);
+
+ sp<GraphicBuffer> outBuffer;
+ ASSERT_EQ(NO_ERROR, sf->captureScreen(displayToken, &outBuffer, Rect(), 0, 0, false));
+ *sc = std::make_unique<ScreenCapture>(outBuffer);
+ }
+
+ static void captureLayers(std::unique_ptr<ScreenCapture>* sc, sp<IBinder>& parentHandle,
+ Rect crop = Rect::EMPTY_RECT, float frameScale = 1.0) {
+ sp<ISurfaceComposer> sf(ComposerService::getComposerService());
+ SurfaceComposerClient::Transaction().apply(true);
+
+ sp<GraphicBuffer> outBuffer;
+ ASSERT_EQ(NO_ERROR, sf->captureLayers(parentHandle, &outBuffer, crop, frameScale));
+ *sc = std::make_unique<ScreenCapture>(outBuffer);
+ }
+
+ static void captureChildLayers(std::unique_ptr<ScreenCapture>* sc, sp<IBinder>& parentHandle,
+ Rect crop = Rect::EMPTY_RECT, float frameScale = 1.0) {
+ sp<ISurfaceComposer> sf(ComposerService::getComposerService());
+ SurfaceComposerClient::Transaction().apply(true);
+
+ sp<GraphicBuffer> outBuffer;
+ ASSERT_EQ(NO_ERROR, sf->captureLayers(parentHandle, &outBuffer, crop, frameScale, true));
+ *sc = std::make_unique<ScreenCapture>(outBuffer);
+ }
+
+ static void captureChildLayersExcluding(
+ std::unique_ptr<ScreenCapture>* sc, sp<IBinder>& parentHandle,
+ std::unordered_set<sp<IBinder>, ISurfaceComposer::SpHash<IBinder>> excludeLayers) {
+ sp<ISurfaceComposer> sf(ComposerService::getComposerService());
+ SurfaceComposerClient::Transaction().apply(true);
+
+ sp<GraphicBuffer> outBuffer;
+ ASSERT_EQ(NO_ERROR,
+ sf->captureLayers(parentHandle, &outBuffer, ui::Dataspace::V0_SRGB,
+ ui::PixelFormat::RGBA_8888, Rect::EMPTY_RECT, excludeLayers,
+ 1.0f, true));
+ *sc = std::make_unique<ScreenCapture>(outBuffer);
+ }
+
+ void expectColor(const Rect& rect, const Color& color, uint8_t tolerance = 0) {
+ ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mOutBuffer->getPixelFormat());
+ expectBufferColor(mOutBuffer, mPixels, rect, color, tolerance);
+ }
+
+ void expectBorder(const Rect& rect, const Color& color, uint8_t tolerance = 0) {
+ ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mOutBuffer->getPixelFormat());
+ const bool leftBorder = rect.left > 0;
+ const bool topBorder = rect.top > 0;
+ const bool rightBorder = rect.right < int32_t(mOutBuffer->getWidth());
+ const bool bottomBorder = rect.bottom < int32_t(mOutBuffer->getHeight());
+
+ if (topBorder) {
+ Rect top(rect.left, rect.top - 1, rect.right, rect.top);
+ if (leftBorder) {
+ top.left -= 1;
+ }
+ if (rightBorder) {
+ top.right += 1;
+ }
+ expectColor(top, color, tolerance);
+ }
+ if (leftBorder) {
+ Rect left(rect.left - 1, rect.top, rect.left, rect.bottom);
+ expectColor(left, color, tolerance);
+ }
+ if (rightBorder) {
+ Rect right(rect.right, rect.top, rect.right + 1, rect.bottom);
+ expectColor(right, color, tolerance);
+ }
+ if (bottomBorder) {
+ Rect bottom(rect.left, rect.bottom, rect.right, rect.bottom + 1);
+ if (leftBorder) {
+ bottom.left -= 1;
+ }
+ if (rightBorder) {
+ bottom.right += 1;
+ }
+ expectColor(bottom, color, tolerance);
+ }
+ }
+
+ void expectQuadrant(const Rect& rect, const Color& topLeft, const Color& topRight,
+ const Color& bottomLeft, const Color& bottomRight, bool filtered = false,
+ uint8_t tolerance = 0) {
+ ASSERT_TRUE((rect.right - rect.left) % 2 == 0 && (rect.bottom - rect.top) % 2 == 0);
+
+ const int32_t centerX = rect.left + (rect.right - rect.left) / 2;
+ const int32_t centerY = rect.top + (rect.bottom - rect.top) / 2;
+ // avoid checking borders due to unspecified filtering behavior
+ const int32_t offsetX = filtered ? 2 : 0;
+ const int32_t offsetY = filtered ? 2 : 0;
+ expectColor(Rect(rect.left, rect.top, centerX - offsetX, centerY - offsetY), topLeft,
+ tolerance);
+ expectColor(Rect(centerX + offsetX, rect.top, rect.right, centerY - offsetY), topRight,
+ tolerance);
+ expectColor(Rect(rect.left, centerY + offsetY, centerX - offsetX, rect.bottom), bottomLeft,
+ tolerance);
+ expectColor(Rect(centerX + offsetX, centerY + offsetY, rect.right, rect.bottom),
+ bottomRight, tolerance);
+ }
+
+ void checkPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b) {
+ ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mOutBuffer->getPixelFormat());
+ const uint8_t* pixel = mPixels + (4 * (y * mOutBuffer->getStride() + x));
+ if (r != pixel[0] || g != pixel[1] || b != pixel[2]) {
+ String8 err(String8::format("pixel @ (%3d, %3d): "
+ "expected [%3d, %3d, %3d], got [%3d, %3d, %3d]",
+ x, y, r, g, b, pixel[0], pixel[1], pixel[2]));
+ EXPECT_EQ(String8(), err) << err.string();
+ }
+ }
+
+ void expectFGColor(uint32_t x, uint32_t y) { checkPixel(x, y, 195, 63, 63); }
+
+ void expectBGColor(uint32_t x, uint32_t y) { checkPixel(x, y, 63, 63, 195); }
+
+ void expectChildColor(uint32_t x, uint32_t y) { checkPixel(x, y, 200, 200, 200); }
+
+ explicit ScreenCapture(const sp<GraphicBuffer>& outBuffer) : mOutBuffer(outBuffer) {
+ mOutBuffer->lock(GRALLOC_USAGE_SW_READ_OFTEN, reinterpret_cast<void**>(&mPixels));
+ }
+
+ ~ScreenCapture() { mOutBuffer->unlock(); }
+
+private:
+ sp<GraphicBuffer> mOutBuffer;
+ uint8_t* mPixels = nullptr;
+};
+} // namespace
+} // namespace android
diff --git a/services/surfaceflinger/tests/utils/TransactionUtils.h b/services/surfaceflinger/tests/utils/TransactionUtils.h
new file mode 100644
index 0000000..f6b33a9
--- /dev/null
+++ b/services/surfaceflinger/tests/utils/TransactionUtils.h
@@ -0,0 +1,188 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+//#include <algorithm>
+#include <chrono>
+//#include <cinttypes>
+//#include <functional>
+//#include <limits>
+//#include <ostream>
+//#include <thread>
+#include <gtest/gtest.h>
+
+#include <android/native_window.h>
+#include <hardware/hwcomposer_defs.h>
+
+#include <binder/IPCThreadState.h>
+
+#include <gui/Surface.h>
+#include <gui/SurfaceComposerClient.h>
+
+#include <private/gui/ComposerService.h>
+
+#include <ui/GraphicBuffer.h>
+#include <ui/Rect.h>
+
+#include "ColorUtils.h"
+//#include <sys/types.h>
+//#include <unistd.h>
+
+namespace android {
+
+namespace {
+
+using namespace std::chrono_literals;
+
+std::ostream& operator<<(std::ostream& os, const Color& color) {
+ os << int(color.r) << ", " << int(color.g) << ", " << int(color.b) << ", " << int(color.a);
+ return os;
+}
+
+// Fill a region with the specified color.
+void fillANativeWindowBufferColor(const ANativeWindow_Buffer& buffer, const Rect& rect,
+ const Color& color) {
+ Rect r(0, 0, buffer.width, buffer.height);
+ if (!r.intersect(rect, &r)) {
+ return;
+ }
+
+ int32_t width = r.right - r.left;
+ int32_t height = r.bottom - r.top;
+
+ for (int32_t row = 0; row < height; row++) {
+ uint8_t* dst =
+ static_cast<uint8_t*>(buffer.bits) + (buffer.stride * (r.top + row) + r.left) * 4;
+ for (int32_t column = 0; column < width; column++) {
+ dst[0] = color.r;
+ dst[1] = color.g;
+ dst[2] = color.b;
+ dst[3] = color.a;
+ dst += 4;
+ }
+ }
+}
+
+// Fill a region with the specified color.
+void fillGraphicBufferColor(const sp<GraphicBuffer>& buffer, const Rect& rect, const Color& color) {
+ Rect r(0, 0, buffer->width, buffer->height);
+ if (!r.intersect(rect, &r)) {
+ return;
+ }
+
+ int32_t width = r.right - r.left;
+ int32_t height = r.bottom - r.top;
+
+ uint8_t* pixels;
+ buffer->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
+ reinterpret_cast<void**>(&pixels));
+
+ for (int32_t row = 0; row < height; row++) {
+ uint8_t* dst = pixels + (buffer->getStride() * (r.top + row) + r.left) * 4;
+ for (int32_t column = 0; column < width; column++) {
+ dst[0] = color.r;
+ dst[1] = color.g;
+ dst[2] = color.b;
+ dst[3] = color.a;
+ dst += 4;
+ }
+ }
+ buffer->unlock();
+}
+
+// Check if a region has the specified color.
+void expectBufferColor(const sp<GraphicBuffer>& outBuffer, uint8_t* pixels, const Rect& rect,
+ const Color& color, uint8_t tolerance) {
+ int32_t x = rect.left;
+ int32_t y = rect.top;
+ int32_t width = rect.right - rect.left;
+ int32_t height = rect.bottom - rect.top;
+
+ int32_t bufferWidth = int32_t(outBuffer->getWidth());
+ int32_t bufferHeight = int32_t(outBuffer->getHeight());
+ if (x + width > bufferWidth) {
+ x = std::min(x, bufferWidth);
+ width = bufferWidth - x;
+ }
+ if (y + height > bufferHeight) {
+ y = std::min(y, bufferHeight);
+ height = bufferHeight - y;
+ }
+
+ auto colorCompare = [tolerance](uint8_t a, uint8_t b) {
+ uint8_t tmp = a >= b ? a - b : b - a;
+ return tmp <= tolerance;
+ };
+ for (int32_t j = 0; j < height; j++) {
+ const uint8_t* src = pixels + (outBuffer->getStride() * (y + j) + x) * 4;
+ for (int32_t i = 0; i < width; i++) {
+ const uint8_t expected[4] = {color.r, color.g, color.b, color.a};
+ EXPECT_TRUE(std::equal(src, src + 4, expected, colorCompare))
+ << "pixel @ (" << x + i << ", " << y + j << "): "
+ << "expected (" << color << "), "
+ << "got (" << Color{src[0], src[1], src[2], src[3]} << ")";
+ src += 4;
+ }
+ }
+}
+
+using Transaction = SurfaceComposerClient::Transaction;
+
+// Fill an RGBA_8888 formatted surface with a single color.
+static void fillSurfaceRGBA8(const sp<SurfaceControl>& sc, uint8_t r, uint8_t g, uint8_t b,
+ bool unlock = true) {
+ ANativeWindow_Buffer outBuffer;
+ sp<Surface> s = sc->getSurface();
+ ASSERT_TRUE(s != nullptr);
+ ASSERT_EQ(NO_ERROR, s->lock(&outBuffer, nullptr));
+ uint8_t* img = reinterpret_cast<uint8_t*>(outBuffer.bits);
+ for (int y = 0; y < outBuffer.height; y++) {
+ for (int x = 0; x < outBuffer.width; x++) {
+ uint8_t* pixel = img + (4 * (y * outBuffer.stride + x));
+ pixel[0] = r;
+ pixel[1] = g;
+ pixel[2] = b;
+ pixel[3] = 255;
+ }
+ }
+ if (unlock) {
+ ASSERT_EQ(NO_ERROR, s->unlockAndPost());
+ }
+}
+
+enum class RenderPath { SCREENSHOT, VIRTUAL_DISPLAY };
+
+// Environment for starting up binder threads. This is required for testing
+// virtual displays, as BufferQueue parameters may be queried over binder.
+class BinderEnvironment : public ::testing::Environment {
+public:
+ void SetUp() override { ProcessState::self()->startThreadPool(); }
+};
+
+/** RAII Wrapper around get/seteuid */
+class UIDFaker {
+ uid_t oldId;
+
+public:
+ UIDFaker(uid_t uid) {
+ oldId = geteuid();
+ seteuid(uid);
+ }
+ ~UIDFaker() { seteuid(oldId); }
+};
+} // namespace
+} // namespace android
diff --git a/services/vr/hardware_composer/Android.bp b/services/vr/hardware_composer/Android.bp
index bc7cc1c..4e461f9 100644
--- a/services/vr/hardware_composer/Android.bp
+++ b/services/vr/hardware_composer/Android.bp
@@ -12,11 +12,14 @@
],
shared_libs: [
- "android.frameworks.vr.composer@1.0",
+ "android.frameworks.vr.composer@2.0",
"android.hardware.graphics.composer@2.1",
+ "android.hardware.graphics.composer@2.2",
+ "android.hardware.graphics.composer@2.3",
"android.hardware.graphics.composer@2.1-resources",
"android.hardware.graphics.mapper@2.0",
"android.hardware.graphics.mapper@3.0",
+ "android.hardware.graphics.mapper@4.0",
"libbase",
"libbufferhubqueue",
"libbinder",
@@ -34,11 +37,11 @@
header_libs: [
"android.hardware.graphics.composer@2.1-command-buffer",
- "android.hardware.graphics.composer@2.1-hal",
+ "android.hardware.graphics.composer@2.3-hal",
],
export_header_lib_headers: [
- "android.hardware.graphics.composer@2.1-hal",
+ "android.hardware.graphics.composer@2.3-hal",
],
export_static_lib_headers: [
@@ -46,8 +49,10 @@
],
export_shared_lib_headers: [
- "android.frameworks.vr.composer@1.0",
+ "android.frameworks.vr.composer@2.0",
"android.hardware.graphics.composer@2.1",
+ "android.hardware.graphics.composer@2.2",
+ "android.hardware.graphics.composer@2.3",
],
export_include_dirs: ["."],
@@ -104,8 +109,8 @@
"libvr_hwc-binder",
],
shared_libs: [
- "android.frameworks.vr.composer@1.0",
- "android.hardware.graphics.composer@2.1",
+ "android.frameworks.vr.composer@2.0",
+ "android.hardware.graphics.composer@2.3",
"libbase",
"libbinder",
"liblog",
diff --git a/services/vr/hardware_composer/impl/vr_composer_client.cpp b/services/vr/hardware_composer/impl/vr_composer_client.cpp
index 786d5fa..36f6b32 100644
--- a/services/vr/hardware_composer/impl/vr_composer_client.cpp
+++ b/services/vr/hardware_composer/impl/vr_composer_client.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include <android/frameworks/vr/composer/1.0/IVrComposerClient.h>
+#include <android/frameworks/vr/composer/2.0/IVrComposerClient.h>
#include <hardware/gralloc.h>
#include <hardware/gralloc1.h>
#include <log/log.h>
@@ -27,8 +27,7 @@
namespace android {
namespace dvr {
-using android::hardware::graphics::common::V1_0::PixelFormat;
-using android::frameworks::vr::composer::V1_0::IVrComposerClient;
+using android::frameworks::vr::composer::V2_0::IVrComposerClient;
VrComposerClient::VrComposerClient(dvr::VrHwc& hal)
: ComposerClient(&hal), mVrHal(hal) {
@@ -51,7 +50,8 @@
VrComposerClient::VrCommandEngine::~VrCommandEngine() {}
bool VrComposerClient::VrCommandEngine::executeCommand(
- IComposerClient::Command command, uint16_t length) {
+ hardware::graphics::composer::V2_1::IComposerClient::Command command,
+ uint16_t length) {
IVrComposerClient::VrCommand vrCommand =
static_cast<IVrComposerClient::VrCommand>(command);
switch (vrCommand) {
@@ -107,12 +107,14 @@
IVrComposerClient::BufferMetadata
VrComposerClient::VrCommandEngine::readBufferMetadata() {
IVrComposerClient::BufferMetadata metadata = {
- .width = read(),
- .height = read(),
- .stride = read(),
- .layerCount = read(),
- .format = static_cast<PixelFormat>(readSigned()),
- .usage = read64(),
+ .width = read(),
+ .height = read(),
+ .stride = read(),
+ .layerCount = read(),
+ .format =
+ static_cast<android::hardware::graphics::common::V1_2::PixelFormat>(
+ readSigned()),
+ .usage = read64(),
};
return metadata;
}
diff --git a/services/vr/hardware_composer/impl/vr_composer_client.h b/services/vr/hardware_composer/impl/vr_composer_client.h
index 0b7ce5e..1b2b5f4 100644
--- a/services/vr/hardware_composer/impl/vr_composer_client.h
+++ b/services/vr/hardware_composer/impl/vr_composer_client.h
@@ -17,10 +17,12 @@
#ifndef ANDROID_DVR_HARDWARE_COMPOSER_IMPL_VR_COMPOSER_CLIENT_H
#define ANDROID_DVR_HARDWARE_COMPOSER_IMPL_VR_COMPOSER_CLIENT_H
-#include <android/frameworks/vr/composer/1.0/IVrComposerClient.h>
-#include <composer-command-buffer/2.1/ComposerCommandBuffer.h>
+#include <android/frameworks/vr/composer/2.0/IVrComposerClient.h>
+#include <composer-command-buffer/2.3/ComposerCommandBuffer.h>
#include <composer-hal/2.1/ComposerClient.h>
#include <composer-hal/2.1/ComposerCommandEngine.h>
+#include <composer-hal/2.2/ComposerClient.h>
+#include <composer-hal/2.3/ComposerClient.h>
namespace android {
namespace dvr {
@@ -28,8 +30,8 @@
class VrHwc;
using hardware::graphics::composer::V2_1::hal::ComposerCommandEngine;
-using hardware::graphics::composer::V2_1::hal::ComposerHal;
-using hardware::graphics::composer::V2_1::hal::detail::ComposerClientImpl;
+using hardware::graphics::composer::V2_3::hal::ComposerHal;
+using hardware::graphics::composer::V2_3::hal::detail::ComposerClientImpl;
using ComposerClient = ComposerClientImpl<IVrComposerClient, ComposerHal>;
@@ -44,8 +46,9 @@
explicit VrCommandEngine(VrComposerClient& client);
~VrCommandEngine() override;
- bool executeCommand(IComposerClient::Command command,
- uint16_t length) override;
+ bool executeCommand(
+ hardware::graphics::composer::V2_1::IComposerClient::Command command,
+ uint16_t length) override;
private:
bool executeSetLayerInfo(uint16_t length);
diff --git a/services/vr/hardware_composer/impl/vr_hwc.cpp b/services/vr/hardware_composer/impl/vr_hwc.cpp
index 7323277..e530b16 100644
--- a/services/vr/hardware_composer/impl/vr_hwc.cpp
+++ b/services/vr/hardware_composer/impl/vr_hwc.cpp
@@ -27,7 +27,7 @@
#include "vr_composer_client.h"
using namespace android::hardware::graphics::common::V1_0;
-using namespace android::hardware::graphics::composer::V2_1;
+using namespace android::hardware::graphics::composer::V2_3;
using android::base::StringPrintf;
using android::hardware::hidl_handle;
@@ -36,12 +36,12 @@
using android::hardware::Return;
using android::hardware::Void;
+namespace types = android::hardware::graphics::common;
+
namespace android {
namespace dvr {
namespace {
-using android::hardware::graphics::common::V1_0::PixelFormat;
-
const Display kDefaultDisplayId = 1;
const Config kDefaultConfigId = 1;
@@ -269,7 +269,8 @@
// onHotplug() call, so it's important to release mutex_ here.
lock.unlock();
event_callback_->onHotplug(kDefaultDisplayId,
- IComposerCallback::Connection::CONNECTED);
+ hardware::graphics::composer::V2_1::
+ IComposerCallback::Connection::CONNECTED);
lock.lock();
UpdateVsyncCallbackEnabledLocked();
}
@@ -282,15 +283,6 @@
uint32_t VrHwc::getMaxVirtualDisplayCount() { return 1; }
-Error VrHwc::createVirtualDisplay(uint32_t width, uint32_t height,
- PixelFormat* format, Display* outDisplay) {
- *format = PixelFormat::RGBA_8888;
- *outDisplay = display_count_;
- displays_[display_count_].reset(new HwcDisplay(width, height));
- display_count_++;
- return Error::NONE;
-}
-
Error VrHwc::destroyVirtualDisplay(Display display) {
std::lock_guard<std::mutex> guard(mutex_);
if (display == kDefaultDisplayId || displays_.erase(display) == 0)
@@ -332,24 +324,6 @@
return Error::NONE;
}
-Error VrHwc::getClientTargetSupport(Display display, uint32_t /* width */,
- uint32_t /* height */,
- PixelFormat /* format */,
- Dataspace /* dataspace */) {
- std::lock_guard<std::mutex> guard(mutex_);
- if (!FindDisplay(display))
- return Error::BAD_DISPLAY;
-
- return Error::NONE;
-}
-
-Error VrHwc::getColorModes(Display /* display */,
- hidl_vec<ColorMode>* outModes) {
- std::vector<ColorMode> color_modes(1, ColorMode::NATIVE);
- *outModes = hidl_vec<ColorMode>(color_modes);
- return Error::NONE;
-}
-
Error VrHwc::getDisplayAttribute(Display display, Config config,
IComposerClient::Attribute attribute,
int32_t* outValue) {
@@ -441,17 +415,6 @@
return Error::NONE;
}
-Error VrHwc::getHdrCapabilities(Display /* display */,
- hidl_vec<Hdr>* /* outTypes */,
- float* outMaxLuminance,
- float* outMaxAverageLuminance,
- float* outMinLuminance) {
- *outMaxLuminance = 0;
- *outMaxAverageLuminance = 0;
- *outMinLuminance = 0;
- return Error::NONE;
-}
-
Error VrHwc::setActiveConfig(Display display, Config config) {
std::lock_guard<std::mutex> guard(mutex_);
auto display_ptr = FindDisplay(display);
@@ -464,47 +427,6 @@
return Error::NONE;
}
-Error VrHwc::setColorMode(Display display, ColorMode mode) {
- std::lock_guard<std::mutex> guard(mutex_);
- auto display_ptr = FindDisplay(display);
- if (!display_ptr)
- return Error::BAD_DISPLAY;
-
- if (mode < ColorMode::NATIVE || mode > ColorMode::DISPLAY_P3)
- return Error::BAD_PARAMETER;
-
- display_ptr->set_color_mode(mode);
- return Error::NONE;
-}
-
-Error VrHwc::setPowerMode(Display display, IComposerClient::PowerMode mode) {
- bool dozeSupported = false;
-
- Error dozeSupportError = getDozeSupport(display, &dozeSupported);
-
- if (dozeSupportError != Error::NONE)
- return dozeSupportError;
-
- std::lock_guard<std::mutex> guard(mutex_);
- auto display_ptr = FindDisplay(display);
- if (!display_ptr)
- return Error::BAD_DISPLAY;
-
- if (mode < IComposerClient::PowerMode::OFF ||
- mode > IComposerClient::PowerMode::DOZE_SUSPEND) {
- return Error::BAD_PARAMETER;
- }
-
- if (!dozeSupported &&
- (mode == IComposerClient::PowerMode::DOZE ||
- mode == IComposerClient::PowerMode::DOZE_SUSPEND)) {
- return Error::UNSUPPORTED;
- }
-
- display_ptr->set_power_mode(mode);
- return Error::NONE;
-}
-
Error VrHwc::setVsyncEnabled(Display display, IComposerClient::Vsync enabled) {
std::lock_guard<std::mutex> guard(mutex_);
auto display_ptr = FindDisplay(display);
@@ -956,6 +878,23 @@
return Void();
}
+Return<void> VrHwc::createClient_2_3(IComposer::createClient_2_3_cb hidl_cb) {
+ std::lock_guard<std::mutex> guard(mutex_);
+
+ Error status = Error::NONE;
+ sp<VrComposerClient> client;
+ if (!client_.promote().get()) {
+ client = new VrComposerClient(*this);
+ } else {
+ ALOGE("Already have a client");
+ status = Error::NO_RESOURCES;
+ }
+
+ client_ = client;
+ hidl_cb(status, client);
+ return Void();
+}
+
void VrHwc::ForceDisplaysRefresh() {
std::lock_guard<std::mutex> guard(mutex_);
if (event_callback_ != nullptr) {
@@ -1044,5 +983,196 @@
callback_ = callback;
}
+// composer::V2_2::ComposerHal
+Error VrHwc::setReadbackBuffer(Display display,
+ const native_handle_t* bufferHandle,
+ android::base::unique_fd fenceFd) {
+ return Error::NONE;
+}
+
+Error VrHwc::getReadbackBufferFence(Display display,
+ android::base::unique_fd* outFenceFd) {
+ return Error::NONE;
+}
+
+Error VrHwc::createVirtualDisplay_2_2(uint32_t width, uint32_t height,
+ types::V1_1::PixelFormat* format,
+ Display* outDisplay) {
+ *format = types::V1_1::PixelFormat::RGBA_8888;
+ *outDisplay = display_count_;
+ displays_[display_count_].reset(new HwcDisplay(width, height));
+ display_count_++;
+ return Error::NONE;
+}
+
+Error VrHwc::setPowerMode_2_2(Display display,
+ IComposerClient::PowerMode mode) {
+ bool dozeSupported = false;
+
+ Error dozeSupportError = getDozeSupport(display, &dozeSupported);
+
+ if (dozeSupportError != Error::NONE)
+ return dozeSupportError;
+
+ std::lock_guard<std::mutex> guard(mutex_);
+ auto display_ptr = FindDisplay(display);
+ if (!display_ptr)
+ return Error::BAD_DISPLAY;
+
+ if (mode < IComposerClient::PowerMode::OFF ||
+ mode > IComposerClient::PowerMode::DOZE_SUSPEND) {
+ return Error::BAD_PARAMETER;
+ }
+
+ if (!dozeSupported && (mode == IComposerClient::PowerMode::DOZE ||
+ mode == IComposerClient::PowerMode::DOZE_SUSPEND)) {
+ return Error::UNSUPPORTED;
+ }
+
+ display_ptr->set_power_mode(mode);
+ return Error::NONE;
+}
+
+Error VrHwc::setLayerFloatColor(Display display, Layer layer,
+ IComposerClient::FloatColor color) {
+ return Error::NONE;
+}
+
+Error VrHwc::getRenderIntents(Display display, types::V1_1::ColorMode mode,
+ std::vector<RenderIntent>* outIntents) {
+ return Error::NONE;
+}
+
+std::array<float, 16> VrHwc::getDataspaceSaturationMatrix(
+ types::V1_1::Dataspace dataspace) {
+ return {};
+}
+
+// composer::V2_3::ComposerHal
+Error VrHwc::getHdrCapabilities_2_3(Display /*display*/,
+ hidl_vec<Hdr>* /*outTypes*/,
+ float* outMaxLuminance,
+ float* outMaxAverageLuminance,
+ float* outMinLuminance) {
+ *outMaxLuminance = 0;
+ *outMaxAverageLuminance = 0;
+ *outMinLuminance = 0;
+ return Error::NONE;
+}
+
+Error VrHwc::setLayerPerFrameMetadata_2_3(
+ Display display, Layer layer,
+ const std::vector<IComposerClient::PerFrameMetadata>& metadata) {
+ return Error::NONE;
+}
+
+Error VrHwc::getPerFrameMetadataKeys_2_3(
+ Display display,
+ std::vector<IComposerClient::PerFrameMetadataKey>* outKeys) {
+ return Error::NONE;
+}
+
+Error VrHwc::setColorMode_2_3(Display display, ColorMode mode,
+ RenderIntent intent) {
+ std::lock_guard<std::mutex> guard(mutex_);
+ auto display_ptr = FindDisplay(display);
+ if (!display_ptr)
+ return Error::BAD_DISPLAY;
+
+ if (mode < ColorMode::NATIVE || mode > ColorMode::DISPLAY_P3)
+ return Error::BAD_PARAMETER;
+
+ display_ptr->set_color_mode(mode);
+ return Error::NONE;
+}
+
+Error VrHwc::getRenderIntents_2_3(Display display, ColorMode mode,
+ std::vector<RenderIntent>* outIntents) {
+ return Error::NONE;
+}
+
+Error VrHwc::getColorModes_2_3(Display display, hidl_vec<ColorMode>* outModes) {
+ return Error::NONE;
+}
+
+Error VrHwc::getClientTargetSupport_2_3(Display display, uint32_t width,
+ uint32_t height, PixelFormat format,
+ Dataspace dataspace) {
+ return Error::NONE;
+}
+
+Error VrHwc::getReadbackBufferAttributes_2_3(Display display,
+ PixelFormat* outFormat,
+ Dataspace* outDataspace) {
+ return Error::NONE;
+}
+
+Error VrHwc::getDisplayIdentificationData(Display display, uint8_t* outPort,
+ std::vector<uint8_t>* outData) {
+ int error = 0;
+ auto display_client = display::DisplayClient::Create(&error);
+ if (!display_client) {
+ ALOGE("Could not connect to display service : %s(%d)", strerror(error),
+ error);
+ return Error::BAD_CONFIG;
+ }
+ auto edid_data = display_client->GetConfigurationData(
+ display::ConfigFileType::kDeviceEdid);
+ auto display_identification_port =
+ display_client->GetDisplayIdentificationPort();
+ *outPort = display_identification_port.get();
+
+ std::copy(edid_data.get().begin(), edid_data.get().end(),
+ std::back_inserter(*outData));
+ return Error::NONE;
+}
+
+Error VrHwc::setLayerColorTransform(Display display, Layer layer,
+ const float* matrix) {
+ return Error::NONE;
+}
+
+Error VrHwc::getDisplayedContentSamplingAttributes(
+ Display display, PixelFormat& format, Dataspace& dataspace,
+ hidl_bitfield<IComposerClient::FormatColorComponent>& componentMask) {
+ return Error::NONE;
+}
+
+Error VrHwc::setDisplayedContentSamplingEnabled(
+ Display display, IComposerClient::DisplayedContentSampling enable,
+ hidl_bitfield<IComposerClient::FormatColorComponent> componentMask,
+ uint64_t maxFrames) {
+ return Error::NONE;
+}
+
+Error VrHwc::getDisplayedContentSample(Display display, uint64_t maxFrames,
+ uint64_t timestamp, uint64_t& frameCount,
+ hidl_vec<uint64_t>& sampleComponent0,
+ hidl_vec<uint64_t>& sampleComponent1,
+ hidl_vec<uint64_t>& sampleComponent2,
+ hidl_vec<uint64_t>& sampleComponent3) {
+ return Error::NONE;
+}
+
+Error VrHwc::getDisplayCapabilities(
+ Display display,
+ std::vector<IComposerClient::DisplayCapability>* outCapabilities) {
+ return Error::NONE;
+}
+
+Error VrHwc::setLayerPerFrameMetadataBlobs(
+ Display display, Layer layer,
+ std::vector<IComposerClient::PerFrameMetadataBlob>& blobs) {
+ return Error::NONE;
+}
+
+Error VrHwc::getDisplayBrightnessSupport(Display display, bool* outSupport) {
+ return Error::NONE;
+}
+
+Error VrHwc::setDisplayBrightness(Display display, float brightness) {
+ return Error::NONE;
+}
+
} // namespace dvr
} // namespace android
diff --git a/services/vr/hardware_composer/impl/vr_hwc.h b/services/vr/hardware_composer/impl/vr_hwc.h
index 15358c5..3e3a630 100644
--- a/services/vr/hardware_composer/impl/vr_hwc.h
+++ b/services/vr/hardware_composer/impl/vr_hwc.h
@@ -17,9 +17,9 @@
#define ANDROID_DVR_HARDWARE_COMPOSER_IMPL_VR_HWC_H
#include <android-base/unique_fd.h>
-#include <android/frameworks/vr/composer/1.0/IVrComposerClient.h>
-#include <android/hardware/graphics/composer/2.1/IComposer.h>
-#include <composer-hal/2.1/ComposerHal.h>
+#include <android/frameworks/vr/composer/2.0/IVrComposerClient.h>
+#include <android/hardware/graphics/composer/2.3/IComposer.h>
+#include <composer-hal/2.3/ComposerHal.h>
#include <private/dvr/vsync_service.h>
#include <ui/Fence.h>
#include <ui/GraphicBuffer.h>
@@ -28,15 +28,21 @@
#include <mutex>
#include <unordered_map>
-using namespace android::frameworks::vr::composer::V1_0;
+using namespace android::frameworks::vr::composer::V2_0;
using namespace android::hardware::graphics::common::V1_0;
-using namespace android::hardware::graphics::composer::V2_1;
+using namespace android::hardware::graphics::composer::V2_3;
+using android::hardware::hidl_bitfield;
using android::hardware::hidl_handle;
using android::hardware::hidl_string;
using android::hardware::hidl_vec;
using android::hardware::Return;
using android::hardware::Void;
+using android::hardware::graphics::composer::V2_1::Config;
+using android::hardware::graphics::composer::V2_1::Display;
+using android::hardware::graphics::composer::V2_1::Error;
+using android::hardware::graphics::composer::V2_1::Layer;
+using android::hardware::graphics::composer::V2_3::IComposerClient;
namespace android {
@@ -46,16 +52,23 @@
class VrComposerClient;
-using android::hardware::graphics::common::V1_0::PixelFormat;
-using android::hardware::graphics::composer::V2_1::hal::ComposerHal;
+using android::hardware::graphics::composer::V2_3::hal::ComposerHal;
+
+namespace types = android::hardware::graphics::common;
+
+using types::V1_1::RenderIntent;
+using types::V1_2::ColorMode;
+using types::V1_2::Dataspace;
+using types::V1_2::Hdr;
+using types::V1_2::PixelFormat;
class ComposerView {
public:
struct ComposerLayer {
- using Recti = hardware::graphics::composer::V2_1::IComposerClient::Rect;
- using Rectf = hardware::graphics::composer::V2_1::IComposerClient::FRect;
+ using Recti = hardware::graphics::composer::V2_3::IComposerClient::Rect;
+ using Rectf = hardware::graphics::composer::V2_3::IComposerClient::FRect;
using BlendMode =
- hardware::graphics::composer::V2_1::IComposerClient::BlendMode;
+ hardware::graphics::composer::V2_3::IComposerClient::BlendMode;
Layer id;
sp<GraphicBuffer> buffer;
@@ -111,7 +124,7 @@
struct HwcLayer {
using Composition =
- hardware::graphics::composer::V2_1::IComposerClient::Composition;
+ hardware::graphics::composer::V2_3::IComposerClient::Composition;
explicit HwcLayer(Layer new_id) { info.id = new_id; }
@@ -205,90 +218,148 @@
Display display, Layer layer,
const IVrComposerClient::BufferMetadata& metadata);
- // ComposerHal
+ // composer::V2_1::ComposerHal
bool hasCapability(hwc2_capability_t capability) override;
std::string dumpDebugInfo() override { return {}; }
- void registerEventCallback(EventCallback* callback) override;
+
+ void registerEventCallback(ComposerHal::EventCallback* callback) override;
void unregisterEventCallback() override;
uint32_t getMaxVirtualDisplayCount() override;
- Error createVirtualDisplay(uint32_t width, uint32_t height,
- PixelFormat* format, Display* outDisplay) override;
Error destroyVirtualDisplay(Display display) override;
Error createLayer(Display display, Layer* outLayer) override;
Error destroyLayer(Display display, Layer layer) override;
Error getActiveConfig(Display display, Config* outConfig) override;
- Error getClientTargetSupport(Display display,
- uint32_t width, uint32_t height,
- PixelFormat format, Dataspace dataspace) override;
- Error getColorModes(Display display, hidl_vec<ColorMode>* outModes) override;
Error getDisplayAttribute(Display display, Config config,
- IComposerClient::Attribute attribute, int32_t* outValue) override;
+ IComposerClient::Attribute attribute,
+ int32_t* outValue) override;
Error getDisplayConfigs(Display display, hidl_vec<Config>* outConfigs) override;
Error getDisplayName(Display display, hidl_string* outName) override;
Error getDisplayType(Display display,
- IComposerClient::DisplayType* outType) override;
+ IComposerClient::DisplayType* outType) override;
Error getDozeSupport(Display display, bool* outSupport) override;
- Error getHdrCapabilities(Display display, hidl_vec<Hdr>* outTypes,
- float* outMaxLuminance, float* outMaxAverageLuminance,
- float* outMinLuminance) override;
Error setActiveConfig(Display display, Config config) override;
- Error setColorMode(Display display, ColorMode mode) override;
- Error setPowerMode(Display display, IComposerClient::PowerMode mode) override;
Error setVsyncEnabled(Display display, IComposerClient::Vsync enabled) override;
Error setColorTransform(Display display, const float* matrix,
- int32_t hint) override;
+ int32_t hint) override;
Error setClientTarget(Display display, buffer_handle_t target,
- int32_t acquireFence, int32_t dataspace,
- const std::vector<hwc_rect_t>& damage) override;
+ int32_t acquireFence, int32_t dataspace,
+ const std::vector<hwc_rect_t>& damage) override;
Error setOutputBuffer(Display display, buffer_handle_t buffer,
- int32_t releaseFence) override;
- Error validateDisplay(Display display,
- std::vector<Layer>* outChangedLayers,
- std::vector<IComposerClient::Composition>* outCompositionTypes,
- uint32_t* outDisplayRequestMask,
- std::vector<Layer>* outRequestedLayers,
- std::vector<uint32_t>* outRequestMasks) override;
+ int32_t releaseFence) override;
+ Error validateDisplay(
+ Display display, std::vector<Layer>* outChangedLayers,
+ std::vector<IComposerClient::Composition>* outCompositionTypes,
+ uint32_t* outDisplayRequestMask, std::vector<Layer>* outRequestedLayers,
+ std::vector<uint32_t>* outRequestMasks) override;
Error acceptDisplayChanges(Display display) override;
Error presentDisplay(Display display, int32_t* outPresentFence,
- std::vector<Layer>* outLayers,
- std::vector<int32_t>* outReleaseFences) override;
+ std::vector<Layer>* outLayers,
+ std::vector<int32_t>* outReleaseFences) override;
- Error setLayerCursorPosition(Display display, Layer layer,
- int32_t x, int32_t y) override;
- Error setLayerBuffer(Display display, Layer layer,
- buffer_handle_t buffer, int32_t acquireFence) override;
+ Error setLayerCursorPosition(Display display, Layer layer, int32_t x,
+ int32_t y) override;
+ Error setLayerBuffer(Display display, Layer layer, buffer_handle_t buffer,
+ int32_t acquireFence) override;
Error setLayerSurfaceDamage(Display display, Layer layer,
- const std::vector<hwc_rect_t>& damage) override;
+ const std::vector<hwc_rect_t>& damage) override;
Error setLayerBlendMode(Display display, Layer layer, int32_t mode) override;
Error setLayerColor(Display display, Layer layer,
- IComposerClient::Color color) override;
+ IComposerClient::Color color) override;
Error setLayerCompositionType(Display display, Layer layer,
- int32_t type) override;
+ int32_t type) override;
Error setLayerDataspace(Display display, Layer layer,
- int32_t dataspace) override;
+ int32_t dataspace) override;
Error setLayerDisplayFrame(Display display, Layer layer,
- const hwc_rect_t& frame) override;
+ const hwc_rect_t& frame) override;
Error setLayerPlaneAlpha(Display display, Layer layer, float alpha) override;
Error setLayerSidebandStream(Display display, Layer layer,
- buffer_handle_t stream) override;
+ buffer_handle_t stream) override;
Error setLayerSourceCrop(Display display, Layer layer,
- const hwc_frect_t& crop) override;
+ const hwc_frect_t& crop) override;
Error setLayerTransform(Display display, Layer layer,
- int32_t transform) override;
+ int32_t transform) override;
Error setLayerVisibleRegion(Display display, Layer layer,
- const std::vector<hwc_rect_t>& visible) override;
+ const std::vector<hwc_rect_t>& visible) override;
Error setLayerZOrder(Display display, Layer layer, uint32_t z) override;
+ // composer::V2_2::ComposerHal
+ Error setReadbackBuffer(Display display, const native_handle_t* bufferHandle,
+ android::base::unique_fd fenceFd) override;
+ Error getReadbackBufferFence(Display display,
+ android::base::unique_fd* outFenceFd) override;
+ Error createVirtualDisplay_2_2(uint32_t width, uint32_t height,
+ types::V1_1::PixelFormat* format,
+ Display* outDisplay) override;
+ Error setPowerMode_2_2(Display display,
+ IComposerClient::PowerMode mode) override;
+ Error setLayerFloatColor(Display display, Layer layer,
+ IComposerClient::FloatColor color) override;
+ Error getRenderIntents(Display display, types::V1_1::ColorMode mode,
+ std::vector<RenderIntent>* outIntents) override;
+ std::array<float, 16> getDataspaceSaturationMatrix(
+ types::V1_1::Dataspace dataspace) override;
+
+ // composer::V2_3::ComposerHal
+ Error getHdrCapabilities_2_3(Display display, hidl_vec<Hdr>* outTypes,
+ float* outMaxLuminance,
+ float* outMaxAverageLuminance,
+ float* outMinLuminance) override;
+ Error setLayerPerFrameMetadata_2_3(
+ Display display, Layer layer,
+ const std::vector<IComposerClient::PerFrameMetadata>& metadata) override;
+ Error getPerFrameMetadataKeys_2_3(
+ Display display,
+ std::vector<IComposerClient::PerFrameMetadataKey>* outKeys) override;
+ Error setColorMode_2_3(Display display, ColorMode mode,
+ RenderIntent intent) override;
+ Error getRenderIntents_2_3(Display display, ColorMode mode,
+ std::vector<RenderIntent>* outIntents) override;
+ Error getColorModes_2_3(Display display,
+ hidl_vec<ColorMode>* outModes) override;
+ Error getClientTargetSupport_2_3(Display display, uint32_t width,
+ uint32_t height, PixelFormat format,
+ Dataspace dataspace) override;
+ Error getReadbackBufferAttributes_2_3(Display display, PixelFormat* outFormat,
+ Dataspace* outDataspace) override;
+ Error getDisplayIdentificationData(Display display, uint8_t* outPort,
+ std::vector<uint8_t>* outData) override;
+ Error setLayerColorTransform(Display display, Layer layer,
+ const float* matrix) override;
+ Error getDisplayedContentSamplingAttributes(
+ Display display, PixelFormat& format, Dataspace& dataspace,
+ hidl_bitfield<IComposerClient::FormatColorComponent>& componentMask)
+ override;
+ Error setDisplayedContentSamplingEnabled(
+ Display display, IComposerClient::DisplayedContentSampling enable,
+ hidl_bitfield<IComposerClient::FormatColorComponent> componentMask,
+ uint64_t maxFrames) override;
+ Error getDisplayedContentSample(
+ Display display, uint64_t maxFrames, uint64_t timestamp,
+ uint64_t& frameCount, hidl_vec<uint64_t>& sampleComponent0,
+ hidl_vec<uint64_t>& sampleComponent1,
+ hidl_vec<uint64_t>& sampleComponent2,
+ hidl_vec<uint64_t>& sampleComponent3) override;
+ Error getDisplayCapabilities(Display display,
+ std::vector<IComposerClient::DisplayCapability>*
+ outCapabilities) override;
+ Error setLayerPerFrameMetadataBlobs(
+ Display display, Layer layer,
+ std::vector<IComposerClient::PerFrameMetadataBlob>& blobs) override;
+ Error getDisplayBrightnessSupport(Display display, bool* outSupport) override;
+ Error setDisplayBrightness(Display display, float brightness) override;
+
// IComposer:
Return<void> getCapabilities(getCapabilities_cb hidl_cb) override;
Return<void> dumpDebugInfo(dumpDebugInfo_cb hidl_cb) override;
Return<void> createClient(createClient_cb hidl_cb) override;
+ Return<void> createClient_2_3(
+ IComposer::createClient_2_3_cb hidl_cb) override;
// ComposerView:
void ForceDisplaysRefresh() override;