From: Michael Schuldt Date: Wed, 6 Oct 2010 15:59:03 +0000 (+0200) Subject: Initial Version of LayerManagementService added. X-Git-Tag: borg_release~56 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=55ecedf52489b841f98c4101951236f0511d2fbc;p=profile%2Fivi%2Flayer-management.git Initial Version of LayerManagementService added. --- diff --git a/AUTHORS.txt b/AUTHORS.txt new file mode 100644 index 0000000..07dce9a --- /dev/null +++ b/AUTHORS.txt @@ -0,0 +1,4 @@ +responsible person Michael Schuldt +E-Mail: Michael.Schuldt@bmw-carit.de +responsible person Sven von Beuningen +E-Mail: Sven.vonBeuningen@bmw-carit.de diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..235f674 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,203 @@ +/* + * Apache License + * Version 2.0, January 2004 + * http://www.apache.org/licenses/ + * + * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * + * 1. Definitions. + * + * "License" shall mean the terms and conditions for use, reproduction, + * and distribution as defined by Sections 1 through 9 of this document. + * + * "Licensor" shall mean the copyright owner or entity authorized by + * the copyright owner that is granting the License. + * + * "Legal Entity" shall mean the union of the acting entity and all + * other entities that control, are controlled by, or are under common + * control with that entity. For the purposes of this definition, + * "control" means (i) the power, direct or indirect, to cause the + * direction or management of such entity, whether by contract or + * otherwise, or (ii) ownership of fifty percent (50%) or more of the + * outstanding shares, or (iii) beneficial ownership of such entity. + * + * "You" (or "Your") shall mean an individual or Legal Entity + * exercising permissions granted by this License. + * + * "Source" form shall mean the preferred form for making modifications, + * including but not limited to software source code, documentation + * source, and configuration files. + * + * "Object" form shall mean any form resulting from mechanical + * transformation or translation of a Source form, including but + * not limited to compiled object code, generated documentation, + * and conversions to other media types. + * + * "Work" shall mean the work of authorship, whether in Source or + * Object form, made available under the License, as indicated by a + * copyright notice that is included in or attached to the work + * (an example is provided in the Appendix below). + * + * "Derivative Works" shall mean any work, whether in Source or Object + * form, that is based on (or derived from) the Work and for which the + * editorial revisions, annotations, elaborations, or other modifications + * represent, as a whole, an original work of authorship. For the purposes + * of this License, Derivative Works shall not include works that remain + * separable from, or merely link (or bind by name) to the interfaces of, + * the Work and Derivative Works thereof. + * + * "Contribution" shall mean any work of authorship, including + * the original version of the Work and any modifications or additions + * to that Work or Derivative Works thereof, that is intentionally + * submitted to Licensor for inclusion in the Work by the copyright owner + * or by an individual or Legal Entity authorized to submit on behalf of + * the copyright owner. For the purposes of this definition, "submitted" + * means any form of electronic, verbal, or written communication sent + * to the Licensor or its representatives, including but not limited to + * communication on electronic mailing lists, source code control systems, + * and issue tracking systems that are managed by, or on behalf of, the + * Licensor for the purpose of discussing and improving the Work, but + * excluding communication that is conspicuously marked or otherwise + * designated in writing by the copyright owner as "Not a Contribution." + * + * "Contributor" shall mean Licensor and any individual or Legal Entity + * on behalf of whom a Contribution has been received by Licensor and + * subsequently incorporated within the Work. + * + * 2. Grant of Copyright License. Subject to the terms and conditions of + * this License, each Contributor hereby grants to You a perpetual, + * worldwide, non-exclusive, no-charge, royalty-free, irrevocable + * copyright license to reproduce, prepare Derivative Works of, + * publicly display, publicly perform, sublicense, and distribute the + * Work and such Derivative Works in Source or Object form. + * + * 3. Grant of Patent License. Subject to the terms and conditions of + * this License, each Contributor hereby grants to You a perpetual, + * worldwide, non-exclusive, no-charge, royalty-free, irrevocable + * (except as stated in this section) patent license to make, have made, + * use, offer to sell, sell, import, and otherwise transfer the Work, + * where such license applies only to those patent claims licensable + * by such Contributor that are necessarily infringed by their + * Contribution(s) alone or by combination of their Contribution(s) + * with the Work to which such Contribution(s) was submitted. If You + * institute patent litigation against any entity (including a + * cross-claim or counterclaim in a lawsuit) alleging that the Work + * or a Contribution incorporated within the Work constitutes direct + * or contributory patent infringement, then any patent licenses + * granted to You under this License for that Work shall terminate + * as of the date such litigation is filed. + * + * 4. Redistribution. You may reproduce and distribute copies of the + * Work or Derivative Works thereof in any medium, with or without + * modifications, and in Source or Object form, provided that You + * meet the following conditions: + * + * (a) You must give any other recipients of the Work or + * Derivative Works a copy of this License; and + * + * (b) You must cause any modified files to carry prominent notices + * stating that You changed the files; and + * + * (c) You must retain, in the Source form of any Derivative Works + * that You distribute, all copyright, patent, trademark, and + * attribution notices from the Source form of the Work, + * excluding those notices that do not pertain to any part of + * the Derivative Works; and + * + * (d) If the Work includes a "NOTICE" text file as part of its + * distribution, then any Derivative Works that You distribute must + * include a readable copy of the attribution notices contained + * within such NOTICE file, excluding those notices that do not + * pertain to any part of the Derivative Works, in at least one + * of the following places: within a NOTICE text file distributed + * as part of the Derivative Works; within the Source form or + * documentation, if provided along with the Derivative Works; or, + * within a display generated by the Derivative Works, if and + * wherever such third-party notices normally appear. The contents + * of the NOTICE file are for informational purposes only and + * do not modify the License. You may add Your own attribution + * notices within Derivative Works that You distribute, alongside + * or as an addendum to the NOTICE text from the Work, provided + * that such additional attribution notices cannot be construed + * as modifying the License. + * + * You may add Your own copyright statement to Your modifications and + * may provide additional or different license terms and conditions + * for use, reproduction, or distribution of Your modifications, or + * for any such Derivative Works as a whole, provided Your use, + * reproduction, and distribution of the Work otherwise complies with + * the conditions stated in this License. + * + * 5. Submission of Contributions. Unless You explicitly state otherwise, + * any Contribution intentionally submitted for inclusion in the Work + * by You to the Licensor shall be under the terms and conditions of + * this License, without any additional terms or conditions. + * Notwithstanding the above, nothing herein shall supersede or modify + * the terms of any separate license agreement you may have executed + * with Licensor regarding such Contributions. + * + * 6. Trademarks. This License does not grant permission to use the trade + * names, trademarks, service marks, or product names of the Licensor, + * except as required for reasonable and customary use in describing the + * origin of the Work and reproducing the content of the NOTICE file. + * + * 7. Disclaimer of Warranty. Unless required by applicable law or + * agreed to in writing, Licensor provides the Work (and each + * Contributor provides its Contributions) on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied, including, without limitation, any warranties or conditions + * of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + * PARTICULAR PURPOSE. You are solely responsible for determining the + * appropriateness of using or redistributing the Work and assume any + * risks associated with Your exercise of permissions under this License. + * + * 8. Limitation of Liability. In no event and under no legal theory, + * whether in tort (including negligence), contract, or otherwise, + * unless required by applicable law (such as deliberate and grossly + * negligent acts) or agreed to in writing, shall any Contributor be + * liable to You for damages, including any direct, indirect, special, + * incidental, or consequential damages of any character arising as a + * result of this License or out of the use or inability to use the + * Work (including but not limited to damages for loss of goodwill, + * work stoppage, computer failure or malfunction, or any and all + * other commercial damages or losses), even if such Contributor + * has been advised of the possibility of such damages. + * + * 9. Accepting Warranty or Additional Liability. While redistributing + * the Work or Derivative Works thereof, You may choose to offer, + * and charge a fee for, acceptance of support, warranty, indemnity, + * or other liability obligations and/or rights consistent with this + * License. However, in accepting such obligations, You may act only + * on Your own behalf and on Your sole responsibility, not on behalf + * of any other Contributor, and only if You agree to indemnify, + * defend, and hold each Contributor harmless for any liability + * incurred by, or claims asserted against, such Contributor by reason + * of your accepting any such warranty or additional liability. + * + * END OF TERMS AND CONDITIONS + * + * APPENDIX: How to apply the Apache License to your work. + * + * To apply the Apache License to your work, attach the following + * boilerplate notice, with the fields enclosed by brackets "[]" + * replaced with your own identifying information. (Don't include + * the brackets!) The text should be enclosed in the appropriate + * comment syntax for the file format. We also recommend that a + * file or class name and description of purpose be included on the + * same "printed page" as the copyright notice for easier + * identification within third-party archives. + * + * Copyright [yyyy] [name of copyright owner] + * + * 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. + */ \ No newline at end of file diff --git a/LayerManagerPlatform/MakeBeagle.defs b/LayerManagerPlatform/MakeBeagle.defs new file mode 100644 index 0000000..5841a50 --- /dev/null +++ b/LayerManagerPlatform/MakeBeagle.defs @@ -0,0 +1,28 @@ +############################################################################ +# +# Copyright 2010 BMW Car IT GmbH +# +# +# 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. +# +############################################################################ + +CXXFLAGS = -Wall -fPIC -O2 + +ADD_INCLUDE_DIR+=/home/carit/beagleIncludes + +ADD_LIB_DIR+= /home/carit/beagleIncludes + +LINKFLAGS = -Xlinker -export-dynamic + +CXX = /home/carit/toolchain/arm-2009q1/bin/arm-none-linux-gnueabi-g++ \ No newline at end of file diff --git a/LayerManagerPlugins/Communicators/DBUSCommunicator/compositeServiceDescription.xml b/LayerManagerPlugins/Communicators/DBUSCommunicator/compositeServiceDescription.xml new file mode 100644 index 0000000..918c718 --- /dev/null +++ b/LayerManagerPlugins/Communicators/DBUSCommunicator/compositeServiceDescription.xml @@ -0,0 +1,404 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LayerManagerPlugins/Communicators/DBUSCommunicator/generateBinding.sh b/LayerManagerPlugins/Communicators/DBUSCommunicator/generateBinding.sh new file mode 100644 index 0000000..c5f888e --- /dev/null +++ b/LayerManagerPlugins/Communicators/DBUSCommunicator/generateBinding.sh @@ -0,0 +1,25 @@ +#!/bin/bash +############################################################################ +# +# Copyright 2010 BMW Car IT GmbH +# +# +# 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. +# +############################################################################ + +# call binding tool to generate server stubs and marshallers +dbus-binding-tool --mode=glib-server --prefix=compositeService --output=./include/compositeServiceBinding.h compositeServiceDescription.xml +dbus-binding-tool --mode=glib-client --prefix=compositeService --output=./include/compositeServiceClient.h compositeServiceDescription.xml +# output java binding files to console: +CreateInterface compositeServiceDescription.xml diff --git a/LayerManagerPlugins/Communicators/DBUSCommunicator/include/DBUSCommunicator.h b/LayerManagerPlugins/Communicators/DBUSCommunicator/include/DBUSCommunicator.h new file mode 100644 index 0000000..bded786 --- /dev/null +++ b/LayerManagerPlugins/Communicators/DBUSCommunicator/include/DBUSCommunicator.h @@ -0,0 +1,109 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _DBUSCOMMUNICATOR_H_ +#define _DBUSCOMMUNICATOR_H_ + +#include "BaseCommunicator.h" +#include "CommandExecutor.h" +#include "Log.h" +#include + +class DBUSCommunicator: public BaseCommunicator{ +public: + DBUSCommunicator(CommandExecutor* executor, ILayerList* ll); + virtual ~DBUSCommunicator(); + virtual bool start(); + virtual void stop(); + virtual void setdebug(bool onoff); + + void Debug(DBusConnection* conn,DBusMessage* msg ); + void ListAllLayerIDS(DBusConnection* conn,DBusMessage* msg ); + void ListAllSurfaceIDS(DBusConnection* conn,DBusMessage* msg ); + void ListAllLayerGroupIDS(DBusConnection* conn,DBusMessage* msg ); + void ListAllSurfaceGroupIDS(DBusConnection* conn,DBusMessage* msg ); + void ListSurfacesOfSurfacegroup(DBusConnection* conn,DBusMessage* msg ); + void ListLayersOfLayergroup(DBusConnection* conn,DBusMessage* msg ); + void ListSurfaceofLayer(DBusConnection* conn,DBusMessage* msg ); + void getPropertiesOfSurface(DBusConnection* conn,DBusMessage* msg ); + void getPropertiesOfLayer(DBusConnection* conn,DBusMessage* msg ); + void CreateSurface(DBusConnection* conn,DBusMessage* msg ); + void RemoveSurface(DBusConnection* conn,DBusMessage* msg ); + void CreateLayer(DBusConnection* conn,DBusMessage* msg ); + void RemoveLayer(DBusConnection* conn,DBusMessage* msg ); + void AddSurfaceToSurfaceGroup(DBusConnection* conn,DBusMessage* msg ); + void RemoveSurfaceFromSurfaceGroup(DBusConnection* conn,DBusMessage* msg ); + void AddLayerToLayerGroup(DBusConnection* conn,DBusMessage* msg ); + void RemoveLayerFromLayerGroup(DBusConnection* conn,DBusMessage* msg ); + void AddSurfaceToLayer(DBusConnection* conn,DBusMessage* msg ); + void RemoveSurfaceFromLayer(DBusConnection* conn,DBusMessage* msg ); + void CreateSurfaceGroup(DBusConnection* conn,DBusMessage* msg ); + void RemoveSurfaceGroup(DBusConnection* conn,DBusMessage* msg ); + void CreateLayerGroup(DBusConnection* conn,DBusMessage* msg ); + void RemoveLayerGroup(DBusConnection* conn,DBusMessage* msg ); + void SetSurfaceSourceRegion(DBusConnection* conn,DBusMessage* msg ); + void SetLayerSourceRegion(DBusConnection* conn,DBusMessage* msg ); + void SetSurfaceDestinationRegion(DBusConnection* conn,DBusMessage* msg ); + void SetSurfacePosition(DBusConnection* conn,DBusMessage* msg ); + void GetSurfacePosition(DBusConnection* conn,DBusMessage* msg ); + void SetSurfaceDimension(DBusConnection* conn,DBusMessage* msg ); + void SetLayerDestinationRegion(DBusConnection* conn,DBusMessage* msg ); + void SetLayerPosition(DBusConnection* conn,DBusMessage* msg ); + void GetLayerPosition(DBusConnection* conn,DBusMessage* msg ); + void SetLayerDimension(DBusConnection* conn,DBusMessage* msg ); + void GetLayerDimension(DBusConnection* conn,DBusMessage* msg ); + void GetSurfaceDimension(DBusConnection* conn,DBusMessage* msg ); + void SetSurfaceOpacity(DBusConnection* conn,DBusMessage* msg ); + void SetLayerOpacity(DBusConnection* conn,DBusMessage* msg ); + void SetSurfacegroupOpacity(DBusConnection* conn,DBusMessage* msg ); + void SetLayergroupOpacity(DBusConnection* conn,DBusMessage* msg ); + void GetSurfaceOpacity(DBusConnection* conn,DBusMessage* msg ); + void GetLayerOpacity(DBusConnection* conn,DBusMessage* msg ); + void GetSurfacegroupOpacity(DBusConnection* conn,DBusMessage* msg ); + void GetLayergroupOpacity(DBusConnection* conn,DBusMessage* msg ); + void SetSurfaceOrientation(DBusConnection* conn,DBusMessage* msg ); + void SetLayerOrientation(DBusConnection* conn,DBusMessage* msg ); + void GetSurfacePixelformat(DBusConnection* conn,DBusMessage* msg ); + void SetSurfaceVisibility(DBusConnection* conn,DBusMessage* msg ); + void SetLayerVisibility(DBusConnection* conn,DBusMessage* msg ); + void GetSurfaceVisibility(DBusConnection* conn,DBusMessage* msg ); + void GetLayerVisibility(DBusConnection* conn,DBusMessage* msg ); + void SetSurfacegroupVisibility(DBusConnection* conn,DBusMessage* msg ); + void SetLayergroupVisibility(DBusConnection* conn,DBusMessage* msg ); + void SetRenderOrderOfLayers(DBusConnection* conn,DBusMessage* msg ); + void SetSurfaceRenderOrderWithinLayer(DBusConnection* conn,DBusMessage* msg ); + void GetLayerType(DBusConnection* conn,DBusMessage* msg ); + void GetLayertypeCapabilities(DBusConnection* conn,DBusMessage* msg ); + void GetLayerCapabilities(DBusConnection* conn,DBusMessage* msg ); + void FadeIn(DBusConnection* conn,DBusMessage* msg ); + void SynchronizedFade(DBusConnection* conn,DBusMessage* msg ); + void FadeOut(DBusConnection* conn,DBusMessage* msg ); + void Exit(DBusConnection* conn,DBusMessage* msg ); + void CommitChanges(DBusConnection* conn,DBusMessage* msg ); + void CreateShader(DBusConnection* conn,DBusMessage* msg ); + void DestroyShader(DBusConnection* conn,DBusMessage* msg ); + void SetShader(DBusConnection* conn,DBusMessage* msg ); + void SetUniforms(DBusConnection* conn,DBusMessage* msg ); +private: + static void* run(void * threadid); + pthread_t m_currentThread; + static DBUSCommunicator* m_reference; + bool m_running; +}; + +#endif /* _DBUSCOMMUNICATOR_H_ */ diff --git a/LayerManagerPlugins/Communicators/DBUSCommunicator/makefile b/LayerManagerPlugins/Communicators/DBUSCommunicator/makefile new file mode 100644 index 0000000..705841b --- /dev/null +++ b/LayerManagerPlugins/Communicators/DBUSCommunicator/makefile @@ -0,0 +1,64 @@ +############################################################################ +# +# Copyright 2010 BMW Car IT GmbH +# +# +# 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. +# +############################################################################ + +ifneq ($(CONFIG),) +include ../../../LayerManagerPlatform/Make$(CONFIG).defs +endif + +SRC += DBUSCommunicator.cpp + +TARGET_NAME = libDBUSCommunicator.so +LIB_NAME = $(TARGET_NAME).1.0 + +ADD_INCLUDE_DIR=include \ + $(PREFIX)/usr/include/dbus-1.0 \ + $(PREFIX)/usr/lib/dbus-1.0/include \ + $(PREFIX)/usr/include/layermanager \ +$(PREFIX)/usr/local/include/dbus-1.0 \ +$(PREFIX)/usr/local/lib/dbus-1.0/include + + +ADD_LIB_DIR+=$(PREFIX)/usr/local/lib/dbus-1 \ + $(PREFIX)/usr/lib/dbus-1 \ + $(PREFIX)/usr/lib/layermanager + +ADD_LIBS+= pthread dbus-1 LayerManagerUtils + +OBJS += $(patsubst %.cpp,build/%.o,$(SRC)) +LINK = +TARGET = build/$(TARGET_NAME) +INCLUDE= $(patsubst %$,-I%,$(ADD_INCLUDE_DIR)) +LIBS+=$(shell pkg-config --libs $(PKG)) $(patsubst %$,-L%,$(ADD_LIB_DIR)) $(patsubst %$,-l%,$(ADD_LIBS)) + +all: $(TARGET) + +build/%.o: src/%.cpp + $(shell mkdir -p $(shell dirname $@)) + $(CXX) -Wall -fPIC -O2 $(INCLUDE) -c -o $@ $< + +$(TARGET): $(OBJS) + $(CXX) -Wall -fPIC -O2 -shared -W1,-soname, -Xlinker -export-dynamic -o $(TARGET) $(OBJS) $(LIBS) + +install: + mkdir -p $(PREFIX)/usr/lib/layermanager/communicator + install -m 755 $(TARGET) $(PREFIX)/usr/lib/layermanager/communicator + +clean: + rm -f $(OBJS) $(TARGET) + rm -rf build diff --git a/LayerManagerPlugins/Communicators/DBUSCommunicator/src/DBUSCommunicator.cpp b/LayerManagerPlugins/Communicators/DBUSCommunicator/src/DBUSCommunicator.cpp new file mode 100644 index 0000000..a954a2d --- /dev/null +++ b/LayerManagerPlugins/Communicators/DBUSCommunicator/src/DBUSCommunicator.cpp @@ -0,0 +1,1327 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 +#include +#include +#include +#include +#include +#include + +#include "DBUSCommunicator.h" +#include "Log.h" + +#define CONNMAN_SERVICE "de.bmw.CompositingService" +#define CONNMAN_PATH "/de/bmw/CompositingService" + +typedef void (DBUSCommunicator::*CallBackMethod) (DBusConnection *connection, DBusMessage *message); + +typedef struct { + const char *name; + const char *signature; + const char *reply; + CallBackMethod function; +} MethodTable; + +static MethodTable manager_methods[] = { + { "Debug", "b", "", &DBUSCommunicator::Debug }, + { "ListAllLayerIDS", "", "au", &DBUSCommunicator::ListAllLayerIDS}, + { "ListAllSurfaceIDS", "", "au", &DBUSCommunicator::ListAllSurfaceIDS}, + { "ListAllLayerGroupIDS", "", "au", &DBUSCommunicator::ListAllLayerGroupIDS}, + { "ListAllSurfaceGroupIDS", "", "au", &DBUSCommunicator::ListAllSurfaceGroupIDS}, + { "ListSurfacesOfSurfacegroup", "u", "au", &DBUSCommunicator::ListSurfacesOfSurfacegroup}, + { "ListLayersOfLayergroup", "u", "au", &DBUSCommunicator::ListLayersOfLayergroup}, + { "ListSurfaceofLayer", "u", "au", &DBUSCommunicator::ListSurfaceofLayer}, + { "getPropertiesOfSurface", "u", "duuuuuuuuyb", &DBUSCommunicator::getPropertiesOfSurface}, + { "getPropertiesOfLayer", "u", "duuuuuuuuyb", &DBUSCommunicator::getPropertiesOfLayer }, + { "CreateSurface", "uuuu", "u", &DBUSCommunicator::CreateSurface}, + { "RemoveSurface", "u", "", &DBUSCommunicator::RemoveSurface }, + { "CreateLayer", "", "u", &DBUSCommunicator::CreateLayer }, + { "RemoveLayer", "u", "", &DBUSCommunicator::RemoveLayer }, + { "AddSurfaceToSurfaceGroup", "uu", "", &DBUSCommunicator::AddSurfaceToSurfaceGroup }, + { "RemoveSurfaceFromSurfaceGroup", "uu", "", &DBUSCommunicator::RemoveSurfaceFromSurfaceGroup }, + { "AddLayerToLayerGroup", "uu", "", &DBUSCommunicator::AddLayerToLayerGroup}, + { "RemoveLayerFromLayerGroup", "uu", "", &DBUSCommunicator::RemoveLayerFromLayerGroup }, + { "AddSurfaceToLayer", "uu", "", &DBUSCommunicator::AddSurfaceToLayer }, + { "RemoveSurfaceFromLayer", "uu", "", &DBUSCommunicator::RemoveSurfaceFromLayer}, + { "CreateSurfaceGroup", "", "u", &DBUSCommunicator::CreateSurfaceGroup }, + { "RemoveSurfaceGroup", "u", "", &DBUSCommunicator::RemoveSurfaceGroup}, + { "CreateLayerGroup", "", "u", &DBUSCommunicator::CreateLayerGroup }, + { "RemoveLayerGroup", "u", "", &DBUSCommunicator::RemoveLayerGroup }, + { "SetSurfaceSourceRegion", "uuuuu", "", &DBUSCommunicator::SetSurfaceSourceRegion }, + { "SetLayerSourceRegion", "uuuuu", "", &DBUSCommunicator::SetLayerSourceRegion}, + { "SetSurfaceDestinationRegion", "uuuuu", "", &DBUSCommunicator::SetSurfaceDestinationRegion}, + { "SetSurfacePosition", "uuu", "", &DBUSCommunicator::SetSurfacePosition }, + { "GetSurfacePosition", "u", "uu", &DBUSCommunicator::GetSurfacePosition }, + { "SetSurfaceDimension", "uuu", "", &DBUSCommunicator::SetSurfaceDimension}, + { "SetLayerDestinationRegion", "uuuuu", "", &DBUSCommunicator::SetLayerDestinationRegion}, + { "SetLayerPosition", "uuu", "", &DBUSCommunicator::SetLayerPosition}, + { "GetLayerPosition", "u", "uu", &DBUSCommunicator::GetLayerPosition}, + { "SetLayerDimension", "uuu", "", &DBUSCommunicator::SetLayerDimension}, + { "GetLayerDimension", "u", "uu", &DBUSCommunicator::GetLayerDimension}, + { "GetSurfaceDimension", "u", "uu", &DBUSCommunicator::GetSurfaceDimension}, + { "SetSurfaceOpacity", "ud", "", &DBUSCommunicator::SetSurfaceOpacity}, + { "SetLayerOpacity", "ud", "", &DBUSCommunicator::SetLayerOpacity }, + { "SetSurfacegroupOpacity", "ud", "", &DBUSCommunicator::SetSurfacegroupOpacity }, + { "SetLayergroupOpacity", "ud", "", &DBUSCommunicator::SetLayergroupOpacity }, + { "GetSurfaceOpacity", "u", "d", &DBUSCommunicator::GetSurfaceOpacity }, + { "GetLayerOpacity", "u", "d", &DBUSCommunicator::GetLayerOpacity }, + { "GetSurfacegroupOpacity", "u", "d", &DBUSCommunicator::GetSurfacegroupOpacity }, + { "GetLayergroupOpacity", "u", "d", &DBUSCommunicator::GetLayergroupOpacity }, + { "SetSurfaceOrientation", "uu", "", &DBUSCommunicator::SetSurfaceOrientation }, + { "SetLayerOrientation", "uu", "", &DBUSCommunicator::SetLayerOrientation }, + { "GetSurfacePixelformat", "u", "u", &DBUSCommunicator::GetSurfacePixelformat }, + { "SetSurfaceVisibility", "ub", "", &DBUSCommunicator::SetSurfaceVisibility }, + { "SetLayerVisibility", "ub", "", &DBUSCommunicator::SetLayerVisibility }, + { "GetSurfaceVisibility", "u", "b", &DBUSCommunicator::GetSurfaceVisibility }, + { "GetLayerVisibility", "u", "b", &DBUSCommunicator::GetLayerVisibility }, + { "SetSurfacegroupVisibility", "ub", "", &DBUSCommunicator::SetSurfacegroupVisibility }, + { "SetLayergroupVisibility", "ub", "", &DBUSCommunicator::SetLayergroupVisibility }, + { "SetRenderOrderOfLayers", "auu", "", &DBUSCommunicator::SetRenderOrderOfLayers }, + { "SetSurfaceRenderOrderWithinLayer", "uau", "", &DBUSCommunicator::SetSurfaceRenderOrderWithinLayer }, + { "GetLayerType", "u", "u",&DBUSCommunicator::GetLayerType }, + { "GetLayertypeCapabilities", "u", "u", &DBUSCommunicator::GetLayertypeCapabilities }, + { "GetLayerCapabilities", "u", "u", &DBUSCommunicator::GetLayerCapabilities }, + { "Exit", "", "", &DBUSCommunicator::Exit }, + { "CommitChanges", "", "", &DBUSCommunicator::CommitChanges }, + { "CreateShader", "ss", "u", &DBUSCommunicator::CreateShader }, + { "DestroyShader", "u", "", &DBUSCommunicator::DestroyShader}, + { "SetShader", "uu", "", &DBUSCommunicator::SetShader }, + { "SetUniforms", "uas", "", &DBUSCommunicator::SetUniforms }, + { "","","",NULL} + }; + +#include + +DBusMessageIter iter; +DBusMessage* currentMsg; +DBusMessage* reply; +dbus_uint32_t serial = 0; +DBusConnection* conn; + +char* getStringFromMessage(){ + char* param; + + if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&iter)){ + LOG_ERROR("DBUSCommunicator", "Argument is not string!"); + }else{ + dbus_message_iter_get_basic(&iter, ¶m); + } + return param; +} + +bool getBoolFromMessage(){ + dbus_bool_t boolparam; + + if (DBUS_TYPE_BOOLEAN != dbus_message_iter_get_arg_type(&iter)){ + LOG_ERROR("DBUSCommunicator", "Argument is not bool!"); + }else{ + dbus_message_iter_get_basic(&iter, &boolparam); + } + bool b; + if (boolparam==0) + b = false; + else + b = true; + return b; +} + +char getByteFromMessage(){ + char param; + + if (DBUS_TYPE_BYTE != dbus_message_iter_get_arg_type(&iter)){ + LOG_ERROR("DBUSCommunicator", "Argument is not byte!"); + }else{ + dbus_message_iter_get_basic(&iter, ¶m); + } + return param; +} + +uint getUIntFromMessage(){ + uint param; + + if (DBUS_TYPE_UINT32 != dbus_message_iter_get_arg_type(&iter)){ + LOG_ERROR("DBUSCommunicator", "Argument is not uint32!"); + }else{ + dbus_message_iter_get_basic(&iter, ¶m); + } + return param; +} + + + +double getDoubleFromMessage(){ + double param; + + if (DBUS_TYPE_DOUBLE != dbus_message_iter_get_arg_type(&iter)){ + LOG_ERROR("DBUSCommunicator","Argument is not double!"); + }else{ + dbus_message_iter_get_basic(&iter, ¶m); + } + return param; +} + + +void appendBool(bool toAppend){ + if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_BOOLEAN, &toAppend)) { + LOG_ERROR("DBUSCommunicator", "Out Of Memory!"); + exit(1); + } +} + +void appendUint(uint toAppend){ + if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT32, &toAppend)) { + LOG_ERROR("DBUSCommunicator", "Out Of Memory!"); + exit(1); + } +} + +void appendDouble(double toAppend){ + if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_DOUBLE, &toAppend)) { + LOG_ERROR("DBUSCommunicator", "Out Of Memory!"); + exit(1); + } +} + +void appendbyte(char toAppend){ + if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_BYTE, &toAppend)) { + LOG_ERROR("DBUSCommunicator", "Out Of Memory!"); + exit(1); + } +} + +void initReceive(DBusMessage* msg){ + currentMsg = msg; + if (!dbus_message_iter_init(currentMsg, &iter)) + LOG_ERROR("DBUSCommunicator", "Message has no arguments!"); +} + +void initReply(){ + // create a reply from the message + reply = dbus_message_new_method_return(currentMsg); + dbus_message_iter_init_append(reply, &iter); +} + +void closeReply(){ + // send the reply && flush the connection + if (!dbus_connection_send(conn, reply, &serial)) { + LOG_ERROR("DBUSCommunicator", "Out Of Memory!"); + exit(1); + } + dbus_connection_flush(conn); + + // free the reply + dbus_message_unref(reply); +} + + + +void addIntrospectHeader(std::string& str){ + str.append(" \n"); +} + +void addIntrospectNode(std::string& str, std::string nodename){ + str.append(" \n"); +} + +void addIntrospectinterface(std::string& str, std::string interfacename){ + str.append(" \n"); +} + +void addIntrospectMethod(std::string& str, std::string methodname){ + str.append(" \n"); +} + +void addIntrospectArg(std::string& str, std::string argname,std::string direction,std::string type){ + str.append(" \n"); +} + +void closeIntrospectMethod(std::string& str){ + str.append(" \n"); +} + +void closeIntrospectInterface(std::string& str){ + str.append(" \n"); +} + +void closeIntrospectNode(std::string& str){ + str.append(" \n"); +} + +std::string generateIntrospectionString(MethodTable* table){ +LOG_DEBUG("DBUSCommunicator", "Generation introspection data"); + std::string introspect; + addIntrospectHeader(introspect); + addIntrospectNode(introspect, "de.bmw.CompositingService"); + addIntrospectinterface(introspect, "org.freedesktop.DBus.Introspectable"); + addIntrospectMethod(introspect,"Introspect"); + addIntrospectArg(introspect,"data","out","s"); + closeIntrospectMethod(introspect); + closeIntrospectInterface(introspect); + + addIntrospectinterface(introspect, "de.bmw.CompositingService"); + + int i=0; + while(strcmp(manager_methods[i].name,"")!=0){ + MethodTable entry = table[i]; + addIntrospectMethod(introspect,std::string(entry.name)); + std::string signatureIN = std::string(entry.signature); + for (int c=0;cm_running = true; + pthread_create(&m_currentThread, NULL, DBUSCommunicator::run, this); + LOG_INFO("DBUSCommunicator", "Started dbus connector"); + return true; +} + +void DBUSCommunicator::stop(){ + LOG_INFO("DBUSCommunicator","stopping"); + this->m_running = false; + pthread_join(m_currentThread,NULL); + DBusError err; + dbus_error_init(&err); + bool errorset = dbus_error_is_set(&err); + if (errorset) + LOG_ERROR("DBUSCommunicator","there was an dbus error"); + LOG_INFO("ask about owner name",0); + dbus_bus_name_has_owner(conn,"de.bmw.CompositingService",&err); + errorset = dbus_error_is_set(&err); + if (errorset) + LOG_ERROR("DBUSCommunicator","there was an dbus error"); + dbus_error_init(&err); + dbus_bus_release_name(conn, "de.bmw.CompositingService",&err); + LOG_INFO("DBUSCommunicator", "Stopped dbus connector"); +} + +void introspectCallback(DBusConnection* conn,DBusMessage* msg ) +{ + DBusMessage* reply; + DBusMessageIter args; + dbus_uint32_t serial = 0; + char* param; + + // create a reply from the message + reply = dbus_message_new_method_return(msg); + + std::string introspect = generateIntrospectionString(manager_methods); + + + const char* string = introspect.c_str(); + // add the arguments to the reply + dbus_message_iter_init_append(reply, &args); + if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &string)) { + LOG_ERROR("DBUSCommunicator", "Out Of Memory!"); + exit(1); + } + + // send the reply && flush the connection + if (!dbus_connection_send(conn, reply, &serial)) { + LOG_ERROR("DBUSCommunicator", "Out Of Memory!"); + exit(1); + } + dbus_connection_flush(conn); + + // free the reply + dbus_message_unref(reply); +} + +void DBUSCommunicator::Debug(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + bool param = getBoolFromMessage(); + + m_reference->m_executor->execute(new DebugCommand(param)); + + initReply(); + closeReply(); +} + +void DBUSCommunicator::ListAllLayerIDS(DBusConnection* conn,DBusMessage* msg ) +{ + currentMsg = msg; + int* array = NULL; + int length = 0; + m_reference->m_layerlist->getLayerIDs(&length,&array); + initReply(); + DBusMessageIter arrayIter; + dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "u", &arrayIter); + for ( int i = 0; i< length;i++) + dbus_message_iter_append_basic(&arrayIter,DBUS_TYPE_UINT32,&array[i]); + dbus_message_iter_close_container(&iter,&arrayIter); + closeReply(); +} + +void DBUSCommunicator::ListAllSurfaceIDS(DBusConnection* conn,DBusMessage* msg ) +{ + currentMsg = msg; + int* array = NULL; + int length = 0; + m_reference->m_layerlist->getSurfaceIDs(&length,&array); + initReply(); + DBusMessageIter arrayIter; + dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "u", &arrayIter); + for ( int i = 0; i< length;i++) + dbus_message_iter_append_basic(&arrayIter,DBUS_TYPE_UINT32,&array[i]); + dbus_message_iter_close_container(&iter,&arrayIter); + closeReply(); +} + +void DBUSCommunicator::ListAllLayerGroupIDS(DBusConnection* conn,DBusMessage* msg ) +{ + currentMsg = msg; + int* array = NULL; + int length = 0; + m_reference->m_layerlist->getLayerGroupIDs(&length,&array); + initReply(); + DBusMessageIter arrayIter; + dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "u", &arrayIter); + for ( int i = 0; i< length;i++) + dbus_message_iter_append_basic(&arrayIter,DBUS_TYPE_UINT32,&array[i]); + dbus_message_iter_close_container(&iter,&arrayIter); + closeReply(); +} + +void DBUSCommunicator::ListAllSurfaceGroupIDS(DBusConnection* conn,DBusMessage* msg ) +{ + currentMsg = msg; + int* array = NULL; + int length = 0; + m_reference->m_layerlist->getSurfaceGroupIDs(&length,&array); + initReply(); + DBusMessageIter arrayIter; + dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "u", &arrayIter); + for ( int i = 0; i< length;i++) + dbus_message_iter_append_basic(&arrayIter,DBUS_TYPE_UINT32,&array[i]); + dbus_message_iter_close_container(&iter,&arrayIter); + closeReply(); +} + +void DBUSCommunicator::ListSurfacesOfSurfacegroup(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + SurfaceGroup* sg = m_reference->m_layerlist->getSurfaceGroup(id); + std::list surfaces = sg->getList(); + initReply(); + DBusMessageIter arrayIter; + dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "u", &arrayIter); + for ( std::list::const_iterator it=surfaces.begin();it!=surfaces.end();it++){ + Surface* s = *it; + int id = s->getID(); + dbus_message_iter_append_basic(&arrayIter,DBUS_TYPE_UINT32,&id); + } + dbus_message_iter_close_container(&iter,&arrayIter); + closeReply(); +} + +void DBUSCommunicator::ListLayersOfLayergroup(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + + LayerGroup* sg = m_reference->m_layerlist->getLayerGroup(id); + std::list layers = sg->getList(); + initReply(); + DBusMessageIter arrayIter; + dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "u", &arrayIter); + for ( std::list::const_iterator it=layers.begin();it!=layers.end();it++){ + Layer* l = *it; + int id = l->getID(); + dbus_message_iter_append_basic(&arrayIter,DBUS_TYPE_UINT32,&id); + } + dbus_message_iter_close_container(&iter,&arrayIter); + closeReply(); +} + +void DBUSCommunicator::ListSurfaceofLayer(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + + Layer* layer = m_reference->m_layerlist->getLayer(id); + std::list surfaces = layer->getAllSurfaces(); + initReply(); + DBusMessageIter arrayIter; + dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "u", &arrayIter); + for ( std::list::const_iterator it=surfaces.begin();it!=surfaces.end();it++){ + Surface* s = *it; + int id = s->getID(); + dbus_message_iter_append_basic(&arrayIter,DBUS_TYPE_UINT32,&id); + } + dbus_message_iter_close_container(&iter,&arrayIter); + closeReply(); +} + +void DBUSCommunicator::getPropertiesOfSurface(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + + Surface* surface = m_reference->m_layerlist->getSurface(id); + + initReply(); + appendDouble(surface->getOpacity()); + Rectangle dest = surface->getDestinationRegion(); + Rectangle src = surface->getDestinationRegion(); + appendUint(src.x); + appendUint(src.y); + appendUint(src.width); + appendUint(src.height); + appendUint(dest.x); + appendUint(dest.y); + appendUint(dest.width); + appendUint(dest.height); + OrientationType orientation = surface->getOrientation(); + appendbyte((char)orientation); + appendBool(surface->getVisibility()); + closeReply(); +} + +void DBUSCommunicator::getPropertiesOfLayer(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + + Layer* layer = m_reference->m_layerlist->getLayer(id); + + initReply(); + appendDouble(layer->getOpacity()); + Rectangle dest = layer->getDestinationRegion(); + Rectangle src = layer->getDestinationRegion(); + appendUint(src.x); + appendUint(src.y); + appendUint(src.width); + appendUint(src.height); + appendUint(dest.x); + appendUint(dest.y); + appendUint(dest.width); + appendUint(dest.height); + OrientationType orientation = layer->getOrientation(); + appendbyte((char)orientation); + appendBool(layer->getVisibility()); + closeReply(); +} + +void DBUSCommunicator::CreateSurface(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint handle = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint pixelformat = getUIntFromMessage(); + PixelFormat pf = (PixelFormat)pixelformat; + + dbus_message_iter_next(&iter); + uint width = getUIntFromMessage(); + + dbus_message_iter_next(&iter); + uint height = getUIntFromMessage(); + uint id; + m_reference->m_executor->execute(new CreateCommand(handle,TypeSurface,pf, width, height,&id)); + initReply(); + appendUint(id); + closeReply(); +} + +void DBUSCommunicator::RemoveSurface(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint param = getUIntFromMessage(); + m_reference->m_executor->execute(new RemoveCommand(param,TypeSurface)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::CreateLayer(DBusConnection* conn,DBusMessage* msg ) +{ + currentMsg = msg; + uint id; + m_reference->m_executor->execute(new CreateCommand(-1,TypeLayer,PIXELFORMAT_R8,0,0,&id)); + initReply(); + appendUint(id); + closeReply(); +} + +void DBUSCommunicator::RemoveLayer(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint param = getUIntFromMessage(); + m_reference->m_executor->execute(new RemoveCommand(param,TypeLayer)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::AddSurfaceToSurfaceGroup(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint surfaceid = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint surfacegroupid = getUIntFromMessage(); + m_reference->m_executor->execute(new SurfacegroupAddSurfaceCommand(surfacegroupid,surfaceid)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::RemoveSurfaceFromSurfaceGroup(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint surfaceid = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint surfacegroupid = getUIntFromMessage(); + m_reference->m_executor->execute(new SurfacegroupRemoveSurfaceCommand(surfacegroupid,surfaceid)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::AddLayerToLayerGroup(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint layerid = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint layergroupid = getUIntFromMessage(); + m_reference->m_executor->execute(new LayergroupAddLayerCommand(layergroupid,layerid)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::RemoveLayerFromLayerGroup(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint layerid = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint layergroupid = getUIntFromMessage(); + m_reference->m_executor->execute(new LayergroupRemoveLayerCommand(layergroupid,layerid)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::AddSurfaceToLayer(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint surfaceid = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint layer = getUIntFromMessage(); + m_reference->m_executor->execute(new LayerAddSurfaceCommand(layer,surfaceid)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::RemoveSurfaceFromLayer(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint surfaceid = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint layerid = getUIntFromMessage(); + m_reference->m_executor->execute(new LayerRemoveSurfaceCommand(layerid,surfaceid)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::CreateSurfaceGroup(DBusConnection* conn,DBusMessage* msg ) +{ + currentMsg = msg; + uint newID; + m_reference->m_executor->execute(new CreateCommand(-1,TypeSurfaceGroup,PIXELFORMAT_R8,0,0,&newID)); + initReply(); + appendUint(newID); + closeReply(); +} + + +void DBUSCommunicator::RemoveSurfaceGroup(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint param = getUIntFromMessage(); + m_reference->m_executor->execute(new RemoveCommand(param,TypeSurfaceGroup)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::CreateLayerGroup(DBusConnection* conn,DBusMessage* msg ) +{ + currentMsg = msg; + uint newID; + m_reference->m_executor->execute(new CreateCommand(-1,TypeLayerGroup,PIXELFORMAT_R8,0,0,&newID)); + initReply(); + appendUint(newID); + closeReply(); +} + +void DBUSCommunicator::RemoveLayerGroup(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint param = getUIntFromMessage(); + m_reference->m_executor->execute(new RemoveCommand(param,TypeLayerGroup)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::SetSurfaceSourceRegion(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint x = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint y = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint width = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint height = getUIntFromMessage(); + m_reference->m_executor->execute(new SetSourceRectangleCommand(id,TypeSurface,x,y,width,height)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::SetLayerSourceRegion(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint x = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint y = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint width = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint height = getUIntFromMessage(); + m_reference->m_executor->execute(new SetSourceRectangleCommand(id,TypeLayer,x,y,width,height)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::SetSurfaceDestinationRegion(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint x = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint y = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint width = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint height = getUIntFromMessage(); + m_reference->m_executor->execute(new SetDestinationRectangleCommand(id,TypeSurface,x,y,width,height)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::SetSurfacePosition(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint x = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint y = getUIntFromMessage(); + m_reference->m_executor->execute(new SetPositionCommand(id,TypeSurface,x,y)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::GetSurfacePosition(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + uint x; + uint y; + m_reference->m_executor->execute(new GetPositionCommand(id,TypeSurface,&x,&y)); + initReply(); + appendUint(x); + appendUint(y); + closeReply(); +} + +void DBUSCommunicator::SetSurfaceDimension(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint width = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint height = getUIntFromMessage(); + m_reference->m_executor->execute(new SetDimensionCommand(id,TypeSurface,width,height)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::SetLayerDestinationRegion(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint x = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint y = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint width = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint height = getUIntFromMessage(); + m_reference->m_executor->execute(new SetDestinationRectangleCommand(id,TypeLayer,x,y,width,height)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::SetLayerPosition(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint x = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint y = getUIntFromMessage(); + m_reference->m_executor->execute(new SetPositionCommand(id,TypeLayer,x,y)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::GetLayerPosition(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + uint x; + uint y; + m_reference->m_executor->execute(new GetPositionCommand(id,TypeLayer,&x,&y)); + initReply(); + appendUint(x); + appendUint(y); + closeReply(); +} + +void DBUSCommunicator::SetLayerDimension(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint width = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint height = getUIntFromMessage(); + m_reference->m_executor->execute(new SetDimensionCommand(id,TypeLayer,width,height)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::GetLayerDimension(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + uint width; + uint height; + m_reference->m_executor->execute(new GetDimensionCommand(id,TypeLayer,&width,&height)); + initReply(); + appendUint(width); + appendUint(height); + closeReply(); +} + +void DBUSCommunicator::GetSurfaceDimension(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + uint width; + uint height; + m_reference->m_executor->execute(new GetDimensionCommand(id,TypeSurface,&width,&height)); + initReply(); + appendUint(width); + appendUint(height); + closeReply(); +} + +void DBUSCommunicator::SetSurfaceOpacity(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + dbus_message_iter_next(&iter); + double param = getDoubleFromMessage(); + m_reference->m_executor->execute(new SetOpacityCommand(id,TypeSurface,param)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::SetLayerOpacity(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + dbus_message_iter_next(&iter); + double param = getDoubleFromMessage(); + m_reference->m_executor->execute(new SetOpacityCommand(id,TypeLayer,param)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::SetSurfacegroupOpacity(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + dbus_message_iter_next(&iter); + double param = getDoubleFromMessage(); + m_reference->m_executor->execute(new SetOpacityCommand(id,TypeSurfaceGroup,param)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::SetLayergroupOpacity(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + dbus_message_iter_next(&iter); + double param = getDoubleFromMessage(); + m_reference->m_executor->execute(new SetOpacityCommand(id,TypeLayerGroup,param)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::GetSurfaceOpacity(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + double param; + m_reference->m_executor->execute(new GetOpacityCommand(id,TypeSurface,¶m)); + initReply(); + appendDouble(param); + closeReply(); +} + +void DBUSCommunicator::GetLayerOpacity(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + double param; + m_reference->m_executor->execute(new GetOpacityCommand(id,TypeLayer,¶m)); + initReply(); + appendDouble(param); + closeReply(); +} + +void DBUSCommunicator::GetSurfacegroupOpacity(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + double param; + m_reference->m_executor->execute(new GetOpacityCommand(id,TypeSurfaceGroup,¶m)); + initReply(); + appendDouble(param); + closeReply(); +} + +void DBUSCommunicator::GetLayergroupOpacity(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + double param; + m_reference->m_executor->execute(new GetOpacityCommand(id,TypeLayerGroup,¶m)); + initReply(); + appendDouble(param); + closeReply(); +} + +void DBUSCommunicator::SetSurfaceOrientation(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint param = getUIntFromMessage(); + OrientationType o = (OrientationType) param; + m_reference->m_executor->execute(new SetOrientationCommand(id,TypeSurface,o)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::SetLayerOrientation(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint param = getUIntFromMessage(); + OrientationType o = (OrientationType) param; + m_reference->m_executor->execute(new SetOrientationCommand(id,TypeLayer,o)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::GetSurfacePixelformat(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + PixelFormat param; + m_reference->m_executor->execute(new GetPixelformatCommand(id,TypeSurface,¶m)); + initReply(); + appendbyte(param); + closeReply(); +} + +void DBUSCommunicator::SetSurfaceVisibility(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + const uint surfaceid = getUIntFromMessage(); + dbus_message_iter_next(&iter); + bool newVis= getBoolFromMessage(); + m_reference->m_executor->execute(new SetVisibilityCommand(surfaceid,TypeSurface,newVis)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::SetLayerVisibility(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint layerid = getUIntFromMessage(); + dbus_message_iter_next(&iter); + bool myparam = getBoolFromMessage(); + m_reference->m_executor->execute(new SetVisibilityCommand(layerid,TypeLayer,myparam)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::GetSurfaceVisibility(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + bool param; + m_reference->m_executor->execute(new GetVisibilityCommand(id,TypeSurface,¶m)); + initReply(); + appendBool(param); + closeReply(); +} + +void DBUSCommunicator::GetLayerVisibility(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + bool param; + m_reference->m_executor->execute(new GetVisibilityCommand(id,TypeLayer,¶m)); + initReply(); + appendBool(param); + closeReply(); +} + +void DBUSCommunicator::SetSurfacegroupVisibility(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint groupid = getUIntFromMessage(); + dbus_message_iter_next(&iter); + bool myparam = getBoolFromMessage(); + m_reference->m_executor->execute(new SetVisibilityCommand(groupid,TypeSurfaceGroup,myparam)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::SetLayergroupVisibility(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint groupid = getUIntFromMessage(); + dbus_message_iter_next(&iter); + bool myparam = getBoolFromMessage(); + m_reference->m_executor->execute(new SetVisibilityCommand(groupid,TypeLayerGroup,myparam)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::SetRenderOrderOfLayers(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + if (DBUS_TYPE_ARRAY != dbus_message_iter_get_arg_type(&iter)) + LOG_ERROR("DBUSCommunicator","Argument is not an array!"); + DBusMessageIter arrayIter; + dbus_message_iter_recurse(&iter,&arrayIter); + int* arr; + int length; + dbus_message_iter_get_fixed_array(&arrayIter,&arr,&length); + + m_reference->m_executor->execute(new SetLayerOrderCommand(arr,length)); + + initReply(); + closeReply(); +} + +void DBUSCommunicator::SetSurfaceRenderOrderWithinLayer(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint layerid = getUIntFromMessage(); + dbus_message_iter_next(&iter); + + if (DBUS_TYPE_ARRAY != dbus_message_iter_get_arg_type(&iter)) + LOG_ERROR("DBUSCommunicator", "Argument is not an array!"); + DBusMessageIter arrayIter; + dbus_message_iter_recurse(&iter,&arrayIter); + int* arr; + int length; + dbus_message_iter_get_fixed_array(&arrayIter,&arr,&length); + + m_reference->m_executor->execute(new SetOrderWithinLayerCommand(layerid,arr,length)); + + initReply(); + closeReply(); +} + +void DBUSCommunicator::GetLayerType(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + Layer* l = m_reference->m_layerlist->getLayer(id); + initReply(); + appendUint(l->getLayerType()); + closeReply(); +} + +void DBUSCommunicator::GetLayertypeCapabilities(DBusConnection* conn,DBusMessage* msg ) +{ + + initReceive(msg); + uint id = getUIntFromMessage(); + LayerType type = (LayerType)id; + uint capabilities = m_reference->m_executor->getLayerTypeCapabilities(type); + initReply(); + appendUint(capabilities); + closeReply(); +} + +void DBUSCommunicator::GetLayerCapabilities(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + Layer* l = m_reference->m_layerlist->getLayer(id); + initReply(); + appendUint(l->getCapabilities()); + closeReply(); +} + +void DBUSCommunicator::FadeIn(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + initReply(); + closeReply(); +} + +void DBUSCommunicator::SynchronizedFade(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + initReply(); + closeReply(); +} + +void DBUSCommunicator::FadeOut(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + initReply(); + closeReply(); +} + +void DBUSCommunicator::Exit(DBusConnection* conn,DBusMessage* msg ) +{ + currentMsg = msg; + m_reference->m_executor->execute(new ExitCommand()); + initReply(); + closeReply(); +} + +void DBUSCommunicator::CommitChanges(DBusConnection* conn,DBusMessage* msg ) +{ + currentMsg = msg; + m_reference->m_executor->execute(new CommitCommand()); + initReply(); + closeReply(); +} + +void DBUSCommunicator::CreateShader(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + char* vertname = getStringFromMessage(); + dbus_message_iter_next(&iter); + char* fragname = getStringFromMessage(); + uint id; + m_reference->m_executor->execute(new CreateShaderCommand(vertname,fragname,&id)); + initReply(); + appendUint(id); + closeReply(); +} + +void DBUSCommunicator::DestroyShader(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint shaderid = getUIntFromMessage(); + m_reference->m_executor->execute(new DestroyShaderCommand(shaderid)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::SetShader(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint objectid = getUIntFromMessage(); + dbus_message_iter_next(&iter); + uint shaderid = getUIntFromMessage(); + m_reference->m_executor->execute(new SetShaderCommand(objectid,shaderid)); + initReply(); + closeReply(); +} + +void DBUSCommunicator::SetUniforms(DBusConnection* conn,DBusMessage* msg ) +{ + initReceive(msg); + uint id = getUIntFromMessage(); + dbus_message_iter_next(&iter); + if (DBUS_TYPE_ARRAY != dbus_message_iter_get_arg_type(&iter)) + LOG_ERROR("DBUSCommunicator", "Argument is not an array!"); + std::vector uniforms; + DBusMessageIter arrayIter; + + dbus_message_iter_recurse(&iter,&arrayIter); + bool hasNext = true; + while(hasNext){ + if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&arrayIter)) + LOG_ERROR("DBUSCommunicator", "Argument is not an string!"); + char* param; + dbus_message_iter_get_basic(&arrayIter,¶m); + uniforms.push_back(std::string(param)); + if (dbus_message_iter_has_next(&arrayIter)) + dbus_message_iter_next(&arrayIter); + else + hasNext = false; + } + + m_reference->m_executor->execute(new SetUniformsCommand(id,uniforms)); + initReply(); + closeReply(); +} + +void* DBUSCommunicator::run(void * arg){ + LOG_INFO("DBUSCommunicator","Running.."); +// pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL); +// pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, NULL); + m_reference = (DBUSCommunicator*)arg; + while(m_reference->m_running){ +// pthread_testcancel(); + dbus_connection_read_write(conn, 50); + DBusMessage* msg = dbus_connection_pop_message(conn); + if (NULL!=msg){ + const char *n = dbus_message_get_member (msg); + + bool found = false; + int i=0; + while(!found && strcmp(manager_methods[i].name,"")!=0){ + if (n && strcmp(manager_methods[i].name,n) == 0){ + MethodTable entry = manager_methods[i]; + LOG_DEBUG("DBUSC","called methodname:" << entry.name); + CallBackMethod m = entry.function; + (m_reference->*m)(conn,msg); + found = true; + } + i++; + } + if (dbus_message_is_method_call(msg, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")){ + LOG_DEBUG("DBUSCommunicator", "Introspection called"); + introspectCallback(conn, msg); + found = true; + } + if (!found){ + DBusMessage* reply = dbus_message_new_method_return(msg); + uint serial = 0; + // send the reply && flush the connection + if (!dbus_connection_send(conn, reply, &serial)) { + LOG_ERROR("DBUSCommunicator", "Out Of Memory!"); + exit(1); + } + dbus_connection_flush(conn); + + // free the reply + dbus_message_unref(reply); + } + + } + } + + LOG_DEBUG("DBUSCommunicator","ending thread"); + return 0; +} + +extern "C" DBUSCommunicator* createDBUSCommunicator(CommandExecutor* executor, LayerList* ll) { + return new DBUSCommunicator(executor,ll); +} + +extern "C" void destroyDBUSCommunicator(DBUSCommunicator* p) { + delete p; +} + + diff --git a/LayerManagerPlugins/Renderers/Base/include/BaseRenderer.h b/LayerManagerPlugins/Renderers/Base/include/BaseRenderer.h new file mode 100644 index 0000000..aa0e4cb --- /dev/null +++ b/LayerManagerPlugins/Renderers/Base/include/BaseRenderer.h @@ -0,0 +1,46 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _BASERENDERER_H_ +#define _BASERENDERER_H_ + +#include "LayerType.h" +#include "LayerList.h" +#include "IRenderer.h" +#include "WindowSystems/BaseWindowSystem.h" + +class BaseRenderer : public IRenderer{ +protected: + BaseRenderer(LayerList* layerlist); + ~BaseRenderer(); + + bool start(int, int, const char*); + void stop(){}; + void setdebug(bool onoff){debugMode = onoff;}; + uint getLayerTypeCapabilities(LayerType layerType); + +protected: + BaseWindowSystem* m_windowSystem; + LayerList* m_layerlist; + +private: + static bool debugMode; +}; + +#endif /* _BASERENDERER_H_*/ diff --git a/LayerManagerPlugins/Renderers/Base/include/RenderUtil.h b/LayerManagerPlugins/Renderers/Base/include/RenderUtil.h new file mode 100644 index 0000000..c9e4f18 --- /dev/null +++ b/LayerManagerPlugins/Renderers/Base/include/RenderUtil.h @@ -0,0 +1,276 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _RENDERUTIL_H_ +#define _RENDERUTIL_H_ + +#include "GLES2/gl2.h" +#include "Log.h" +#include +#include +#include +#include + +// Loads a file containing shader code +static char* RenderUtilLoadShaderFile(const char *szFilename) +{ + if(!szFilename) + { + return(NULL); + } + + FILE *pFile; + pFile = fopen(szFilename, "rb"); + if(!pFile) + { + LOG_ERROR("RenderUtilLoadShaderFile","Unable to open ShaderFile " << szFilename); + return(NULL); + } + + fseek(pFile, 0, SEEK_END); + long size = ftell(pFile); + fseek(pFile, 0, SEEK_SET); + + char *pBuffer = new char[size+1]; + if(!pBuffer) + { + LOG_ERROR("RenderUtilLoadShaderFile","Unable to allocate Memory for ShaderFile " << szFilename); + fclose(pFile); + return(NULL); + } + + if(1 != fread(pBuffer, size, 1, pFile)) + { + LOG_ERROR("RenderUtilLoadShaderFile","Unable to allocate Memory for ShaderFile " << szFilename); + fclose(pFile); + delete [] pBuffer; + return(NULL); + } + + pBuffer[size] = 0; + fclose(pFile); + LOG_DEBUG("RenderUtilShaderDebug","loaded file with bytes: " << size); + return(pBuffer); +} + + + +// If shader compilation fails, prints the associated logs +static void RenderUtilShaderDebug(GLuint obj, GLenum status, const char* op) +{ + char errorMessage[1024]; + int success; + // log output. + int len; + char *str = NULL; + if (status == GL_COMPILE_STATUS) { + glGetShaderiv(obj, GL_INFO_LOG_LENGTH, &len); + if (len > 0) { + str = new char[len]; + glGetShaderInfoLog(obj, len, NULL, str); + } + } else { // LINK + glGetProgramiv(obj, GL_INFO_LOG_LENGTH, &len); + if (len > 0) { + str = new char[len]; + glGetProgramInfoLog(obj, len, NULL, str); + } + } + if (str != NULL && *str != '\0') { + strncpy(errorMessage, "--- ",1024); + strncat(errorMessage,op, 1000); + strncat(errorMessage, " log ---", 8); + LOG_DEBUG("RenderUtilShaderDebug",errorMessage); + LOG_DEBUG("RenderUtilShaderDebug",str); + } + if (str) { delete[] str; } + + // check the compile / link status. + if (status == GL_COMPILE_STATUS) { + glGetShaderiv(obj, status, &success); + if (!success) { + glGetShaderiv(obj, GL_SHADER_SOURCE_LENGTH, &len); + if (len > 0) { + str = new char[len]; + glGetShaderSource(obj, len, NULL, str); + if (str != NULL && *str != '\0') { + strncpy(errorMessage, "--- ",1024); + strncat(errorMessage,op, 1000); + strncat(errorMessage, " log ---", 8); + LOG_DEBUG("RenderUtilShaderDebug",errorMessage); + LOG_DEBUG("RenderUtilShaderDebug",str); + } + delete[] str; + } + } + } else { // LINK + glGetProgramiv(obj, status, &success); + } + + if (!success) + { + strncpy(errorMessage, "--- ",1024); + strncat(errorMessage,op, 1000); + strncat(errorMessage, " failed ---", 7); + LOG_DEBUG("RenderUtilShaderDebug",errorMessage); + } +} + +// Take precompiled shader binaries and builds a shader program +static GLuint RenderUtilLoadShaderBinaries( + const char* vertBin, GLuint vertBinSize, + const char* fragBin, GLuint fragBinSize, + GLuint binaryFormat, + GLboolean debugging) +{ +// Binary shaders not supportable for non-ES OpenGL +#ifdef GL_ES_VERSION_2_0 + + GLuint prog; + GLuint vertShader; + GLuint fragShader; + + // Create the program + prog = glCreateProgram(); + + // Create the GL shader objects + vertShader = glCreateShader(GL_VERTEX_SHADER); + fragShader = glCreateShader(GL_FRAGMENT_SHADER); + + // Load the binary data into the shader objects + glShaderBinary(1, &vertShader, + binaryFormat, vertBin, vertBinSize); + glShaderBinary(1, &fragShader, + binaryFormat, fragBin, fragBinSize); + + // Attach the shaders to the program + glAttachShader(prog, vertShader); + glAttachShader(prog, fragShader); + +#if 0 + // Delete the shaders + glDeleteShader(vertShader); + glDeleteShader(fragShader); +#endif + + // Link the shader program + glLinkProgram(prog); + if (debugging) + RenderUtilShaderDebug(prog, GL_LINK_STATUS, "Program Link"); + + return prog; +#else // GL_ES_VERSION_2_0 + return 0; +#endif // GL_ES_VERSION_2_0 +} + +// Takes shader source files, compiles them, and builds a shader program +static GLuint RenderUtilLoadShaderSources( + const char* vertFile, + const char* fragFile, + GLboolean debugging) +{ + LOG_DEBUG("RenderUtilShaderDebug","loading shaders sources"); + LOG_DEBUG("RenderUtilShaderDebug","loading vertex shader: " << vertFile); + LOG_DEBUG("RenderUtilShaderDebug","loading fragment shader: " << fragFile); + GLuint prog = 0; + char* vertSource; + char* fragSource; + GLint vertSourceLen; + GLint fragSourceLen; + GLuint vertShader; + GLuint fragShader; + GLint compiled; + GLint linked; + + // Load the shader files + vertSource =RenderUtilLoadShaderFile(vertFile); + fragSource = RenderUtilLoadShaderFile(fragFile); + LOG_DEBUG("RenderUtilShaderDebug","loaded shaders source files"); + if (!vertSource || !fragSource) goto done; + vertSourceLen = (GLint)strlen(vertSource); + fragSourceLen = (GLint)strlen(fragSource); + + // Create the program + prog = glCreateProgram(); +if (prog==0) + LOG_DEBUG("RenderUtilShaderDebug","could not create prog, prog is 0"); + + // Create the GL shader objects + vertShader = glCreateShader(GL_VERTEX_SHADER); + fragShader = glCreateShader(GL_FRAGMENT_SHADER); + + // Load shader sources into GL and compile + glShaderSource(vertShader, 1, (const char**)&vertSource, &vertSourceLen); + glCompileShader(vertShader); + if (debugging) + RenderUtilShaderDebug(vertShader, GL_COMPILE_STATUS, "Vert Compile"); + + glGetShaderiv(vertShader, GL_COMPILE_STATUS, &compiled); + if (compiled) + { + glShaderSource(fragShader, 1, (const char**)&fragSource, &fragSourceLen); + glCompileShader(fragShader); + if (debugging) + RenderUtilShaderDebug(fragShader, GL_COMPILE_STATUS, "Frag Compile"); + glGetShaderiv(fragShader, GL_COMPILE_STATUS, &compiled); + if (compiled) + { + // Attach the shaders to the program + glAttachShader(prog, vertShader); + glAttachShader(prog, fragShader); + + // Delete the shaders + glDeleteShader(vertShader); + glDeleteShader(fragShader); + + // Link and validate the shader program + glLinkProgram(prog); + + if (debugging) + RenderUtilShaderDebug(prog, GL_LINK_STATUS, "Program Link"); + glValidateProgram(prog); + if (debugging) + RenderUtilShaderDebug(prog, GL_VALIDATE_STATUS, "Program Validate"); + + glGetProgramiv(prog, GL_LINK_STATUS, &linked); + if (!linked) + LOG_DEBUG("RenderUtilShaderDebug","could not link shader"); + }else{ + LOG_DEBUG("RenderUtilShaderDebug","could not compile fragment shader"); +} + + }else{ + LOG_DEBUG("RenderUtilShaderDebug","could not compile vertex shader"); +} + + if (!compiled || !linked) + { + glDeleteProgram(prog); + prog = 0; + } + + done: + + delete[] fragSource; + delete[] vertSource; + return prog; +} + +#endif /* _RENDERUTIL_H_ */ diff --git a/LayerManagerPlugins/Renderers/Base/src/BaseRenderer.cpp b/LayerManagerPlugins/Renderers/Base/src/BaseRenderer.cpp new file mode 100644 index 0000000..9eed4e9 --- /dev/null +++ b/LayerManagerPlugins/Renderers/Base/src/BaseRenderer.cpp @@ -0,0 +1,57 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 "LayerCapabilities.h" +#include "BaseRenderer.h" +bool BaseRenderer::debugMode = true; + +BaseRenderer::BaseRenderer(LayerList* layerlist) : m_layerlist(layerlist) +{ + LOG_DEBUG("BaseRenderer", "Creating Renderer"); +}; +BaseRenderer::~BaseRenderer() +{ +}; + +uint BaseRenderer::getLayerTypeCapabilities(LayerType layerType){ + uint result = 0; + switch(layerType) + { + case Software_2D: + { + result = LayerPosition & LayerScalable & LayerOrientable; + } + break; + case Software_2_5D: + { + result = LayerPosition & LayerScalable & LayerOrientable & Layer3D; + } + break; + default : + { + result = 0; + } + } + return result; +} + +bool BaseRenderer::start(int displayWidth, int displayHeight, const char* DisplayName){ + bool windowSystemStatus = m_windowSystem->start(displayWidth,displayHeight,DisplayName); + return windowSystemStatus; +} diff --git a/LayerManagerPlugins/Renderers/Graphic/include/GraphicSystems/BaseGraphicSystem.h b/LayerManagerPlugins/Renderers/Graphic/include/GraphicSystems/BaseGraphicSystem.h new file mode 100644 index 0000000..d101590 --- /dev/null +++ b/LayerManagerPlugins/Renderers/Graphic/include/GraphicSystems/BaseGraphicSystem.h @@ -0,0 +1,39 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _BASEGRAPHICSYSTEM_H_ +#define _BASEGRAPHICSYSTEM_H_ + +#include "TextureBinders/ITextureBinder.h" +#include "PlatformSurface.h" +#include "Surface.h" +#include "Layer.h" + +class BaseGraphicSystem { +public: + virtual bool init(void* display, void* WindowID,int WindowHeight, int WindowWidth)=0; + virtual void drawSurface(Layer*,Surface*)=0; + virtual void clearBackground()=0; + virtual void swapBuffers()=0; + + ITextureBinder* m_binder; + +}; + +#endif /* _BASEGRAPHICSYSTEM_H_ */ diff --git a/LayerManagerPlugins/Renderers/Graphic/include/GraphicSystems/GLESGraphicSystem.h b/LayerManagerPlugins/Renderers/Graphic/include/GraphicSystems/GLESGraphicSystem.h new file mode 100644 index 0000000..67d290d --- /dev/null +++ b/LayerManagerPlugins/Renderers/Graphic/include/GraphicSystems/GLESGraphicSystem.h @@ -0,0 +1,52 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _GLESGRAPHICSYSTEM_H_ +#define _GLESGRAPHICSYSTEM_H_ + +#include "GraphicSystems/BaseGraphicSystem.h" +#include "ShaderProgramFactory.h" +#include "EGL/egl.h" +#include "Log.h" +#include "Shader.h" + +class GLESGraphicsystem : public BaseGraphicSystem { +public: + GLESGraphicsystem(PfnShaderProgramCreator shaderProgram, ITextureBinder* binder); + + bool init(void* display, void* WindowID,int WindowHeight, int WindowWidth); + void clearBackground(); + void swapBuffers(); + void drawSurface(Layer* currentLayer, Surface* surface); + bool initOpenGLES(EGLint displayWidth, EGLint displayHeight); + void resize(EGLint displayWidth, EGLint displayHeight); + + PfnShaderProgramCreator m_shaderCreatorFunc; + EGLConfig m_eglConfig; + EGLContext m_eglContext; + EGLSurface m_eglSurface; + EGLDisplay m_eglDisplay; + uint m_vbo; + EGLint m_displayWidth; + EGLint m_displayHeight; + EGLBoolean m_blendingStatus; + Shader* defaultShader; +}; + +#endif /* _GLESGRAPHICSYSTEM_H_ */ diff --git a/LayerManagerPlugins/Renderers/Graphic/include/PlatformSurfaces/BeaglePlatformSurface.h b/LayerManagerPlugins/Renderers/Graphic/include/PlatformSurfaces/BeaglePlatformSurface.h new file mode 100644 index 0000000..c79592a --- /dev/null +++ b/LayerManagerPlugins/Renderers/Graphic/include/PlatformSurfaces/BeaglePlatformSurface.h @@ -0,0 +1,51 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _BEAGLEPLATFORMSURFACE_H_ +#define _BEAGLEPLATFORMSURFACE_H_ + +#include "Surface.h" +#include "GLES2/gl2.h" +#include "EGL/egl.h" +#include "EGL/eglext.h" +#include "PlatformSurface.h" + +typedef struct _NATIVE_PIXMAP_STRUCT +{ + long ePixelFormat; + long eRotation; + long lWidth; + long lHeight; + long lStride; + long lSizeInBytes; + long pvAddress; + long lAddress; +}NATIVE_PIXMAP_STRUCT; + +class BeaglePlatformSurface : public PlatformSurface { +public: + BeaglePlatformSurface (Surface* surface) : PlatformSurface(surface), eglImage(0){}; + ~BeaglePlatformSurface(){}; + + EGLImageKHR eglImage; + NATIVE_PIXMAP_STRUCT* pixmap; + GLuint texture; +}; + +#endif /* _BEAGLEPLATFORMSURFACE_H_ */ diff --git a/LayerManagerPlugins/Renderers/Graphic/include/PlatformSurfaces/EglXPlatformSurface.h b/LayerManagerPlugins/Renderers/Graphic/include/PlatformSurfaces/EglXPlatformSurface.h new file mode 100644 index 0000000..72c6963 --- /dev/null +++ b/LayerManagerPlugins/Renderers/Graphic/include/PlatformSurfaces/EglXPlatformSurface.h @@ -0,0 +1,37 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _EGLXPLATFORMSURFACE_H_ +#define _EGLXPLATFORMSURFACE_H_ + +#include "Surface.h" +#include "GLES2/gl2.h" +#include "EGL/egl.h" +#include "EGL/eglext.h" +#include "XPlatformSurface.h" + +class EglXPlatformSurface : public XPlatformSurface { +public: + EglXPlatformSurface (Surface* surface) : XPlatformSurface(surface), eglImage(0){}; + ~EglXPlatformSurface(){}; + + EGLImageKHR eglImage; +}; + +#endif /* _EGLXPLATFORMSURFACE_H_ */ diff --git a/LayerManagerPlugins/Renderers/Graphic/include/PlatformSurfaces/XPlatformSurface.h b/LayerManagerPlugins/Renderers/Graphic/include/PlatformSurfaces/XPlatformSurface.h new file mode 100644 index 0000000..43ba8ea --- /dev/null +++ b/LayerManagerPlugins/Renderers/Graphic/include/PlatformSurfaces/XPlatformSurface.h @@ -0,0 +1,37 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _XPLATFORMSURFACE_H_ +#define _XPLATFORMSURFACE_H_ + +#include "PlatformSurface.h" +#include "Surface.h" +#include "X11/X.h" + +class XPlatformSurface : public PlatformSurface { +public: + XPlatformSurface (Surface* surface) : PlatformSurface(surface), isMapped(false){}; + ~XPlatformSurface(){}; + + Pixmap pixmap; + bool isMapped; + uint texture; +}; + +#endif /* _XPLATFORMSURFACE_H_ */ diff --git a/LayerManagerPlugins/Renderers/Graphic/include/TextureBinders/BeagleEglImage.h b/LayerManagerPlugins/Renderers/Graphic/include/TextureBinders/BeagleEglImage.h new file mode 100644 index 0000000..6131d6e --- /dev/null +++ b/LayerManagerPlugins/Renderers/Graphic/include/TextureBinders/BeagleEglImage.h @@ -0,0 +1,119 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _BEAGLEEGLIMAGE_H_ +#define _BEAGLEEGLIMAGE_H_ + +#include "TextureBinders/ITextureBinder.h" +#include +#include "EGL/eglext.h" +#include +#include +#include +#include "PlatformSurfaces/BeaglePlatformSurface.h" + +class BeagleEglImage : public ITextureBinder { +public: + BeagleEglImage(){ + LOG_INFO("BeagleEglImage", "Query EGL Extensions ..."); + CMEM_init(); + m_pfGLEglImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) + eglGetProcAddress("glEGLImageTargetTexture2DOES"); + m_pfEglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC) + eglGetProcAddress("eglCreateImageKHR"); + m_pfEglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC) + eglGetProcAddress("eglDestroyImageKHR"); + + if (!m_pfEglCreateImageKHR || !m_pfEglDestroyImageKHR || !m_pfGLEglImageTargetTexture2DOES) + { + LOG_ERROR("BeagleEglImage", "Query EGL Extensions failed"); + } + + m_eglDisplay = eglGetDisplay(0); + } + void bindSurfaceTexture(Surface*s){ + // LOG_INFO("BeagleEglImage", "bindSurfaceTexture"); + BeaglePlatformSurface* nativeSurface = (BeaglePlatformSurface*)s->platform; + glBindTexture(GL_TEXTURE_2D, nativeSurface->texture); + if (nativeSurface->eglImage != NULL){ + // LOG_INFO("BeagleEglImage", "bindSurfaceTexture"); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + eglWaitNative(EGL_CORE_NATIVE_ENGINE); + m_pfGLEglImageTargetTexture2DOES(GL_TEXTURE_2D, nativeSurface->eglImage); + } + } + + void unbindSurfaceTexture(Surface*s){ + + } + + PlatformSurface* createPlatformSurface(Surface* s){ + return new BeaglePlatformSurface(s); + } + + void createClientBuffer(Surface* surface){ + LOG_INFO("BeagleEglImage", "createClientBuffer"); + BeaglePlatformSurface* nativeSurface = (BeaglePlatformSurface*)surface->platform; + NATIVE_PIXMAP_STRUCT* pNativePixmap = (NATIVE_PIXMAP_STRUCT*)malloc(sizeof(NATIVE_PIXMAP_STRUCT)); + pNativePixmap->ePixelFormat = 2; + pNativePixmap->eRotation = 0; + pNativePixmap->lWidth = 256;//surface->OriginalSourceWidth;//480; + pNativePixmap->lHeight = 256;//surface->OriginalSourceHeight;//640; + pNativePixmap->lStride = pNativePixmap->lWidth* 32/8; //bitwidth/8 + pNativePixmap->lSizeInBytes = pNativePixmap->lHeight * pNativePixmap->lStride; + pNativePixmap->lAddress = (long)CMEM_registerAlloc(surface->nativeHandle); + if(!pNativePixmap->lAddress) + { + LOG_ERROR("BeagleEglImage","CMEM_alloc returned NULL\n"); + exit(-1); + } + //Get the physical page corresponding to the above cmem buffer + pNativePixmap->pvAddress = surface->nativeHandle; //;CMEM_getPhys((void*)pNativePixmap->lAddress); + LOG_DEBUG("BeagleEglImage","Physical address = "<< pNativePixmap->pvAddress); + LOG_DEBUG("BeagleEglImage","Logical address = "<< pNativePixmap->lAddress); + + nativeSurface->eglImage = m_pfEglCreateImageKHR( + m_eglDisplay, + EGL_NO_CONTEXT, //eglContext, + EGL_NATIVE_PIXMAP_KHR, //EGL_GL_TEXTURE_2D_KHR, + pNativePixmap, //(void*)textureId0,// + NULL //miplevel 0 is fine, thank you + ); + + if (nativeSurface->eglImage == 0) + { + LOG_DEBUG("BeagleEglImage", "could not allocate EGL Image for window"); + } else { + glGenTextures(1,&nativeSurface->texture); + } + } + + void destroyClientBuffer(Surface* surface){ + } +private: + PFNEGLCREATEIMAGEKHRPROC m_pfEglCreateImageKHR; + PFNEGLDESTROYIMAGEKHRPROC m_pfEglDestroyImageKHR; + PFNGLEGLIMAGETARGETTEXTURE2DOESPROC m_pfGLEglImageTargetTexture2DOES; + EGLDisplay m_eglDisplay; +}; + +#endif /* _BEAGLEEGLIMAGE_H_ */ diff --git a/LayerManagerPlugins/Renderers/Graphic/include/TextureBinders/ITextureBinder.h b/LayerManagerPlugins/Renderers/Graphic/include/TextureBinders/ITextureBinder.h new file mode 100644 index 0000000..d74de5b --- /dev/null +++ b/LayerManagerPlugins/Renderers/Graphic/include/TextureBinders/ITextureBinder.h @@ -0,0 +1,34 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _ITEXTUREBINDER_H_ +#define _ITEXTUREBINDER_H_ + +#include "Surface.h" + +class ITextureBinder { +public: + virtual void bindSurfaceTexture(Surface*s)=0; + virtual void unbindSurfaceTexture(Surface*s)=0; + virtual void createClientBuffer(Surface*s)=0; + virtual void destroyClientBuffer(Surface*s)=0; + virtual PlatformSurface* createPlatformSurface(Surface* s)=0; +}; + +#endif /* _ITEXTUREBINDER_H_ */ diff --git a/LayerManagerPlugins/Renderers/Graphic/include/TextureBinders/X11Copy.h b/LayerManagerPlugins/Renderers/Graphic/include/TextureBinders/X11Copy.h new file mode 100644 index 0000000..6a66dd5 --- /dev/null +++ b/LayerManagerPlugins/Renderers/Graphic/include/TextureBinders/X11Copy.h @@ -0,0 +1,42 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _X11COPY_H_ +#define _X11COPY_H_ + +#include "TextureBinders/ITextureBinder.h" +#include +#include +#include "PlatformSurfaces/XPlatformSurface.h" +#include + +class X11Copy : public ITextureBinder { +public: + X11Copy(Display* display); + void virtual bindSurfaceTexture(Surface* surface)=0; + void unbindSurfaceTexture(Surface*s); + void virtual createClientBuffer(Surface*s) =0; + void destroyClientBuffer(Surface*s); + virtual PlatformSurface* createPlatformSurface(Surface* s); + +protected: + Display* dpy; +}; + +#endif /* _X11COPY_H_ */ diff --git a/LayerManagerPlugins/Renderers/Graphic/include/TextureBinders/X11CopyGLES.h b/LayerManagerPlugins/Renderers/Graphic/include/TextureBinders/X11CopyGLES.h new file mode 100644 index 0000000..de7c1e4 --- /dev/null +++ b/LayerManagerPlugins/Renderers/Graphic/include/TextureBinders/X11CopyGLES.h @@ -0,0 +1,37 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _X11COPYGLES_H_ +#define _X11COPYGLES_H_ + +#include "TextureBinders/X11Copy.h" +#include +#include +#include "PlatformSurfaces/XPlatformSurface.h" +#include + +class X11CopyGLES : public X11Copy { +public: + X11CopyGLES(Display* display) : X11Copy(display){}; + void bindSurfaceTexture(Surface* surface); + void createClientBuffer(Surface*s); + +}; + +#endif /* _X11COPYGLES_H_ */ diff --git a/LayerManagerPlugins/Renderers/Graphic/include/TextureBinders/X11EglImage.h b/LayerManagerPlugins/Renderers/Graphic/include/TextureBinders/X11EglImage.h new file mode 100644 index 0000000..e6898e6 --- /dev/null +++ b/LayerManagerPlugins/Renderers/Graphic/include/TextureBinders/X11EglImage.h @@ -0,0 +1,47 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _X11EGLIMAGE_H_ +#define _X11EGLIMAGE_H_ + +#include "TextureBinders/ITextureBinder.h" +#include "X11/extensions/Xcomposite.h" +#include +#include +#include +#include + +class X11EglImage : public ITextureBinder { +public: + X11EglImage(Display* x11display); + void bindSurfaceTexture(Surface*s); + void unbindSurfaceTexture(Surface*s); + void createClientBuffer(Surface* surface); + void destroyClientBuffer(Surface* surface); + virtual PlatformSurface* createPlatformSurface(Surface* s); + +private: + PFNEGLCREATEIMAGEKHRPROC m_pfEglCreateImageKHR; + PFNEGLDESTROYIMAGEKHRPROC m_pfEglDestroyImageKHR; + PFNGLEGLIMAGETARGETTEXTURE2DOESPROC m_pfGLEglImageTargetTexture2DOES; + EGLDisplay m_eglDisplay; + Display* m_x11display; +}; + +#endif /* _X11EGLIMAGE_H_ */ diff --git a/LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/BaseWindowSystem.h b/LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/BaseWindowSystem.h new file mode 100644 index 0000000..f44344e --- /dev/null +++ b/LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/BaseWindowSystem.h @@ -0,0 +1,37 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _BASEWINDOWSYSTEM_H_ +#define _BASEWINDOWSYSTEM_H_ + +#include "GraphicSystems/BaseGraphicSystem.h" +#include "LayerList.h" + +class BaseWindowSystem { +public: + BaseWindowSystem(LayerList* layerlist, BaseGraphicSystem* graphicSystem) : graphicSystem(graphicSystem), layerlist(layerlist){}; + virtual bool start(int, int, const char*)=0; + virtual void stop()=0; + +protected: + BaseGraphicSystem* graphicSystem; + LayerList* layerlist; +}; + +#endif /* _BASEWINDOWSYSTEM_H_ */ diff --git a/LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/NullWindowSystem.h b/LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/NullWindowSystem.h new file mode 100644 index 0000000..51cd78a --- /dev/null +++ b/LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/NullWindowSystem.h @@ -0,0 +1,52 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _NULLWINDOWSYSTEM_H_ +#define _NULLWINDOWSYSTEM_H_ + +#include "WindowSystems/BaseWindowSystem.h" +#include "Surface.h" +#include "Log.h" + +class NullWindowSystem : public BaseWindowSystem { +public: + NullWindowSystem(LayerList* layerlist, BaseGraphicSystem* graphicSystem) : BaseWindowSystem(layerlist, graphicSystem){ + LOG_DEBUG("NullWindowSystem", "creating BeagleWindowSystem"); + }; + bool start(int, int, const char*); + void stop(){}; + +private: + static void* EventLoop(void * ptr); + +protected: + static int windowWidth; + static int windowHeight; + static bool m_success; + static bool m_initialized; + +private: + void Redraw(); + void printDebug(int posx,int posy); + static bool debugMode; + static int resolutionWidth; + static int resolutionHeight; +}; + +#endif /* _NULLWINDOWSYSTEM_H_ */ diff --git a/LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/X11WindowSystem.h b/LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/X11WindowSystem.h new file mode 100644 index 0000000..a3e52e0 --- /dev/null +++ b/LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/X11WindowSystem.h @@ -0,0 +1,84 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _X11WINDOWSYSTEM_H_ +#define _X11WINDOWSYSTEM_H_ + +#include "WindowSystems/BaseWindowSystem.h" +#include "X11/Xlib.h" +#include "Surface.h" +#include "PlatformSurfaces/XPlatformSurface.h" +#include +#include "Log.h" + +typedef XVisualInfo* (*GetVisualInfoFunction)(Display *dpy); + +class X11WindowSystem : public BaseWindowSystem { +public: + X11WindowSystem(LayerList* layerlist, BaseGraphicSystem* graphicSystem,GetVisualInfoFunction func=X11WindowSystem::getDefaultVisual ); + bool start(int, int, const char*); + void stop(){}; + + static XVisualInfo * + getDefaultVisual(Display *dpy); +private: + static void* EventLoop(void * ptr); + static int error (Display *dpy, XErrorEvent *ev); + GetVisualInfoFunction getVisualFunc; + +protected: + Display* x11Display; + bool initXServer(); + //void setDisplayMode(); + int windowWidth; + int windowHeight; + // Window background; + Window CompositorWindow; + XVisualInfo* windowVis; + static bool m_success; + static bool m_initialized; + +private: + void Redraw(); + void OpenDisplayConnection(); + void checkForCompositeExtension(); + void createSurfaceForWindow(Window w); + void configureSurfaceWindow(Window w); + Surface* getSurfaceForWindow(Window w); + void destroy_surface(Window w); + void updateSurface(Surface* s, Window w, XPlatformSurface* x11surf); + void MapWindow(Window w); + void UnMapWindow(Window w); + void NewWindow(Surface* s, Window w); + void DestroyWindow(Window w); + bool isWindowValid(Window w); + bool CreatePixmapsForAllWindows(); + bool CreateCompositorWindow(); + void UnredirectSpecialWIndows(Window w); + void printDebug(int posx,int posy); + bool debugMode; + int resolutionWidth; + int resolutionHeight; + static int composite_opcode; + int composite_event, composite_error; + int composite_major, composite_minor; + static const char CompositorWindowTitle[]; +}; + +#endif /* _X11WINDOWSYSTEM_H_ */ diff --git a/LayerManagerPlugins/Renderers/Graphic/src/GraphicSystems/GLESGraphicSystem.cpp b/LayerManagerPlugins/Renderers/Graphic/src/GraphicSystems/GLESGraphicSystem.cpp new file mode 100644 index 0000000..594c84d --- /dev/null +++ b/LayerManagerPlugins/Renderers/Graphic/src/GraphicSystems/GLESGraphicSystem.cpp @@ -0,0 +1,275 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 "GraphicSystems/GLESGraphicSystem.h" + +#include "string.h" +#include "EGL/egl.h" +#include "GLES2/gl2.h" + +static const float vertices[8*12] = { + 0.0, 0.0, + 1.0, 0.0, + 1.0, 1.0, + 1.0, 1.0, + 0.0, 1.0, + 0.0, 0.0, + + 0.0, 0.0, + 1.0, 0.0, + 1.0, 1.0, + 1.0, 1.0, + 0.0, 1.0, + 0.0, 0.0, + + 0.0, 0.0, + 1.0, 0.0, + 1.0, 1.0, + 1.0, 1.0, + 0.0, 1.0, + 0.0, 0.0, + + 1.0, 0.0, + 1.0, 1.0, + 0.0, 1.0, + 0.0, 1.0, + 0.0, 0.0, + 1.0, 0.0, + + 0.0, 0.0, + 1.0, 0.0, + 1.0, 1.0, + 1.0, 1.0, + 0.0, 1.0, + 0.0, 0.0, + + 1.0, 1.0, + 0.0, 1.0, + 0.0, 0.0, + 0.0, 0.0, + 1.0, 0.0, + 1.0, 1.0, + + 0.0, 0.0, + 1.0, 0.0, + 1.0, 1.0, + 1.0, 1.0, + 0.0, 1.0, + 0.0, 0.0, + + 0.0, 1.0, + 0.0, 0.0, + 1.0, 0.0, + 1.0, 0.0, + 1.0, 1.0, + 0.0, 1.0 + +}; + +GLESGraphicsystem::GLESGraphicsystem(PfnShaderProgramCreator shaderProgram, ITextureBinder* binder ) : m_shaderCreatorFunc(shaderProgram){ + LOG_DEBUG("GLESGraphicsystem", "creating GLESGraphicsystem"); + m_binder = binder; +}; + +bool GLESGraphicsystem::init(void* displayPtr, void* WIndowIDPtr,int WindowHeight, int WindowWidth){ + EGLNativeDisplayType display = *(EGLNativeDisplayType*)displayPtr; + LOG_DEBUG("GLESGraphicsystem", "Using EGLNativeDisplay:" << display); + EGLNativeWindowType WIndowID = *(EGLNativeWindowType*)WIndowIDPtr; + LOG_DEBUG("GLESGraphicsystem", "Using EGLNativeWindow:" << WIndowID); + + EGLint iMajorVersion, iMinorVersion; + LOG_DEBUG("GLESGraphicsystem", "Getting EGL Display"); + m_eglDisplay = eglGetDisplay(display); + + LOG_DEBUG("GLESGraphicsystem", "Initialising EGL"); + if (!eglInitialize(m_eglDisplay, &iMajorVersion, &iMinorVersion)) + return false; + + LOG_DEBUG("GLESGraphicsystem", "Binding GLES API"); + eglBindAPI(EGL_OPENGL_ES_API); + + EGLint pi32ConfigAttribs[]={ + EGL_SURFACE_TYPE,EGL_WINDOW_BIT | EGL_PIXMAP_BIT, + EGL_RENDERABLE_TYPE,EGL_OPENGL_ES2_BIT, + EGL_ALPHA_SIZE,8, + EGL_NONE + }; + + LOG_DEBUG("GLESGraphicsystem", "EGLChooseConfig"); + int iConfigs; + if (!eglChooseConfig(m_eglDisplay, pi32ConfigAttribs, &m_eglConfig, 1, &iConfigs) || (iConfigs != 1)) + { + LOG_DEBUG("GLESGraphicsystem", "Error: eglChooseConfig() failed."); + return false; + } + EGLint id =0; + eglGetConfigAttrib(m_eglDisplay, m_eglConfig, EGL_CONFIG_ID, &id); + + LOG_DEBUG("GLESGraphicsystem", "Config chosen:" << id); + LOG_DEBUG("GLESGraphicsystem", "Create Window surface"); + + m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, WIndowID, NULL); + if (!m_eglSurface){ + LOG_DEBUG("GLESGraphicsystem", "create unsucessfull"); + }else{ + LOG_DEBUG("GLESGraphicsystem", "create successfull"); + } + EGLint contextAttrs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; + m_eglContext = eglCreateContext(m_eglDisplay, + m_eglConfig, + NULL, + contextAttrs); + if (!m_eglContext) + { + LOG_ERROR("GLESGraphicsystem","EGL couldn't create context\n"); + return false; + } + LOG_INFO("GLESGraphicsystem", "EGL make current ..."); + // Make the context and surface current for rendering + EGLBoolean eglStatus = false; + eglStatus = eglMakeCurrent(m_eglDisplay, + m_eglSurface, m_eglSurface, + m_eglContext); + LOG_INFO("GLESGraphicsystem", "made current"); + + + if (!initOpenGLES(WindowWidth,WindowHeight) ) + { + return false; + } + return true; +} + +void GLESGraphicsystem::clearBackground() +{ + glClear(GL_COLOR_BUFFER_BIT); +} +void GLESGraphicsystem::swapBuffers() +{ + eglSwapBuffers(m_eglDisplay,m_eglSurface); +} + +void GLESGraphicsystem::drawSurface(Layer* currentLayer,Surface* surface) +{ + ShaderProgram::CommonUniforms uniforms; + Shader* layerShader = currentLayer->getShader(); + if (!layerShader) + { + // use default shader if no custom shader is assigned to this layer + layerShader = defaultShader; + } + Shader* shader = (surface)->getShader(); + if (!shader) + { + // use layer shader if no custom shader is assigned to this surface + shader = layerShader; + } + Rectangle dest = (surface)->getDestinationRegion(); + Rectangle src = (surface)->getSourceRegion(); + float surfaceXOfScreen = (float) dest.x / m_displayWidth; + float surfaceYOfScreen = (float) dest.y / m_displayHeight; + float surfaceWidthOfScreen = (float) dest.width / m_displayWidth; + float surfaceHeightOfScreen = (float) dest.height / m_displayHeight; + + float sourceViewportWidthPercent = (float)src.width/(surface)->OriginalSourceWidth; + float sourceViewportHeightpercent = (float)src.height/(surface)->OriginalSourceHeight; + float sourceViewportXPercent = (float)src.x/(surface)->OriginalSourceWidth; + float sourceViewportYPercent = (float)src.y/(surface)->OriginalSourceHeight; + + // LOG_INFO("GLESGraphicsystem", "Binding Buffer"); + glBindBuffer(GL_ARRAY_BUFFER,m_vbo); + + // LOG_INFO("GLESGraphicsystem", "Binding Buffer done"); + shader->use(); + + // LOG_INFO("GLESGraphicsystem", "Update Uniforms"); + // update all common uniforms + uniforms.x = surfaceXOfScreen; + uniforms.y = surfaceYOfScreen; + uniforms.width = surfaceWidthOfScreen; + uniforms.height = surfaceHeightOfScreen; + uniforms.opacity = (surface)->getOpacity() * currentLayer->getOpacity(); + uniforms.texRange[0] = sourceViewportWidthPercent; + uniforms.texRange[1] = sourceViewportHeightpercent; + uniforms.texOffset[0] = sourceViewportXPercent; + uniforms.texOffset[1] = -sourceViewportYPercent; + uniforms.texUnit = 0; + + // LOG_INFO("GLESGraphicsystem", "Load Common Uniforms"); + shader->loadCommonUniforms(uniforms); + + // LOG_INFO("GLESGraphicsystem", "Load Custom Uniforms"); + // update all custom defined uniforms + shader->loadUniforms(); + /* Bind texture and set section */ + glActiveTexture(GL_TEXTURE0); + m_binder->bindSurfaceTexture(surface); + + // rotated positions are saved sequentially in vbo + // offset in multiples of 12 decide rotation + int orientation = (surface)->getOrientation() + (currentLayer)->getOrientation(); + orientation %= 4; + int index = orientation * 12; +// LOG_INFO("GLESGraphicsystem", "Drawing surface"); + // Draw two triangles + glDrawArrays(GL_TRIANGLES, 0, 6); + // get the next surface + glBindBuffer(GL_ARRAY_BUFFER,NULL); +// LOG_INFO("GLESGraphicsystem", "Drawing surface done"); +// LOG_INFO("GLESGraphicsystem", "Drawing surface done now checking for error"); + GLenum status = glGetError(); +} + +bool GLESGraphicsystem::initOpenGLES(EGLint displayWidth,EGLint displayHeight) +{ + LOG_DEBUG("GLESGraphicsystem", "initEGL"); + bool result = true; + ShaderProgramFactory::setCreatorFunc(m_shaderCreatorFunc); + defaultShader = Shader::createShader("default", "default"); + if (!defaultShader) + { + LOG_ERROR("GLESGraphicsystem", "Failed to create and link default shader program"); + delete defaultShader; + result = false; + } + else + { + LOG_INFO("GLESGraphicsystem", "Default Shader successfully applied"); + glGenBuffers(1,&m_vbo); + glBindBuffer(GL_ARRAY_BUFFER, m_vbo); + glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0); + glEnableVertexAttribArray(0); + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)(sizeof(float) *12)); + glEnableVertexAttribArray(1); + + glEnable (GL_BLEND); + glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + m_blendingStatus = true; + glClearColor(1.0, 0.0, 0.0, 1.0); + resize(displayWidth,displayHeight); + } + return result; +} +void GLESGraphicsystem::resize(EGLint displayWidth,EGLint displayHeight) +{ + m_displayWidth = displayWidth; + m_displayHeight = displayHeight; + glViewport(0, 0, m_displayWidth, m_displayHeight); +} diff --git a/LayerManagerPlugins/Renderers/Graphic/src/TextureBinders/X11Copy.cpp b/LayerManagerPlugins/Renderers/Graphic/src/TextureBinders/X11Copy.cpp new file mode 100644 index 0000000..8f453ed --- /dev/null +++ b/LayerManagerPlugins/Renderers/Graphic/src/TextureBinders/X11Copy.cpp @@ -0,0 +1,34 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 "TextureBinders/X11Copy.h" +#include "Surface.h" +#include "X11/Xlib.h" +#include "Log.h" + +X11Copy::X11Copy(Display* display) : dpy(display) {}; + +PlatformSurface* X11Copy::createPlatformSurface(Surface*s){ +LOG_DEBUG("X11Copy", "give back new platformsurface"); + return new XPlatformSurface(s); +} + +void X11Copy::unbindSurfaceTexture(Surface*s){} + +void X11Copy::destroyClientBuffer(Surface*s){} diff --git a/LayerManagerPlugins/Renderers/Graphic/src/TextureBinders/X11CopyGLES.cpp b/LayerManagerPlugins/Renderers/Graphic/src/TextureBinders/X11CopyGLES.cpp new file mode 100644 index 0000000..a4481f9 --- /dev/null +++ b/LayerManagerPlugins/Renderers/Graphic/src/TextureBinders/X11CopyGLES.cpp @@ -0,0 +1,46 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 "TextureBinders/X11CopyGLES.h" +#include "Surface.h" +#include "X11/Xlib.h" +#include "Log.h" + +#include "GLES2/gl2.h" + +void X11CopyGLES::bindSurfaceTexture(Surface* surface){ + XPlatformSurface* nativeSurface = (XPlatformSurface*)surface->platform; + Pixmap p = 0; + p= XCompositeNameWindowPixmap (dpy, surface->nativeHandle); + if (p==0) + LOG_ERROR("X11CopyGLES", "didnt create pixmap!"); + nativeSurface->pixmap = p; + XImage * xim = XGetImage(dpy, nativeSurface->pixmap, 0, 0, surface->OriginalSourceWidth, surface->OriginalSourceHeight, AllPlanes, ZPixmap); + glBindTexture(GL_TEXTURE_2D, nativeSurface->texture); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surface->OriginalSourceWidth,surface->OriginalSourceHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, xim->data); + XDestroyImage(xim); +} + +void X11CopyGLES::createClientBuffer(Surface*s){ + XPlatformSurface* nativeSurface = (XPlatformSurface*)s->platform; + glGenTextures(1,&nativeSurface->texture); +} diff --git a/LayerManagerPlugins/Renderers/Graphic/src/TextureBinders/X11EglImage.cpp b/LayerManagerPlugins/Renderers/Graphic/src/TextureBinders/X11EglImage.cpp new file mode 100644 index 0000000..35c12e0 --- /dev/null +++ b/LayerManagerPlugins/Renderers/Graphic/src/TextureBinders/X11EglImage.cpp @@ -0,0 +1,101 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 "TextureBinders/X11EglImage.h" +#include "X11/extensions/Xcomposite.h" +#include +#include +#include +#include "PlatformSurfaces/EglXPlatformSurface.h" +#include "Log.h" + + X11EglImage::X11EglImage(Display* x11display) : m_x11display(x11display){ + LOG_INFO("X11EglImage", "Query EGL Extensions ..."); + + m_pfGLEglImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) + eglGetProcAddress("glEGLImageTargetTexture2DOES"); + m_pfEglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC) + eglGetProcAddress("eglCreateImageKHR"); + m_pfEglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC) + eglGetProcAddress("eglDestroyImageKHR"); + + if (!m_pfEglCreateImageKHR || !m_pfEglDestroyImageKHR || !m_pfGLEglImageTargetTexture2DOES) + { + LOG_ERROR("X11EglImage", "Query EGL Extensions failed"); + } + + m_eglDisplay = eglGetDisplay((EGLNativeDisplayType)m_x11display); + } + void X11EglImage::bindSurfaceTexture(Surface*s){ + EglXPlatformSurface* nativeSurface = (EglXPlatformSurface*)s->platform; + glBindTexture(GL_TEXTURE_2D, nativeSurface->texture); + if (nativeSurface->eglImage != NULL){ + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + m_pfGLEglImageTargetTexture2DOES(GL_TEXTURE_2D, nativeSurface->eglImage); + } + } + + void X11EglImage::unbindSurfaceTexture(Surface*s){ + + } + + void X11EglImage::createClientBuffer(Surface* surface){ + LOG_DEBUG("X11EglImage", "creating client buffer"); + EglXPlatformSurface* nativeSurface = (EglXPlatformSurface*)surface->platform; + Pixmap windowPixmap = 0; + windowPixmap= XCompositeNameWindowPixmap (m_x11display, surface->nativeHandle); + if (windowPixmap==0) + LOG_ERROR("X11EglImage", "didnt create pixmap!"); + + EGLImageKHR eglImage = 0; + LOG_DEBUG("X11EglImage", "creating EGL Image from client buffer"); + if (nativeSurface->eglImage != NULL) + { + m_pfEglDestroyImageKHR(m_eglDisplay, nativeSurface->eglImage); + glDeleteTextures(1,&nativeSurface->texture); + } + eglImage = m_pfEglCreateImageKHR(m_eglDisplay, + EGL_NO_CONTEXT, + EGL_NATIVE_PIXMAP_KHR, + (EGLClientBuffer)windowPixmap, + NULL); + if (eglImage == 0) + { + LOG_DEBUG("X11EglImage", "could not allocate EGL Image for window"); + } else { + nativeSurface->eglImage = eglImage; + glGenTextures(1,&nativeSurface->texture); + } + } + + PlatformSurface* X11EglImage::createPlatformSurface(Surface* s){ + return new EglXPlatformSurface(s); + } + + void X11EglImage::destroyClientBuffer(Surface* surface){ + EglXPlatformSurface* nativeSurface = (EglXPlatformSurface*)surface->platform; + if (nativeSurface->eglImage != NULL ) + { + m_pfEglDestroyImageKHR(m_eglDisplay, nativeSurface->eglImage); + } + glDeleteTextures(1,&nativeSurface->texture); + } diff --git a/LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/NullWindowSystem.cpp b/LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/NullWindowSystem.cpp new file mode 100644 index 0000000..7365e50 --- /dev/null +++ b/LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/NullWindowSystem.cpp @@ -0,0 +1,212 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 "WindowSystems/NullWindowSystem.h" +#include "Log.h" +#include "Layer.h" +#include +#include +#include +#include +#include +#include +#include + + +int NullWindowSystem::windowWidth= 1280; + + +int NullWindowSystem::windowHeight= 480; + + +int NullWindowSystem::resolutionWidth= 1280; + + +int NullWindowSystem::resolutionHeight= 480; + + +bool NullWindowSystem::m_initialized= false; + + +bool NullWindowSystem::m_success= false; + + +bool NullWindowSystem::debugMode= false; + + +void NullWindowSystem::printDebug(int posx,int posy){ + // print stuff about layerlist + std::stringstream debugmessage; + debugmessage << "Layer: ID | X | Y | W | H | Al. \n"; + // loop the layers + std::list list = layerlist->getCurrentRenderOrder(); + for(std::list::const_iterator currentLayer = list.begin(); + currentLayer != list.end(); currentLayer++) + { + Rectangle dest = (*currentLayer)->getDestinationRegion(); + debugmessage << " " << std::setw(4) << (*currentLayer)->getID() << " " << std::setw(3) << dest.x << " " << std::setw(3) << dest.y << " " << std::setw(3) << dest.width << " " << std::setw(3) << dest.height << " " << std::setw(3) << (*currentLayer)->opacity << "\n"; + + debugmessage << " Surface: ID |Al.| SVP: X | Y | W | H DVP: X | Y | W | H \n"; + // loop the surfaces of within each layer + for(std::list::iterator current = (*currentLayer)->surfaces.begin(); + current != (*currentLayer)->surfaces.end(); current++) + { + Rectangle src = (*current)->getSourceRegion(); + Rectangle dest = (*current)->getDestinationRegion(); + debugmessage << " " << std::setw(4) << (*current)->getID() << " " << std::setprecision(3) << (*current)->opacity<< " " << std::setw(3) << src.x << " " << std::setw(3) << src.y << " " << std::setw(3) << src.width << " " << std::setw(3) << src.height << " " << std::setw(3) << dest.x << " " << std::setw(3) << dest.y << " " << std::setw(3) << dest.width << " " << std::setw(3) << dest.height << "\n"; + } + } + LOG_INFO("NullWindowSystem",debugmessage.str()); +} + +float TimeCounter, LastFrameTimeCounter, DT, prevTime = 0.0, FPS; +struct timeval tv, tv0; +int Frame = 1, FramesPerFPS; + +void UpdateTimeCounter() { + LastFrameTimeCounter = TimeCounter; + gettimeofday(&tv, NULL); + TimeCounter = (float)(tv.tv_sec-tv0.tv_sec) + 0.000001*((float)(tv.tv_usec-tv0.tv_usec)); + DT = TimeCounter - LastFrameTimeCounter; } + +void CalculateFPS() { + Frame ++; + + if((Frame%FramesPerFPS) == 0) { + FPS = ((float)(FramesPerFPS)) / (TimeCounter-prevTime); + prevTime = TimeCounter; } } + + +void NullWindowSystem::Redraw() +{ +// LOG_INFO("NullWindowSystem","redraw"); + // draw all the layers + graphicSystem->clearBackground(); + std::list layers = layerlist->getCurrentRenderOrder(); + for(std::list::const_iterator current = layers.begin(); current != layers.end(); current++){ + Layer* currentLayer = (Layer*)*current; + if ((*currentLayer).visibility && (*currentLayer).opacity>0.0f){ + // glPushMatrix(); + // glRotated(-90*currentLayer->getOrientation(),0,0,1.0); + // draw all the surfaces of the layer + std::list surfaces = currentLayer->surfaces; + for(std::list::const_iterator currentS = surfaces.begin(); currentS != surfaces.end(); currentS++){ + if ((*currentS)->visibility && (*currentS)->opacity>0.0f){ + Surface* currentSurface = (Surface*)*currentS; + PlatformSurface* nativeSurface = (PlatformSurface*)currentSurface->platform; + if (NULL==nativeSurface) + { + LOG_INFO("NullWindowSystem","creating native surface for new window"); + // this surface does not have a native platform surface attached yet! + currentSurface->platform = graphicSystem->m_binder->createPlatformSurface(currentSurface); + currentSurface->OriginalSourceWidth=256; + currentSurface->OriginalSourceHeight=256; + graphicSystem->m_binder->createClientBuffer(currentSurface); + LOG_INFO("NullWindowSystem","created native surface for new window"); + } + graphicSystem->drawSurface(currentLayer,currentSurface); + + } + } + } + } + + if (debugMode) + { + printDebug(200,windowHeight-40); + } + UpdateTimeCounter(); + CalculateFPS(); + char floatStringBuffer[256]; + sprintf(floatStringBuffer, "FPS: %f", FPS); + if ((Frame % 1000 ) == 0) + { + LOG_INFO("NullWindowSystem",floatStringBuffer); + } + + graphicSystem->swapBuffers(); + +} + + + +void* NullWindowSystem::EventLoop(void * ptr) +{ + LOG_DEBUG("NullWindowSystem", "Enter thread"); + NullWindowSystem *windowsys = (NullWindowSystem *) ptr; + + // init own stuff + m_success = false; + + // then init graphiclib + int display = 0; + void* window = NULL; + m_success = windowsys->graphicSystem->init(&display,&window,windowHeight,windowWidth); + + m_initialized = true; + // start +// // get instance of Renderer for this thread + Layer* defaultLayer; +// X11WindowSystem *renderer = (X11WindowSystem *) ptr; +// if (renderer != NULL) +// { +// } +// // initialize the renderer (OpenGL etc) +// renderer->init(); +// // run the main event loop while rendering + bool running = windowsys->m_success; + gettimeofday(&tv0, NULL); + FramesPerFPS = 30; + if (debugMode) + { + defaultLayer = windowsys->layerlist->createLayer(); + defaultLayer->setOpacity(1.0); + defaultLayer->setDestinationRegion(Rectangle(0,0,windowsys->resolutionWidth,windowsys->resolutionHeight)); + defaultLayer->setSourceRegion(Rectangle(0,0,windowsys->resolutionWidth,windowsys->resolutionHeight)); + windowsys->layerlist->getCurrentRenderOrder().push_back(defaultLayer); + } + LOG_DEBUG("NullWindowSystem", "Enter render loop"); + while (running) + { + windowsys->Redraw(); + } + LOG_INFO("NullWindowSystem", "Renderer thread finished"); + return NULL; +} + + +bool NullWindowSystem::start(int displayWidth, int displayHeight, const char* DisplayName){ + LOG_INFO("NullWindowSystem", "Starting / Creating thread"); + pthread_t renderThread; + NullWindowSystem *renderer = this; + resolutionWidth = displayWidth; + resolutionHeight = displayHeight; + int status = pthread_create( &renderThread, NULL, NullWindowSystem::EventLoop, (void*) renderer); + if (0 != status ) + { + return false; + } + while ( m_initialized == false ) + { + sleep(1); + LOG_INFO("NullWindowSystem","Waiting start complete " << m_initialized); + } + LOG_INFO("NullWindowSystem","Start complete " << m_initialized << " success " << m_success); + return m_success; +} diff --git a/LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/X11WindowSystem.cpp b/LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/X11WindowSystem.cpp new file mode 100644 index 0000000..4301ec8 --- /dev/null +++ b/LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/X11WindowSystem.cpp @@ -0,0 +1,702 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 "WindowSystems/X11WindowSystem.h" +#include "Log.h" +#include "Layer.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int X11WindowSystem::composite_opcode; +const char X11WindowSystem::CompositorWindowTitle[] = "LayerManager"; +bool X11WindowSystem::m_success = false; +bool X11WindowSystem::m_initialized = false; + +X11WindowSystem::X11WindowSystem(LayerList* layerlist, BaseGraphicSystem* graphicSystem,GetVisualInfoFunction func) : BaseWindowSystem(layerlist, graphicSystem), getVisualFunc(func), windowWidth(1280), windowHeight(480),resolutionWidth(1280),resolutionHeight(480),debugMode(false){ + LOG_DEBUG("X11WindowSystem", "creating X11WindowSystem"); + + }; + +XVisualInfo* X11WindowSystem::getDefaultVisual(Display *dpy) + { + XVisualInfo* windowVis = new XVisualInfo(); + windowVis->depth = DefaultDepth(dpy, 0);; + XMatchVisualInfo( dpy, 0, windowVis->depth, TrueColor, windowVis); + if (!windowVis) + { + LOG_ERROR("X11WindowSystem", "Error: Unable to acquire visual\n"); + } + return windowVis; + }; + +void X11WindowSystem::OpenDisplayConnection(){ + x11Display = XOpenDisplay(NULL); + if (!x11Display) + { + LOG_ERROR("X11WindowSystem", "Couldn't open default display!"); + } +} + +void X11WindowSystem::checkForCompositeExtension(){ + if (!XQueryExtension (x11Display, COMPOSITE_NAME, &composite_opcode, + &composite_event, &composite_error)) + { + LOG_ERROR("X11WindowSystem", "No composite extension"); + } + XCompositeQueryVersion (x11Display, &composite_major, &composite_minor); + LOG_DEBUG("X11WindowSystem", "Found composite extension: composite opcode: " << composite_opcode); + LOG_DEBUG("X11WindowSystem", "composite_major: " << composite_major); + LOG_DEBUG("X11WindowSystem", "composite_minor: " << composite_minor); +} + +void X11WindowSystem::printDebug(int posx,int posy){ + // print stuff about layerlist + std::stringstream debugmessage; + debugmessage << "Layer: ID | X | Y | W | H | Al. \n"; + // loop the layers + std::list list = layerlist->getCurrentRenderOrder(); + for(std::list::const_iterator currentLayer = list.begin(); + currentLayer != list.end(); currentLayer++) + { + Rectangle dest = (*currentLayer)->getDestinationRegion(); + debugmessage << " " << std::setw(4) << (*currentLayer)->getID() << " " << std::setw(3) << dest.x << " " << std::setw(3) << dest.y << " " << std::setw(3) << dest.width << " " << std::setw(3) << dest.height << " " << std::setw(3) << (*currentLayer)->opacity << "\n"; + + debugmessage << " Surface: ID |Al.| SVP: X | Y | W | H DVP: X | Y | W | H \n"; + // loop the surfaces of within each layer + for(std::list::iterator current = (*currentLayer)->surfaces.begin(); + current != (*currentLayer)->surfaces.end(); current++) + { + Rectangle src = (*current)->getSourceRegion(); + Rectangle dest = (*current)->getDestinationRegion(); + debugmessage << " " << std::setw(4) << (*current)->getID() << " " << std::setprecision(3) << (*current)->opacity<< " " << std::setw(3) << src.x << " " << std::setw(3) << src.y << " " << std::setw(3) << src.width << " " << std::setw(3) << src.height << " " << std::setw(3) << dest.x << " " << std::setw(3) << dest.y << " " << std::setw(3) << dest.width << " " << std::setw(3) << dest.height << "\n"; + } + } + LOG_INFO("X11WindowSystem",debugmessage.str()); +} + +Window * getListOfAllTopLevelWindows (Display *disp, unsigned int *len) { + LOG_DEBUG("X11WindowSystem", "Getting list of all windows"); + Window *children; + Window root_return, parent_return; + Window root = XDefaultRootWindow(disp); + XQueryTree (disp, root, &root_return, &parent_return, &children, len); + return children; +} + +bool X11WindowSystem::isWindowValid(Window w){ + // skip our own two windows + if (w != CompositorWindow) + return true; + else + return false; +} + +Surface* X11WindowSystem::getSurfaceForWindow(Window w){ + LOG_DEBUG("X11WindowSystem", "finding surface for window " << w); + // go though all surfaces + const std::map surfaces = layerlist->getAllSurfaces(); + for(std::map::const_iterator currentS = surfaces.begin(); currentS != surfaces.end(); currentS++){ + Surface* currentSurface = (*currentS).second; + XPlatformSurface* x11surf = NULL; + if (NULL != currentSurface->platform){ + x11surf = (XPlatformSurface*)currentSurface->platform; + if (currentSurface->nativeHandle == w){ + LOG_DEBUG("X11WindowSystem", "surface " << currentSurface->getID() << " corresponds to window" << w); + return currentSurface; + } + } + } + LOG_DEBUG("X11WindowSystem", "could not find surface for window " << w); + return NULL; +} + + +void X11WindowSystem::configureSurfaceWindow(Window w){ + int status = 0; + if (isWindowValid(w)){ + LOG_DEBUG("X11WindowSystem", "Updating window " << w); + UnMapWindow(w); + MapWindow(w); + LOG_INFO("X11WindowSystem","after map 1"); + XWindowAttributes att; + status = XGetWindowAttributes (x11Display, w, &att); + int winWidth = att.width; + int winHeight = att.height; + + Surface*s = getSurfaceForWindow(w); + if (s==NULL){ + LOG_ERROR("X11WindowSystem", "surface emtpy"); + return; + } + if (s->platform==NULL){ + LOG_ERROR("X11WindowSystem", "platform surface empty"); + return; + } + + LOG_DEBUG("X11WindowSystem", "Updating surface " << s->getID()); + + s->OriginalSourceHeight =winHeight; + s->OriginalSourceWidth = winWidth; + s->setDestinationRegion(Rectangle(0,0,winWidth,winHeight)); + s->setSourceRegion(Rectangle(0,0,winWidth,winHeight)); + + LOG_DEBUG("X11WindowSystem", "Done Updating window " << w); + } +} + +void X11WindowSystem::MapWindow(Window window){ + int status = 0; + if (isWindowValid(window)) + { + XWindowAttributes att; + status = XGetWindowAttributes (x11Display, window, &att); + if (att.map_state == IsViewable && att.override_redirect==0){ + LOG_DEBUG("X11WindowSystem", "Mapping window " << window); + Surface* surface = getSurfaceForWindow(window); + if (surface==NULL){ + LOG_ERROR("X11WindowSystem", "surface emtpy"); + return; + } + if (surface->platform==NULL){ + LOG_ERROR("X11WindowSystem", "platform surface empty"); + return; + } + + XPlatformSurface* x11surf = (XPlatformSurface*)surface->platform; + if (x11surf->isMapped){ + LOG_ERROR("X11WindowSystem", "already mapped!"); + return; + } + x11surf->isMapped = true; + + + LOG_DEBUG("X11WindowSystem", "getting pixmap for window"); + LOG_DEBUG("X11WindowSystem", "window width: " << att.width); + LOG_DEBUG("X11WindowSystem", "window height: " << att.height); + LOG_DEBUG("X11WindowSystem", "map state: " << att.map_state); + LOG_DEBUG("X11WindowSystem", "window x: " << att.x); + LOG_DEBUG("X11WindowSystem", "window backing: " << att.backing_pixel); + LOG_DEBUG("X11WindowSystem", "window save under: " << att.save_under); + LOG_DEBUG("X11WindowSystem", "window orride: " << att.override_redirect); + LOG_DEBUG("X11WindowSystem", "parent/root: " << att.root); + LOG_DEBUG("X11WindowSystem", "root window: " << DefaultRootWindow(x11Display)); + + int winWidth = att.width; + int winHeight = att.height; + + surface->OriginalSourceHeight = winHeight; + surface->OriginalSourceWidth = winWidth; + surface->setDestinationRegion(Rectangle(0,0,winWidth,winHeight)); + surface->setSourceRegion(Rectangle(0,0,winWidth,winHeight)); + + graphicSystem->m_binder->createClientBuffer(surface); + XSync(x11Display, 0); + + surface->visibility = true; + surface->setOpacity(1.0); + LOG_DEBUG("X11WindowSystem", "Mapping Surface " << surface->getID()); + LOG_DEBUG("X11WindowSystem", "Done mapping"); + } + } + LOG_INFO("EglXCompositeRenderer","mapping end"); +} + +void X11WindowSystem::UnMapWindow(Window window){ + if (isWindowValid(window)){ + LOG_DEBUG("X11WindowSystem", "Unmapping window " << window); + Surface* surface = getSurfaceForWindow(window); + if (surface==NULL){ + LOG_ERROR("X11WindowSystem", "surface emtpy"); + return; + } + // set invisible first, so it wont be used for rendering anymore + surface->visibility = false; + if (surface->platform==NULL){ + LOG_ERROR("X11WindowSystem", "platform surface empty"); + return; + } + XPlatformSurface* x11surf = (XPlatformSurface*)surface->platform; + LOG_DEBUG("X11WindowSystem", "Unmapping surface " << surface->getID()); + x11surf->isMapped = false; + + + LOG_DEBUG("X11WindowSystem", "Destroying ClientBuffer"); + graphicSystem->m_binder->destroyClientBuffer(surface); + XSync(x11Display, 0); + + LOG_DEBUG("X11WindowSystem", "Removing X Pixmap"); + + XSync(x11Display, 0); + } + LOG_DEBUG("X11WindowSystem", "Unmap finished"); +} + +void X11WindowSystem::NewWindow(Surface* surface, Window window) +{ + if (isWindowValid(window)){ + LOG_DEBUG("X11WindowSystem", "Creating Surface for new window " << window); + // get the windows attributes + XWindowAttributes att; + int status = XGetWindowAttributes (x11Display, window, &att); + LOG_DEBUG("X11WindowSystem", "Got window attrbutes"); + char* name; + status = XFetchName(x11Display, window, &name); + LOG_DEBUG("X11WindowSystem", "Got window name"); + if (status >= Success) + { + LOG_DEBUG("X11WindowSystem", "Found window: " << window << " " << name); + char GuiTitle[] = "Layermanager Remote GUI\0"; + if (name != NULL && strcmp(name,GuiTitle)==0){ + LOG_DEBUG("X11WindowSystem", "Found gui window: repositioning it"); + XCompositeUnredirectWindow(x11Display,window,CompositeRedirectManual); +//XLowerWindow(x11Display,window); + XMoveWindow(x11Display, window, 50, 500); + XMapRaised(x11Display, window); + } + }else { + LOG_DEBUG("X11WindowSystem", "Error fetching window name"); + } + XFree(name); +XLowerWindow(x11Display,window); +//XMoveWindow(x11Display,window,-1000,-1000); + // Surface* s = layerlist->createSurface(); + + surface->nativeHandle = window; + XPlatformSurface * platformSurface = (XPlatformSurface*)graphicSystem->m_binder->createPlatformSurface(surface); + platformSurface->isMapped = false; + + LOG_DEBUG("X11WindowSystem", "Created native Surface for X11 Window id " << window); + + surface->nativeHandle = window; + surface->platform = platformSurface; + surface->visibility = false; + + int winWidth = att.width; + int winHeight = att.height; + + surface->OriginalSourceHeight =winHeight; + surface->OriginalSourceWidth = winWidth; + surface->setDestinationRegion(Rectangle(0,0,winWidth,winHeight)); + surface->setSourceRegion(Rectangle(0,0,winWidth,winHeight)); + LOG_DEBUG("X11WindowSystem", "orig width " << surface->OriginalSourceWidth); + LOG_DEBUG("X11WindowSystem", "orig heigth " << surface->OriginalSourceHeight); + }else{ + LOG_DEBUG("X11WindowSystem", "skipping window"); + } + LOG_DEBUG("X11WindowSystem", "created the new surface"); +} + +void X11WindowSystem::DestroyWindow(Window window){ + if (isWindowValid(window)){ + LOG_DEBUG("X11WindowSystem", "Destroying Surface for window " << window); + Surface* surface = getSurfaceForWindow(window); + if (surface==NULL){ + LOG_ERROR("X11WindowSystem", "surface empty"); + return; + } + graphicSystem->m_binder->destroyClientBuffer(surface); + UnMapWindow(window); + layerlist->removeSurface(surface); + LOG_DEBUG("X11WindowSystem", "Removed Surface " << surface->getID()); + } +} + +bool +X11WindowSystem::CreatePixmapsForAllWindows() +{ + bool result = true; + LOG_DEBUG("X11WindowSystem", "redirecting all windows"); + Window root = RootWindow(x11Display, 0); + XGrabServer (x11Display); + unsigned int numberOfWindows = 0; + Window *children = getListOfAllTopLevelWindows(x11Display,&numberOfWindows); + + LOG_DEBUG("X11WindowSystem", "Found " << numberOfWindows << " windows"); + XCompositeRedirectSubwindows(x11Display,root,CompositeRedirectManual); + +/* for (unsigned int i=0;i< (numberOfWindows-1);i++) + { + Window w = (Window) children[i]; + NewWindow(w); + MapWindow(w); + } */ + XFree(children); + XUngrabServer (x11Display); + XSync(x11Display, 0); + + return result; +} + + + + +bool X11WindowSystem::CreateCompositorWindow() +{ + LOG_DEBUG("X11WindowSystem", "Get root window"); + bool result = true; + Window root = XDefaultRootWindow(x11Display); + + LOG_DEBUG("X11WindowSystem", "Get default screen"); + // draw a black background the full size of the resolution + long x11Screen = XDefaultScreen( x11Display ); + + LOG_DEBUG("X11WindowSystem", "Creating Compositor Window"); + // create the actual content window +// CompositorWindow = XCreateSimpleWindow( x11Display, root, 0, 0, windowWidth, windowHeight, +// 0, BlackPixel(x11Display, x11Screen), WhitePixel(x11Display, x11Screen)); + XSetWindowAttributes attr; + // draw a black background the full size of the resolution + attr.override_redirect = True; + attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask | StructureNotifyMask; + attr.background_pixel = 0; + attr.border_pixel = 0; + windowVis = getVisualFunc(x11Display); + attr.colormap = XCreateColormap(x11Display, root, windowVis->visual, AllocNone); + + attr.override_redirect = True; + + // Window overlaywindow = XCompositeGetOverlayWindow(x11Display,root); + + CompositorWindow = XCreateWindow(x11Display, root, 0, 0, windowWidth, windowHeight, + 0, windowVis->depth, InputOutput, + windowVis->visual, CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect, &attr); + + + if (!CompositorWindow) + { + LOG_ERROR("X11WindowSystem", "Could not create window"); + return false; + } + LOG_DEBUG("X11WindowSystem", "Created the Compositor Window"); + XSelectInput (x11Display, root, + SubstructureNotifyMask| + ExposureMask| + StructureNotifyMask| + PropertyChangeMask); + + LOG_DEBUG("X11WindowSystem", "Created the window"); + XSizeHints sizehints; + sizehints.width = windowWidth; + sizehints.height = windowHeight; + sizehints.flags = USSize; + XSetNormalHints(x11Display, CompositorWindow, &sizehints); + XSetStandardProperties(x11Display, CompositorWindow, CompositorWindowTitle, CompositorWindowTitle, + None, (char **)NULL, 0, &sizehints); + XMapRaised(x11Display, CompositorWindow); + return result; +} + +float TimeCounter, LastFrameTimeCounter, DT, prevTime = 0.0, FPS; +struct timeval tv, tv0; +int Frame = 1, FramesPerFPS; + +void UpdateTimeCounter() { + LastFrameTimeCounter = TimeCounter; + gettimeofday(&tv, NULL); + TimeCounter = (float)(tv.tv_sec-tv0.tv_sec) + 0.000001*((float)(tv.tv_usec-tv0.tv_usec)); + DT = TimeCounter - LastFrameTimeCounter; } + +void CalculateFPS() { + Frame ++; + + if((Frame%FramesPerFPS) == 0) { + FPS = ((float)(FramesPerFPS)) / (TimeCounter-prevTime); + prevTime = TimeCounter; } } + +void +X11WindowSystem::Redraw() +{ + // draw all the layers + graphicSystem->clearBackground(); + std::list layers = layerlist->getCurrentRenderOrder(); + for(std::list::const_iterator current = layers.begin(); current != layers.end(); current++){ + Layer* currentLayer = (Layer*)*current; + if ((*currentLayer).visibility && (*currentLayer).opacity>0.0f){ + // glRotated(-90*currentLayer->getOrientation(),0,0,1.0); + // draw all the surfaces of the layer + std::list surfaces = currentLayer->surfaces; + for(std::list::const_iterator currentS = surfaces.begin(); currentS != surfaces.end(); currentS++){ + if ((*currentS)->visibility && (*currentS)->opacity>0.0f){ + Surface* currentSurface = (Surface*)*currentS; + XPlatformSurface* nativeSurface = (XPlatformSurface*)currentSurface->platform; + if (NULL==nativeSurface) + { + LOG_INFO("X11WindowSystem","creating native surface for new window"); + // this surface does not have a native platform surface attached yet! + NewWindow(currentSurface,currentSurface->nativeHandle); + MapWindow(currentSurface->nativeHandle); + } + graphicSystem->drawSurface(currentLayer,currentSurface); + + } + } + } + } + + if (debugMode) + { + printDebug(200,windowHeight-40); + } + UpdateTimeCounter(); + CalculateFPS(); + char floatStringBuffer[256]; + sprintf(floatStringBuffer, "FPS: %f", FPS); + if ((Frame % 1000 ) == 0) + { + LOG_INFO("X11WindowSystem",floatStringBuffer); + } + graphicSystem->swapBuffers(); +} + +int +X11WindowSystem::error (Display *dpy, XErrorEvent *ev) +{ + const char *name = NULL; + static char buffer[256]; + + if (ev->request_code == composite_opcode && + ev->minor_code == X_CompositeRedirectWindow) + { + LOG_ERROR("X11WindowSystem", "Another composite manager is already running!"); + } + + if (name == NULL) + { + buffer[0] = '\0'; + XGetErrorText (dpy, ev->error_code, buffer, sizeof (buffer)); + name = buffer; + } + name = (strlen (name) > 0) ? name : "unknown"; + LOG_ERROR("X11WindowSystem", "X Error: " << (int)ev->error_code << " " << name << " request : " << (int)ev->request_code << " minor: " << (int)ev->minor_code << " serial: " << (int)ev->serial); + return 0; +} + +//void X11WindowSystem::setDisplayMode(){ +// XF86VidModeModeInfo **modes; +// int modeNum; +// int bestMode = -1; +// LOG_DEBUG("X11WindowSystem", "trying for fullscreen mode " << resolutionWidth << " " << resolutionHeight); +// XF86VidModeGetAllModeLines(x11Display, 0, &modeNum, &modes); +// LOG_DEBUG("X11WindowSystem", "found " << modeNum << " modes"); +// /* look for mode with requested resolution */ +// for (int i = 0; i < modeNum; i++) +// if ((modes[i]->hdisplay == resolutionWidth) && (modes[i]->vdisplay == resolutionHeight)) +// bestMode = i; +// if (bestMode==-1){ +// int bestHeight = 0; +// for (int i = 0; i < modeNum; i++) +// if (modes[i]->hdisplay == resolutionWidth && modes[i]->vdisplay >= bestHeight){ +// bestMode = i; +// bestHeight = modes[i]->vdisplay; +// } +// } +// if (bestMode>=0){ +// LOG_DEBUG("X11WindowSystem", "changing mode to "<< modes[bestMode]->hdisplay << " " << modes[bestMode]->vdisplay ); +// XF86VidModeSwitchToMode(x11Display, 0, modes[bestMode]); +// XF86VidModeSetViewPort(x11Display, 0, 0, 0); +// +// }else{ +// LOG_ERROR("X11WindowSystem", "could not find appropriate mode!"); +// // take last mode, its probably the highest resolution +// resolutionWidth = modes[modeNum-1]->hdisplay; +// resolutionHeight = modes[modeNum-1]->vdisplay; +// windowWidth = resolutionWidth; +// if (windowHeight>resolutionHeight) +// windowHeight = resolutionHeight; +// XF86VidModeSwitchToMode(x11Display, 0, modes[modeNum-1]); +// XF86VidModeSetViewPort(x11Display, 0, 0, 0); +// } +// LOG_DEBUG("X11WindowSystem", "Set the mode"); +// LOG_DEBUG("X11WindowSystem", "mode: " << resolutionWidth << "x" << resolutionHeight); +// LOG_DEBUG("X11WindowSystem", "renderwindow: " << windowWidth << "x" << windowHeight); +//} + +bool X11WindowSystem::initXServer() +{ + LOG_DEBUG("X11WindowSystem", "Initialising XServer connection"); + bool result = true; + + //setDisplayMode(); + if ( !CreateCompositorWindow() ) + { + LOG_ERROR("X11WindowSystem", "Compositor Window creation failed " ); + return false; + } + + LOG_DEBUG("X11WindowSystem", "Compositor Window ID: " << CompositorWindow); + + // LOG_DEBUG("X11WindowSystem", "Allocate Pixmaps for all the offscreen windows"); + CreatePixmapsForAllWindows(); + // LOG_DEBUG("X11WindowSystem", "Allocated Pixmaps"); + + //unredirect our window +#ifdef FULLSCREEN + XCompositeUnredirectWindow(x11Display,background,CompositeRedirectManual); +#endif + XCompositeUnredirectWindow(x11Display,CompositorWindow,CompositeRedirectManual); + + //unredirect special windows if present + XGrabServer (x11Display); + unsigned int numberOfWindows = 0; + Window *children = getListOfAllTopLevelWindows(x11Display,&numberOfWindows); + LOG_DEBUG("X11WindowSystem", "unredirecting special windows"); + for (unsigned int i=0;i= Success) + { + char GuiTitle[] = "Layermanager Remote GUI\0"; + char DFEETTITLE[] = "D-Feet D-Bus debugger\0"; + if (name != NULL && (strcmp(name,GuiTitle)==0 || strcmp(name,DFEETTITLE)==0 ) ){ + LOG_DEBUG("X11WindowSystem", "Found gui window: repositioning it"); + XCompositeUnredirectWindow(x11Display,w,CompositeRedirectManual); + XCompositeUnredirectSubwindows(x11Display,w,CompositeRedirectAutomatic); + XMoveWindow(x11Display, w, 50, 500); + XMapRaised(x11Display, w); + } + } + } + XFree(children); + XUngrabServer (x11Display); + XSync(x11Display, 0); + + LOG_DEBUG("X11WindowSystem", "Initialised XServer connection"); + return result; +} + +void* X11WindowSystem::EventLoop(void * ptr) +{ + LOG_DEBUG("X11WindowSystem", "Enter thread"); + X11WindowSystem *windowsys = (X11WindowSystem *) ptr; + + // init own stuff + m_success = false; + + windowsys->OpenDisplayConnection(); + windowsys->checkForCompositeExtension(); + windowsys->initXServer(); + + // then init graphiclib + m_success = windowsys->graphicSystem->init(&windowsys->x11Display,&windowsys->CompositorWindow,windowsys->windowHeight,windowsys->windowWidth); + m_initialized = true; + + Layer* defaultLayer; + + // run the main event loop while rendering + bool running = windowsys->m_success; + gettimeofday(&tv0, NULL); + FramesPerFPS = 30; + if (windowsys->debugMode) + { + defaultLayer = windowsys->layerlist->createLayer(); + defaultLayer->setOpacity(1.0); + defaultLayer->setDestinationRegion(Rectangle(0,0,windowsys->resolutionWidth,windowsys->resolutionHeight)); + defaultLayer->setSourceRegion(Rectangle(0,0,windowsys->resolutionWidth,windowsys->resolutionHeight)); + windowsys->layerlist->getCurrentRenderOrder().push_back(defaultLayer); + } + LOG_DEBUG("X11WindowSystem", "Enter render loop"); + while (running) + { + if ( XPending(windowsys->x11Display) > 0) { + XEvent event; + XNextEvent(windowsys->x11Display, &event); + switch (event.type) { + case CreateNotify: + { + if (windowsys->debugMode) + { + LOG_DEBUG("X11WindowSystem", "CreateNotify Event"); + Surface* s = windowsys->layerlist->createSurface(); + s->setOpacity(1.0); + windowsys->NewWindow(s, event.xcreatewindow.window); + defaultLayer->addSurface(s); + } + break; + } + case ConfigureNotify: + LOG_DEBUG("X11WindowSystem", "Configure notify Event"); + windowsys->configureSurfaceWindow( event.xconfigure.window); + break; + + case DestroyNotify: + LOG_DEBUG("X11WindowSystem", "Destroy Event"); + windowsys->DestroyWindow(event.xdestroywindow.window); + break; + case Expose: + LOG_DEBUG("X11WindowSystem", "Expose Event"); + windowsys->Redraw(); + break; + case ButtonPress: + LOG_DEBUG("X11WindowSystem", "Button press Event"); + //running = False; + break; + case MapNotify: + LOG_DEBUG("X11WindowSystem", "Map Event"); + windowsys->MapWindow(event.xmap.window); + break; + case UnmapNotify: + LOG_DEBUG("X11WindowSystem", "Unmap Event"); + windowsys->UnMapWindow(event.xunmap.window); + break; + case ReparentNotify: + LOG_DEBUG("X11WindowSystem", "Reparent Event"); + // if (event.xreparent.parent == root) + // renderer->NewWindow(event.xreparent.window); + // else + // renderer->DestroyWindow(event.xreparent.window); + break; + + default: + ; /*no-op*/ + } + } + windowsys->Redraw(); + } + LOG_INFO("X11WindowSystem", "Renderer thread finished"); + return NULL; +} + + +bool X11WindowSystem::start(int displayWidth, int displayHeight, const char* DisplayName){ + LOG_INFO("X11WindowSystem", "Starting / Creating thread"); + pthread_t renderThread; + X11WindowSystem *renderer = this; + resolutionWidth = displayWidth; + resolutionHeight = displayHeight; + int status = pthread_create( &renderThread, NULL, X11WindowSystem::EventLoop, (void*) renderer); + if (0 != status ) + { + return false; + } + while ( m_initialized == false ) + { + sleep(1); + LOG_INFO("X11WindowSystem","Waiting start complete " << m_initialized); + } + LOG_INFO("X11WindowSystem","Start complete " << m_initialized << " success " << m_success); + return m_success; +} diff --git a/LayerManagerPlugins/Renderers/Platform/BeagleRenderer/include/BeagleRenderer.h b/LayerManagerPlugins/Renderers/Platform/BeagleRenderer/include/BeagleRenderer.h new file mode 100644 index 0000000..85d65f5 --- /dev/null +++ b/LayerManagerPlugins/Renderers/Platform/BeagleRenderer/include/BeagleRenderer.h @@ -0,0 +1,49 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 BEAGLERENDERER_H_ +#define BEAGLERENDERER_H_ + +#include "BaseRenderer.h" +#include "TextureBinders/BeagleEglImage.h" +#include "GraphicSystems/GLESGraphicSystem.h" +#include "WindowSystems/NullWindowSystem.h" +#include "ShaderProgramBeagle.h" + +class BeagleRenderer : public BaseRenderer +{ +public: + BeagleRenderer(LayerList* layerlist) : BaseRenderer(layerlist) + { + LOG_DEBUG("BeagleRenderer", "Creating Renderer"); + ITextureBinder* binder = new BeagleEglImage(); + BaseGraphicSystem* graphicSystem = new GLESGraphicsystem( ShaderProgramBeagle::createProgram, binder); + m_windowSystem = new NullWindowSystem(layerlist, graphicSystem); + }; +}; + +extern "C" BaseRenderer* createBeagleRenderer(LayerList* layerlist) { + return new BeagleRenderer(layerlist); +} + +extern "C" void destroyBeagleRenderer(BeagleRenderer* p) { + delete p; +} + +#endif /* BEAGLERENDERER_H_ */ diff --git a/LayerManagerPlugins/Renderers/Platform/BeagleRenderer/include/ShaderProgramBeagle.h b/LayerManagerPlugins/Renderers/Platform/BeagleRenderer/include/ShaderProgramBeagle.h new file mode 100644 index 0000000..5841289 --- /dev/null +++ b/LayerManagerPlugins/Renderers/Platform/BeagleRenderer/include/ShaderProgramBeagle.h @@ -0,0 +1,115 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 BEAGLESHADERPROGRAM_H_ +#define BEAGLESHADERPROGRAM_H_ + +#include +#include + + +/// pointer to shader program creator function +typedef ShaderProgram* (*PfnShaderProgramCreator)(const std::string&, const std::string&); + +/** + * Factory for creating platform specific shader programs. + */ +class ShaderProgramBeagle : public ShaderProgram +{ +public: + /** + * Create a new shader program. + * + * @param vertName File name of vertex shader. + * @param fragName File name of fragment shader. + * @return new Program instance, NULL if program could not be created. + */ + static ShaderProgram* createProgram(const std::string& vertName, const std::string& fragName); + + /** + * Destructor + */ + virtual ~ShaderProgramBeagle(void); + + /** + * Start using the shader program for rendering. + */ + virtual void use(void) const; + + virtual int getUniformLocation(const char* name) const + { + return glGetUniformLocation(_progHandle, name); + } + + virtual void uniform1iv(int location, int count, const int* v) const + { + glUniform1iv(location, count, v); + } + + virtual void uniform1fv(int location, int count, const float* v) const + { + glUniform1fv(location, count, v); + } + + virtual void uniform2fv(int location, int count, const float* v) const + { + glUniform2fv(location, count, v); + } + + virtual void uniform3fv(int location, int count, const float* v) const + { + glUniform3fv(location, count, v); + } + + virtual void uniform4fv(int location, int count, const float* v) const + { + glUniform4fv(location, count, v); + } + + virtual void uniformMatrix2fv(int location, int count, bool transpose, const float* v) const + { + glUniformMatrix2fv(location, count, transpose, v); + } + + virtual void uniformMatrix3fv(int location, int count, bool transpose, const float* v) const + { + glUniformMatrix3fv(location, count, transpose, v); + } + + virtual void uniformMatrix4fv(int location, int count, bool transpose, const float* v) const + { + glUniformMatrix4fv(location, count, transpose, v); + } + +protected: + /** + * Protected constructor. + * New instances of this class are supposed to be created by ShaderProgramBeagle::createProgram. + * + * @param vertName File name of vertex shader. + * @param fragName File name of fragment shader. + */ + ShaderProgramBeagle(const std::string& vertName, const std::string& fragName, GLuint handle); + +private: + /// OpenGL ES program handle + GLuint _progHandle; +}; + +#endif /* BEAGLESHADERPROGRAM_H_ */ diff --git a/LayerManagerPlugins/Renderers/Platform/BeagleRenderer/makefile b/LayerManagerPlugins/Renderers/Platform/BeagleRenderer/makefile new file mode 100644 index 0000000..5902f61 --- /dev/null +++ b/LayerManagerPlugins/Renderers/Platform/BeagleRenderer/makefile @@ -0,0 +1,78 @@ +############################################################################ +# +# Copyright 2010 BMW Car IT GmbH +# +# +# 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. +# +############################################################################ +ifneq ($(CONFIG),) +include ../../../../LayerManagerPlatform/Make$(CONFIG).defs +endif + +SRC = BeagleRenderer.cpp \ + GLESGraphicSystem.cpp \ + NullWindowSystem.cpp \ + BaseRenderer.cpp \ + ShaderProgramBeagle.cpp + +TARGET_NAME = libBeagleRenderer.so + +ADD_INCLUDE_DIR+=include \ + ../../Base/include \ + ../../Graphic/include \ + $(PREFIX)/usr/include/layermanager + +ADD_LIB_DIR+= $(PREFIX)/usr/lib/layermanager + +ADD_LIBS+= EGL Xcomposite pthread GLESv2 LayerManagerUtils Xxf86vm + +OBJS = $(patsubst %.cpp,build/%.o,$(SRC)) +TARGET = build/$(TARGET_NAME) +INCLUDE= $(patsubst %$,-I%,$(ADD_INCLUDE_DIR)) +LIBS+=$(shell pkg-config --libs $(PKG)) $(patsubst %$,-L%,$(ADD_LIB_DIR)) $(patsubst %$,-l%,$(ADD_LIBS)) +LIBS+= cmem.a470uC + +all: $(TARGET) + +build/%.o: src/%.cpp + $(shell mkdir -p $(shell dirname $@)) + $(CXX) $(CXXFLAGS) $(INCLUDE) -c -o $@ $< + +build/%.o: ../../Base/src/%.cpp + $(shell mkdir -p $(shell dirname $@)) + $(CXX) $(CXXFLAGS) $(INCLUDE) -c -o $@ $< + +build/%.o: ../../Graphic/src/GraphicSystems/%.cpp + $(shell mkdir -p $(shell dirname $@)) + $(CXX) $(CXXFLAGS) $(INCLUDE) -c -o $@ $< + +build/%.o: ../../Graphic/src/WindowSystems/%.cpp + $(shell mkdir -p $(shell dirname $@)) + $(CXX) $(CXXFLAGS) $(INCLUDE) -c -o $@ $< + +build/%.o: ../../Graphic/src/TextureBinders/%.cpp + $(shell mkdir -p $(shell dirname $@)) + $(CXX) $(CXXFLAGS) $(INCLUDE) -c -o $@ $< + +$(TARGET): $(SHADERS) $(OBJS) + $(CXX) $(CXXFLAGS) -shared -W1,-soname,$(TARGET) -o $(TARGET) $(OBJS) $(LIBS) + +install: + mkdir -p $(PREFIX)/usr/lib/layermanager/renderer + install -m 755 $(TARGET) $(PREFIX)/usr/lib/layermanager/renderer + +clean: + rm -f $(OBJS) $(TARGET) + rm -rf build + diff --git a/LayerManagerPlugins/Renderers/Platform/BeagleRenderer/renderer_frag.glslf b/LayerManagerPlugins/Renderers/Platform/BeagleRenderer/renderer_frag.glslf new file mode 100644 index 0000000..fa75b92 --- /dev/null +++ b/LayerManagerPlugins/Renderers/Platform/BeagleRenderer/renderer_frag.glslf @@ -0,0 +1,33 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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. +* +****************************************************************************/ +// alpha value of the surfaces +uniform mediump float uAlphaVal; +// textureunit which is accessed +uniform mediump sampler2D uTexUnit; + +// texture coordinates sended by the vertex shader +varying mediump vec2 vTexout; + +void main() +{ + // correct Texture Coords; + mediump vec4 color = texture2D(uTexUnit, vTexout ) * vec4(1.0,1.0,1.0,uAlphaVal); + gl_FragColor = color; +// gl_FragColor.a = 1.0; +} diff --git a/LayerManagerPlugins/Renderers/Platform/BeagleRenderer/renderer_vert.glslv b/LayerManagerPlugins/Renderers/Platform/BeagleRenderer/renderer_vert.glslv new file mode 100644 index 0000000..2b6475c --- /dev/null +++ b/LayerManagerPlugins/Renderers/Platform/BeagleRenderer/renderer_vert.glslv @@ -0,0 +1,50 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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. +* +****************************************************************************/ + +// Vertex position. Will be in range 0 to 1 +attribute highp vec2 aPosition; +attribute highp vec2 aTexCoords; + +// normalized window position +// (0, 0 is upper left, 1, 1 is lower right) +uniform mediump float uX; +uniform mediump float uY; + +// normalized window size +// 1.0 will cover the entire viewport +uniform mediump float uWidth; +uniform mediump float uHeight; + +// texrange describes the width and height of texture area which should be rendered +uniform mediump vec2 uTexRange; +// texrange describes the x and y position of the texture area which should be rendered +uniform mediump vec2 uTexOffset; + +// texture coordinates +varying mediump vec2 vTexout; + +void main() +{ + // Get the size correct. Multiply by 2 because -1 to +1 is mapped to + // the viewport + gl_Position.xy = 2.0 * aPosition.xy * vec2( uWidth, uHeight); // rechte seite des fensters: volle breite sonst 0 +gl_Position.xy += vec2(uX * 2.0 - 1.0+0.5, 1.0 - ((uY + uHeight)* 2.0)); + gl_Position.zw = vec2(0.0, 1.0); + vTexout = vec2(uTexOffset.x + uTexRange.x * aTexCoords.x,1.0-(uTexOffset.y + aTexCoords.y*uTexRange.y+(1.0-uTexRange.y))); +} diff --git a/LayerManagerPlugins/Renderers/Platform/BeagleRenderer/src/BeagleRenderer.cpp b/LayerManagerPlugins/Renderers/Platform/BeagleRenderer/src/BeagleRenderer.cpp new file mode 100644 index 0000000..6e0508e --- /dev/null +++ b/LayerManagerPlugins/Renderers/Platform/BeagleRenderer/src/BeagleRenderer.cpp @@ -0,0 +1,23 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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. +* +****************************************************************************/ + +// this define causes a second window to be created behind the actual compositor +// this window is black and covers the rest of the screen, it has no other funcionality + +#include "BeagleRenderer.h" diff --git a/LayerManagerPlugins/Renderers/Platform/BeagleRenderer/src/ShaderProgramBeagle.cpp b/LayerManagerPlugins/Renderers/Platform/BeagleRenderer/src/ShaderProgramBeagle.cpp new file mode 100644 index 0000000..655eb19 --- /dev/null +++ b/LayerManagerPlugins/Renderers/Platform/BeagleRenderer/src/ShaderProgramBeagle.cpp @@ -0,0 +1,81 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 +#include +#include + + +ShaderProgram* ShaderProgramBeagle::createProgram(const std::string& vertName, const std::string& fragName) +{ + GLuint progHandle; + ShaderProgramBeagle* program = 0; + + if (vertName=="default" && fragName=="default") + { + progHandle = RenderUtilLoadShaderSources("renderer_vert.glslv", "renderer_frag.glslf", GL_TRUE); + } + else + { + // load shader sources from file, compile and link them: + progHandle = RenderUtilLoadShaderSources(vertName.c_str(), fragName.c_str(), GL_TRUE); + } + + if (progHandle!=0) + { + // bind attrib locations for vertex positions and texture coordinates + glBindAttribLocation(progHandle, 0, "aPosition"); + glBindAttribLocation(progHandle, 1, "aTexCoords"); + + // re-link the program as we have changed the attrib bindings + glLinkProgram(progHandle); + + program = new ShaderProgramBeagle(vertName, fragName, progHandle); + } + else + { + LOG_ERROR("ShaderProgramBeagle", "Failed to create and link shader program"); + } + + return program; +} + +ShaderProgramBeagle::ShaderProgramBeagle(const std::string& vertName, const std::string& fragName, GLuint handle) + : ShaderProgram(vertName, fragName) + , _progHandle(handle) +{ + // Update the uniform locations. + // Don't move this call to the base class constructor as we need + // to set the OpenGL program handle first. + updateCommonUniformLocations(); +} + +ShaderProgramBeagle::~ShaderProgramBeagle(void) +{ + if (_progHandle) + { + glDeleteProgram(_progHandle); + } +} + +void ShaderProgramBeagle::use(void) const +{ + glUseProgram(_progHandle); +} + diff --git a/LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/include/ShaderProgramGLES.h b/LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/include/ShaderProgramGLES.h new file mode 100644 index 0000000..72e2f8c --- /dev/null +++ b/LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/include/ShaderProgramGLES.h @@ -0,0 +1,115 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _SHADERPROGRAMGLES_H_ +#define _SHADERPROGRAMGLES_H_ + +#include +#include + +/// pointer to shader program creator function +//typedef ShaderProgram* (*PfnShaderProgramCreator)(const std::string&, const std::string&); + +/** + * Factory for creating platform specific shader programs. + */ +class ShaderProgramGLES : public ShaderProgram +{ +public: + /** + * Create a new shader program. + * + * @param vertName File name of vertex shader. + * @param fragName File name of fragment shader. + * @return new Program instance, NULL if program could not be created. + */ + static ShaderProgram* createProgram(const std::string& vertName, const std::string& fragName); + + /** + * Destructor + */ + virtual ~ShaderProgramGLES(void); + + /** + * Start using the shader program for rendering. + */ + virtual void use(void) const; + + virtual int getUniformLocation(const char* name) const + { + return glGetUniformLocation(_progHandle, name); + } + + virtual void uniform1iv(int location, int count, const int* v) const + { + glUniform1iv(location, count, v); + } + + virtual void uniform1fv(int location, int count, const float* v) const + { + glUniform1fv(location, count, v); + } + + virtual void uniform2fv(int location, int count, const float* v) const + { + glUniform2fv(location, count, v); + } + + virtual void uniform3fv(int location, int count, const float* v) const + { + glUniform3fv(location, count, v); + } + + virtual void uniform4fv(int location, int count, const float* v) const + { + glUniform4fv(location, count, v); + } + + virtual void uniformMatrix2fv(int location, int count, bool transpose, const float* v) const + { + glUniformMatrix2fv(location, count, transpose, v); + } + + virtual void uniformMatrix3fv(int location, int count, bool transpose, const float* v) const + { + glUniformMatrix3fv(location, count, transpose, v); + } + + virtual void uniformMatrix4fv(int location, int count, bool transpose, const float* v) const + { + glUniformMatrix4fv(location, count, transpose, v); + } + +protected: + /** + * Protected constructor. + * New instances of this class are supposed to be created by ShaderProgramGLES::createProgram. + * + * @param vertName File name of vertex shader. + * @param fragName File name of fragment shader. + */ + ShaderProgramGLES(const std::string& vertName, const std::string& fragName, GLuint handle); + +private: + /// OpenGL ES program handle + GLuint _progHandle; +}; + +#endif /* _SHADERPROGRAMFACTORY_H */ + diff --git a/LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/include/X11GLESRenderer.h b/LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/include/X11GLESRenderer.h new file mode 100644 index 0000000..44e86c3 --- /dev/null +++ b/LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/include/X11GLESRenderer.h @@ -0,0 +1,33 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _X11GLESRENDERER_H_ +#define _X11GLESRENDERER_H_ + +#include "BaseRenderer.h" +#include "LayerList.h" + +class X11GLESRenderer : public BaseRenderer +{ +public: + X11GLESRenderer(LayerList* layerlist); + +}; + +#endif /* _X11GLESRENDERER_H_*/ diff --git a/LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/makefile b/LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/makefile new file mode 100644 index 0000000..fe32fa4 --- /dev/null +++ b/LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/makefile @@ -0,0 +1,82 @@ +############################################################################ +# +# Copyright 2010 BMW Car IT GmbH +# +# +# 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. +# +############################################################################ + +ifneq ($(CONFIG),) +include ../../../../LayerManagerPlatform/Make$(CONFIG).defs +endif + +SRC = X11GLESRenderer.cpp \ + GLESGraphicSystem.cpp \ + BaseRenderer.cpp \ + X11WindowSystem.cpp \ + ShaderProgramGLES.cpp \ + X11Copy.cpp \ + X11CopyGLES.cpp \ + X11EglImage.cpp + +TARGET_NAME = libX11GLESRenderer.so + +ADD_INCLUDE_DIR+=include \ + ../../Base/include \ + ../../Graphic/include \ + $(PREFIX)/usr/include/layermanager + +ADD_LIB_DIR+= $(PREFIX)/usr/lib/layermanager + +ADD_LIBS+= EGL GLESv2 pthread Xcomposite LayerManagerUtils + +OBJS = $(patsubst %.cpp,build/%.o,$(SRC)) +TARGET = build/$(TARGET_NAME) +INCLUDE= $(patsubst %$,-I%,$(ADD_INCLUDE_DIR)) +LIBS+=$(shell pkg-config --libs $(PKG)) $(patsubst %$,-L%,$(ADD_LIB_DIR)) $(patsubst %$,-l%,$(ADD_LIBS)) + +all: $(TARGET) + +build/%.o: src/%.cpp + $(shell mkdir -p $(shell dirname $@)) + $(CXX) $(CXXFLAGS) $(INCLUDE) -c -o $@ $< + +build/%.o: ../../Base/src/%.cpp + $(shell mkdir -p $(shell dirname $@)) + $(CXX) $(CXXFLAGS) $(INCLUDE) -c -o $@ $< + +build/%.o: ../../Graphic/src/GraphicSystems/%.cpp + $(shell mkdir -p $(shell dirname $@)) + $(CXX) $(CXXFLAGS) $(INCLUDE) -c -o $@ $< + +build/%.o: ../../Graphic/src/WindowSystems/%.cpp + $(shell mkdir -p $(shell dirname $@)) + $(CXX) $(CXXFLAGS) $(INCLUDE) -c -o $@ $< + +build/%.o: ../../Graphic/src/TextureBinders/%.cpp + $(shell mkdir -p $(shell dirname $@)) + $(CXX) $(CXXFLAGS) $(INCLUDE) -c -o $@ $< + + +$(TARGET): $(OBJS) + $(CXX) $(CXXFLAGS) -shared -W1,-soname,$(TARGET) -o $(TARGET) $(OBJS) $(LIBS) + +install: + mkdir -p $(PREFIX)/usr/lib/layermanager/renderer + install -m 755 $(TARGET) $(PREFIX)/usr/lib/layermanager/renderer + +clean: + rm -f $(OBJS) $(TARGET) + rm -rf build + diff --git a/LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/renderer_frag.glslf b/LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/renderer_frag.glslf new file mode 100644 index 0000000..3c30def --- /dev/null +++ b/LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/renderer_frag.glslf @@ -0,0 +1,32 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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. +* +****************************************************************************/ +// alpha value of the surfaces +uniform float uAlphaVal; +// textureunit which is accessed +uniform mediump sampler2D uTexUnit; + +// texture coordinates sended by the vertex shader +varying mediump vec2 vTexout; + +void main() +{ + // correct Texture Coords; + vec4 mediump color = texture2D(uTexUnit, vTexout ) * vec4(1.0,1.0,1.0,uAlphaVal); + gl_FragColor = color; +} diff --git a/LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/renderer_vert.glslv b/LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/renderer_vert.glslv new file mode 100644 index 0000000..c4b8be6 --- /dev/null +++ b/LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/renderer_vert.glslv @@ -0,0 +1,50 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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. +* +****************************************************************************/ + +// Vertex position. Will be in range 0 to 1 +attribute highp vec2 aPosition; +attribute highp vec2 aTexCoords; + +// normalized window position +// (0, 0 is upper left, 1, 1 is lower right) +uniform mediump float uX; +uniform mediump float uY; + +// normalized window size +// 1.0 will cover the entire viewport +uniform mediump float uWidth; +uniform mediump float uHeight; + +// texrange describes the width and height of texture area which should be rendered +uniform mediump vec2 uTexRange; +// texrange describes the x and y position of the texture area which should be rendered +uniform mediump vec2 uTexOffset; + +// texture coordinates +varying mediump vec2 vTexout; + +void main() +{ + // Get the size correct. Multiply by 2 because -1 to +1 is mapped to + // the viewport + gl_Position.xy = 2.0 * aPosition.xy * vec2( uWidth, uHeight); // rechte seite des fensters: volle breite sonst 0 + gl_Position.xy += vec2(uX * 2.0 - 1.0, 1.0 - ((uY + uHeight)* 2.0)); // linke seite des fensters + gl_Position.zw = vec2(0.0, 1.0); + vTexout = vec2(uTexOffset.x + uTexRange.x * aTexCoords.x,1.0-(uTexOffset.y + aTexCoords.y*uTexRange.y+(1.0-uTexRange.y))); +} diff --git a/LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/src/ShaderProgramGLES.cpp b/LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/src/ShaderProgramGLES.cpp new file mode 100644 index 0000000..63897ee --- /dev/null +++ b/LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/src/ShaderProgramGLES.cpp @@ -0,0 +1,89 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 "ShaderProgramGLES.h" +#include +#include +#include + +static const char defaultVertShaderBinary[] = { +#include "renderer_vert.cghex" +}; +static const char defaultFragShaderBinary[] = { +#include "renderer_frag.cghex" +}; + +ShaderProgram* ShaderProgramGLES::createProgram(const std::string& vertName, const std::string& fragName) +{ + GLuint progHandle; + ShaderProgramGLES* program = 0; + + if (vertName=="default" && fragName=="default") + { + // load default shader from binary data + progHandle = RenderUtilLoadShaderSources("renderer_vert.glslv", "renderer_frag.glslf", GL_TRUE); + } + else + { + // load shader sources from file, compile and link them: + progHandle = RenderUtilLoadShaderSources(vertName.c_str(), fragName.c_str(), GL_FALSE); + } + + if (progHandle!=0) + { + // bind attrib locations for vertex positions and texture coordinates + glBindAttribLocation(progHandle, 0, "aPosition"); + glBindAttribLocation(progHandle, 1, "aTexCoords"); + + // re-link the program as we have changed the attrib bindings + glLinkProgram(progHandle); + + program = new ShaderProgramGLES(vertName, fragName, progHandle); + } + else + { + LOG_ERROR("ShaderProgramGLES", "Failed to create and link shader program"); + } + + return program; +} + +ShaderProgramGLES::ShaderProgramGLES(const std::string& vertName, const std::string& fragName, GLuint handle) + : ShaderProgram(vertName, fragName) + , _progHandle(handle) +{ + // Update the uniform locations. + // Don't move this call to the base class constructor as we need + // to set the OpenGL program handle first. + updateCommonUniformLocations(); +} + +ShaderProgramGLES::~ShaderProgramGLES(void) +{ + if (_progHandle) + { + glDeleteProgram(_progHandle); + } +} + +void ShaderProgramGLES::use(void) const +{ + glUseProgram(_progHandle); +} + diff --git a/LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/src/X11GLESRenderer.cpp b/LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/src/X11GLESRenderer.cpp new file mode 100644 index 0000000..efc3ba1 --- /dev/null +++ b/LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/src/X11GLESRenderer.cpp @@ -0,0 +1,54 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 "X11GLESRenderer.h" +#include "ShaderProgramGLES.h" +#include "GraphicSystems/GLESGraphicSystem.h" +#include "WindowSystems/X11WindowSystem.h" +#include "X11/Xlib.h" +#include "TextureBinders/X11CopyGLES.h" +#include "TextureBinders/X11EglImage.h" + +X11GLESRenderer::X11GLESRenderer(LayerList* layerlist) : BaseRenderer(layerlist) +{ + LOG_DEBUG("X11GLESRenderer", "Creating Renderer"); + + // if no binder has been set yet + Display* display = XOpenDisplay(0); + EGLDisplay m_eglDisplay = eglGetDisplay(display); + ITextureBinder* binder=NULL; + const char* query = eglQueryString(m_eglDisplay, EGL_EXTENSIONS); + LOG_DEBUG("X11GLESRenderer", "EGL_EXTENSIONS: " << query); + #ifdef EGL_NATIVE_PIXMAP_KHR + binder = new X11EglImage((Display*)display); + #else + binder = new X11CopyGLES((Display*)display); + #endif + + BaseGraphicSystem* graphicSystem = new GLESGraphicsystem( ShaderProgramGLES::createProgram, binder); + m_windowSystem = new X11WindowSystem(layerlist, graphicSystem); +}; + +extern "C" BaseRenderer* createX11GLESRenderer(LayerList* layerlist){ + return new X11GLESRenderer(layerlist); +} + +extern "C" void destroyX11GLESRenderer(X11GLESRenderer* p){ + delete p; +} diff --git a/LayerManagerService/include/BaseCommunicator.h b/LayerManagerService/include/BaseCommunicator.h new file mode 100644 index 0000000..6bcbdd5 --- /dev/null +++ b/LayerManagerService/include/BaseCommunicator.h @@ -0,0 +1,67 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _BASECOMMUNICATOR_H_ +#define _BASECOMMUNICATOR_H_ + +class BaseCommunicator; + +#include + +class CommandExecutor; +class ILayerList; + +/** + * Abstract base for all communicator plugins. Subclasses construct command objects + * objects from invidual values and give these to the executor object for processing. + */ +class BaseCommunicator { +public: + + /** + * Constructor + * @param executor Pointer to an object to send commands to + * @param layerlist Pointer to the layerlist currently in use + */ + BaseCommunicator(CommandExecutor * executor, ILayerList* layerlist) : m_executor(executor), m_layerlist(layerlist){}; + virtual ~BaseCommunicator(){}; + + /** + * Start communication process, ie start specific listening process of communication method + */ + virtual bool start()=0; + + /** + * Stop communication. Stop sending command objects. + */ + virtual void stop()=0; + + /** + * Switch debug mode of this component on or off + * @param onoff Turn on debug mode (true) or off (false) + */ + virtual void setdebug(bool onoff)=0; + +protected: + // the object to send received commands to + CommandExecutor* m_executor; + ILayerList* m_layerlist; +}; + +#endif /* _BASECOMMUNICATOR_H_ */ diff --git a/LayerManagerService/include/CommandExecutor.h b/LayerManagerService/include/CommandExecutor.h new file mode 100644 index 0000000..40cdb50 --- /dev/null +++ b/LayerManagerService/include/CommandExecutor.h @@ -0,0 +1,73 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _COMMANDEXECUTOR_H_ +#define _COMMANDEXECUTOR_H_ + +#include "commands/Command.h" +#include "commands/CommitCommand.h" +#include "commands/CreateCommand.h" +#include "commands/GetDimensionCommand.h" +#include "commands/GetOpacityCommand.h" +#include "commands/GetPixelformatCommand.h" +#include "commands/GetVisibilityCommand.h" +#include "commands/LayerAddSurfaceCommand.h" +#include "commands/LayerRemoveSurface.h" +#include "commands/RemoveCommand.h" +#include "commands/GetOrientationCommand.h" +#include "commands/LayergroupAddLayerCommand.h" +#include "commands/LayergroupRemoveLayerCommand.h" +#include "commands/SetDestinationRectangleCommand.h" +#include "commands/SetOpacityCommand.h" +#include "commands/SetSourceRectangleCommand.h" +#include "commands/SetOrientationCommand.h" +#include "commands/SurfacegroupAddSurfaceCommand.h" +#include "commands/SurfacegroupRemoveSurfaceCommand.h" +#include "commands/SetVisibilityCommand.h" +#include "commands/DebugCommand.h" +#include "commands/ExitCommand.h" +#include "commands/SetLayerOrderCommand.h" +#include "commands/SetOrderWithinLayerCommand.h" +#include "commands/SetDimensionCommand.h" +#include "commands/SetPositionCommand.h" +#include "commands/GetPositionCommand.h" +#include "commands/CreateShaderCommand.h" +#include "commands/DestroyShaderCommand.h" +#include "commands/SetShaderCommand.h" +#include "commands/SetUniformsCommand.h" + +/** + * Objects who implement this interface can be used to have command objects executed. Communication + * classes must only know this interface of a class to be able to pass along command objects. + * + * Implementation detail: This interface is used to reduce dependency of communicators on the main layermanagement component + */ +class CommandExecutor{ +public: + /** + * Have a command processed. + * @param commandToBeExecuted The command to be processed + */ + virtual void execute(Command* commandToBeExecuted)=0; + + virtual uint getLayerTypeCapabilities(LayerType layertype)=0; + +}; + +#endif /* _COMMANDEXECUTOR_H_ */ diff --git a/LayerManagerService/include/GraphicalGroup.h b/LayerManagerService/include/GraphicalGroup.h new file mode 100644 index 0000000..813a35b --- /dev/null +++ b/LayerManagerService/include/GraphicalGroup.h @@ -0,0 +1,67 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _GRAPHICALGROUP_H_ +#define _GRAPHICALGROUP_H_ + +#include "LogicalGraphicsObject.h" +#include + +/** + * Containerclass grouping objects. Grouping makes it possible to call Commands on multiple targets(the group) at once. + * @param T defines the element class. (Layergroup has Layer* as element type for instance) + * @param FIRST_ID a group is parameterized by the first ID given to the group (counting upwards) + */ +template +class GraphicalGroup : public GraphicalObject{ +public: + + GraphicalGroup() : GraphicalObject(thetype,1,true){ + list = std::list(); + }; + + /** + * Set visibility on every element of the group + */ + virtual void setVisibility(bool visible){ + this->visibility = visible; + for(typename std::list::iterator it = list.begin(); it != list.end(); it++) + (*it)->setVisibility(visible); + }; + + /** + * Set opacity on every element of the group + */ + virtual void setOpacity(double opacity){ + this->opacity = opacity; + for(typename std::list::iterator it = list.begin(); it != list.end(); it++) + (*it)->setOpacity(opacity); + }; + + const std::list getList(){return list;}; + void addElement(T* element){list.push_back(element);}; + void removeElement(T* element){list.remove(element);}; + +private: + + // the list containing the elements represented by the group + std::list list; +}; + +#endif /* _GRAPHICALGROUP_H_ */ diff --git a/LayerManagerService/include/GraphicalSurface.h b/LayerManagerService/include/GraphicalSurface.h new file mode 100644 index 0000000..4e30aef --- /dev/null +++ b/LayerManagerService/include/GraphicalSurface.h @@ -0,0 +1,74 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _GRAPHICALSURFACE_H_ +#define _GRAPHICALSURFACE_H_ + +#include "LogicalGraphicsObject.h" +#include "Rectangle.h" +#include "Vector2.h" +#include "Orientation.h" + +/** + * Abstract Type representing a graphical surface. + */ +class GraphicalSurface : public GraphicalObject{ +public: + GraphicalSurface(ObjectType type) : GraphicalObject(type,1,true),orientation(Zero),SourceViewport(0,0,0,0),DestinationViewport(0,0,0,0) { + }; + + /** + * Set Orientation value + * @param orientation the new value. Multiples of 90 degrees. (0->0°, 1->90°, 2->180°,3->279°) + */ + void setOrientation(OrientationType newOrientation){orientation = newOrientation;}; + const OrientationType getOrientation(){return orientation;}; + + /** + * Set Source Viewport (only use portion of source graphics) + * @param x Horizontal x position within source (clip from the left) + * @param y Vertical y position within source (clip from the top) + * @param width Width within source (can be used to clip from the right) + * @param height Height within source (can be used to clip fromt he bottom) + */ + void setSourceRegion(const Rectangle& newSource){SourceViewport = newSource;}; + const Rectangle& getSourceRegion(){ return SourceViewport;}; + + /** + * Set Destination Viewport (Scale output) + * @param x Horizontal x position of destination + * @param y Vertical y position of destination + * @param width Width of destination + * @param height Height of destination + */ + void setDestinationRegion(const Rectangle& newDestination){DestinationViewport = newDestination;}; + + void setPosition(const int& x, const int& y){DestinationViewport.x = x; DestinationViewport.y = y;}; + Vector2 getPosition(){ return Vector2(DestinationViewport.x,DestinationViewport.y);} + void setDimension(const int& width, const int& height){DestinationViewport.width = width; DestinationViewport.height = height;}; + const Rectangle& getDestinationRegion(){ return DestinationViewport;}; + Vector2 getDimension(){ return Vector2(DestinationViewport.width, DestinationViewport.height);}; +private: + OrientationType orientation; // Rotation of the graphical content + Rectangle SourceViewport; + Rectangle DestinationViewport; + +}; + +#endif /* _GRAPHICALSURFACE_H_ */ diff --git a/LayerManagerService/include/ILayerList.h b/LayerManagerService/include/ILayerList.h new file mode 100644 index 0000000..5f9c95b --- /dev/null +++ b/LayerManagerService/include/ILayerList.h @@ -0,0 +1,69 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _ILAYERLIST_H_ +#define _ILAYERLIST_H_ + +#include +#include +#include +#include "Layer.h" +#include "GraphicalGroup.h" + +typedef GraphicalGroup LayerGroup; +typedef GraphicalGroup SurfaceGroup; + +/* + * Represents a list of Layers which contain the Surfaces. Sorting is based upon zorder of the contained layers. + */ +class ILayerList{ +public: + virtual Layer* createLayer()=0; + virtual Surface* createSurface()=0; + virtual void removeLayer(Layer* layer)=0; + virtual void removeSurface(Surface* surface)=0; + virtual Layer* getLayer(int id)=0; + virtual Surface* getSurface(int id)=0; + virtual SurfaceGroup* getSurfaceGroup(const int id)=0; + virtual LayerGroup* getLayerGroup(const int id)=0; + + /** + * Get list of ids of all layers currently existing. + * @return list of ids of all currently know layers + */ + virtual void getLayerIDs(int* length, int** array)=0; + virtual void getSurfaceIDs(int* length, int** array)=0; + + /** + * Get list of ids of all layers currently existing. + * @return list of ids of all currently know layers + */ + virtual void getLayerGroupIDs(int* length, int* array[])=0; + + /** + * Get list of ids of all layers currently existing. + * @return list of ids of all currently know layers + */ + virtual void getSurfaceGroupIDs(int* length, int* array[])=0; + + bool debugMode; + +}; + +#endif /* _ILAYERLIST_H_ */ diff --git a/LayerManagerService/include/IRenderer.h b/LayerManagerService/include/IRenderer.h new file mode 100644 index 0000000..3e6b591 --- /dev/null +++ b/LayerManagerService/include/IRenderer.h @@ -0,0 +1,54 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _IRENDERER_H_ +#define _IRENDERER_H_ + +#include "LayerList.h" +#include "Log.h" +#include "LayerType.h" + +/** + * Abstract Base of all CompositingControllers, ie Renderers. + */ +class IRenderer { +public: + virtual ~IRenderer(){}; + + /** + * Start the actual renderingprocess (renderloop) + */ + virtual bool start(int width, int height, const char* displayName )=0; + + /** + * Stop renderingprocess + */ + virtual void stop()=0; + + /** + * Switch debug mode of this component on or off + * @param onoff Turn on debug mode (true) or off (false) + */ + virtual void setdebug(bool onoff)=0; + + virtual uint getLayerTypeCapabilities(LayerType layertype)=0; + + +}; +#endif /* _IRENDERER_H_ */ diff --git a/LayerManagerService/include/Layer.h b/LayerManagerService/include/Layer.h new file mode 100644 index 0000000..977a11c --- /dev/null +++ b/LayerManagerService/include/Layer.h @@ -0,0 +1,54 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _LAYER_H_ +#define _LAYER_H_ + +#include "Surface.h" +#include "LayerType.h" +#include +/* + * A graphical Layerobject which contains Surfaces. + */ +class Layer : public GraphicalSurface{ + +public: + + LayerType getLayerType(){ return layerType; }; + void setLayerType(LayerType lt){ layerType = lt; } + + void setLayerCapabilities(uint newCapabilities){ capabilities = newCapabilities; }; + uint getCapabilities(){ return capabilities; }; + + void addSurface(Surface* s) { surfaces.push_back(s); }; + void removeSurface(Surface* s){ surfaces.remove(s); }; + + std::list& getAllSurfaces(){return surfaces;} + + std::list surfaces; +private: + LayerType layerType; + uint capabilities; + Layer() : GraphicalSurface(TypeLayer), layerType(Software_2D), capabilities(0){}; + friend class LayerList; + +}; + + +#endif /* _LAYER_H_ */ diff --git a/LayerManagerService/include/LayerCapabilities.h b/LayerManagerService/include/LayerCapabilities.h new file mode 100644 index 0000000..d97f749 --- /dev/null +++ b/LayerManagerService/include/LayerCapabilities.h @@ -0,0 +1,34 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _LAYERCAPABILITIES_H_ +#define _LAYERCAPABILITIES_H_ + +/** + * Enumeration of possible PixelFormats + */ +enum LayerCapabilities{ + LayerPosition, + LayerScalable, + LayerOrientable, + Layer3D, + LayerComposedByAlpha +}; + +#endif /* _LAYERCAPABILITIES_H_ */ diff --git a/LayerManagerService/include/LayerList.h b/LayerManagerService/include/LayerList.h new file mode 100644 index 0000000..7117855 --- /dev/null +++ b/LayerManagerService/include/LayerList.h @@ -0,0 +1,69 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _LAYERLIST_H_ +#define _LAYERLIST_H_ + +#include +#include +#include "Layer.h" +#include "GraphicalGroup.h" +#include "ILayerList.h" + +#include "Shader.h" +#include + +class Command; +/* + * Represents a list of Layers which contain the Surfaces. + */ +class LayerList : public ILayerList { +public: + Layer* createLayer(); + Surface* createSurface(); + SurfaceGroup* createSurfaceGroup(); + LayerGroup* createlayerGroup(); + void removeLayer(Layer* layer); + void removeSurface(Surface* surface); + void removeLayerGroup(LayerGroup* layer); + void removeSurfaceGroup(SurfaceGroup* surface); + Layer* getLayer(int id); + Surface* getSurface(int id); + SurfaceGroup* getSurfaceGroup(const int id); + LayerGroup* getLayerGroup(const int id); + void getLayerIDs(int* length, int** array); + void getSurfaceIDs(int* length, int** array); + void getLayerGroupIDs(int* length, int** array); + void getSurfaceGroupIDs(int* length, int** array); + + std::list& getCurrentRenderOrder(){return currentRenderOrder;} + const std::map getAllLayers(){return allLayers;} + const std::map getAllSurfaces(){return allSurfaces;} + std::list toBeCommittedList; + std::map shaderList; + +private: + std::map layerGroupList; + std::map surfaceGroupList; + std::map allSurfaces; + std::map allLayers; + std::list currentRenderOrder; +}; + +#endif /* _LAYERLIST_H_ */ diff --git a/LayerManagerService/include/LayerType.h b/LayerManagerService/include/LayerType.h new file mode 100644 index 0000000..cc5ed4d --- /dev/null +++ b/LayerManagerService/include/LayerType.h @@ -0,0 +1,32 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _LAYERTYPE_H_ +#define _LAYERTYPE_H_ + +/** + * Enumeration of possible LayerTypes + */ +enum LayerType{ + Hardware = 0, + Software_2D = 1, + Software_2_5D = 2 +}; + +#endif /* _LAYERTYPE_H_ */ diff --git a/LayerManagerService/include/Layermanager.h b/LayerManagerService/include/Layermanager.h new file mode 100644 index 0000000..3f3dfa0 --- /dev/null +++ b/LayerManagerService/include/Layermanager.h @@ -0,0 +1,60 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _LAYERMANAGER_H_ +#define _LAYERMANAGER_H_ + +#include "ObjectType.h" +#include "IRenderer.h" +#include "Surface.h" +#include "Layer.h" +#include "CommandExecutor.h" +#include "LayerList.h" +#include "BaseCommunicator.h" +#include "LogicalGraphicsObject.h" +#include "GraphicalSurface.h" +#include "GraphicalGroup.h" +#include "errors.h" +#include "commands/Command.h" +#include +#include "LayerType.h" + +class Layermanager : public CommandExecutor{ +public: + // the singleton reference + static Layermanager* instance; + void execute(Command* commandToBeExecuted); + uint getLayerTypeCapabilities(LayerType layertype); + + LayerList layerlist; + + void addRenderer(IRenderer* renderer); + void RemoveRenderer(IRenderer* renderer); + void addCommunicator(BaseCommunicator* communicator); + bool startManagement( int width,int height,const char* displayName ); + +private: + Layermanager(); + + std::list compositingControllers; + std::list communicationControllers; + void printDebugInformation(); +}; + +#endif /* _LAYERMANAGER_H_ */ diff --git a/LayerManagerService/include/LogicalGraphicsObject.h b/LayerManagerService/include/LogicalGraphicsObject.h new file mode 100644 index 0000000..4ff5f7d --- /dev/null +++ b/LayerManagerService/include/LogicalGraphicsObject.h @@ -0,0 +1,85 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _LOGICALGRAPHICSOBJECT_H_ +#define _LOGICALGRAPHICSOBJECT_H_ + +#include "ObjectType.h" + +class Shader; +/** + * Base class of all objects representing graphical objects within the layermanagement. + */ +class GraphicalObject{ +public: + + GraphicalObject(ObjectType type, double opacity, bool visibility) : type(type),id(NextID++),shader(0),opacity(opacity),visibility(visibility) + {}; + + /** + * Set alpha value + * @param alpha The new Alpha Value between 0.0 (full transparency) and 1.0 (fully visible) + */ + virtual void setOpacity(double newOpacity){opacity = newOpacity;}; + double getOpacity(){return opacity;}; + + /** + * Set the visibility + * @param visible set this object visible (true) or invisible (false) + */ + virtual void setVisibility(bool newVisibility){visibility = newVisibility;}; + bool getVisibility(){ return visibility;}; + + int getID() const {return id;}; + + /** + * Assign custom shader for rendering + * + * @param s Custom shader. If NULL, default shader will be used. + */ + void setShader(Shader* s) + { + shader = s; + } + + /** + * @return currently assigned custom shader object + */ + Shader* getShader() + { + return shader; + } + + ObjectType type; + +public: + /** + * ID of this graphical object (Layerid, surfaceid etc) + */ + int id; + /** + * Pointer to currently assigned shader. If NULL, a default shader will be used. + */ + Shader* shader; + double opacity; + bool visibility; + static int NextID; +}; + +#endif /* _LOGICALGRAPHICSOBJECT_H_ */ diff --git a/LayerManagerService/include/ObjectType.h b/LayerManagerService/include/ObjectType.h new file mode 100644 index 0000000..a2f9952 --- /dev/null +++ b/LayerManagerService/include/ObjectType.h @@ -0,0 +1,33 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _GRAPHICALOBJECTTYPE_H_ +#define _GRAPHICALOBJECTTYPE_H_ + +/** + * Enumeration of possible graphicalObjectTypes + */ +enum ObjectType{ + TypeSurface, + TypeLayer, + TypeSurfaceGroup, + TypeLayerGroup +}; + +#endif /* _GRAPHICALOBJECTTYPE_H_ */ diff --git a/LayerManagerService/include/Orientation.h b/LayerManagerService/include/Orientation.h new file mode 100644 index 0000000..7818bfc --- /dev/null +++ b/LayerManagerService/include/Orientation.h @@ -0,0 +1,34 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _ORIENTATION_H +#define _ORIENTATION_H + +/** + * Enumeration of possible orientations. Orientation in this context means Rotation. + * Surfaces and Layers can be rotated for composition. Values mean clockwise rotation. + */ +enum OrientationType { + Zero = 0, + Ninety = 1, + OneEighty = 2, + TwoSeventy = 3 +}; + +#endif /* _ORIENTATION_H */ diff --git a/LayerManagerService/include/PixelFormat.h b/LayerManagerService/include/PixelFormat.h new file mode 100644 index 0000000..e83ba7b --- /dev/null +++ b/LayerManagerService/include/PixelFormat.h @@ -0,0 +1,37 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _PIXELFORMAT_H_ +#define _PIXELFORMAT_H_ + +/** + * Enumeration of possible PixelFormats + */ +enum PixelFormat +{ + PIXELFORMAT_R8, + PIXELFORMAT_RGB888, + PIXELFORMAT_RGBA8888, + PIXELFORMAT_RGB565, + PIXELFORMAT_RGBA5551, + PIXELFORMAT_RGBA6661, + PIXELFORMAT_RGBA4444 +}; + +#endif /* _PIXELFORMAT_H_ */ diff --git a/LayerManagerService/include/PlatformSurface.h b/LayerManagerService/include/PlatformSurface.h new file mode 100644 index 0000000..a64c880 --- /dev/null +++ b/LayerManagerService/include/PlatformSurface.h @@ -0,0 +1,42 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _PLATFORMSURFACE_H_ +#define _PLATFORMSURFACE_H_ + +class Surface; + +/* + * Contains platform specific information ie specifics for the rendering used, for instance platform specific handles + */ +class PlatformSurface{ +public: + /** + * Platform specific Surface information is contained in subclasses of PlatformSurface. + * The Platformspecific implementation can gain access to platform independant attributes (position, alpha) of the corresponding surface + * through the given reference + */ + PlatformSurface(Surface* surface) : s(surface){}; + virtual ~PlatformSurface(){}; + + // Reference to platform independant surface type for access to size etc + Surface* s; +}; + +#endif /* _PLATFORMSURFACE_H_ */ diff --git a/LayerManagerService/include/Rectangle.h b/LayerManagerService/include/Rectangle.h new file mode 100644 index 0000000..69d8008 --- /dev/null +++ b/LayerManagerService/include/Rectangle.h @@ -0,0 +1,41 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _RECTANGLE_H_ +#define _RECTANGLE_H_ + +#include + +class Rectangle { +public: + Rectangle(){}; + Rectangle(int x, int y, int width, int height) : x(x),y(y),width(width),height(height){}; + int x; + int y; + int width; + int height; + + bool operator ==(const Rectangle rhs) const{ + return (x==rhs.x && y == rhs.y && width==rhs.width && height==rhs.height); + } + + friend std::ostream& operator<<(std::ostream& stream, const Rectangle& obj); +}; + +#endif /* _RECTANGLE_H_ */ diff --git a/LayerManagerService/include/Shader.h b/LayerManagerService/include/Shader.h new file mode 100644 index 0000000..d5b224f --- /dev/null +++ b/LayerManagerService/include/Shader.h @@ -0,0 +1,115 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _SHADER_H_ +#define _SHADER_H_ + +#include +#include +#include +#include + +/** + * Represents a shader instance. + * + * It stores a set of uniform parameters and refers to an OpenGL program object. + * Some uniform variables are pre-defined, like surface position and size, + * opacity, etc... Additionally, there may be user-defined uniforms. + */ +class Shader +{ +public: + /** + * Creates a new shader instance by vertex and fragment shader name. + * @param vertName File name of vertex shader. + * @param fragName File name of fragment shader. + * @return new Shader instance, NULL if shader could not be loaded, compiled or linked. + */ + static Shader* createShader(const std::string& vertName, const std::string& fragName); + + /** + * Destructor + */ + ~Shader(); + + /** + * @return Unique ID of this instance + */ + int getId(void) const + { + return _id; + } + + /** + * Start using this shader for rendering. + */ + void use(void) const + { + _program.use(); + } + + /** + * Set a uniform. + */ + void setUniform(const ShaderUniform& uniform); + + /** + * Update uniform values. + * Please note that this method doesn't update the standard uniforms + * used for position, size, etc... They need to be set separately + * by loadCommonUniforms(). + */ + void loadUniforms(void) const; + + /** + * Load uniform values for common surface properties, like position, + * size, opacity, etc... + * + * @param uniforms Uniform values + */ + void loadCommonUniforms(const ShaderProgram::CommonUniforms& uniforms) const + { + _program.loadCommonUniforms(uniforms); + } + +private: + /** + * Private constructor. + * New instances of this class are supposed to be created by createShader(...). + * + * @param program Program object to be used + */ + Shader(ShaderProgram& program); + +private: + /// unique shader ID + const int _id; + + /// reference to OpenGL program object used by this shader instance + ShaderProgram& _program; + + /// a map of user-defined uniforms + std::map _uniformMap; + + /// next unique ID + static int _nextId; +}; + +#endif /* _SHADER_H_ */ + diff --git a/LayerManagerService/include/ShaderProgram.h b/LayerManagerService/include/ShaderProgram.h new file mode 100644 index 0000000..cba39c3 --- /dev/null +++ b/LayerManagerService/include/ShaderProgram.h @@ -0,0 +1,165 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _SHADERPROGRAM_H_ +#define _SHADERPROGRAM_H_ + +#include +#include + +/** + * Represents an OpenGL shader program. + * + * There is a global list of allocated shader programs. Each instance is reference + * counted, so if program is no longer in use by any shader instance, it will + * be deleted automatically. + */ +class ShaderProgram +{ +public: + /** + * Stores uniform values for common surface properties, + * like position, size, opacity, etc... + */ + struct CommonUniforms + { + float x; + float y; + float width; + float height; + float opacity; + float texRange[2]; + float texOffset[2]; + int texUnit; + }; + + /** + * Return a shader program from the gobal list. If no matching instance is found, a new + * one will be created and added to the list. + * + * @param vertName File name of vertex shader. + * @param fragName File name of fragment shader. + * @return new Program instance, NULL if shader could not be loaded, compiled or linked. + */ + static ShaderProgram* obtain(const std::string& vertName, const std::string& fragName); + + /** + * Destructor + */ + virtual ~ShaderProgram(); + + /** + * Start using the shader program for rendering. + */ + virtual void use(void) const = 0; + + /** + * Load uniform values for common surface properties, like position, + * size, opacity, etc... + * + * @param uniforms Uniform values + */ + void loadCommonUniforms(const CommonUniforms& uniforms) const; + + /** + * @return The name of the vertex shader + */ + const std::string& getVertexName(void) const + { + return _vertName; + } + + /** + * @return The name of the fragment shader + */ + const std::string& getFragmentName(void) const + { + return _fragName; + } + + /** + * Increment usage counter for this object. + */ + void ref(void); + + /** + * Decrement usage counter for this object. + * It will be delete if usage counter reaches 0. + */ + void unref(void); + + virtual int getUniformLocation(const char* name) const = 0; + + virtual void uniform1iv(int location, int count, const int* v) const = 0; + + virtual void uniform1fv(int location, int count, const float* v) const = 0; + + virtual void uniform2fv(int location, int count, const float* v) const = 0; + + virtual void uniform3fv(int location, int count, const float* v) const = 0; + + virtual void uniform4fv(int location, int count, const float* v) const = 0; + + virtual void uniformMatrix2fv(int location, int count, bool transpose, const float* v) const = 0; + + virtual void uniformMatrix3fv(int location, int count, bool transpose, const float* v) const = 0; + + virtual void uniformMatrix4fv(int location, int count, bool transpose, const float* v) const = 0; + +protected: + /** + * Protected constructor. + * New instances of this class are supposed to be created by the shader program factory. + * + * @param vertName File name of vertex shader. + * @param fragName File name of fragment shader. + */ + ShaderProgram(const std::string& vertName, const std::string& fragName); + + /** + * Update the list of uniform locations + */ + void updateCommonUniformLocations(void); + +private: + /// usage counter + int _refCounter; + + /// name of the vertex shader + std::string _vertName; + + /// name of the fragment shader + std::string _fragName; + + // uniform locations + int _xLoc; + int _yLoc; + int _widthLoc; + int _heightLoc; + int _opacityLoc; + int _texRangeLoc; + int _texOffsetLoc; + int _texUnitLoc; + + /// global list of programs + static std::list _programList; +}; + +#endif /* _SHADERPROGRAM_H_ */ + diff --git a/LayerManagerService/include/ShaderProgramFactory.h b/LayerManagerService/include/ShaderProgramFactory.h new file mode 100644 index 0000000..09a152d --- /dev/null +++ b/LayerManagerService/include/ShaderProgramFactory.h @@ -0,0 +1,63 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _SHADERPROGRAMFACTORY_H_ +#define _SHADERPROGRAMFACTORY_H_ + +#include +#include + +/// pointer to shader program creator function +typedef ShaderProgram* (*PfnShaderProgramCreator)(const std::string&, const std::string&); + +/** + * Factory for creating platform specific shader programs. + */ +class ShaderProgramFactory +{ +public: + /** + * Create a new shader program. + * + * @param vertName File name of vertex shader. + * @param fragName File name of fragment shader. + * @return new Program instance, NULL if program could not be created. + */ + static ShaderProgram* createProgram(const std::string& vertName, const std::string& fragName); + + /** + * Set shader program creator function + * + * @param creatorFunc Pointer to shader program creator function + */ + static void setCreatorFunc(PfnShaderProgramCreator creatorFunc); + +private: + /** + * Dummy private constructor. Prevents creation of instances of this class. + */ + ShaderProgramFactory(void); + +private: + /// pointer to shader program creator function + static PfnShaderProgramCreator _creator; +}; + +#endif /* _SHADERPROGRAMFACTORY_H_ */ + diff --git a/LayerManagerService/include/ShaderUniform.h b/LayerManagerService/include/ShaderUniform.h new file mode 100644 index 0000000..0c666ae --- /dev/null +++ b/LayerManagerService/include/ShaderUniform.h @@ -0,0 +1,141 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _SHADERUNIFORM_H_ +#define _SHADERUNIFORM_H_ + +#include +#include + +class ShaderProgram; + +/** + * Stores values for a shader uniform. + */ +class ShaderUniform +{ +public: + /** Uniform data value type */ + enum Type + { + Undefined, + Vector1f, + Vector2f, + Vector3f, + Vector4f, + Matrix2f, + Matrix3f, + Matrix4f + }; + + /** + * Create a uniform from a string description. + * + * The string description must in the format as follows: + * "name type count [transpose] value1 value2 ..." + * + * String parameter: + * name = the uniform name + * type = the element type (1f,2f,3f,4f,m2f,m3f,m4f) + * count = number of elements + * transpose = 0|1, only available if type is a matrix + * value = the data values + * + * Examples: + * "uBlurRadius 1f 1 2.7" + * "uSize 2f 1 2.5 1.25" + * "uTransform 4f 1 0 1.0 0.0 0.0 1.0 0.0 ..." + * + * @param desc The description + * @return Uniform object or NULL in case of a parse error + */ + static ShaderUniform* createFromStringDescription(const std::string& desc); + + /** + * constructor. + * + * @param name Name of uniform + * @param location Uniform location in program + */ + ShaderUniform(const std::string& name, int location=-1); + + /** + * Copy constructor + */ + ShaderUniform(const ShaderUniform& other); + + /** + * Destructor + */ + ~ShaderUniform(); + + /** + * @return Uniform name + */ + const std::string& getName(void) const + { + return _name; + } + + /** + * Set uniform data of type "float" + * This can be Vector1f..Vector4f or Matrix2f..Matrix4f + * + * @param type Data type + * @param count Number of data elements + * @param value Data values. Actual number of floats must be (count*(size of type)). + * @param transpose Whether to transpose a matrix. Only needed if element type is a matrix. + */ + void setData(Type type, int count, const std::vector& values, bool transpose=false); + + /** + * Copy data from another uniform + */ + void setData(const ShaderUniform& other); + + /** + * Load uniform data in current OpenGL context. + */ + void load(const ShaderProgram& program) const; + +private: + /// the uniform name + std::string _name; + + /// location in shader program + int _location; + + /// the uniform data type + Type _type; + + /// number of data elements + int _count; + + /// the data for float types + std::vector _floatData; + + /// whether to transpose the matrix array + bool _transpose; + + /// lookup table for element sizes + static const int _vectorSizesOfDataTypes[]; +}; + +#endif /* _SHADERUNIFORM_H_ */ + diff --git a/LayerManagerService/include/Surface.h b/LayerManagerService/include/Surface.h new file mode 100644 index 0000000..4c34152 --- /dev/null +++ b/LayerManagerService/include/Surface.h @@ -0,0 +1,60 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _SURFACE_H_ +#define _SURFACE_H_ + +#include "GraphicalSurface.h" +#include +#include "PlatformSurface.h" +#include "PixelFormat.h" + +/** + * Represents a graphical surface generated by an application. Always contained in layers. + */ +class Surface : public GraphicalSurface { + +public: + PixelFormat getPixelFormat(){ return pixformat; } + void setPixelFormat(PixelFormat pf){pixformat = pf;} + + // dimensions actually generated by the source application + // needed for calculations when using a source viewport + int OriginalSourceWidth; + int OriginalSourceHeight; + + /** + * Platform specific Object containing surface information specific to a used platform. + * This typically contains a native window handle/surface handle or information only used + * by a specific renderer.unsigned + */ + PlatformSurface *platform; // platform/rendering specific window attributes + + long nativeHandle; + + int frameCounter; +private: + Surface(): GraphicalSurface(TypeSurface) , platform (NULL), frameCounter(0) {} + + friend class LayerList; + PixelFormat pixformat; + +}; + +#endif /* _SURFACE_H_ */ diff --git a/LayerManagerService/include/Vector2.h b/LayerManagerService/include/Vector2.h new file mode 100644 index 0000000..bfa257c --- /dev/null +++ b/LayerManagerService/include/Vector2.h @@ -0,0 +1,39 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _VECTOR2_H_ +#define _VECTOR2_H_ + +#include + +class Vector2 { +public: + Vector2(){}; + Vector2(int val1, int val2) : val1(val1), val2(val2){}; + int val1; + int val2; + + bool operator ==(const Vector2 rhs) const{ + return (val1==rhs.val1 && val2 == rhs.val2); + } + + friend std::ostream& operator<<(std::ostream& stream, const Vector2& obj); +}; + +#endif /* _VECTOR2_H_ */ diff --git a/LayerManagerService/include/commands/Command.h b/LayerManagerService/include/commands/Command.h new file mode 100644 index 0000000..e2a88a7 --- /dev/null +++ b/LayerManagerService/include/commands/Command.h @@ -0,0 +1,67 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _COMMAND_H_ +#define _COMMAND_H_ + +#include +#include + +class Command { +public: + enum CommandType{ + Create, + Remove, + SetVisibility, + SetOpacity, + GetVisibility, + GetOpacity, + SetSourceRectangle, + SetDestinationRectangle, + SetPosition, + SetDimension, + SetOrientation, + GetOrientation, + GetDimension, + GetPosition, + GetPixelformat, + LayerAddSurface, + LayerRemoveSurface, + LayergroupAddLayer, + LayergroupRemoveLayer, + SurfacegroupAddSurface, + SurfacegroupRemoveSurface, + CommitChanges, + SetLayerRenderOrder, + SetSurfaceRenderOrderWithinLayer, + Debug, + Exit, + CreateShader, + DestroyShader, + SetShader, + SetUniforms + }; + + Command(CommandType commandType) :commandType(commandType) {}; + virtual ~Command(){}; + const CommandType commandType; + virtual void execute(LayerList& layerlist)=0; +}; + +#endif /* _COMMAND_H_ */ diff --git a/LayerManagerService/include/commands/CommitCommand.h b/LayerManagerService/include/commands/CommitCommand.h new file mode 100644 index 0000000..09c32d0 --- /dev/null +++ b/LayerManagerService/include/commands/CommitCommand.h @@ -0,0 +1,41 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _COMMITCOMMAND_H_ +#define _COMMITCOMMAND_H_ + +#include "Command.h" +#include "ObjectType.h" +#include "Log.h" + +class CommitCommand : public Command{ +public: + CommitCommand() : Command(CommitChanges){}; + virtual void execute(LayerList& layerlist){ + for (std::list::iterator it = layerlist.toBeCommittedList.begin();it!=layerlist.toBeCommittedList.end();it++){ + Command* c = (*it); + c->execute(layerlist); + delete c; + } + layerlist.toBeCommittedList.clear(); + }; +}; + + +#endif /* _COMMITCOMMAND_H_ */ diff --git a/LayerManagerService/include/commands/CreateCommand.h b/LayerManagerService/include/commands/CreateCommand.h new file mode 100644 index 0000000..2c52600 --- /dev/null +++ b/LayerManagerService/include/commands/CreateCommand.h @@ -0,0 +1,64 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _CREATECOMMAND_H_ +#define _CREATECOMMAND_H_ + +#include "Command.h" +#include "ObjectType.h" +#include "Log.h" + +class CreateCommand : public Command{ +public: + CreateCommand(int handle, ObjectType createType, PixelFormat pixelformat,uint OriginalWidth,uint OriginalHeight,unsigned int* idReturn) : Command(Create), createType(createType), nativeHandle(handle), pixelformat(pixelformat),OriginalWidth(OriginalWidth),OriginalHeight(OriginalHeight), idReturn(idReturn){}; + const ObjectType createType; + const int nativeHandle; + const PixelFormat pixelformat; + unsigned int OriginalWidth; + unsigned int OriginalHeight; + unsigned int* idReturn; + virtual void execute(LayerList& layerlist){ + switch(createType){ + case TypeSurface: {Surface* s = layerlist.createSurface(); + *idReturn = s->getID(); + s->nativeHandle = nativeHandle; + s->setPixelFormat(pixelformat); + s->OriginalSourceWidth = OriginalWidth; + s->OriginalSourceHeight = OriginalHeight; + LOG_DEBUG("created surface with id:", s->getID()); + break;} + case TypeLayer: {Layer* l = layerlist.createLayer(); + *idReturn = l->getID(); +// LOG_DEBUG("created layer with id:", l->getID()); + break;} + case TypeSurfaceGroup: {SurfaceGroup* sg = layerlist.createSurfaceGroup(); + *idReturn = sg->getID(); +// LOG_DEBUG("created surfacegroup with id:", sg->getID()); + break;} + case TypeLayerGroup: {LayerGroup* lg = layerlist.createlayerGroup(); + *idReturn = lg->getID(); +// LOG_DEBUG("created layergroup with id:", lg->getID()); + break;} + } + }; + +}; + + +#endif /* _CREATECOMMAND_H_ */ diff --git a/LayerManagerService/include/commands/CreateShaderCommand.h b/LayerManagerService/include/commands/CreateShaderCommand.h new file mode 100644 index 0000000..a2b8409 --- /dev/null +++ b/LayerManagerService/include/commands/CreateShaderCommand.h @@ -0,0 +1,62 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _CREATESHADERCOMMAND_H_ +#define _CREATESHADERCOMMAND_H_ + +#include +#include +#include "Shader.h" + +class CreateShaderCommand : public Command +{ +public: + CreateShaderCommand(const std::string& vertName, const std::string& fragName, uint* id) + : Command(CreateShader) + , _vertName(vertName) + , _fragName(fragName) + , returnID(id) + { + // void + }; + + void execute(LayerList& layerlist){ + Shader* shader; + int id=0; + + // create new shader instance + shader = Shader::createShader(_vertName, _fragName); + + if (shader) + { + // insert shader to shader map + id = shader->getId(); + layerlist.shaderList.insert(std::pair(id, shader)); + } + + *returnID = id; + } +private: + const std::string _vertName; + const std::string _fragName; + uint* returnID; +}; + +#endif /* _CREATESHADERCOMMAND_H_ */ + diff --git a/LayerManagerService/include/commands/DebugCommand.h b/LayerManagerService/include/commands/DebugCommand.h new file mode 100644 index 0000000..ddb6e3e --- /dev/null +++ b/LayerManagerService/include/commands/DebugCommand.h @@ -0,0 +1,37 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _DEBUGCOMMAND_H_ +#define _DEBUGCOMMAND_H_ + +#include "Command.h" +#include "ObjectType.h" + +class DebugCommand : public Command{ +public: + DebugCommand(bool onoff) : Command(Debug), onoff(onoff){}; + const bool onoff; + + virtual void execute(LayerList& layerlist){ + layerlist.debugMode = onoff; + }; +}; + + +#endif /* _DEBUGCOMMAND_H_ */ diff --git a/LayerManagerService/include/commands/DestroyShaderCommand.h b/LayerManagerService/include/commands/DestroyShaderCommand.h new file mode 100644 index 0000000..7721c77 --- /dev/null +++ b/LayerManagerService/include/commands/DestroyShaderCommand.h @@ -0,0 +1,84 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _DESTROYSHADERCOMMAND_H_ +#define _DESTROYSHADERCOMMAND_H_ + +#include +#include "LogicalGraphicsObject.h" + +class DestroyShaderCommand : public Command +{ +public: + DestroyShaderCommand(int shaderid) + : Command(DestroyShader) + , _id(shaderid) + { + // void + }; + + void execute(LayerList& layerlist){ + std::map::iterator it; + + // get shader by its ID + it = layerlist.shaderList.find(_id); + if (it!=layerlist.shaderList.end()) + { + Shader* shader = (*it).second; + if (shader) + { + // detach shader from all surfaces, surface groups, etc... + // from surfaces + for (std::map::const_iterator surfit = layerlist.getAllSurfaces().begin();surfit!=layerlist.getAllSurfaces().end();surfit++) + { + GraphicalObject* obj = surfit->second; + if (obj && obj->getShader()==shader) + { + obj->setShader(NULL); + } + } + // from layers + for (std::map::const_iterator layerit = layerlist.getAllLayers().begin();layerit!=layerlist.getAllLayers().end();layerit++) + { + GraphicalObject* obj = layerit->second; + if (obj && obj->getShader()==shader) + { + obj->setShader(NULL); + } + } + + // remove shader from global shader list + layerlist.shaderList.erase(it); + + // finally delete it + delete shader; + } + } + else + { + // shader not found + LOG_ERROR("Layermanager", "shader ID "<<_id<<" not found"); + } + } + +private: + const int _id; +}; + +#endif /* _DESTROYSHADERCOMMAND_H_ */ diff --git a/LayerManagerService/include/commands/ExitCommand.h b/LayerManagerService/include/commands/ExitCommand.h new file mode 100644 index 0000000..c24fff4 --- /dev/null +++ b/LayerManagerService/include/commands/ExitCommand.h @@ -0,0 +1,33 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _EXITCOMMAND_H_ +#define _EXITCOMMAND_H_ + +#include "Command.h" +#include "ObjectType.h" + +class ExitCommand : public Command{ +public: + ExitCommand() : Command(Exit){}; + virtual void execute(LayerList&){}; +}; + + +#endif /* _EXITCOMMAND_H_ */ diff --git a/LayerManagerService/include/commands/GetDimensionCommand.h b/LayerManagerService/include/commands/GetDimensionCommand.h new file mode 100644 index 0000000..18ff98e --- /dev/null +++ b/LayerManagerService/include/commands/GetDimensionCommand.h @@ -0,0 +1,54 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _GETDIMENSIONCOMMAND_H_ +#define _GETDIMENSIONCOMMAND_H_ + +#include "Command.h" +#include "ObjectType.h" + +class GetDimensionCommand : public Command{ +public: + GetDimensionCommand(int id, ObjectType type, uint* widthRet, uint* heightRet) : Command(GetDimension), id(id), type(type), width(widthRet), height(heightRet){}; + const int id; + const ObjectType type; + uint* width; + uint* height; + virtual void execute(LayerList& layerlist){ + GraphicalSurface* go = NULL; + switch(type){ + case TypeSurface: {go = layerlist.getSurface(id); break;} + case TypeLayer: {go = layerlist.getLayer(id); break;} + case TypeSurfaceGroup: {break;} + case TypeLayerGroup: { break;} + } + if ( NULL != go ) + { + Vector2 dim = go->getDimension(); + *width = dim.val1; + *height = dim.val2; + } else { + *width = 0; + *height = 0; + } + } +}; + + +#endif /* _GETDIMENSIONCOMMAND_H_ */ diff --git a/LayerManagerService/include/commands/GetOpacityCommand.h b/LayerManagerService/include/commands/GetOpacityCommand.h new file mode 100644 index 0000000..f21891e --- /dev/null +++ b/LayerManagerService/include/commands/GetOpacityCommand.h @@ -0,0 +1,46 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _GETOPACITYCOMMAND_H_ +#define _GETOPACITYCOMMAND_H_ + +#include "Command.h" +#include "ObjectType.h" + +class GetOpacityCommand : public Command{ +public: + GetOpacityCommand(int id, ObjectType type, double* returnOpacity) : Command(GetOpacity), id(id), type(type), returnOpacity(returnOpacity){}; + const int id; + const ObjectType type; + double* returnOpacity; + + virtual void execute(LayerList& layerlist){ + GraphicalObject* go; + switch(type){ + case TypeSurface: {go = layerlist.getSurface(id); break;} + case TypeLayer: {go = layerlist.getLayer(id); break;} + case TypeSurfaceGroup: {go = layerlist.getSurfaceGroup(id); break;} + case TypeLayerGroup: { go = layerlist.getLayerGroup(id); break;} + } + *returnOpacity = go->getOpacity(); + } +}; + + +#endif /* _GETOPACITYCOMMAND_H_ */ diff --git a/LayerManagerService/include/commands/GetOrientationCommand.h b/LayerManagerService/include/commands/GetOrientationCommand.h new file mode 100644 index 0000000..03addc5 --- /dev/null +++ b/LayerManagerService/include/commands/GetOrientationCommand.h @@ -0,0 +1,54 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _GETORIENTATIONCOMMAND_H_ +#define _GETORIENTATIONCOMMAND_H_ + +#include "Command.h" +#include "ObjectType.h" +#include "Orientation.h" + +class GetOrientationCommand : public Command{ +public: + GetOrientationCommand(int id, ObjectType type, OrientationType* orientation) : Command(GetOrientation), id(id), type(type), returnOrientation(orientation){}; + const int id; + const ObjectType type; + OrientationType* returnOrientation; + + virtual void execute(LayerList& layerlist){ + switch(type){ + case TypeSurface: { + Surface* s = layerlist.getSurface(id); + *returnOrientation = s->getOrientation(); + break; + } + case TypeLayer: { + Layer*l =layerlist.getLayer(id); + *returnOrientation = l->getOrientation(); + break; + } + case TypeSurfaceGroup: {break;} + case TypeLayerGroup: {break;} + } + + } +}; + + +#endif /* _GETORIENTATIONCOMMAND_H_ */ diff --git a/LayerManagerService/include/commands/GetPixelformatCommand.h b/LayerManagerService/include/commands/GetPixelformatCommand.h new file mode 100644 index 0000000..8b15be6 --- /dev/null +++ b/LayerManagerService/include/commands/GetPixelformatCommand.h @@ -0,0 +1,51 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _GETPIXELFORMATCOMMAND_H_ +#define _GETPIXELFORMATCOMMAND_H_ + +#include "Command.h" +#include "ObjectType.h" +#include "PixelFormat.h" + +class GetPixelformatCommand : public Command{ +public: + GetPixelformatCommand(int id, ObjectType type, PixelFormat* f) : Command(GetPixelformat), id(id), type(type), formatreturn(f){}; + const int id; + const ObjectType type; + PixelFormat* formatreturn; + virtual void execute(LayerList& layerlist){ + switch(type){ + case TypeSurface: { + Surface* s = layerlist.getSurface(id); + *formatreturn = s->getPixelFormat(); + break; + } + case TypeLayer:{ + //Layer* l = layerlist.getLayer(id); + //*formatreturn = l->getPixelFormat(); + break; + } + case TypeSurfaceGroup: break; + case TypeLayerGroup: break; + } + } +}; + +#endif /* _GETPIXELFORMATCOMMAND_H_ */ diff --git a/LayerManagerService/include/commands/GetPositionCommand.h b/LayerManagerService/include/commands/GetPositionCommand.h new file mode 100644 index 0000000..5dc6577 --- /dev/null +++ b/LayerManagerService/include/commands/GetPositionCommand.h @@ -0,0 +1,54 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _GETPOSITIONCOMMAND_H_ +#define _GETPOSITIONCOMMAND_H_ + +#include "Command.h" +#include "ObjectType.h" + +class GetPositionCommand : public Command{ +public: + GetPositionCommand(int id, ObjectType type, uint* xRet, uint* yRet) : Command(GetPosition), id(id), type(type), x(xRet),y(yRet){}; + const int id; + const ObjectType type; + uint* x; + uint* y; + virtual void execute(LayerList& layerlist){ + GraphicalSurface* go = NULL; + switch(type){ + case TypeSurface: {go = layerlist.getSurface(id); break;} + case TypeLayer: {go = layerlist.getLayer(id); break;} + case TypeSurfaceGroup: {break;} + case TypeLayerGroup: { break;} + } + if ( NULL != go ) + { + Vector2 dim = go->getPosition(); + *x = dim.val1; + *y = dim.val2; + } else { + *x = 0; + *y = 0; + } + } +}; + + +#endif /* _GETPOSITIONCOMMAND_H_ */ diff --git a/LayerManagerService/include/commands/GetVisibilityCommand.h b/LayerManagerService/include/commands/GetVisibilityCommand.h new file mode 100644 index 0000000..dd58fc1 --- /dev/null +++ b/LayerManagerService/include/commands/GetVisibilityCommand.h @@ -0,0 +1,49 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _GETVISIBILITYCOMMAND_H_ +#define _GETVISIBILITYCOMMAND_H_ + +#include "Command.h" +#include "ObjectType.h" + +class GetVisibilityCommand : public Command{ +public: + GetVisibilityCommand(int id, ObjectType type, bool* visibility) : Command(GetVisibility), id(id), type(type), visibility(visibility){}; + const int id; + const ObjectType type; + bool * visibility; + void execute(LayerList& layerlist){ + GraphicalObject* go; + switch(type){ + case TypeSurface: go = layerlist.getSurface(id); + break; + case TypeLayer: go = layerlist.getLayer(id); + break; + case TypeSurfaceGroup: go = layerlist.getSurfaceGroup(id); + break; + case TypeLayerGroup: go = layerlist.getLayerGroup(id); + break; + } + *visibility = go->getVisibility(); + } +}; + + +#endif /* _GETVISIBILITYCOMMAND_H_ */ diff --git a/LayerManagerService/include/commands/LayerAddSurfaceCommand.h b/LayerManagerService/include/commands/LayerAddSurfaceCommand.h new file mode 100644 index 0000000..1be01ec --- /dev/null +++ b/LayerManagerService/include/commands/LayerAddSurfaceCommand.h @@ -0,0 +1,40 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _LAYERADDSURFACECOMMAND_H_ +#define _LAYERADDSURFACECOMMAND_H_ + +#include "Command.h" +#include "ObjectType.h" + +class LayerAddSurfaceCommand : public Command{ +public: + LayerAddSurfaceCommand(int layerid, int surfaceid) : Command(LayerAddSurface), layerid(layerid), surfaceid(surfaceid){}; + const int layerid; + const int surfaceid; + + virtual void execute(LayerList& layerlist){ + Layer* l = layerlist.getLayer(layerid); + Surface* s = layerlist.getSurface(surfaceid); + l->addSurface(s); + }; +}; + + +#endif /* _LAYERADDSURFACECOMMAND_H_ */ diff --git a/LayerManagerService/include/commands/LayerRemoveSurface.h b/LayerManagerService/include/commands/LayerRemoveSurface.h new file mode 100644 index 0000000..5415046 --- /dev/null +++ b/LayerManagerService/include/commands/LayerRemoveSurface.h @@ -0,0 +1,40 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _LAYERREMOVESURFACECOMMAND_H_ +#define _LAYERREMOVESURFACECOMMAND_H_ + +#include "Command.h" +#include "ObjectType.h" + +class LayerRemoveSurfaceCommand : public Command{ +public: + LayerRemoveSurfaceCommand(int layerid, int surfaceid) : Command(LayerRemoveSurface), layerid(layerid), surfaceid(surfaceid){}; + const int layerid; + const int surfaceid; + + virtual void execute(LayerList& layerlist){ + Layer* l = layerlist.getLayer(layerid); + Surface* s = layerlist.getSurface(surfaceid); + l->removeSurface(s); + }; +}; + + +#endif /* _LAYERREMOVESURFACECOMMAND_H_ */ diff --git a/LayerManagerService/include/commands/LayergroupAddLayerCommand.h b/LayerManagerService/include/commands/LayergroupAddLayerCommand.h new file mode 100644 index 0000000..44d1f3a --- /dev/null +++ b/LayerManagerService/include/commands/LayergroupAddLayerCommand.h @@ -0,0 +1,40 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _LAYERGROUPADDLAYERCOMMAND_H_ +#define _LAYERGROUPADDLAYERCOMMAND_H_ + +#include "Command.h" +#include "ObjectType.h" + +class LayergroupAddLayerCommand : public Command{ +public: + LayergroupAddLayerCommand(int layergroupid, int layerid) : Command(LayergroupAddLayer), layergroupid(layergroupid), layerid(layerid){}; + const int layergroupid; + const int layerid; + + virtual void execute(LayerList& layerlist){ + LayerGroup* lg = layerlist.getLayerGroup(layergroupid); + Layer* layer = layerlist.getLayer(layerid); + lg->addElement(layer); + }; +}; + + +#endif /* _LAYERGROUPADDLAYERCOMMAND_H_ */ diff --git a/LayerManagerService/include/commands/LayergroupRemoveLayerCommand.h b/LayerManagerService/include/commands/LayergroupRemoveLayerCommand.h new file mode 100644 index 0000000..ebf5f79 --- /dev/null +++ b/LayerManagerService/include/commands/LayergroupRemoveLayerCommand.h @@ -0,0 +1,40 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _LAYERGROUPREMOVELAYERCOMMAND_H_ +#define _LAYERGROUPREMOVELAYERCOMMAND_H_ + +#include "Command.h" +#include "ObjectType.h" + +class LayergroupRemoveLayerCommand : public Command{ +public: + LayergroupRemoveLayerCommand(int layergroupid, int layerid) : Command(LayergroupRemoveLayer), layergroupid(layergroupid), layerid(layerid){}; + const int layergroupid; + const int layerid; + + virtual void execute(LayerList& layerlist){ + LayerGroup* lg = layerlist.getLayerGroup(layergroupid); + Layer* layer = layerlist.getLayer(layerid); + lg->removeElement(layer); + }; +}; + + +#endif /* _LAYERGROUPREMOVELAYERCOMMAND_H_ */ diff --git a/LayerManagerService/include/commands/RemoveCommand.h b/LayerManagerService/include/commands/RemoveCommand.h new file mode 100644 index 0000000..8dcb968 --- /dev/null +++ b/LayerManagerService/include/commands/RemoveCommand.h @@ -0,0 +1,51 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _REMOVECOMMAND_H_ +#define _REMOVECOMMAND_H_ + +#include "Command.h" +#include "ObjectType.h" + +class RemoveCommand : public Command{ +public: + RemoveCommand(int objectID, ObjectType typeToRemove) : Command(Remove), idToRemove(objectID), typeToRemove(typeToRemove){}; + const int idToRemove; + const ObjectType typeToRemove; + + virtual void execute(LayerList& layerlist){ + switch(typeToRemove){ + case TypeSurface: {Surface* s = layerlist.getSurface(idToRemove); + layerlist.removeSurface(s); + break;} + case TypeLayer: {Layer* l = layerlist.getLayer(idToRemove); + layerlist.removeLayer(l); + break;} + case TypeSurfaceGroup: {SurfaceGroup* sg = layerlist.getSurfaceGroup(idToRemove); + layerlist.removeSurfaceGroup(sg); + break;} + case TypeLayerGroup: {LayerGroup* lg = layerlist.getLayerGroup(idToRemove); + layerlist.removeLayerGroup(lg); + break;} + } + }; +}; + + +#endif /* _REMOVECOMMAND_H_ */ diff --git a/LayerManagerService/include/commands/SetDestinationRectangleCommand.h b/LayerManagerService/include/commands/SetDestinationRectangleCommand.h new file mode 100644 index 0000000..b584007 --- /dev/null +++ b/LayerManagerService/include/commands/SetDestinationRectangleCommand.h @@ -0,0 +1,54 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _SETDESTINATIONRECTANGLECOMMAND_H_ +#define _SETDESTINATIONRECTANGLECOMMAND_H_ + +#include "Command.h" +#include "ObjectType.h" +#include + +class SetDestinationRectangleCommand : public Command{ +public: + SetDestinationRectangleCommand(int id, ObjectType typeToSetOn, int x, int y, int width, int height) : Command(SetDestinationRectangle), id(id), typeToSet(typeToSetOn), x(x),y(y),width(width),height(height){}; + const int id; + const ObjectType typeToSet; + const int x; + const int y; + const int width; + const int height; + + virtual void execute(LayerList& layerlist){ + GraphicalSurface* go = NULL; + switch(typeToSet){ + case TypeSurface: {go = layerlist.getSurface(id); break;} + case TypeLayer: {go = layerlist.getLayer(id); break;} + case TypeSurfaceGroup: {break;} + case TypeLayerGroup: { break;} + } + const Rectangle r(x,y,width,height); + if (NULL != go ) + { + go->setDestinationRegion(r); + } + } +}; + + +#endif /* _SETDESTINATIONRECTANGLECOMMAND_H_ */ diff --git a/LayerManagerService/include/commands/SetDimensionCommand.h b/LayerManagerService/include/commands/SetDimensionCommand.h new file mode 100644 index 0000000..d15a57f --- /dev/null +++ b/LayerManagerService/include/commands/SetDimensionCommand.h @@ -0,0 +1,51 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _SETDIMENSIONCOMMAND_H_ +#define _SETDIMENSIONCOMMAND_H_ + +#include "Command.h" +#include "ObjectType.h" +#include + +class SetDimensionCommand : public Command{ +public: + SetDimensionCommand(int id, ObjectType typeToSetOn, int width, int height) : Command(SetDimension), id(id), typeToSet(typeToSetOn), width(width),height(height){}; + const int id; + const ObjectType typeToSet; + const int width; + const int height; + + virtual void execute(LayerList& layerlist){ + GraphicalSurface* go = NULL; + switch(typeToSet){ + case TypeSurface: {go = layerlist.getSurface(id); break;} + case TypeLayer: {go = layerlist.getLayer(id); break;} + case TypeSurfaceGroup: {break;} + case TypeLayerGroup: { break;} + } + if ( NULL != go ) + { + go->setDimension(width,height); + } + } +}; + + +#endif /* _SETDIMENSIONCOMMAND_H_ */ diff --git a/LayerManagerService/include/commands/SetLayerOrderCommand.h b/LayerManagerService/include/commands/SetLayerOrderCommand.h new file mode 100644 index 0000000..007f564 --- /dev/null +++ b/LayerManagerService/include/commands/SetLayerOrderCommand.h @@ -0,0 +1,42 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _SETLAYERORDERCOMMAND_H_ +#define _SETLAYERORDERCOMMAND_H_ + +#include "Command.h" +#include "ObjectType.h" + +class SetLayerOrderCommand : public Command{ +public: + SetLayerOrderCommand(int* array, int length) : Command(SetLayerRenderOrder), array(array), length(length){}; + int* array; + const int length; + + virtual void execute(LayerList& layerlist){ + layerlist.getCurrentRenderOrder().clear(); + for (int i=0;isetOpacity(Opacity); + } +}; + + +#endif /* _SETOPACITYCOMMAND_H_ */ diff --git a/LayerManagerService/include/commands/SetOrderWithinLayerCommand.h b/LayerManagerService/include/commands/SetOrderWithinLayerCommand.h new file mode 100644 index 0000000..e6cc405 --- /dev/null +++ b/LayerManagerService/include/commands/SetOrderWithinLayerCommand.h @@ -0,0 +1,44 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _SETORDERWITHINLAYERCOMMAND_H_ +#define _SETORDERWITHINLAYERCOMMAND_H_ + +#include "Command.h" +#include "ObjectType.h" + +class SetOrderWithinLayerCommand : public Command{ +public: + SetOrderWithinLayerCommand(int layerid, int* array, int length) : Command(SetSurfaceRenderOrderWithinLayer), layerid(layerid), array(array), length(length){}; + const int layerid; + int* array; + int length; + + virtual void execute(LayerList& layerlist){ + Layer* l = layerlist.getLayer(layerid); + l->getAllSurfaces().clear(); + for (int i=0;igetAllSurfaces().push_back(s); + } + }; +}; + + +#endif /* _SETORDERWITHINLAYERCOMMAND_H_ */ diff --git a/LayerManagerService/include/commands/SetOrientationCommand.h b/LayerManagerService/include/commands/SetOrientationCommand.h new file mode 100644 index 0000000..256f4f4 --- /dev/null +++ b/LayerManagerService/include/commands/SetOrientationCommand.h @@ -0,0 +1,48 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _SETORIENTATIONCOMMAND_H_ +#define _SETORIENTATIONCOMMAND_H_ + +#include "Command.h" +#include "ObjectType.h" +#include "Orientation.h" + +class SetOrientationCommand : public Command{ +public: + SetOrientationCommand(int id, ObjectType type, OrientationType Orientation) : Command(SetOrientation), id(id), type(type), Orientation(Orientation){}; + const int id; + const ObjectType type; + const OrientationType Orientation; + + virtual void execute(LayerList& layerlist){ + GraphicalSurface* gs = NULL; + switch(type){ + case TypeSurface: {gs = layerlist.getSurface(id); break;} + case TypeLayer:{gs = layerlist.getLayer(id); break;} + case TypeSurfaceGroup:{ break;} + case TypeLayerGroup:{break;} + } + if (NULL != gs) + gs->setOrientation(Orientation); + } +}; + + +#endif /* _SETORIENTATIONCOMMAND_H_ */ diff --git a/LayerManagerService/include/commands/SetPositionCommand.h b/LayerManagerService/include/commands/SetPositionCommand.h new file mode 100644 index 0000000..006b0c6 --- /dev/null +++ b/LayerManagerService/include/commands/SetPositionCommand.h @@ -0,0 +1,51 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _SETPOSITIONCOMMAND_H_ +#define _SETPOSITIONCOMMAND_H_ + +#include "Command.h" +#include "ObjectType.h" +#include + +class SetPositionCommand : public Command{ +public: + SetPositionCommand(int id, ObjectType typeToSetOn, int x, int y ) : Command(SetPosition), id(id), typeToSet(typeToSetOn), x(x),y(y){}; + const int id; + const ObjectType typeToSet; + const int x; + const int y; + + virtual void execute(LayerList& layerlist){ + GraphicalSurface* go = NULL; + switch(typeToSet){ + case TypeSurface: {go = layerlist.getSurface(id); break;} + case TypeLayer: {go = layerlist.getLayer(id); break;} + case TypeSurfaceGroup: {break;} + case TypeLayerGroup: { break;} + } + if (NULL != go) + { + go->setPosition(x,y); + } + } +}; + + +#endif /* _SETPOSITIONCOMMAND_H_ */ diff --git a/LayerManagerService/include/commands/SetShaderCommand.h b/LayerManagerService/include/commands/SetShaderCommand.h new file mode 100644 index 0000000..e5d3aee --- /dev/null +++ b/LayerManagerService/include/commands/SetShaderCommand.h @@ -0,0 +1,76 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _SETSHADERCOMMAND_H_ +#define _SETSHADERCOMMAND_H_ + +#include + +class SetShaderCommand : public Command +{ +public: + SetShaderCommand(int id, int shaderid) + : Command(SetShader) + , _id(id) + , _shaderid(shaderid) + { + // void + }; + + void execute(LayerList& layerlist){ + std::map::iterator it; + GraphicalObject* object = layerlist.getSurface(_id); + Shader* shader = NULL; + + if (object) + { + // get shader by its ID + it = layerlist.shaderList.find(_shaderid); + if (it!=layerlist.shaderList.end()) + { + shader = (*it).second; + } + + if (shader!=NULL || _shaderid==0) + { + // shaderId==0 detaches the custom shader + // (shader is supposed to be NULL in this case) + + object->setShader(shader); + } + else + { + // shader not found + LOG_ERROR("Layermanager", "shader ID "<<_shaderid<<" not found"); + } + } + else + { + // object not found + LOG_ERROR("Layermanager", "object ID "<<_id<<" not found"); + } + } + +private: + const int _id; + const int _shaderid; +}; + +#endif /* _SETSHADERCOMMAND_H_ */ + diff --git a/LayerManagerService/include/commands/SetSourceRectangleCommand.h b/LayerManagerService/include/commands/SetSourceRectangleCommand.h new file mode 100644 index 0000000..c120484 --- /dev/null +++ b/LayerManagerService/include/commands/SetSourceRectangleCommand.h @@ -0,0 +1,53 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _SETSOURCERECTANGLECOMMAND_H_ +#define _SETSOURCERECTANGLECOMMAND_H_ + +#include "Command.h" +#include "ObjectType.h" +#include + +class SetSourceRectangleCommand : public Command{ +public: + SetSourceRectangleCommand(int id, ObjectType type, int x, int y, int width, int height) : Command(SetSourceRectangle), id(id), typeToSet(type), x(x),y(y),width(width),height(height){}; + const int id; + const ObjectType typeToSet; + const int x; + const int y; + const int width; + const int height; + virtual void execute(LayerList& layerlist){ + GraphicalSurface* go = NULL; + switch(typeToSet){ + case TypeSurface: {go = layerlist.getSurface(id); break;} + case TypeLayer: {go = layerlist.getLayer(id); break;} + case TypeSurfaceGroup: {break;} + case TypeLayerGroup: { break;} + } + const Rectangle r(x,y,width,height); + if ( NULL != go ) + { + go->setSourceRegion(r); + } + } +}; + + +#endif /* _SETSOURCERECTANGLECOMMAND_H_ */ diff --git a/LayerManagerService/include/commands/SetUniformsCommand.h b/LayerManagerService/include/commands/SetUniformsCommand.h new file mode 100644 index 0000000..d7a8234 --- /dev/null +++ b/LayerManagerService/include/commands/SetUniformsCommand.h @@ -0,0 +1,83 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _SETUNIFORMSCOMMAND_H_ +#define _SETUNIFORMSCOMMAND_H_ + +#include +#include +#include + +class SetUniformsCommand : public Command +{ +public: + SetUniformsCommand(int shaderid, const std::vector& uniforms) + : Command(SetUniforms) + , _shaderid(shaderid) + , _uniforms(uniforms) + { + // void + }; + + const std::vector getUniforms(){ + return _uniforms; + } + + void execute(LayerList& layerlist){ + // get shader by its ID + std::map::iterator siterator; + siterator = layerlist.shaderList.find(_shaderid); + + if (siterator!=layerlist.shaderList.end()) + { + Shader* shader = (*siterator).second; + + // get uniform descriptions + const std::vector uniformDesc = _uniforms; + std::vector::const_iterator uiterator; + + for (uiterator=uniformDesc.begin(); uiterator!=uniformDesc.end(); uiterator++) + { + // parse description string and create uniform object + ShaderUniform* uniform = ShaderUniform::createFromStringDescription(*uiterator); + if (uniform) + { + shader->setUniform(*uniform); + delete uniform; + } + else + { + LOG_ERROR("Layermanager", "Failed to parse uniform description"); + } + } + } + else + { + // shader not found + LOG_ERROR("Layermanager", "shader ID "<<_shaderid<<" not found"); + } + } +private: + const int _shaderid; + const std::vector _uniforms; +}; + +#endif /* _SETUNIFORMSCOMMAND_H_ */ + + diff --git a/LayerManagerService/include/commands/SetVisibilityCommand.h b/LayerManagerService/include/commands/SetVisibilityCommand.h new file mode 100644 index 0000000..0c9a49d --- /dev/null +++ b/LayerManagerService/include/commands/SetVisibilityCommand.h @@ -0,0 +1,50 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _SETVISIBILITYCOMMAND_H_ +#define _SETVISIBILITYCOMMAND_H_ + +#include "Command.h" +#include "ObjectType.h" + +class SetVisibilityCommand : public Command{ +public: + SetVisibilityCommand(const uint givenid, ObjectType Objecttype, bool newvisibility) : Command(SetVisibility), idtoSet(givenid), otype(Objecttype), visibility(newvisibility){}; + const uint idtoSet; + const ObjectType otype; + const bool visibility; + + virtual void execute(LayerList& layerlist){ + GraphicalObject* go; + switch(otype){ + case TypeSurface: go = layerlist.getSurface(idtoSet); + break; + case TypeLayer: go = layerlist.getLayer(idtoSet); + break; + case TypeSurfaceGroup: go = layerlist.getSurfaceGroup(idtoSet); + break; + case TypeLayerGroup: go = layerlist.getLayerGroup(idtoSet); + break; + } + go->setVisibility(visibility); + } +}; + + +#endif /* _SETVISIBILITYCOMMAND_H_ */ diff --git a/LayerManagerService/include/commands/SurfacegroupAddSurfaceCommand.h b/LayerManagerService/include/commands/SurfacegroupAddSurfaceCommand.h new file mode 100644 index 0000000..b72b725 --- /dev/null +++ b/LayerManagerService/include/commands/SurfacegroupAddSurfaceCommand.h @@ -0,0 +1,40 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _SURFACEGROUPADDSURFACECOMMAND_H_ +#define _SURFACEGROUPADDSURFACECOMMAND_H_ + +#include "Command.h" +#include "ObjectType.h" + +class SurfacegroupAddSurfaceCommand : public Command{ +public: + SurfacegroupAddSurfaceCommand(int surfacegroupid, int surfaceid) : Command(SurfacegroupAddSurface), surfacegroupid(surfacegroupid), surfaceid(surfaceid){}; + const int surfacegroupid; + const int surfaceid; + + virtual void execute(LayerList& layerlist){ + SurfaceGroup* sg = layerlist.getSurfaceGroup(surfacegroupid); + Surface* surface = layerlist.getSurface(surfaceid); + sg->addElement(surface); + }; +}; + + +#endif /* _SURFACEGROUPADDSURFACECOMMAND_H_ */ diff --git a/LayerManagerService/include/commands/SurfacegroupRemoveSurfaceCommand.h b/LayerManagerService/include/commands/SurfacegroupRemoveSurfaceCommand.h new file mode 100644 index 0000000..6574ed3 --- /dev/null +++ b/LayerManagerService/include/commands/SurfacegroupRemoveSurfaceCommand.h @@ -0,0 +1,40 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _SURFACEGROUPREMOVESURFACECOMMAND_H_ +#define _SURFACEGROUPREMOVESURFACECOMMAND_H_ + +#include "Command.h" +#include "ObjectType.h" + +class SurfacegroupRemoveSurfaceCommand : public Command{ +public: + SurfacegroupRemoveSurfaceCommand(int surfacegroupid, int surfaceid) : Command(SurfacegroupRemoveSurface), surfacegroupid(surfacegroupid), surfaceid(surfaceid){}; + const int surfacegroupid; + const int surfaceid; + + virtual void execute(LayerList& layerlist){ + SurfaceGroup* sg = layerlist.getSurfaceGroup(surfacegroupid); + Surface* surface = layerlist.getSurface(surfaceid); + sg->removeElement(surface); + }; +}; + + +#endif /* _SURFACEGROUPREMOVESURFACECOMMAND_H_ */ diff --git a/LayerManagerService/include/errors.h b/LayerManagerService/include/errors.h new file mode 100644 index 0000000..895a063 --- /dev/null +++ b/LayerManagerService/include/errors.h @@ -0,0 +1,32 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _ERRORS_H_ +#define _ERRORS_H_ + +#include + +class IDNotFoundException { +public: + IDNotFoundException(std::string s) : message(s){}; + + std::string message; +}; + +#endif /* _ERRORS_H_ */ diff --git a/LayerManagerService/makefile b/LayerManagerService/makefile new file mode 100644 index 0000000..84a439a --- /dev/null +++ b/LayerManagerService/makefile @@ -0,0 +1,64 @@ +############################################################################ +# +# Copyright 2010 BMW Car IT GmbH +# +# +# 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. +# +############################################################################ + +ifneq ($(CONFIG),) +include ../LayerManagerPlatform/Make$(CONFIG).defs +endif + +SRC = LogicalGraphicsObject.cpp \ + LayerList.cpp \ + Layermanager.cpp \ + main.cpp \ + shader/Shader.cpp \ + shader/ShaderProgram.cpp \ + shader/ShaderProgramFactory.cpp \ + shader/ShaderUniform.cpp + +TARGET_NAME = layermanager + +ADD_INCLUDE_DIR+= include \ + $(PREFIX)/usr/include/layermanager + +ADD_LIB_DIR+=$(PREFIX)/usr/lib/layermanager + +ADD_LIBS+= pthread dl LayerManagerUtils + +OBJS = $(patsubst %.cpp,build/%.o,$(SRC)) +TARGET = build/$(TARGET_NAME) +INCLUDE= $(patsubst %$,-I%,$(ADD_INCLUDE_DIR)) +LIBS=$(shell pkg-config --libs $(PKG)) $(patsubst %$,-L%,$(ADD_LIB_DIR)) $(patsubst %$,-l%,$(ADD_LIBS)) + +all: $(TARGET) + +build/%.o: src/%.cpp + $(shell mkdir -p $(shell dirname $@)) + $(CXX) $(CXXFLAGS) $(INCLUDE) -c -o $@ $< + +$(TARGET): $(OBJS) + $(CXX) -Xlinker -export-dynamic -o $(TARGET) $(OBJS) $(LIBS) + +install: + mkdir -p $(PREFIX)/usr/include/layermanager + install -m 755 include/*.h $(PREFIX)/usr/include/layermanager + mkdir -p $(PREFIX)/usr/include/layermanager/commands + install -m 755 include/commands/*.h $(PREFIX)/usr/include/layermanager/commands + +clean: + rm -f $(OBJS) $(TARGET) + rm -rf build diff --git a/LayerManagerService/src/LayerList.cpp b/LayerManagerService/src/LayerList.cpp new file mode 100644 index 0000000..78f47d6 --- /dev/null +++ b/LayerManagerService/src/LayerList.cpp @@ -0,0 +1,164 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 "LayerList.h" +#include "errors.h" +#include "Layermanager.h" +#include "Log.h" +#include + +Layer* LayerList::createLayer(){ + Layer* l = new Layer(); + allLayers.insert(std::pair(l->getID(),l)); + return l; +} + +Surface* LayerList::createSurface(){ + Surface* s = new Surface(); + allSurfaces.insert(std::pair(s->getID(),s)); + return s; +} + +SurfaceGroup* LayerList::createSurfaceGroup(){ + SurfaceGroup* s = new SurfaceGroup(); + surfaceGroupList.insert(std::pair(s->getID(),s)); + return s; +} + +LayerGroup* LayerList::createlayerGroup(){ + LayerGroup* s = new LayerGroup(); + layerGroupList.insert(std::pair(s->getID(),s)); + return s; +} + +Layer* LayerList::getLayer(int id){ + Layer* l = NULL; + try{ + l = allLayers.at(id); + }catch (std::out_of_range& e){ + LOG_ERROR("layer not found",id); + throw IDNotFoundException("Layer not found"); + } + + return l; +} + +Surface* LayerList::getSurface(int id){ + Surface* s = NULL; + try{ + s = allSurfaces.at(id); + }catch (std::out_of_range& e){ + LOG_ERROR("surface not found",id); + throw IDNotFoundException("Surface not found"); + } + return s; +} + +SurfaceGroup* LayerList::getSurfaceGroup(const int id){ + return surfaceGroupList.at(id); +} + +LayerGroup* LayerList::getLayerGroup(const int id){ + return layerGroupList.at(id); +} + +void LayerList::removeLayer(Layer* l){ + // take layer out of list of layers + allLayers.erase(l->getID()); + // remove layer from all layergroups it might be part of + for (std::map::iterator groupIterator=layerGroupList.begin();groupIterator!=layerGroupList.end();groupIterator++){ + LayerGroup* lg = groupIterator->second; + lg->removeElement(l); + } + delete l; +} + +void LayerList::removeSurface(Surface* s){ + // take surface out of list of surfaces + allSurfaces.erase(s->getID()); + // remove surface from all layers it might be on + for (std::map::iterator layerIterator=allLayers.begin();layerIterator!=allLayers.end();layerIterator++){ + Layer* l = layerIterator->second; + l->removeSurface(s); + } + // remove surface from all surfacegroups it might be part of + for (std::map::iterator groupIterator=surfaceGroupList.begin();groupIterator!=surfaceGroupList.end();groupIterator++){ + SurfaceGroup* sg = groupIterator->second; + sg->removeElement(s); + } + delete s; +} + +void LayerList::removeLayerGroup(LayerGroup* l){ + layerGroupList.erase(l->getID()); + delete l; +} + +void LayerList::removeSurfaceGroup(SurfaceGroup* s){ + surfaceGroupList.erase(s->getID()); + delete s; +} + +void LayerList::getLayerIDs(int* length, int** array){ + int numOfLayers = allLayers.size(); + *length = numOfLayers; + *array = new int[numOfLayers]; + int i=0; + for (std::map::const_iterator it = allLayers.begin(); it != allLayers.end(); it++){ + (*array)[i] = (*it).first; + i++; + } +} + +void LayerList::getSurfaceIDs(int* length, int** array){ + int numOfSurfaces = allSurfaces.size(); + *length = numOfSurfaces; + *array = new int[numOfSurfaces]; + int i=0; + for (std::map::const_iterator it = allSurfaces.begin(); it != allSurfaces.end(); it++){ + (*array)[i] = (*it).first; + i++; + } +} + +void LayerList::getSurfaceGroupIDs(int* length, int** array){ + int numOfSurfaceGroups = surfaceGroupList.size(); + *length = numOfSurfaceGroups; + *array = new int[numOfSurfaceGroups]; + + int i=0; + for (std::map::const_iterator it = surfaceGroupList.begin(); it != surfaceGroupList.end(); it++){ + (*array)[i] = (*it).first; + i++; + } +} + +void LayerList::getLayerGroupIDs(int* length, int** array){ + int numOfLayergroups = layerGroupList.size(); + *length = numOfLayergroups; + *array = new int[numOfLayergroups]; + + int i=0; + for (std::map::const_iterator it = layerGroupList.begin(); it != layerGroupList.end(); it++){ + (*array)[i] = (*it).first; + i++; + } +} + + diff --git a/LayerManagerService/src/Layermanager.cpp b/LayerManagerService/src/Layermanager.cpp new file mode 100644 index 0000000..a1c6b66 --- /dev/null +++ b/LayerManagerService/src/Layermanager.cpp @@ -0,0 +1,153 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 "Layermanager.h" +#include "Log.h" +#include + +Layermanager* Layermanager::instance = new Layermanager(); + +Layermanager::Layermanager() { + // default layer + //Layer* defaultLayer = layerlist.createLayer(); +} + + +uint Layermanager::getLayerTypeCapabilities(LayerType layertype){ + // get the first renderer for now TODO + IRenderer* renderer = *compositingControllers.begin(); + if (NULL!=renderer) + return renderer->getLayerTypeCapabilities(layertype); + else + return 0; +} + +void Layermanager::addRenderer(IRenderer* renderer){ + compositingControllers.push_back(renderer); +} +void Layermanager::RemoveRenderer(IRenderer* renderer){ + compositingControllers.remove(renderer); +} +void Layermanager::addCommunicator(BaseCommunicator* communicator){ + communicationControllers.push_back(communicator); +} + +void Layermanager::printDebugInformation(){ + // print stuff about layerlist + LOG_INFO("LayerManager", "Layer: ID | X | Y | W | H |Al.| Z \n"); + // loop the layers + int length; + int* LayerIDs; + layerlist.getLayerIDs(&length,&LayerIDs); + for (int i=0;i::iterator currentLayerID = LayerIDs.begin(); +// currentLayerID != LayerIDs.end(); currentLayerID++) + { + Layer* currentLayer = layerlist.getLayer(LayerIDs[i]); + LOG_INFO("LayerManager", " " << std::setw(4) << currentLayer->getID() << "\n"); + + LOG_INFO("LayerManager", " Surface: ID |Al.| Z | SVP: X | Y | W | H DVP: X | Y | W | H \n"); + // loop the surfaces of within each layer + for(std::list::iterator current = currentLayer->surfaces.begin(); + current != currentLayer->surfaces.end(); current++) + { + LOG_INFO("LayerManager", " " << std::setw(4) << (*current)->getID() << std::setw(4) << std::setprecision(3) << (*current)->opacity << "\n"); + } + } + +} + + +void Layermanager::execute(Command* commandToBeExecuted){ + LOG_DEBUG("Layermanager", "executing a command"); + switch(commandToBeExecuted->commandType){ + case Command::Remove: + case Command::SetVisibility: + case Command::SetOpacity: + case Command::SetSourceRectangle: + case Command::SetDestinationRectangle: + case Command::SetPosition: + case Command::SetDimension: + case Command::SetOrientation: + case Command::LayerAddSurface: + case Command::LayerRemoveSurface: + case Command::LayergroupAddLayer: + case Command::LayergroupRemoveLayer: + case Command::SurfacegroupAddSurface: + case Command::SurfacegroupRemoveSurface: + case Command::SetLayerRenderOrder: + case Command::SetSurfaceRenderOrderWithinLayer: + { + layerlist.toBeCommittedList.push_back(commandToBeExecuted); + break; + } + case Command::Create: + default: { + commandToBeExecuted->execute(layerlist); + delete commandToBeExecuted; + break; + } + } +} + + +bool Layermanager::startManagement(int width,int height,const char* displayName) +{ + bool result = false; + + for( std::list::iterator list_iter = compositingControllers.begin(); + list_iter != compositingControllers.end(); list_iter++) + { + if ( (NULL != *list_iter) && ( true==(*list_iter)->start(width, height, displayName) ) ) + { + result = true; + } + else + { + result = false; + break; + } + } + if (result == false) + { + LOG_ERROR("LayerManager","Could not start Compositing Controllers"); + } + else + { + for(std::list::iterator list_iter = communicationControllers.begin(); + list_iter != communicationControllers.end(); list_iter++) + { + if ( (NULL != *list_iter) && ( true==(*list_iter)->start() ) ) + { + result = true; + } + else + { + result = false; + break; + } + } + if (result == false) + { + LOG_ERROR("LayerManager","Could not start Communication Controllers"); + } + } + + return result; +} diff --git a/LayerManagerService/src/LogicalGraphicsObject.cpp b/LayerManagerService/src/LogicalGraphicsObject.cpp new file mode 100644 index 0000000..a913113 --- /dev/null +++ b/LayerManagerService/src/LogicalGraphicsObject.cpp @@ -0,0 +1,22 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 "LogicalGraphicsObject.h" + +int GraphicalObject::NextID = 1; diff --git a/LayerManagerService/src/main.cpp b/LayerManagerService/src/main.cpp new file mode 100644 index 0000000..f1fa8d3 --- /dev/null +++ b/LayerManagerService/src/main.cpp @@ -0,0 +1,195 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 "Layermanager.h" +#include "IRenderer.h" +#include "BaseCommunicator.h" +#include +#include +#include +#include +#include +#include +#include "Log.h" +#include +const char* displayName = "Tegra:VGA0"; +int displayWidth = 1280; +int displayHeight = 480; +const char* USAGE_DESCRIPTION = + "Usage:\t layerManager [options]\n" + "Option:\t\n\n" + "\t-w: Window Width\t\n" + "\t-h: Window Height\t\n" + "\t-d: displayName \t\n"; +template +T* getCreateFunction(std::string libname) +{ + void *libraryHandle; + libraryHandle = dlopen (libname.c_str(), RTLD_LAZY); + if (NULL == libraryHandle) { + LOG_ERROR("Main", dlerror()); + } + // cut off directories + int lastSlashPosition = libname.rfind('/')+1; + int lengthOfFilenameWithoutDirectories = libname.length()-lastSlashPosition; + std::string createfunctionname = libname.substr(lastSlashPosition,lengthOfFilenameWithoutDirectories); + LOG_DEBUG("without directory:", createfunctionname); + // cut off "lib" in front and cut off .so end" + createfunctionname = "create" + createfunctionname.substr(3, createfunctionname.length()-6); + dlerror(); /* Clear any existing error */ + LOG_DEBUG("loading external function with name:", createfunctionname); + T* createFunction = (T*) dlsym(libraryHandle, createfunctionname.c_str()); + const char* dlsym_error = dlerror(); + if (dlsym_error) + { + LOG_ERROR("Main", "Cannot load symbol create: " << dlsym_error); + } + return createFunction; +} +void parsecommandline(int argc, char **argv) +{ + while (optind < argc) + { + int option = getopt(argc,argv,"w::h::d::?::"); + switch (option) + { + case 'd' : + displayName = optarg; + break; + case 'w': + displayWidth = atoi(optarg); + break; + case 'h': + displayHeight = atoi(optarg); + break; + case '?': + default: + exit(-1); + } + } +} + + +std::string getfirstFileFromDirectory(std::string dirName){ + DIR *dp; + std::string returnValue; + struct dirent *dirp; + if((dp = opendir(dirName.c_str())) == NULL) { + LOG_ERROR("Main", "Error(" << errno << ") opening " << dirName); + returnValue = ""; + }else{ + + while ((dirp = readdir(dp)) != NULL) { + if (strcmp(dirp->d_name,".")==0) + continue; + if (strcmp(dirp->d_name,"..")==0) + continue; + if (strstr (dirp->d_name, ".so")==0) + continue; + LOG_INFO("Main", "loading file " << dirName << "/" << dirp->d_name); + returnValue = std::string(dirName + "/" + dirp->d_name); + break; + } + closedir(dp); + } + return returnValue; + //error +} + +BaseCommunicator* loadCommunicator(Layermanager* executor, ILayerList* layerList){ + std::string sharedLibraryName = getfirstFileFromDirectory("/usr/lib/layermanager/communicator"); + BaseCommunicator* (*createFunc)(Layermanager*, ILayerList*) = getCreateFunction(sharedLibraryName); + LOG_DEBUG("Main", "instantiating communicator"); + BaseCommunicator* ret = createFunc(executor, layerList); + LOG_DEBUG("Main", "found communicator"); + return ret; +} + +IRenderer* loadRenderer(LayerList* list) +{ IRenderer* ret = NULL; + LOG_DEBUG("Main", "Searching for renderer."); + std::string sharedLibraryName = getfirstFileFromDirectory("/usr/lib/layermanager/renderer"); + if (sharedLibraryName==""){ + LOG_ERROR("Main","No renderer found!"); + }else{ + LOG_DEBUG("Main", "Shared Renderer library " << sharedLibraryName << " found !"); + IRenderer* (*createFunc)(LayerList*) = getCreateFunction(sharedLibraryName); + if ( NULL != createFunc ) + { + LOG_DEBUG("Main", "Entry point of Renderer found !"); + ret = createFunc(list); + if ( NULL == ret ) + { + LOG_ERROR("Main","Render could not initiliazed. Entry Function not callable !"); + } + } else { + LOG_ERROR("Main","Render could not initiliazed. Entry Function not found !"); + } + } + return ret; +} + + +int main(int argc, char **argv) +{ + + parsecommandline(argc,(char**)argv); + LOG_INFO("Main", "Starting Layermanager."); + + // Create Singleton Instance of Layermanager + Layermanager *manager = Layermanager::instance; + + LOG_INFO("Main", "Loading communicator."); + // Create a communication mechanism to use + BaseCommunicator* comm = loadCommunicator(manager,&manager->layerlist); +//comm->start(); +//while(true) +// { +// sleep(2000); +// } + + LOG_INFO("Main", "Loading renderer."); + // Create Grafikcontroller to use + IRenderer* renderer = loadRenderer(&manager->layerlist); + + // inform the layermanager about the renderer + manager->addRenderer(renderer); + + // inform the layermanager about the communication class + manager->addCommunicator(comm); + if ( true == manager->startManagement(displayWidth,displayHeight,displayName) ) + { + // must stay within main method or else application would completely exit + LOG_INFO("Main", "Enter Mainloop."); + while(true) + { + sleep(2000); + } + } else { + LOG_ERROR("Main", "Exiting Application."); + return -1; + } + LOG_INFO("Main", "Exiting Application."); + // cleanup + delete renderer; + delete comm; + delete manager; + + return 0; +} diff --git a/LayerManagerService/src/shader/Shader.cpp b/LayerManagerService/src/shader/Shader.cpp new file mode 100644 index 0000000..c296b89 --- /dev/null +++ b/LayerManagerService/src/shader/Shader.cpp @@ -0,0 +1,94 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 + +int Shader::_nextId=1; + +Shader* Shader::createShader(const std::string& vertName, const std::string& fragName) +{ + Shader* shader = 0; + ShaderProgram* program; + + // Obtain shader program. If a shader program of the same name already exists, + // its instance will be returned. If it doesn't exist, a new program is returned. + program = ShaderProgram::obtain(vertName, fragName); + + if (program) + { + // create shader instance + shader = new Shader(*program); + } + else + { + // failed to load, compile or link the program + } + + return shader; +} + +Shader::Shader(ShaderProgram& program) + : _id(_nextId++) + , _program(program) + , _uniformMap() +{ + // increase program reference counter + _program.ref(); +} + +Shader::~Shader() +{ + // decrease program reference counter. + // This might destroy the program if no longer in use. + _program.unref(); +} + +void Shader::setUniform(const ShaderUniform& uniform) +{ + const std::string& name = uniform.getName(); + std::map::iterator it; + + it = _uniformMap.find(name); + + if (it==_uniformMap.end()) + { + // add new uniform + int location = _program.getUniformLocation(name.c_str()); + ShaderUniform u(name, location); + u.setData(uniform); + _uniformMap.insert(std::pair(name, u)); + } + else + { + // update uniform data + (*it).second.setData(uniform); + } +} + +void Shader::loadUniforms(void) const +{ + std::map::const_iterator it; + + for (it=_uniformMap.begin(); it!=_uniformMap.end(); it++) + { + const ShaderUniform& uniform = (*it).second; + uniform.load(_program); + } +} + diff --git a/LayerManagerService/src/shader/ShaderProgram.cpp b/LayerManagerService/src/shader/ShaderProgram.cpp new file mode 100644 index 0000000..7bb5257 --- /dev/null +++ b/LayerManagerService/src/shader/ShaderProgram.cpp @@ -0,0 +1,122 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 +#include + +// global program list +std::list ShaderProgram::_programList; + +ShaderProgram* ShaderProgram::obtain(const std::string& vertName, const std::string& fragName) +{ + std::list::iterator it; + ShaderProgram* program = 0; + + // search for a matching shader program in the global list + for (it=_programList.begin(); it!=_programList.end(); ++it) + { + ShaderProgram* p = *it; + if (p && p->getVertexName()==vertName && p->getFragmentName()==fragName) + { + program = p; + break; + } + } + + if (!program) + { + // no matching program object found in global list -> create a new one + + // we are using a factory approach to create platform specific shader programs: + program = ShaderProgramFactory::createProgram(vertName, fragName); + + if (program) + { + // add program to global list + _programList.push_back(program); + } + } + + return program; +} + +ShaderProgram::ShaderProgram(const std::string& vertName, const std::string& fragName) + : _refCounter(0) + , _vertName(vertName) + , _fragName(fragName) +{ + // void +} + +ShaderProgram::~ShaderProgram() +{ + // void +} + +void ShaderProgram::ref(void) +{ + _refCounter++; +} + +void ShaderProgram::unref(void) +{ + _refCounter--; + if (_refCounter<=0) + { + // remove program from global list + _programList.remove(this); + + // destroy object + delete this; + } +} + +void ShaderProgram::loadCommonUniforms(const CommonUniforms& uniforms) const +{ + if (_xLoc>=0) + uniform1fv(_xLoc, 1, &uniforms.x); + if (_yLoc>=0) + uniform1fv(_yLoc, 1, &uniforms.y); + if (_widthLoc>=0) + uniform1fv(_widthLoc, 1, &uniforms.width); + if (_heightLoc>=0) + uniform1fv(_heightLoc, 1, &uniforms.height); + if (_opacityLoc>=0) + uniform1fv(_opacityLoc, 1, &uniforms.opacity); + if (_texRangeLoc>=0) + uniform2fv(_texRangeLoc, 1, uniforms.texRange); + if (_texOffsetLoc>=0) + uniform2fv(_texOffsetLoc, 1, uniforms.texOffset); + if (_texUnitLoc>=0) + uniform1iv(_texUnitLoc, 1, &uniforms.texUnit); +} + +void ShaderProgram::updateCommonUniformLocations(void) +{ + // get uniform locations for common surface properties + _xLoc = getUniformLocation("uX"); + _yLoc = getUniformLocation("uY"); + _widthLoc = getUniformLocation("uWidth"); + _heightLoc = getUniformLocation("uHeight"); + _opacityLoc = getUniformLocation("uAlphaVal"); + _texRangeLoc = getUniformLocation("uTexRange"); + _texOffsetLoc = getUniformLocation("uTexOffset"); + _texUnitLoc = getUniformLocation("uTexUnit"); +} + diff --git a/LayerManagerService/src/shader/ShaderProgramFactory.cpp b/LayerManagerService/src/shader/ShaderProgramFactory.cpp new file mode 100644 index 0000000..ba773f5 --- /dev/null +++ b/LayerManagerService/src/shader/ShaderProgramFactory.cpp @@ -0,0 +1,37 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 + +// pointer to shader program creator function +PfnShaderProgramCreator ShaderProgramFactory::_creator = 0; + +ShaderProgram* ShaderProgramFactory::createProgram(const std::string& vertName, const std::string& fragName) +{ + if (_creator!=0) + return _creator(vertName, fragName); + else + return 0; +} + +void ShaderProgramFactory::setCreatorFunc(PfnShaderProgramCreator creatorFunc) +{ + _creator = creatorFunc; +} + diff --git a/LayerManagerService/src/shader/ShaderUniform.cpp b/LayerManagerService/src/shader/ShaderUniform.cpp new file mode 100644 index 0000000..e9b02cc --- /dev/null +++ b/LayerManagerService/src/shader/ShaderUniform.cpp @@ -0,0 +1,211 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 +#include +#include +#include +#include +#include "Log.h" + +using namespace std; + +const int ShaderUniform::_vectorSizesOfDataTypes[]= +{ + 0, // Undefined + 1, // Vector1f + 2, // Vector2f + 3, // Vector3f + 4, // Vector4f + 4, // Matrix2f + 9, // Matrix3f + 16 // Matrix4f +}; + +ShaderUniform* ShaderUniform::createFromStringDescription(const std::string& desc) +{ + istringstream iss(desc); + vector floatData; + Type type = Undefined; + string name; + string token; + + // get name + iss >> name; + + // get type + iss >> token; + if (token=="1f") + type = Vector1f; + else if (token=="2f") + type = Vector2f; + else if (token=="3f") + type = Vector3f; + else if (token=="4f") + type = Vector4f; + else if (token=="m2f") + type = Matrix2f; + else if (token=="m3f") + type = Matrix3f; + else if (token=="m4f") + type = Matrix4f; + else + { + LOG_ERROR("Shader Uniform","Can not parse Type " << token); + return NULL; + } + + // get element count + int count; + if((iss >> count).fail()) + { + // failed to parse element count + LOG_ERROR("Shader Uniform","Fail to parse element count " << count); + return NULL; + } + + // get transpose parameter if uniform is a matrix + bool transpose = false; + if (type==Matrix2f || type==Matrix3f || type==Matrix4f) + { + if ((iss >> transpose).fail()) + { + LOG_ERROR("Shader Uniform","Fail to parse value "); + return NULL; + } + } + + // parse data values + size_t numValuesExpected = count*_vectorSizesOfDataTypes[type]; + for (size_t i=0; i> value).fail()) + { + // failed to parse value + LOG_ERROR("Shader Uniform","Fail to parse value " << value); + return NULL; + } + floatData.push_back(value); + } + + if (floatData.size()!=numValuesExpected) + { + LOG_ERROR("Shader Uniform","Invalid number of values"); + return NULL; + } + + ShaderUniform* uniform = new ShaderUniform(name); + uniform->setData(type, count, floatData, transpose); + + return uniform; +} + +ShaderUniform::ShaderUniform(const std::string& name, int location) + : _name(name) + , _location(location) + , _type(Undefined) + , _count(0) + , _floatData() + , _transpose(false) +{ +} + +ShaderUniform::ShaderUniform(const ShaderUniform& other) + : _name(other._name) + , _location(other._location) + , _type(other._type) + , _count(other._count) + , _floatData(other._floatData) + , _transpose(other._transpose) +{ +} + +ShaderUniform::~ShaderUniform() +{ +} + +void ShaderUniform::setData(Type type, int count, const std::vector& values, bool transpose) +{ + size_t numValuesExpected = _vectorSizesOfDataTypes[type] * count; + + if (values.size()==numValuesExpected) + { + _floatData = values; + _type = type; + _count = count; + _transpose = transpose; + } + else + { + // invalid number of floats in vector + } +} + +void ShaderUniform::setData(const ShaderUniform& other) +{ + _type = other._type; + _count = other._count; + _floatData = other._floatData; + _transpose = other._transpose; +} + +void ShaderUniform::load(const ShaderProgram& program) const +{ + if (_location==-1) + return; + + // Get C array from vector. We assume the data is internally stored in consecutive memory locations. + const float* values = &(*_floatData.begin()); + + switch(_type) + { + case Vector1f: + program.uniform1fv(_location, _count, values); + break; + + case Vector2f: + program.uniform2fv(_location, _count, values); + break; + + case Vector3f: + program.uniform3fv(_location, _count, values); + break; + + case Vector4f: + program.uniform4fv(_location, _count, values); + break; + + case Matrix2f: + program.uniformMatrix2fv(_location, _count, _transpose, values); + break; + + case Matrix3f: + program.uniformMatrix3fv(_location, _count, _transpose, values); + break; + + case Matrix4f: + program.uniformMatrix4fv(_location, _count, _transpose, values); + break; + + default: + break; + } +} + diff --git a/LayerManagerUtils/include/Log.h b/LayerManagerUtils/include/Log.h new file mode 100644 index 0000000..c518495 --- /dev/null +++ b/LayerManagerUtils/include/Log.h @@ -0,0 +1,60 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _LOG_H_ +#define _LOG_H_ +#include "LogMessageBuffer.h" +#include +#include +typedef enum { + LOG_INFO = 1, + LOG_WARNING = 2, + LOG_ERROR = 4, + LOG_DEBUG = 8 +} LOG_MODES; + +class Log { + +public: + virtual ~Log(); + static Log* instance; + void warning (const std::string moduleName, const std::basic_string& output ); + void info (const std::string moduleName, const std::basic_string& output ); + void error (const std::string moduleName, const std::basic_string& output ); + void debug (const std::string moduleName, const std::basic_string& output ); + void log(LOG_MODES logMode, const std::string moduleName, const std::basic_string& output ); +private: + void LogToFile(std::string logMode, const std::string moduleName, const std::basic_string& output); + void LogToConsole(std::string logMode,const std::string moduleName,const std::basic_string& output); + Log(); + std::ofstream* m_fileStream; +}; +#define LOG_ERROR(module, message) { \ + LogMessageBuffer oss_; \ + Log::instance->error(module, oss_.str(oss_<< message)); } +#define LOG_INFO(module, message) { \ + LogMessageBuffer oss_; \ + Log::instance->info(module, oss_.str(oss_<< message)); } +#define LOG_DEBUG(module, message) { \ + LogMessageBuffer oss_; \ + Log::instance->debug(module, oss_.str(oss_<< message)); } +#define LOG_WARNING(module, message) { \ + LogMessageBuffer oss_; \ + Log::instance->warning(module, oss_.str(oss_<< message)); } +#endif /* _LOG_H_ */ diff --git a/LayerManagerUtils/include/LogMessageBuffer.h b/LayerManagerUtils/include/LogMessageBuffer.h new file mode 100644 index 0000000..493112a --- /dev/null +++ b/LayerManagerUtils/include/LogMessageBuffer.h @@ -0,0 +1,102 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 _LOGMESSAGEBUFFER_H_ +#define _LOGMESSAGEBUFFER_H_ +#include + +class LogMessageBuffer { + typedef std::ios_base& (*ios_base_manip)(std::ios_base&); +public: + /** + * Creates a new instance. + */ + LogMessageBuffer(); + /** + * Destructor. + */ + ~LogMessageBuffer(); + + + LogMessageBuffer& operator<<(const std::basic_string& msg); + + LogMessageBuffer& operator<<(const char* msg); + + LogMessageBuffer& operator<<(char* msg); + + LogMessageBuffer& operator<<(const char msg); + + std::ostream& operator<<(ios_base_manip manip); + + std::ostream& operator<<(bool val); + + std::ostream& operator<<(short val); + + std::ostream& operator<<(int val); + + std::ostream& operator<<(unsigned int val); + + std::ostream& operator<<(long val); + + std::ostream& operator<<(unsigned long val); + + std::ostream& operator<<(float val); + + std::ostream& operator<<(double val); + + std::ostream& operator<<(long double val); + + std::ostream& operator<<(void* val); + + /** + * Cast to ostream. + */ + operator std::basic_ostream&(); + + const std::basic_string& str(std::basic_ostream& os); + + const std::basic_string& str(); + + bool hasStream() const; + + private: + /** + * No default copy constructor. + */ + LogMessageBuffer(const LogMessageBuffer&); + /** + * No assignment operator. + */ + LogMessageBuffer& operator=(const LogMessageBuffer&); + + /** + * Encapsulated std::string. + */ + std::basic_string buf; + + /** + * Encapsulated stream, created on demand. + */ + std::basic_ostringstream* stream; + }; +template +std::basic_ostream& operator<<(LogMessageBuffer& os, const V& val) { + return ((std::basic_ostream&) os) << val; +} + +#endif /* _LOGMESSAGEBUFFER_H_ */ diff --git a/LayerManagerUtils/makefile b/LayerManagerUtils/makefile new file mode 100644 index 0000000..4131a28 --- /dev/null +++ b/LayerManagerUtils/makefile @@ -0,0 +1,64 @@ +############################################################################ +# +# Copyright 2010 BMW Car IT GmbH +# +# +# 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. +# +############################################################################ + + +ifneq ($(CONFIG),) +include ../LayerManagerPlatform/Make$(CONFIG).defs +endif + +SRC += Log.cpp \ + LogMessageBuffer.cpp + +TARGET_NAME = libLayerManagerUtils.a +LIB_NAME = $(TARGET_NAME).1.0 + + +# ADD PACKAGES/INCLUDE_DIRS/LIBS +PKG= +ADD_INCLUDE_DIR+= include \ + $(PREFIX)/usr/include + +ADD_LIB_DIR+= +ADD_LIBS+= + +OBJS += $(patsubst %.cpp,build/%.o,$(SRC)) +LINK = +TARGET = build/$(TARGET_NAME) +INCLUDE= $(patsubst %$,-I%,$(ADD_INCLUDE_DIR)) +LIBS+=$(shell pkg-config --libs $(PKG)) $(patsubst %$,-L%,$(ADD_LIB_DIR)) $(patsubst %$,-l%,$(ADD_LIBS)) + +all: $(TARGET) + +build/%.o: src/%.cpp + $(shell mkdir -p $(shell dirname $@)) + $(CXX) $(CXXFLAGS) $(INCLUDE) -c -o $@ $< + +$(TARGET): $(OBJS) + $(AR) rcs $(TARGET) $(OBJS) + +install: + mkdir -p $(PREFIX)/usr/lib/layermanager + install -m 755 $(TARGET) $(PREFIX)/usr/lib/layermanager + mkdir -p $(PREFIX)/usr/include/layermanager/ + install -m 755 include/Log.h $(PREFIX)/usr/include/layermanager/ + install -m 755 include/LogMessageBuffer.h $(PREFIX)/usr/include/layermanager/ + +clean: + rm -f $(OBJS) $(TARGET) + rm -rf build diff --git a/LayerManagerUtils/src/Log.cpp b/LayerManagerUtils/src/Log.cpp new file mode 100644 index 0000000..f0c0414 --- /dev/null +++ b/LayerManagerUtils/src/Log.cpp @@ -0,0 +1,82 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 "Log.h" + +Log* Log::instance = new Log(); + +Log::~Log() { + // TODO Auto-generated destructor stub + m_fileStream->close(); + Log::instance = NULL; +} +Log::Log() { + // TODO Auto-generated constructor stub + m_fileStream = new std::ofstream("log.txt"); + +} + +void Log::warning (const std::string moduleName,const std::basic_string& output ) +{ + log(LOG_WARNING,moduleName,output); +} +void Log::info (const std::string moduleName,const std::basic_string& output ) +{ + log(LOG_INFO,moduleName,output); +} +void Log::error (const std::string moduleName,const std::basic_string& output ) +{ + log(LOG_ERROR,moduleName,output); +} +void Log::debug (const std::string moduleName,const std::basic_string& output ) +{ + log(LOG_DEBUG,moduleName,output); +} + +void Log::log(LOG_MODES logMode, const std::string moduleName,const std::basic_string& output ) +{ + + if (logMode == LOG_ERROR) + { + LogToConsole("ERROR",moduleName,output); + } + else if (logMode == LOG_DEBUG) + { + LogToConsole("DEBUG",moduleName,output); + } + else if (logMode == LOG_INFO) + { + LogToConsole("INFO",moduleName,output); + } + switch (logMode ) + { + case LOG_ERROR : LogToFile("ERROR",moduleName,output); break; + case LOG_WARNING : LogToFile("WARNING",moduleName,output); break; + case LOG_INFO : LogToFile("INFO",moduleName,output); break; + case LOG_DEBUG : LogToFile("DEBUG",moduleName,output); break; + } + +} +void Log::LogToFile(std::string logMode,const std::string moduleName,const std::basic_string& output) +{ + *m_fileStream << "[" << moduleName << "][" << logMode << "] " << output << std::endl; +} +void Log::LogToConsole(std::string logMode,const std::string moduleName,const std::basic_string& output) +{ + std::cout << "[" << moduleName << "][" << logMode << "] " << output << std::endl; +} diff --git a/LayerManagerUtils/src/LogMessageBuffer.cpp b/LayerManagerUtils/src/LogMessageBuffer.cpp new file mode 100644 index 0000000..71e34ba --- /dev/null +++ b/LayerManagerUtils/src/LogMessageBuffer.cpp @@ -0,0 +1,100 @@ +/*************************************************************************** +* +* Copyright 2010 BMW Car IT GmbH +* +* +* 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 "LogMessageBuffer.h" + +LogMessageBuffer::LogMessageBuffer() : stream(0) {} + +LogMessageBuffer::~LogMessageBuffer() { + delete stream; +} + +LogMessageBuffer& LogMessageBuffer::operator<<(const std::basic_string& msg) { + if (stream == 0) { + buf.append(msg); + } else { + *stream << msg; + } + return *this; +} + +LogMessageBuffer& LogMessageBuffer::operator<<(const char* msg) { + const char* actualMsg = msg; + if (actualMsg == 0) { + actualMsg = "null"; + } + if (stream == 0) { + buf.append(actualMsg); + } else { + *stream << actualMsg; + } + return *this; +} +LogMessageBuffer& LogMessageBuffer::operator<<(char* msg) { + return operator<<((const char*) msg); +} + +LogMessageBuffer& LogMessageBuffer::operator<<(const char msg) { + if (stream == 0) { + buf.append(1, msg); + } else { + buf.assign(1, msg); + *stream << buf; + } + return *this; +} + +LogMessageBuffer::operator std::basic_ostream&() { + if (stream == 0) { + stream = new std::basic_ostringstream(); + if (!buf.empty()) { + *stream << buf; + } + } + return *stream; +} + +const std::basic_string& LogMessageBuffer::str(std::basic_ostream&) { + buf = stream->str(); + return buf; +} + +const std::basic_string& LogMessageBuffer::str() { + return buf; +} + +bool LogMessageBuffer::hasStream() const { + return (stream != 0); +} + +std::ostream& LogMessageBuffer::operator<<(ios_base_manip manip) { + std::ostream& s = *this; + (*manip)(s); + return s; +} + +std::ostream& LogMessageBuffer::operator<<(bool val) { return ((std::ostream&) *this).operator<<(val); } +std::ostream& LogMessageBuffer::operator<<(short val) { return ((std::ostream&) *this).operator<<(val); } +std::ostream& LogMessageBuffer::operator<<(int val) { return ((std::ostream&) *this).operator<<(val); } +std::ostream& LogMessageBuffer::operator<<(unsigned int val) { return ((std::ostream&) *this).operator<<(val); } +std::ostream& LogMessageBuffer::operator<<(long val) { return ((std::ostream&) *this).operator<<(val); } +std::ostream& LogMessageBuffer::operator<<(unsigned long val) { return ((std::ostream&) *this).operator<<(val); } +std::ostream& LogMessageBuffer::operator<<(float val) { return ((std::ostream&) *this).operator<<(val); } +std::ostream& LogMessageBuffer::operator<<(double val) { return ((std::ostream&) *this).operator<<(val); } +std::ostream& LogMessageBuffer::operator<<(long double val) { return ((std::ostream&) *this).operator<<(val); } +std::ostream& LogMessageBuffer::operator<<(void* val) { return ((std::ostream&) *this).operator<<(val); } diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt new file mode 100644 index 0000000..4e1e5ac --- /dev/null +++ b/RELEASE_NOTES.txt @@ -0,0 +1,3 @@ +Version 0.1.0 +------------- +Initial published Version.