diff --git a/Android.mk b/Android.mk index a3295d0..373fbfc 100644 --- a/Android.mk +++ b/Android.mk @@ -1,4 +1,4 @@ #Enables the listed display HAL modules -display-hals := libhwcomposer liboverlay libgralloc libgenlock libcopybit +display-hals := libhwcomposer liboverlay libgralloc libgenlock libcopybit libtilerenderer include $(call all-named-subdir-makefiles,$(display-hals)) diff --git a/libtilerenderer/Android.mk b/libtilerenderer/Android.mk new file mode 100644 index 0000000..e0bf342 --- /dev/null +++ b/libtilerenderer/Android.mk @@ -0,0 +1,26 @@ +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +ifeq ($(USE_OPENGL_RENDERER),true) +LOCAL_PRELINK_MODULE := false +LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES) +LOCAL_SHARED_LIBRARIES := libutils libcutils libGLESv2 libhwui + +LOCAL_C_INCLUDES += \ + frameworks/base/include/utils \ + frameworks/base/libs/hwui \ + external/skia/include/core \ + external/skia/include/effects \ + external/skia/include/images \ + external/skia/src/ports \ + external/skia/include/utils \ + hardware/libhardware/include/hardware \ + frameworks/base/opengl/include/GLES2 + +LOCAL_SRC_FILES := \ + tilerenderer.cpp + +LOCAL_MODULE := libtilerenderer +LOCAL_MODULE_TAGS := optional +include $(BUILD_SHARED_LIBRARY) +endif diff --git a/libtilerenderer/tilerenderer.cpp b/libtilerenderer/tilerenderer.cpp new file mode 100644 index 0000000..ae12ecf --- /dev/null +++ b/libtilerenderer/tilerenderer.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * Copyright (c) 2011 Code Aurora Forum. All rights reserved. + * + * 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 "tilerenderer.h" + +namespace android { +ANDROID_SINGLETON_STATIC_INSTANCE(uirenderer::TileRenderer) ; +namespace uirenderer { + +TileRenderer::TileRenderer() { + mIsTiled = false; +} + +TileRenderer::~TileRenderer() { +} + +void TileRenderer::startTileRendering(OpenGLRenderer* renderer, + int left, int top, + int right, int bottom) { + int width = 0; + int height = 0; + GLenum status = GL_NO_ERROR; + + if (renderer != NULL) { + renderer->getViewport(width, height); + } + + if (!left && !right && !top && !bottom) { + left = 0; + top = 0; + right = width; + bottom = height; + } + + if (!left && !right && !top && !bottom) { + //can't do tile rendering + LOGE("can't tile render; drity region, width, height not available"); + return; + } + + int l = left, t = (height - bottom), w = (right - left), h = (bottom - top), preserve = 0; + + if (l < 0 || t < 0) { + l = (l < 0) ? 0 : l; + t = (t < 0) ? 0 : t; + preserve = 1; + } + + if (w > width || h > height) { + w = (w > width) ? width : w; + h = (h > height) ? height : h; + preserve = 1; + } + + //clear off all errors before tiling, if any + while ((status = glGetError()) != GL_NO_ERROR) { + LOGE("glStartTilingQCOM: 0x%x", status); + } + + if (preserve) + glStartTilingQCOM(l, t, w, h, GL_COLOR_BUFFER_BIT0_QCOM); + else + glStartTilingQCOM(l, t, w, h, GL_NONE); + + status = glGetError(); + if (status == GL_NO_ERROR) + mIsTiled = true; + else + LOGE("glStartTilingQCOM: 0x%x", status); +} + +void TileRenderer::endTileRendering(OpenGLRenderer*) { + if (!mIsTiled) { + return; + } + glEndTilingQCOM(GL_COLOR_BUFFER_BIT0_QCOM); + mIsTiled = false; + GLenum status = GL_NO_ERROR; + while ((status = glGetError()) != GL_NO_ERROR) { + LOGE("glEndTilingQCOM: 0x%x", status); + } +} + +}; // namespace uirenderer +}; // namespace android diff --git a/libtilerenderer/tilerenderer.h b/libtilerenderer/tilerenderer.h new file mode 100644 index 0000000..bec225d --- /dev/null +++ b/libtilerenderer/tilerenderer.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * Copyright (c) 2011, Code Aurora Forum. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef ANDROID_TILE_RENDERER_H +#define ANDROID_TILE_RENDERER_H + +#include + +namespace android { +namespace uirenderer { + +class OpenGLRenderer; + +class TileRenderer: public Singleton { +public: + TileRenderer(); + ~TileRenderer(); + + void startTileRendering(OpenGLRenderer* renderer, int left, int top, int right, int bottom); + void endTileRendering(OpenGLRenderer*); + +private: + bool mIsTiled; +}; + +}; // namespace uirenderer +}; // namespace android + +#endif