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.
This commit is contained in:
Michael Wu 2012-08-24 15:42:45 -04:00
parent c2e71774f4
commit d881e202dd
5 changed files with 146 additions and 1 deletions

View File

@ -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 @@ 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,6 +577,12 @@ public:
bool SwapBuffers()
{
if (mSurface && !mPlatformContext) {
#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<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 File

@ -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 File

@ -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

58
widget/gonk/HWComposer.h Normal file
View File

@ -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 File

@ -34,6 +34,7 @@ LIBXUL_LIBRARY = 1
CPPSRCS = \
Framebuffer.cpp \
HWComposer.cpp \
nsAppShell.cpp \
nsWidgetFactory.cpp \
nsWindow.cpp \