diff --git a/gfx/gl/GLContextProviderEGL.cpp b/gfx/gl/GLContextProviderEGL.cpp index 9966afd3362..6291118aaea 100644 --- a/gfx/gl/GLContextProviderEGL.cpp +++ b/gfx/gl/GLContextProviderEGL.cpp @@ -19,6 +19,7 @@ #define GET_NATIVE_WINDOW(aWidget) (EGLNativeWindowType)static_cast(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 @@ public: #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 @@ public: 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 @@ protected: bool mIsDoubleBuffered; bool mCanBindToTexture; bool mShareWithEGLImage; +#ifdef MOZ_WIDGET_GONK + nsAutoPtr 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. diff --git a/gfx/gl/Makefile.in b/gfx/gl/Makefile.in index 0b1ffa884ad..0515a038918 100644 --- a/gfx/gl/Makefile.in +++ b/gfx/gl/Makefile.in @@ -86,6 +86,7 @@ endif ifeq ($(MOZ_WIDGET_TOOLKIT),gonk) GL_PROVIDER = EGL +LOCAL_INCLUDES = -I$(topsrcdir)/widget/gonk endif ifdef MOZ_GL_PROVIDER diff --git a/widget/gonk/HWComposer.cpp b/widget/gonk/HWComposer.cpp new file mode 100644 index 00000000000..12f90a353be --- /dev/null +++ b/widget/gonk/HWComposer.cpp @@ -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 +#include "HWComposer.h" +#include +#include + +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 diff --git a/widget/gonk/HWComposer.h b/widget/gonk/HWComposer.h new file mode 100644 index 00000000000..a463c5e772e --- /dev/null +++ b/widget/gonk/HWComposer.h @@ -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 +#include + +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 diff --git a/widget/gonk/Makefile.in b/widget/gonk/Makefile.in index 30e12bd87e9..0ebd9ebcecb 100644 --- a/widget/gonk/Makefile.in +++ b/widget/gonk/Makefile.in @@ -34,6 +34,7 @@ LIBXUL_LIBRARY = 1 CPPSRCS = \ Framebuffer.cpp \ + HWComposer.cpp \ nsAppShell.cpp \ nsWidgetFactory.cpp \ nsWindow.cpp \