Permalink
Browse files

Bug 771653 - Use HWComposer instead of swapBuffer where appropriate, …

…r=cjones

Some vendors provide a hw composer module which should be used instead of swapBuffers on hardware surfaces.

Based on romaxa's patch.
  • Loading branch information...
1 parent 16fb2b5 commit c0698c0ad5bdf7ed247df560378894c8bbcafdb1 @michaelwu michaelwu committed Aug 24, 2012
Showing with 146 additions and 1 deletion.
  1. +20 −1 gfx/gl/GLContextProviderEGL.cpp
  2. +1 −0 gfx/gl/Makefile.in
  3. +66 −0 widget/gonk/HWComposer.cpp
  4. +58 −0 widget/gonk/HWComposer.h
  5. +1 −0 widget/gonk/Makefile.in
@@ -19,6 +19,7 @@
#define GET_NATIVE_WINDOW(aWidget) (EGLNativeWindowType)static_cast<QWidget*>(aWidget->GetNativeData(NS_NATIVE_SHELLWIDGET))->winId()
#elif defined(MOZ_WIDGET_GONK)
#define GET_NATIVE_WINDOW(aWidget) ((EGLNativeWindowType)aWidget->GetNativeData(NS_NATIVE_WINDOW))
+#include "HWComposer.h"
#endif
#if defined(MOZ_X11)
@@ -267,6 +268,15 @@ class GLContextEGL : public GLContext
#ifdef DEBUG
printf_stderr("Initializing context %p surface %p on display %p\n", mContext, mSurface, EGL_DISPLAY());
+#endif
+#ifdef MOZ_WIDGET_GONK
+ if (!aIsOffscreen)
+ mHwc = new HWComposer();
+
+ if (mHwc && mHwc->init()) {
+ NS_WARNING("HWComposer initialization failed!");
+ mHwc = nullptr;
+ }
#endif
}
@@ -567,7 +577,13 @@ class GLContextEGL : public GLContext
bool SwapBuffers()
{
if (mSurface && !mPlatformContext) {
- return sEGLLibrary.fSwapBuffers(EGL_DISPLAY(), mSurface);
+#ifdef MOZ_WIDGET_GONK
+ if (mHwc)
+ return !mHwc->swapBuffers((hwc_display_t)EGL_DISPLAY(),
+ (hwc_surface_t)mSurface);
+ else
+#endif
+ return sEGLLibrary.fSwapBuffers(EGL_DISPLAY(), mSurface);
} else {
return false;
}
@@ -679,6 +695,9 @@ class GLContextEGL : public GLContext
bool mIsDoubleBuffered;
bool mCanBindToTexture;
bool mShareWithEGLImage;
+#ifdef MOZ_WIDGET_GONK
+ nsAutoPtr<HWComposer> mHwc;
+#endif
// A dummy texture ID that can be used when we need a texture object whose
// images we're going to define with EGLImageTargetTexture2D.
View
@@ -86,6 +86,7 @@ endif
ifeq ($(MOZ_WIDGET_TOOLKIT),gonk)
GL_PROVIDER = EGL
+LOCAL_INCLUDES = -I$(topsrcdir)/widget/gonk
endif
ifdef MOZ_GL_PROVIDER
View
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <string.h>
+#include "HWComposer.h"
+#include <hardware/hardware.h>
+#include <EGL/egl.h>
+
+namespace android {
+// ---------------------------------------------------------------------------
+
+HWComposer::HWComposer()
+ : mModule(0), mHwc(0),
+ mDpy(EGL_NO_DISPLAY), mSur(EGL_NO_SURFACE)
+{
+}
+
+HWComposer::~HWComposer() {
+ if (mHwc) {
+ hwc_close(mHwc);
+ }
+}
+
+int HWComposer::init() {
+ int err = hw_get_module(HWC_HARDWARE_MODULE_ID, &mModule);
+ LOGW_IF(err, "%s module not found", HWC_HARDWARE_MODULE_ID);
+ if (err)
+ return err;
+
+ err = hwc_open(mModule, &mHwc);
+ LOGE_IF(err, "%s device failed to initialize (%s)",
+ HWC_HARDWARE_COMPOSER, strerror(-err));
+ if (err) {
+ mHwc = NULL;
+ return err;
+ }
+
+ if (mHwc->registerProcs) {
+ mCBContext.hwc = this;
+ mHwc->registerProcs(mHwc, &mCBContext.procs);
+ }
+
+ return 0;
+}
+
+status_t HWComposer::swapBuffers(hwc_display_t dpy, hwc_surface_t surf) const {
+ mHwc->prepare(mHwc, NULL);
+ int err = mHwc->set(mHwc, dpy, surf, 0);
+ return (status_t)err;
+}
+
+// ---------------------------------------------------------------------------
+}; // namespace android
View
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_SF_HWCOMPOSER_H
+#define ANDROID_SF_HWCOMPOSER_H
+
+#include <hardware/hwcomposer.h>
+#include <utils/Vector.h>
+
+namespace android {
+// ---------------------------------------------------------------------------
+
+class String8;
+
+class HWComposer
+{
+public:
+
+ HWComposer();
+ ~HWComposer();
+
+ int init();
+
+ // swap buffers using vendor specific implementation
+ status_t swapBuffers(hwc_display_t dpy, hwc_surface_t surf) const;
+
+private:
+ struct cb_context {
+ hwc_procs_t procs;
+ HWComposer* hwc;
+ };
+ void invalidate();
+
+ hw_module_t const* mModule;
+ hwc_composer_device_t* mHwc;
+ hwc_display_t mDpy;
+ hwc_surface_t mSur;
+ cb_context mCBContext;
+};
+
+
+// ---------------------------------------------------------------------------
+}; // namespace android
+
+#endif // ANDROID_SF_HWCOMPOSER_H
View
@@ -34,6 +34,7 @@ LIBXUL_LIBRARY = 1
CPPSRCS = \
Framebuffer.cpp \
+ HWComposer.cpp \
nsAppShell.cpp \
nsWidgetFactory.cpp \
nsWindow.cpp \

0 comments on commit c0698c0

Please sign in to comment.