Bug 1308363 - Remove GONK specific code from gfx/. r=jrmuizel,sotaro

This commit is contained in:
Matt Woodrow
2016-10-27 13:17:10 +13:00
parent 401fbf4e88
commit 16f8a8bdeb
85 changed files with 25 additions and 5565 deletions

View File

@@ -51,7 +51,6 @@
#include "mozilla/layers/CompositorBridgeChild.h"
#include "mozilla/layers/ContentProcessController.h"
#include "mozilla/layers/ImageBridgeChild.h"
#include "mozilla/layers/SharedBufferManagerChild.h"
#include "mozilla/layout/RenderFrameChild.h"
#include "mozilla/net/NeckoChild.h"
#include "mozilla/plugins/PluginInstanceParent.h"
@@ -1214,13 +1213,6 @@ ContentChild::RecvReinitRendering(Endpoint<PCompositorBridgeChild>&& aCompositor
return true;
}
PSharedBufferManagerChild*
ContentChild::AllocPSharedBufferManagerChild(mozilla::ipc::Transport* aTransport,
base::ProcessId aOtherProcess)
{
return SharedBufferManagerChild::StartUpInChildProcess(aTransport, aOtherProcess);
}
PBackgroundChild*
ContentChild::AllocPBackgroundChild(Transport* aTransport,
ProcessId aOtherProcess)

View File

@@ -173,10 +173,6 @@ public:
Endpoint<PImageBridgeChild>&& aImageBridge,
Endpoint<PVRManagerChild>&& aVRBridge) override;
PSharedBufferManagerChild*
AllocPSharedBufferManagerChild(mozilla::ipc::Transport* aTransport,
base::ProcessId aOtherProcess) override;
PProcessHangMonitorChild*
AllocPProcessHangMonitorChild(Transport* aTransport,
ProcessId aOtherProcess) override;

View File

@@ -85,7 +85,6 @@
#include "mozilla/layers/CompositorThread.h"
#include "mozilla/layers/ImageBridgeParent.h"
#include "mozilla/layers/LayerTreeOwnerTracker.h"
#include "mozilla/layers/SharedBufferManagerParent.h"
#include "mozilla/layout/RenderFrameParent.h"
#include "mozilla/LookAndFeel.h"
#include "mozilla/media/MediaParent.h"
@@ -2214,10 +2213,6 @@ ContentParent::InitInternal(ProcessPriority aInitialPriority,
gpm->AddListener(this);
}
#ifdef MOZ_WIDGET_GONK
DebugOnly<bool> opened = PSharedBufferManager::Open(this);
MOZ_ASSERT(opened);
#endif
}
if (gAppData) {
@@ -2847,13 +2842,6 @@ ContentParent::AllocPProcessHangMonitorParent(Transport* aTransport,
return mHangMonitorActor;
}
PSharedBufferManagerParent*
ContentParent::AllocPSharedBufferManagerParent(mozilla::ipc::Transport* aTransport,
base::ProcessId aOtherProcess)
{
return SharedBufferManagerParent::Create(aTransport, aOtherProcess);
}
bool
ContentParent::RecvGetProcessAttributes(ContentParentId* aCpId,
bool* aIsForApp, bool* aIsForBrowser)

View File

@@ -67,7 +67,6 @@ class PJavaScriptParent;
} // namespace jsipc
namespace layers {
class PSharedBufferManagerParent;
struct TextureFactoryIdentifier;
} // namespace layers
@@ -702,10 +701,6 @@ private:
AllocPGMPServiceParent(mozilla::ipc::Transport* aTransport,
base::ProcessId aOtherProcess) override;
PSharedBufferManagerParent*
AllocPSharedBufferManagerParent(mozilla::ipc::Transport* aTranport,
base::ProcessId aOtherProcess) override;
PBackgroundParent*
AllocPBackgroundParent(Transport* aTransport, ProcessId aOtherProcess)
override;

View File

@@ -41,7 +41,6 @@ include protocol PSendStream;
include protocol POfflineCacheUpdate;
include protocol PRenderFrame;
include protocol PScreenManager;
include protocol PSharedBufferManager;
include protocol PSpeechSynthesis;
include protocol PStorage;
include protocol PTelephony;
@@ -344,7 +343,6 @@ nested(upto inside_cpow) sync protocol PContent
parent spawns PPluginModule;
parent opens PProcessHangMonitor;
parent opens PSharedBufferManager;
parent opens PGMPService;
child opens PBackground;

View File

@@ -372,10 +372,7 @@ void RecordingFontUserDataDestroyFunc(void *aUserData)
RecordingFontUserData *userData =
static_cast<RecordingFontUserData*>(aUserData);
// TODO support font in b2g recordings
#ifndef MOZ_WIDGET_GONK
userData->recorder->RecordEvent(RecordedScaledFontDestruction(userData->refPtr));
#endif
delete userData;
}
@@ -390,8 +387,6 @@ DrawTargetRecording::FillGlyphs(ScaledFont *aFont,
EnsurePatternDependenciesStored(aPattern);
if (!aFont->GetUserData(reinterpret_cast<UserDataKey*>(mRecorder.get()))) {
// TODO support font in b2g recordings
#ifndef MOZ_WIDGET_GONK
RecordedFontData fontData(aFont);
RecordedFontDetails fontDetails;
if (fontData.GetFontDetails(fontDetails)) {
@@ -412,7 +407,6 @@ DrawTargetRecording::FillGlyphs(ScaledFont *aFont,
gfxWarning() << "DrawTargetRecording::FillGlyphs failed to serialise ScaledFont";
}
}
#endif
RecordingFontUserData *userData = new RecordingFontUserData;
userData->refPtr = aFont;
userData->recorder = mRecorder;
@@ -420,10 +414,7 @@ DrawTargetRecording::FillGlyphs(ScaledFont *aFont,
&RecordingFontUserDataDestroyFunc);
}
// TODO support font in b2g recordings
#ifndef MOZ_WIDGET_GONK
mRecorder->RecordEvent(RecordedFillGlyphs(this, aFont, aPattern, aOptions, aBuffer.mGlyphs, aBuffer.mNumGlyphs));
#endif
mFinalDT->FillGlyphs(aFont, aBuffer, aPattern, aOptions, aRenderingOptions);
}

View File

@@ -16,7 +16,7 @@
#endif
#include "mozilla/Tuple.h"
#if defined(MOZ_WIDGET_GONK) || defined(MOZ_WIDGET_ANDROID)
#if defined(MOZ_WIDGET_ANDROID)
#include "nsDebug.h"
#endif
#include "Point.h"
@@ -140,7 +140,7 @@ struct BasicLogger
// in the appropriate places in that method.
static bool ShouldOutputMessage(int aLevel) {
if (LoggingPrefs::sGfxLogLevel >= aLevel) {
#if defined(MOZ_WIDGET_GONK) || defined(MOZ_WIDGET_ANDROID)
#if defined(MOZ_WIDGET_ANDROID)
return true;
#else
#if defined(MOZ_LOGGING)
@@ -173,7 +173,7 @@ struct BasicLogger
// make the corresponding change in the ShouldOutputMessage method
// above.
if (LoggingPrefs::sGfxLogLevel >= aLevel) {
#if defined(MOZ_WIDGET_GONK) || defined(MOZ_WIDGET_ANDROID)
#if defined(MOZ_WIDGET_ANDROID)
printf_stderr("%s%s", aString.c_str(), aNoNewline ? "" : "\n");
#else
#if defined(MOZ_LOGGING)

View File

@@ -207,12 +207,12 @@ FINAL_LIBRARY = 'xul'
for var in ('USE_CAIRO', 'MOZ2D_HAS_MOZ_CAIRO'):
DEFINES[var] = True
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gtk2', 'gtk3', 'gonk'):
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gtk2', 'gtk3'):
DEFINES['MOZ_ENABLE_FREETYPE'] = True
CXXFLAGS += CONFIG['MOZ_CAIRO_CFLAGS']
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gtk2', 'gtk3', 'gonk'):
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gtk2', 'gtk3'):
CXXFLAGS += CONFIG['CAIRO_FT_CFLAGS']
LOCAL_INCLUDES += CONFIG['SKIA_INCLUDES']

View File

@@ -15,11 +15,6 @@
#include "mozilla/gfx/Matrix.h"
#include "mozilla/UniquePtr.h"
#ifdef MOZ_WIDGET_GONK
#include "GrallocImages.h"
#include "GLLibraryEGL.h"
#endif
#ifdef MOZ_WIDGET_ANDROID
#include "AndroidSurfaceTexture.h"
#include "GLImages.h"
@@ -152,7 +147,7 @@ GLBlitHelper::InitTexQuadProgram(BlitType target)
vTexCoord * uTexCoordMult); \n\
} \n\
";
#ifdef ANDROID /* MOZ_WIDGET_ANDROID || MOZ_WIDGET_GONK */
#ifdef ANDROID /* MOZ_WIDGET_ANDROID */
const char kTexExternalBlit_FragShaderSource[] = "\
#version 100 \n\
#extension GL_OES_EGL_image_external : require \n\
@@ -684,38 +679,6 @@ GLBlitHelper::BindAndUploadEGLImage(EGLImage image, GLuint target)
mGL->fEGLImageTargetTexture2D(target, image);
}
#ifdef MOZ_WIDGET_GONK
bool
GLBlitHelper::BlitGrallocImage(layers::GrallocImage* grallocImage)
{
ScopedBindTextureUnit boundTU(mGL, LOCAL_GL_TEXTURE0);
mGL->fClear(LOCAL_GL_COLOR_BUFFER_BIT);
EGLint attrs[] = {
LOCAL_EGL_IMAGE_PRESERVED, LOCAL_EGL_TRUE,
LOCAL_EGL_NONE, LOCAL_EGL_NONE
};
EGLImage image = sEGLLibrary.fCreateImage(sEGLLibrary.Display(),
EGL_NO_CONTEXT,
LOCAL_EGL_NATIVE_BUFFER_ANDROID,
grallocImage->GetNativeBuffer(), attrs);
if (image == EGL_NO_IMAGE)
return false;
int oldBinding = 0;
mGL->fGetIntegerv(LOCAL_GL_TEXTURE_BINDING_EXTERNAL_OES, &oldBinding);
BindAndUploadEGLImage(image, LOCAL_GL_TEXTURE_EXTERNAL_OES);
mGL->fDrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4);
sEGLLibrary.fDestroyImage(sEGLLibrary.Display(), image);
mGL->fBindTexture(LOCAL_GL_TEXTURE_EXTERNAL_OES, oldBinding);
return true;
}
#endif
#ifdef MOZ_WIDGET_ANDROID
#define ATTACH_WAIT_MS 50
@@ -873,13 +836,6 @@ GLBlitHelper::BlitImageToFramebuffer(layers::Image* srcImage,
srcOrigin = OriginPos::TopLeft;
break;
#ifdef MOZ_WIDGET_GONK
case ImageFormat::GRALLOC_PLANAR_YCBCR:
type = ConvertGralloc;
srcOrigin = OriginPos::TopLeft;
break;
#endif
#ifdef MOZ_WIDGET_ANDROID
case ImageFormat::SURFACE_TEXTURE:
type = ConvertSurfaceTexture;
@@ -915,11 +871,6 @@ GLBlitHelper::BlitImageToFramebuffer(layers::Image* srcImage,
mGL->fViewport(0, 0, destSize.width, destSize.height);
switch (type) {
#ifdef MOZ_WIDGET_GONK
case ConvertGralloc:
return BlitGrallocImage(static_cast<layers::GrallocImage*>(srcImage));
#endif
case ConvertPlanarYCbCr: {
const auto saved = mGL->GetIntAs<GLint>(LOCAL_GL_UNPACK_ALIGNMENT);
mGL->fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, 1);

View File

@@ -107,9 +107,6 @@ class GLBlitHelper final
void BindAndUploadYUVTexture(Channel which, uint32_t width, uint32_t height, void* data, bool allocation);
void BindAndUploadEGLImage(EGLImage image, GLuint target);
#ifdef MOZ_WIDGET_GONK
bool BlitGrallocImage(layers::GrallocImage* grallocImage);
#endif
bool BlitPlanarYCbCrImage(layers::PlanarYCbCrImage* yuvImage);
#ifdef MOZ_WIDGET_ANDROID
// Blit onto the current FB.

View File

@@ -16,12 +16,6 @@
#endif
#if defined(XP_UNIX)
#ifdef MOZ_WIDGET_GONK
#include "libdisplay/GonkDisplay.h"
#include "nsWindow.h"
#include "nsScreenManagerGonk.h"
#endif
#ifdef MOZ_WIDGET_ANDROID
#include <android/native_window.h>
#include <android/native_window_jni.h>
@@ -30,13 +24,6 @@
#ifdef ANDROID
#include <android/log.h>
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "Gonk" , ## args)
#ifdef MOZ_WIDGET_GONK
#include "cutils/properties.h"
#include <ui/GraphicBuffer.h>
using namespace android;
#endif
#endif
#define GLES2_LIB "libGLESv2.so"
@@ -237,17 +224,6 @@ GLContextEGL::~GLContextEGL()
sEGLLibrary.fDestroyContext(EGL_DISPLAY(), mContext);
sEGLLibrary.UnsetCachedCurrentContext();
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION < 17
if (!mIsOffscreen) {
// In ICS, SurfaceFlinger's DisplayHardware::fini() does not destroy the EGLSurface associated with the
// native framebuffer. Destroying it causes crashes in the ICS emulator
// EGL implementation, specifically because the egl_window_surface_t dtor
// calls nativeWindow->cancelBuffer and FramebufferNativeWindow does not initialize
// the cancelBuffer function pointer, see bug 986836
return;
}
#endif
mozilla::gl::DestroySurface(mSurface);
}
@@ -437,12 +413,6 @@ GLContextEGL::SwapBuffers()
? mSurfaceOverride
: mSurface;
if (surface) {
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION < 17
if (!mIsOffscreen) {
// eglSwapBuffers() is called by hwcomposer.
return true;
}
#endif
return sEGLLibrary.fSwapBuffers(EGL_DISPLAY(), surface);
} else {
return false;
@@ -633,9 +603,6 @@ static const EGLint kEGLConfigAttribsRGBA32[] = {
LOCAL_EGL_GREEN_SIZE, 8,
LOCAL_EGL_BLUE_SIZE, 8,
LOCAL_EGL_ALPHA_SIZE, 8,
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
LOCAL_EGL_FRAMEBUFFER_TARGET_ANDROID, LOCAL_EGL_TRUE,
#endif
EGL_ATTRIBS_LIST_SAFE_TERMINATION_WORKING_AROUND_BUGS
};
@@ -667,29 +634,6 @@ CreateConfig(EGLConfig* aConfig, int32_t depth, nsIWidget* aWidget)
return false;
}
#ifdef MOZ_WIDGET_GONK
// On gonk, it's important to select a configuration with the
// the correct order as well as bits per channel.
// EGL_NATIVE_VISUAL_ID gives us the Android pixel format which
// is an enum that tells us both order and bits per channel.
// For example -
// HAL_PIXEL_FORMAT_RGBX_8888
// HAL_PIXEL_FORMAT_BGRA_8888
// HAL_PIXEL_FORMAT_RGB_565
nsWindow* window = static_cast<nsWindow*>(aWidget);
for (int j = 0; j < ncfg; ++j) {
EGLConfig config = configs[j];
EGLint format;
if (sEGLLibrary.fGetConfigAttrib(EGL_DISPLAY(), config,
LOCAL_EGL_NATIVE_VISUAL_ID, &format) &&
format == window->GetScreen()->GetSurfaceFormat())
{
*aConfig = config;
return true;
}
}
#endif
for (int j = 0; j < ncfg; ++j) {
EGLConfig config = configs[j];
EGLint r, g, b, a;

View File

@@ -431,11 +431,6 @@ GLLibraryEGL::EnsureInitialized(bool forceAccel, nsACString* const out_failureId
Unused << GLLibraryLoader::LoadSymbols(mEGLLibrary, &optionalSymbols[0],
nullptr, nullptr, false);
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 18
MOZ_RELEASE_ASSERT(mSymbols.fQueryStringImplementationANDROID,
"GFX: Couldn't find eglQueryStringImplementationANDROID");
#endif
InitClientExtensions();
const auto lookupFunction =

View File

@@ -24,11 +24,6 @@
#include "mozilla/gfx/DeviceManagerDx.h"
#endif
#ifdef MOZ_WIDGET_GONK
#include "SharedSurfaceGralloc.h"
#include "nsXULAppAPI.h"
#endif
#ifdef XP_MACOSX
#include "SharedSurfaceIO.h"
#endif
@@ -89,8 +84,6 @@ GLScreenBuffer::CreateFactory(GLContext* gl,
case mozilla::layers::LayersBackend::LAYERS_OPENGL: {
#if defined(XP_MACOSX)
factory = SurfaceFactory_IOSurface::Create(gl, caps, ipcChannel, flags);
#elif defined(MOZ_WIDGET_GONK)
factory = MakeUnique<SurfaceFactory_Gralloc>(gl, caps, ipcChannel, flags);
#elif defined(GL_PROVIDER_GLX)
if (sGLXLibrary.UseTextureFromPixmap())
factory = SurfaceFactory_GLXDrawable::Create(gl, caps, ipcChannel, flags);

View File

@@ -1,294 +0,0 @@
/* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40; -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/Preferences.h"
#include "mozilla/UniquePtr.h"
#include "SharedSurfaceGralloc.h"
#include "GLContext.h"
#include "SharedSurface.h"
#include "GLLibraryEGL.h"
#include "mozilla/layers/GrallocTextureClient.h"
#include "mozilla/layers/ShadowLayers.h"
#include "ui/GraphicBuffer.h"
#include "../layers/ipc/ShadowLayers.h"
#include "ScopedGLHelpers.h"
#include "gfxPlatform.h"
#include "gfxPrefs.h"
#define DEBUG_GRALLOC
#ifdef DEBUG_GRALLOC
#define DEBUG_PRINT(...) do { printf_stderr(__VA_ARGS__); } while (0)
#else
#define DEBUG_PRINT(...) do { } while (0)
#endif
namespace mozilla {
namespace gl {
using namespace mozilla::layers;
using namespace android;
SurfaceFactory_Gralloc::SurfaceFactory_Gralloc(GLContext* prodGL, const SurfaceCaps& caps,
const RefPtr<layers::LayersIPCChannel>& allocator,
const layers::TextureFlags& flags)
: SurfaceFactory(SharedSurfaceType::Gralloc, prodGL, caps, allocator, flags)
{
MOZ_ASSERT(mAllocator);
}
/*static*/ UniquePtr<SharedSurface_Gralloc>
SharedSurface_Gralloc::Create(GLContext* prodGL,
const GLFormats& formats,
const gfx::IntSize& size,
bool hasAlpha,
layers::TextureFlags flags,
LayersIPCChannel* allocator)
{
GLLibraryEGL* egl = &sEGLLibrary;
MOZ_ASSERT(egl);
UniquePtr<SharedSurface_Gralloc> ret;
DEBUG_PRINT("SharedSurface_Gralloc::Create -------\n");
if (!HasExtensions(egl, prodGL))
return Move(ret);
gfxContentType type = hasAlpha ? gfxContentType::COLOR_ALPHA
: gfxContentType::COLOR;
GrallocTextureData* texData = GrallocTextureData::CreateForGLRendering(
size, gfxPlatform::GetPlatform()->Optimal2DFormatForContent(type), allocator
);
if (!texData) {
return Move(ret);
}
RefPtr<TextureClient> grallocTC = new TextureClient(texData, flags, allocator);
sp<GraphicBuffer> buffer = texData->GetGraphicBuffer();
EGLDisplay display = egl->Display();
EGLClientBuffer clientBuffer = buffer->getNativeBuffer();
EGLint attrs[] = {
LOCAL_EGL_NONE, LOCAL_EGL_NONE
};
EGLImage image = egl->fCreateImage(display,
EGL_NO_CONTEXT,
LOCAL_EGL_NATIVE_BUFFER_ANDROID,
clientBuffer, attrs);
if (!image) {
return Move(ret);
}
prodGL->MakeCurrent();
GLuint prodTex = 0;
prodGL->fGenTextures(1, &prodTex);
ScopedBindTexture autoTex(prodGL, prodTex);
prodGL->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
prodGL->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR);
prodGL->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
prodGL->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
prodGL->fEGLImageTargetTexture2D(LOCAL_GL_TEXTURE_2D, image);
egl->fDestroyImage(display, image);
ret.reset( new SharedSurface_Gralloc(prodGL, size, hasAlpha, egl,
allocator, grallocTC,
prodTex) );
DEBUG_PRINT("SharedSurface_Gralloc::Create: success -- surface %p,"
" GraphicBuffer %p.\n",
ret.get(), buffer.get());
return Move(ret);
}
SharedSurface_Gralloc::SharedSurface_Gralloc(GLContext* prodGL,
const gfx::IntSize& size,
bool hasAlpha,
GLLibraryEGL* egl,
layers::LayersIPCChannel* allocator,
layers::TextureClient* textureClient,
GLuint prodTex)
: SharedSurface(SharedSurfaceType::Gralloc,
AttachmentType::GLTexture,
prodGL,
size,
hasAlpha,
true)
, mEGL(egl)
, mSync(0)
, mAllocator(allocator)
, mTextureClient(textureClient)
, mProdTex(prodTex)
{
}
bool
SharedSurface_Gralloc::HasExtensions(GLLibraryEGL* egl, GLContext* gl)
{
return egl->HasKHRImageBase() &&
gl->IsExtensionSupported(GLContext::OES_EGL_image);
}
SharedSurface_Gralloc::~SharedSurface_Gralloc()
{
DEBUG_PRINT("[SharedSurface_Gralloc %p] destroyed\n", this);
if (!mGL || !mGL->MakeCurrent())
return;
mGL->fDeleteTextures(1, &mProdTex);
if (mSync) {
MOZ_ALWAYS_TRUE( mEGL->fDestroySync(mEGL->Display(), mSync) );
mSync = 0;
}
}
void
SharedSurface_Gralloc::ProducerReleaseImpl()
{
if (mSync) {
MOZ_ALWAYS_TRUE( mEGL->fDestroySync(mEGL->Display(), mSync) );
mSync = 0;
}
bool disableSyncFence = false;
// Disable sync fence on AdrenoTM200.
// AdrenoTM200's sync fence does not work correctly. See Bug 1022205.
if (mGL->Renderer() == GLRenderer::AdrenoTM200) {
disableSyncFence = true;
}
// When Android native fences are available, try
// them first since they're more likely to work.
// Android native fences are also likely to perform better.
if (!disableSyncFence &&
mEGL->IsExtensionSupported(GLLibraryEGL::ANDROID_native_fence_sync))
{
mGL->MakeCurrent();
EGLSync sync = mEGL->fCreateSync(mEGL->Display(),
LOCAL_EGL_SYNC_NATIVE_FENCE_ANDROID,
nullptr);
if (sync) {
mGL->fFlush();
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
int fenceFd = mEGL->fDupNativeFenceFDANDROID(mEGL->Display(), sync);
if (fenceFd != -1) {
mEGL->fDestroySync(mEGL->Display(), sync);
mTextureClient->SetAcquireFenceHandle(FenceHandle(new FenceHandle::FdObj(fenceFd)));
} else {
mSync = sync;
}
#else
mSync = sync;
#endif
return;
}
}
if (!disableSyncFence &&
mEGL->IsExtensionSupported(GLLibraryEGL::KHR_fence_sync))
{
mGL->MakeCurrent();
mSync = mEGL->fCreateSync(mEGL->Display(),
LOCAL_EGL_SYNC_FENCE,
nullptr);
if (mSync) {
mGL->fFlush();
return;
}
}
// We should be able to rely on genlock write locks/read locks.
// But they're broken on some configs, and even a glFinish doesn't
// work. glReadPixels seems to, though.
if (gfxPrefs::GrallocFenceWithReadPixels()) {
mGL->MakeCurrent();
UniquePtr<char[]> buf = MakeUnique<char[]>(4);
mGL->fReadPixels(0, 0, 1, 1, LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE, buf.get());
}
}
void
SharedSurface_Gralloc::WaitForBufferOwnership()
{
mTextureClient->WaitForBufferOwnership();
}
bool
SharedSurface_Gralloc::ToSurfaceDescriptor(layers::SurfaceDescriptor* const out_descriptor)
{
mTextureClient->mWorkaroundAnnoyingSharedSurfaceOwnershipIssues = true;
return mTextureClient->ToSurfaceDescriptor(*out_descriptor);
}
bool
SharedSurface_Gralloc::ReadbackBySharedHandle(gfx::DataSourceSurface* out_surface)
{
MOZ_ASSERT(out_surface);
sp<GraphicBuffer> buffer = static_cast<GrallocTextureData*>(
mTextureClient->GetInternalData()
)->GetGraphicBuffer();
const uint8_t* grallocData = nullptr;
auto result = buffer->lock(
GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_NEVER,
const_cast<void**>(reinterpret_cast<const void**>(&grallocData))
);
if (result == BAD_VALUE) {
return false;
}
gfx::DataSourceSurface::ScopedMap map(out_surface, gfx::DataSourceSurface::WRITE);
if (!map.IsMapped()) {
buffer->unlock();
return false;
}
uint32_t stride = buffer->getStride() * android::bytesPerPixel(buffer->getPixelFormat());
uint32_t height = buffer->getHeight();
uint32_t width = buffer->getWidth();
for (uint32_t i = 0; i < height; i++) {
memcpy(map.GetData() + i * map.GetStride(),
grallocData + i * stride, width * 4);
}
buffer->unlock();
android::PixelFormat srcFormat = buffer->getPixelFormat();
MOZ_ASSERT(srcFormat == PIXEL_FORMAT_RGBA_8888 ||
srcFormat == PIXEL_FORMAT_BGRA_8888 ||
srcFormat == PIXEL_FORMAT_RGBX_8888);
bool isSrcRGB = srcFormat == PIXEL_FORMAT_RGBA_8888 ||
srcFormat == PIXEL_FORMAT_RGBX_8888;
gfx::SurfaceFormat destFormat = out_surface->GetFormat();
MOZ_ASSERT(destFormat == gfx::SurfaceFormat::R8G8B8X8 ||
destFormat == gfx::SurfaceFormat::R8G8B8A8 ||
destFormat == gfx::SurfaceFormat::B8G8R8X8 ||
destFormat == gfx::SurfaceFormat::B8G8R8A8);
bool isDestRGB = destFormat == gfx::SurfaceFormat::R8G8B8X8 ||
destFormat == gfx::SurfaceFormat::R8G8B8A8;
if (isSrcRGB != isDestRGB) {
SwapRAndBComponents(out_surface);
}
return true;
}
} // namespace gl
} // namespace mozilla

View File

@@ -1,104 +0,0 @@
/* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40; -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef SHARED_SURFACE_GRALLOC_H_
#define SHARED_SURFACE_GRALLOC_H_
#include "mozilla/layers/CompositorTypes.h"
#include "mozilla/layers/LayersSurfaces.h"
#include "SharedSurface.h"
namespace mozilla {
namespace layers {
class LayersIPCChannel;
class TextureClient;
}
namespace gl {
class GLContext;
class GLLibraryEGL;
class SharedSurface_Gralloc
: public SharedSurface
{
public:
static UniquePtr<SharedSurface_Gralloc> Create(GLContext* prodGL,
const GLFormats& formats,
const gfx::IntSize& size,
bool hasAlpha,
layers::TextureFlags flags,
layers::LayersIPCChannel* allocator);
static SharedSurface_Gralloc* Cast(SharedSurface* surf) {
MOZ_ASSERT(surf->mType == SharedSurfaceType::Gralloc);
return (SharedSurface_Gralloc*)surf;
}
protected:
GLLibraryEGL* const mEGL;
EGLSync mSync;
RefPtr<layers::LayersIPCChannel> mAllocator;
RefPtr<layers::TextureClient> mTextureClient;
const GLuint mProdTex;
SharedSurface_Gralloc(GLContext* prodGL,
const gfx::IntSize& size,
bool hasAlpha,
GLLibraryEGL* egl,
layers::LayersIPCChannel* allocator,
layers::TextureClient* textureClient,
GLuint prodTex);
static bool HasExtensions(GLLibraryEGL* egl, GLContext* gl);
public:
virtual ~SharedSurface_Gralloc();
virtual void ProducerAcquireImpl() override {}
virtual void ProducerReleaseImpl() override;
virtual void WaitForBufferOwnership() override;
virtual void LockProdImpl() override {}
virtual void UnlockProdImpl() override {}
virtual GLuint ProdTexture() override {
return mProdTex;
}
layers::TextureClient* GetTextureClient() {
return mTextureClient;
}
virtual bool ToSurfaceDescriptor(layers::SurfaceDescriptor* const out_descriptor) override;
virtual bool ReadbackBySharedHandle(gfx::DataSourceSurface* out_surface) override;
};
class SurfaceFactory_Gralloc
: public SurfaceFactory
{
public:
SurfaceFactory_Gralloc(GLContext* prodGL, const SurfaceCaps& caps,
const RefPtr<layers::LayersIPCChannel>& allocator,
const layers::TextureFlags& flags);
virtual UniquePtr<SharedSurface> CreateShared(const gfx::IntSize& size) override {
bool hasAlpha = mReadCaps.alpha;
UniquePtr<SharedSurface> ret;
if (mAllocator) {
ret = SharedSurface_Gralloc::Create(mGL, mFormats, size, hasAlpha,
mFlags, mAllocator);
}
return Move(ret);
}
};
} /* namespace gl */
} /* namespace mozilla */
#endif /* SHARED_SURFACE_GRALLOC_H_ */

View File

@@ -19,8 +19,6 @@ elif 'gtk' in CONFIG['MOZ_WIDGET_TOOLKIT']:
gl_provider = 'GLX'
elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
gl_provider = 'EGL'
elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
gl_provider = 'EGL'
if CONFIG['MOZ_GL_PROVIDER']:
gl_provider = CONFIG['MOZ_GL_PROVIDER']
@@ -84,12 +82,6 @@ if CONFIG['MOZ_ENABLE_SKIA_GPU']:
# Suppress warnings from Skia header files.
SOURCES['SkiaGLGlue.cpp'].flags += ['-Wno-implicit-fallthrough']
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
UNIFIED_SOURCES += ['SharedSurfaceGralloc.cpp']
EXPORTS += ['SharedSurfaceGralloc.h']
LOCAL_INCLUDES += ['/widget/gonk']
LOCAL_INCLUDES += ['%' + '%s/%s' % (CONFIG['ANDROID_SOURCE'], 'hardware/libhardware/include')]
if gl_provider == 'CGL':
# These files include Mac headers that are unfriendly to unified builds
SOURCES += [

View File

@@ -14,13 +14,6 @@
#include "gfx2DGlue.h"
#include "nsAppRunner.h"
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
#include "libdisplay/GonkDisplay.h" // for GonkDisplay
#include <ui/Fence.h>
#include "nsWindow.h"
#include "nsScreenManagerGonk.h"
#endif
namespace mozilla {
namespace layers {
@@ -607,37 +600,6 @@ Compositor::IsValid() const
return !!mParent;
}
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
void
Compositor::SetDispAcquireFence(Layer* aLayer)
{
// OpenGL does not provide ReleaseFence for rendering.
// Instead use DispAcquireFence as layer buffer's ReleaseFence
// to prevent flickering and tearing.
// DispAcquireFence is DisplaySurface's AcquireFence.
// AcquireFence will be signaled when a buffer's content is available.
// See Bug 974152.
if (!aLayer || !mWidget) {
return;
}
nsWindow* window = static_cast<nsWindow*>(mWidget->RealWidget());
RefPtr<FenceHandle::FdObj> fence = new FenceHandle::FdObj(
window->GetScreen()->GetPrevDispAcquireFd());
mReleaseFenceHandle.Merge(FenceHandle(fence));
}
FenceHandle
Compositor::GetReleaseFence()
{
if (!mReleaseFenceHandle.IsValid()) {
return FenceHandle();
}
RefPtr<FenceHandle::FdObj> fdObj = mReleaseFenceHandle.GetDupFdObj();
return FenceHandle(fdObj);
}
#else
void
Compositor::SetDispAcquireFence(Layer* aLayer)
{
@@ -648,7 +610,6 @@ Compositor::GetReleaseFence()
{
return FenceHandle();
}
#endif
} // namespace layers
} // namespace mozilla

View File

@@ -683,10 +683,6 @@ protected:
bool mIsDestroyed;
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
FenceHandle mReleaseFenceHandle;
#endif
gfx::Color mClearColor;
gfx::Color mDefaultClearColor;

View File

@@ -1,478 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "GrallocImages.h"
#include <stddef.h> // for size_t
#include <stdint.h> // for int8_t, uint8_t, uint32_t, etc
#include "nsDebug.h" // for NS_WARNING, NS_PRECONDITION
#include "mozilla/layers/ImageBridgeChild.h"
#include "mozilla/layers/GrallocTextureClient.h"
#include "gfx2DGlue.h"
#include "YCbCrUtils.h" // for YCbCr conversions
#include <ColorConverter.h>
#include <OMX_IVCommon.h>
using namespace mozilla::ipc;
using namespace android;
#define ALIGN(x, align) ((x + align - 1) & ~(align - 1))
namespace mozilla {
namespace layers {
int32_t GrallocImage::sColorIdMap[] = {
HAL_PIXEL_FORMAT_YCbCr_420_P, OMX_COLOR_FormatYUV420Planar,
HAL_PIXEL_FORMAT_YCbCr_422_P, OMX_COLOR_FormatYUV422Planar,
HAL_PIXEL_FORMAT_YCbCr_420_SP, OMX_COLOR_FormatYUV420SemiPlanar,
HAL_PIXEL_FORMAT_YCrCb_420_SP, -1,
HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO, -1,
HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED, HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED,
HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS, HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS,
HAL_PIXEL_FORMAT_YV12, OMX_COLOR_FormatYUV420Planar,
HAL_PIXEL_FORMAT_RGBA_8888, -1,
0, 0
};
struct GraphicBufferAutoUnlock {
android::sp<GraphicBuffer> mGraphicBuffer;
GraphicBufferAutoUnlock(android::sp<GraphicBuffer>& aGraphicBuffer)
: mGraphicBuffer(aGraphicBuffer) { }
~GraphicBufferAutoUnlock() { mGraphicBuffer->unlock(); }
};
GrallocImage::GrallocImage()
: RecyclingPlanarYCbCrImage(nullptr)
{
mFormat = ImageFormat::GRALLOC_PLANAR_YCBCR;
}
GrallocImage::~GrallocImage()
{
}
bool
GrallocImage::SetData(const Data& aData)
{
MOZ_ASSERT(!mTextureClient, "TextureClient is already set");
NS_PRECONDITION(aData.mYSize.width % 2 == 0, "Image should have even width");
NS_PRECONDITION(aData.mYSize.height % 2 == 0, "Image should have even height");
NS_PRECONDITION(aData.mYStride % 16 == 0, "Image should have stride of multiple of 16 pixels");
mData = aData;
mSize = aData.mPicSize;
if (gfxPlatform::GetPlatform()->IsInGonkEmulator()) {
// Emulator does not support HAL_PIXEL_FORMAT_YV12.
return false;
}
RefPtr<LayersIPCChannel> allocator = ImageBridgeChild::GetSingleton();
GrallocTextureData* texData = GrallocTextureData::Create(mData.mYSize, HAL_PIXEL_FORMAT_YV12,
gfx::BackendType::NONE,
GraphicBuffer::USAGE_SW_READ_OFTEN |
GraphicBuffer::USAGE_SW_WRITE_OFTEN |
GraphicBuffer::USAGE_HW_TEXTURE,
allocator
);
if (!texData) {
return false;
}
mTextureClient = new TextureClient(texData, TextureFlags::DEFAULT, allocator);
sp<GraphicBuffer> graphicBuffer = texData->GetGraphicBuffer();
void* vaddr;
if (graphicBuffer->lock(GraphicBuffer::USAGE_SW_WRITE_OFTEN,
&vaddr) != OK) {
return false;
}
uint8_t* yChannel = static_cast<uint8_t*>(vaddr);
gfx::IntSize ySize = aData.mYSize;
int32_t yStride = graphicBuffer->getStride();
uint8_t* vChannel = yChannel + (yStride * ySize.height);
gfx::IntSize uvSize = gfx::IntSize(ySize.width / 2,
ySize.height / 2);
// Align to 16 bytes boundary
int32_t uvStride = ((yStride / 2) + 15) & ~0x0F;
uint8_t* uChannel = vChannel + (uvStride * uvSize.height);
// Memory outside of the image width may not writable. If the stride
// equals to the image width then we can use only one copy.
if (yStride == mData.mYStride &&
yStride == ySize.width) {
memcpy(yChannel, mData.mYChannel, yStride * ySize.height);
} else {
for (int i = 0; i < ySize.height; i++) {
memcpy(yChannel + i * yStride,
mData.mYChannel + i * mData.mYStride,
ySize.width);
}
}
if (uvStride == mData.mCbCrStride &&
uvStride == uvSize.width) {
memcpy(uChannel, mData.mCbChannel, uvStride * uvSize.height);
memcpy(vChannel, mData.mCrChannel, uvStride * uvSize.height);
} else {
for (int i = 0; i < uvSize.height; i++) {
memcpy(uChannel + i * uvStride,
mData.mCbChannel + i * mData.mCbCrStride,
uvSize.width);
memcpy(vChannel + i * uvStride,
mData.mCrChannel + i * mData.mCbCrStride,
uvSize.width);
}
}
graphicBuffer->unlock();
// Initialze the channels' addresses.
// Do not cache the addresses when gralloc buffer is not locked.
// gralloc hal could map gralloc buffer only when the buffer is locked,
// though some gralloc hals implementation maps it when it is allocated.
mData.mYChannel = nullptr;
mData.mCrChannel = nullptr;
mData.mCbChannel = nullptr;
return true;
}
void
GrallocImage::AdoptData(TextureClient* aGraphicBuffer, const gfx::IntSize& aSize)
{
mTextureClient = aGraphicBuffer;
mSize = aSize;
}
/**
* Converts YVU420 semi planar frames to RGB565, possibly taking different
* stride values.
* Needed because the Android ColorConverter class assumes that the Y and UV
* channels have equal stride.
*/
static void
ConvertYVU420SPToRGB565(void *aYData, uint32_t aYStride,
void *aUData, void *aVData, uint32_t aUVStride,
void *aOut,
uint32_t aWidth, uint32_t aHeight)
{
uint8_t *y = (uint8_t*)aYData;
bool isCbCr;
int8_t *uv;
if (aUData < aVData) {
// The color format is YCbCr
isCbCr = true;
uv = (int8_t*)aUData;
} else {
// The color format is YCrCb
isCbCr = false;
uv = (int8_t*)aVData;
}
uint16_t *rgb = (uint16_t*)aOut;
for (size_t i = 0; i < aHeight; i++) {
for (size_t j = 0; j < aWidth; j++) {
int8_t d, e;
if (isCbCr) {
d = uv[j & ~1] - 128;
e = uv[j | 1] - 128;
} else {
d = uv[j | 1] - 128;
e = uv[j & ~1] - 128;
}
// Constants taken from https://en.wikipedia.org/wiki/YUV
int32_t r = (298 * y[j] + 409 * e + 128) >> 11;
int32_t g = (298 * y[j] - 100 * d - 208 * e + 128) >> 10;
int32_t b = (298 * y[j] + 516 * d + 128) >> 11;
r = r > 0x1f ? 0x1f : r < 0 ? 0 : r;
g = g > 0x3f ? 0x3f : g < 0 ? 0 : g;
b = b > 0x1f ? 0x1f : b < 0 ? 0 : b;
*rgb++ = (uint16_t)(r << 11 | g << 5 | b);
}
y += aYStride;
if (i % 2) {
uv += aUVStride;
}
}
}
/**
* Converts the format of vendor-specific YVU420(planar and semi-planar)
* with the help of GraphicBuffer::lockYCbCr. In this way, we can convert
* the YUV color format without awaring actual definition/enumeration
* of vendor formats.
*/
static status_t
ConvertVendorYUVFormatToRGB565(android::sp<GraphicBuffer>& aBuffer,
gfx::DataSourceSurface *aSurface,
gfx::DataSourceSurface::MappedSurface *aMappedSurface)
{
status_t rv = BAD_VALUE;
#if ANDROID_VERSION >= 18
android_ycbcr ycbcr;
// Check if the vendor provides explicit addresses of Y/Cb/Cr buffer from lockYCbCr
rv = aBuffer->lockYCbCr(android::GraphicBuffer::USAGE_SW_READ_OFTEN, &ycbcr);
if (rv != OK) {
NS_WARNING("Couldn't lock graphic buffer using lockYCbCr()");
return rv;
}
GraphicBufferAutoUnlock unlock(aBuffer);
uint32_t width = aSurface->GetSize().width;
uint32_t height = aSurface->GetSize().height;
if (ycbcr.chroma_step == 2) {
// From the system/core/include/system/graphics.h
// @chroma_step is the distance in bytes from one chroma pixel value to
// the next. This is 2 bytes for semiplanar (because chroma values are
// interleaved and each chroma value is one byte) and 1 for planar.
ConvertYVU420SPToRGB565(ycbcr.y, ycbcr.ystride,
ycbcr.cb, ycbcr.cr, ycbcr.cstride,
aMappedSurface->mData,
width, height);
} else {
layers::PlanarYCbCrData ycbcrData;
ycbcrData.mYChannel = static_cast<uint8_t*>(ycbcr.y);
ycbcrData.mYStride = ycbcr.ystride;
ycbcrData.mYSize = aSurface->GetSize();
ycbcrData.mCbChannel = static_cast<uint8_t*>(ycbcr.cb);
ycbcrData.mCrChannel = static_cast<uint8_t*>(ycbcr.cr);
ycbcrData.mCbCrStride = ycbcr.cstride;
ycbcrData.mCbCrSize = aSurface->GetSize() / 2;
ycbcrData.mPicSize = aSurface->GetSize();
gfx::ConvertYCbCrToRGB(ycbcrData,
aSurface->GetFormat(),
aSurface->GetSize(),
aMappedSurface->mData,
aMappedSurface->mStride);
}
#endif
return rv;
}
static status_t
ConvertOmxYUVFormatToRGB565(android::sp<GraphicBuffer>& aBuffer,
gfx::DataSourceSurface *aSurface,
gfx::DataSourceSurface::MappedSurface *aMappedSurface,
const layers::PlanarYCbCrData& aYcbcrData)
{
uint32_t omxFormat =
GrallocImage::GetOmxFormat(aBuffer->getPixelFormat());
if (!omxFormat) {
NS_WARNING("Unknown color format");
return BAD_VALUE;
}
status_t rv;
uint8_t *buffer;
rv = aBuffer->lock(android::GraphicBuffer::USAGE_SW_READ_OFTEN,
reinterpret_cast<void **>(&buffer));
if (rv != OK) {
NS_WARNING("Couldn't lock graphic buffer");
return BAD_VALUE;
}
GraphicBufferAutoUnlock unlock(aBuffer);
uint32_t format = aBuffer->getPixelFormat();
uint32_t width = aSurface->GetSize().width;
uint32_t height = aSurface->GetSize().height;
uint32_t stride = aBuffer->getStride();
if (format == GrallocImage::HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO) {
// The Adreno hardware decoder aligns image dimensions to a multiple of 32,
// so we have to account for that here
uint32_t alignedWidth = ALIGN(width, 32);
uint32_t alignedHeight = ALIGN(height, 32);
uint32_t uvOffset = ALIGN(alignedHeight * alignedWidth, 4096);
uint32_t uvStride = 2 * ALIGN(width / 2, 32);
ConvertYVU420SPToRGB565(buffer, alignedWidth,
buffer + uvOffset + 1,
buffer + uvOffset,
uvStride,
aMappedSurface->mData,
width, height);
return OK;
}
if (format == HAL_PIXEL_FORMAT_YCrCb_420_SP) {
uint32_t uvOffset = height * stride;
ConvertYVU420SPToRGB565(buffer, stride,
buffer + uvOffset + 1,
buffer + uvOffset,
stride,
aMappedSurface->mData,
width, height);
return OK;
}
if (format == HAL_PIXEL_FORMAT_YV12) {
// Depend on platforms, it is possible for HW decoder to output YV12 format.
// It means the mData won't be configured during the SetData API because the
// yuv data has already stored in GraphicBuffer. Here we try to confgiure the
// mData if it doesn't contain valid configuration.
layers::PlanarYCbCrData ycbcrData = aYcbcrData;
if (!ycbcrData.mYChannel) {
ycbcrData.mYChannel = buffer;
ycbcrData.mYSkip = 0;
ycbcrData.mYStride = aBuffer->getStride();
ycbcrData.mYSize = aSurface->GetSize();
ycbcrData.mCbSkip = 0;
ycbcrData.mCbCrSize = aSurface->GetSize() / 2;
ycbcrData.mPicSize = aSurface->GetSize();
ycbcrData.mCrChannel = buffer + ycbcrData.mYStride * aBuffer->getHeight();
ycbcrData.mCrSkip = 0;
// Align to 16 bytes boundary
ycbcrData.mCbCrStride = ALIGN(ycbcrData.mYStride / 2, 16);
ycbcrData.mCbChannel = ycbcrData.mCrChannel + (ycbcrData.mCbCrStride * aBuffer->getHeight() / 2);
} else {
// Update channels' address.
// Gralloc buffer could map gralloc buffer only when the buffer is locked.
ycbcrData.mYChannel = buffer;
ycbcrData.mCrChannel = buffer + ycbcrData.mYStride * aBuffer->getHeight();
ycbcrData.mCbChannel = ycbcrData.mCrChannel + (ycbcrData.mCbCrStride * aBuffer->getHeight() / 2);
}
gfx::ConvertYCbCrToRGB(ycbcrData,
aSurface->GetFormat(),
aSurface->GetSize(),
aMappedSurface->mData,
aMappedSurface->mStride);
return OK;
}
if (format == HAL_PIXEL_FORMAT_RGBA_8888) {
uint32_t* src = (uint32_t*)(buffer);
uint16_t* dest = (uint16_t*)(aMappedSurface->mData);
// Convert RGBA8888 to RGB565
for (size_t i = 0; i < width * height; i++) {
uint32_t r = ((*src >> 0 ) & 0xFF);
uint32_t g = ((*src >> 8 ) & 0xFF);
uint32_t b = ((*src >> 16) & 0xFF);
*dest++ = ((r >> 3) << 11) | ((g >> 2) << 5) | ((b >> 3) << 0);
src++;
}
return OK;
}
android::ColorConverter colorConverter((OMX_COLOR_FORMATTYPE)omxFormat,
OMX_COLOR_Format16bitRGB565);
if (!colorConverter.isValid()) {
NS_WARNING("Invalid color conversion");
return BAD_VALUE;
}
uint32_t pixelStride = aMappedSurface->mStride/gfx::BytesPerPixel(gfx::SurfaceFormat::R5G6B5_UINT16);
rv = colorConverter.convert(buffer, width, height,
0, 0, width - 1, height - 1 /* source crop */,
aMappedSurface->mData, pixelStride, height,
0, 0, width - 1, height - 1 /* dest crop */);
if (rv) {
NS_WARNING("OMX color conversion failed");
return BAD_VALUE;
}
return OK;
}
already_AddRefed<gfx::DataSourceSurface>
GetDataSourceSurfaceFrom(android::sp<android::GraphicBuffer>& aGraphicBuffer,
gfx::IntSize aSize,
const layers::PlanarYCbCrData& aYcbcrData)
{
MOZ_ASSERT(aGraphicBuffer.get());
RefPtr<gfx::DataSourceSurface> surface =
gfx::Factory::CreateDataSourceSurface(aSize, gfx::SurfaceFormat::R5G6B5_UINT16);
if (NS_WARN_IF(!surface)) {
return nullptr;
}
gfx::DataSourceSurface::MappedSurface mappedSurface;
if (!surface->Map(gfx::DataSourceSurface::WRITE, &mappedSurface)) {
NS_WARNING("Could not map DataSourceSurface");
return nullptr;
}
int32_t rv;
rv = ConvertOmxYUVFormatToRGB565(aGraphicBuffer, surface, &mappedSurface, aYcbcrData);
if (rv == OK) {
surface->Unmap();
return surface.forget();
}
rv = ConvertVendorYUVFormatToRGB565(aGraphicBuffer, surface, &mappedSurface);
surface->Unmap();
if (rv != OK) {
NS_WARNING("Unknown color format");
return nullptr;
}
return surface.forget();
}
already_AddRefed<gfx::SourceSurface>
GrallocImage::GetAsSourceSurface()
{
if (!mTextureClient) {
return nullptr;
}
android::sp<GraphicBuffer> graphicBuffer = GetGraphicBuffer();
RefPtr<gfx::DataSourceSurface> surface =
GetDataSourceSurfaceFrom(graphicBuffer, mSize, mData);
return surface.forget();
}
android::sp<android::GraphicBuffer>
GrallocImage::GetGraphicBuffer() const
{
if (!mTextureClient) {
return nullptr;
}
return static_cast<GrallocTextureData*>(mTextureClient->GetInternalData())->GetGraphicBuffer();
}
void*
GrallocImage::GetNativeBuffer()
{
if (!mTextureClient) {
return nullptr;
}
android::sp<android::GraphicBuffer> graphicBuffer = GetGraphicBuffer();
if (!graphicBuffer.get()) {
return nullptr;
}
return graphicBuffer->getNativeBuffer();
}
TextureClient*
GrallocImage::GetTextureClient(KnowsCompositor* aForwarder)
{
return mTextureClient;
}
} // namespace layers
} // namespace mozilla

View File

@@ -1,136 +0,0 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef GRALLOCIMAGES_H
#define GRALLOCIMAGES_H
#ifdef MOZ_WIDGET_GONK
#include "ImageLayers.h"
#include "ImageContainer.h"
#include "mozilla/gfx/Point.h"
#include "mozilla/layers/AtomicRefCountedWithFinalize.h"
#include "mozilla/layers/FenceUtils.h"
#include "mozilla/layers/LayersSurfaces.h"
#include <ui/GraphicBuffer.h>
namespace mozilla {
namespace layers {
class TextureClient;
already_AddRefed<gfx::DataSourceSurface>
GetDataSourceSurfaceFrom(android::sp<android::GraphicBuffer>& aGraphicBuffer,
gfx::IntSize aSize,
const layers::PlanarYCbCrData& aYcbcrData);
/**
* The YUV format supported by Android HAL
*
* 4:2:0 - CbCr width and height is half that of Y.
*
* This format assumes
* - an even width
* - an even height
* - a horizontal stride multiple of 16 pixels
* - a vertical stride equal to the height
*
* y_size = stride * height
* c_size = ALIGN(stride/2, 16) * height/2
* size = y_size + c_size * 2
* cr_offset = y_size
* cb_offset = y_size + c_size
*
* The Image that is rendered is the picture region defined by
* mPicX, mPicY and mPicSize. The size of the rendered image is
* mPicSize, not mYSize or mCbCrSize.
*/
class GrallocImage : public RecyclingPlanarYCbCrImage
{
typedef PlanarYCbCrData Data;
static int32_t sColorIdMap[];
public:
GrallocImage();
virtual ~GrallocImage();
/**
* This makes a copy of the data buffers, in order to support functioning
* in all different layer managers.
*/
virtual bool SetData(const Data& aData);
using RecyclingPlanarYCbCrImage::AdoptData;
/**
* Share the SurfaceDescriptor without making the copy, in order
* to support functioning in all different layer managers.
*/
void AdoptData(TextureClient* aGraphicBuffer, const gfx::IntSize& aSize);
// From [android 4.0.4]/hardware/msm7k/libgralloc-qsd8k/gralloc_priv.h
enum {
/* OEM specific HAL formats */
HAL_PIXEL_FORMAT_YCbCr_422_P = 0x102,
HAL_PIXEL_FORMAT_YCbCr_420_P = 0x103,
HAL_PIXEL_FORMAT_YCbCr_420_SP = 0x109,
HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO = 0x10A,
HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED = 0x7FA30C03,
HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS = 0x7FA30C04,
};
enum {
GRALLOC_SW_UAGE = android::GraphicBuffer::USAGE_SOFTWARE_MASK,
};
virtual already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() override;
android::sp<android::GraphicBuffer> GetGraphicBuffer() const;
void* GetNativeBuffer();
virtual bool IsValid() { return !!mTextureClient; }
virtual TextureClient* GetTextureClient(KnowsCompositor* aForwarder) override;
virtual GrallocImage* AsGrallocImage() override
{
return this;
}
virtual uint8_t* GetBuffer()
{
return static_cast<uint8_t*>(GetNativeBuffer());
}
int GetUsage()
{
return (static_cast<ANativeWindowBuffer*>(GetNativeBuffer()))->usage;
}
static int GetOmxFormat(int aFormat)
{
uint32_t omxFormat = 0;
for (int i = 0; sColorIdMap[i]; i += 2) {
if (sColorIdMap[i] == aFormat) {
omxFormat = sColorIdMap[i + 1];
break;
}
}
return omxFormat;
}
private:
RefPtr<TextureClient> mTextureClient;
};
} // namespace layers
} // namespace mozilla
#endif
#endif /* GRALLOCIMAGES_H */

View File

@@ -24,9 +24,6 @@
#include "mozilla/gfx/gfxVars.h"
#include "nsISupportsUtils.h" // for NS_IF_ADDREF
#include "YCbCrUtils.h" // for YCbCr conversions
#ifdef MOZ_WIDGET_GONK
#include "GrallocImages.h"
#endif
#include "gfx2DGlue.h"
#include "mozilla/gfx/2D.h"
@@ -178,18 +175,6 @@ ImageContainer::CreateSharedRGBImage()
return new SharedRGBImage(mImageClient);
}
#ifdef MOZ_WIDGET_GONK
RefPtr<OverlayImage>
ImageContainer::CreateOverlayImage()
{
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
if (!mImageClient || !mImageClient->AsImageClientSingle()) {
return nullptr;
}
return new OverlayImage();
}
#endif
void
ImageContainer::SetCurrentImageInternal(const nsTArray<NonOwningImage>& aImages)
{

View File

@@ -152,7 +152,6 @@ class SharedPlanarYCbCrImage;
class PlanarYCbCrImage;
class TextureClient;
class KnowsCompositor;
class GrallocImage;
class NVImage;
struct ImageBackendData
@@ -171,8 +170,6 @@ class SharedRGBImage;
class SurfaceTextureImage;
#elif defined(XP_MACOSX)
class MacIOSurfaceImage;
#elif defined(MOZ_WIDGET_GONK)
class OverlayImage;
#endif
/**
@@ -215,11 +212,6 @@ public:
virtual already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() = 0;
virtual GrallocImage* AsGrallocImage()
{
return nullptr;
}
virtual bool IsValid() { return true; }
virtual uint8_t* GetBuffer() { return nullptr; }
@@ -385,10 +377,6 @@ public:
// Factory methods for shared image types.
RefPtr<SharedRGBImage> CreateSharedRGBImage();
#ifdef MOZ_WIDGET_GONK
RefPtr<OverlayImage> CreateOverlayImage();
#endif
struct NonOwningImage {
explicit NonOwningImage(Image* aImage = nullptr,
TimeStamp aTimeStamp = TimeStamp(),
@@ -909,54 +897,6 @@ private:
TextureFlags mTextureFlags;
};
#ifdef MOZ_WIDGET_GONK
class OverlayImage : public Image {
/**
* OverlayImage is a special Image type that does not hold any buffer.
* It only hold an Id as identifier to the real content of the Image.
* Therefore, OverlayImage must be handled by some specialized hardware(e.g. HWC)
* to show its content.
*/
public:
struct Data {
int32_t mOverlayId;
gfx::IntSize mSize;
};
struct SidebandStreamData {
GonkNativeHandle mStream;
gfx::IntSize mSize;
};
OverlayImage() : Image(nullptr, ImageFormat::OVERLAY_IMAGE) { mOverlayId = INVALID_OVERLAY; }
void SetData(const Data& aData)
{
mOverlayId = aData.mOverlayId;
mSize = aData.mSize;
mSidebandStream = GonkNativeHandle();
}
void SetData(const SidebandStreamData& aData)
{
mSidebandStream = aData.mStream;
mSize = aData.mSize;
mOverlayId = INVALID_OVERLAY;
}
already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() { return nullptr; } ;
int32_t GetOverlayId() { return mOverlayId; }
GonkNativeHandle& GetSidebandStream() { return mSidebandStream; }
gfx::IntSize GetSize() { return mSize; }
private:
int32_t mOverlayId;
GonkNativeHandle mSidebandStream;
gfx::IntSize mSize;
};
#endif
} // namespace layers
} // namespace mozilla

View File

@@ -461,101 +461,6 @@ protected:
int64_t mFrameStamp;
};
#ifdef MOZ_WIDGET_GONK
// B2G optimization.
class DebugGLGraphicBuffer final: public DebugGLData {
public:
DebugGLGraphicBuffer(void *layerRef,
GLenum target,
GLuint name,
const LayerRenderState &aState,
bool aIsMask,
UniquePtr<Packet> aPacket)
: DebugGLData(Packet::TEXTURE),
mLayerRef(reinterpret_cast<uint64_t>(layerRef)),
mTarget(target),
mName(name),
mState(aState),
mIsMask(aIsMask),
mPacket(Move(aPacket))
{
}
virtual bool Write() override {
return WriteToStream(*mPacket);
}
bool TryPack(bool packData) {
android::sp<android::GraphicBuffer> buffer = mState.mSurface;
MOZ_ASSERT(buffer.get());
mPacket->set_type(mDataType);
TexturePacket* tp = mPacket->mutable_texture();
tp->set_layerref(mLayerRef);
tp->set_name(mName);
tp->set_target(mTarget);
tp->set_ismask(mIsMask);
int pFormat = buffer->getPixelFormat();
if (HAL_PIXEL_FORMAT_RGBA_8888 != pFormat &&
HAL_PIXEL_FORMAT_RGBX_8888 != pFormat) {
return false;
}
int32_t stride = buffer->getStride() * 4;
int32_t height = buffer->getHeight();
int32_t width = buffer->getWidth();
int32_t sourceSize = stride * height;
if (sourceSize <= 0) {
return false;
}
uint32_t dFormat = mState.FormatRBSwapped() ?
LOCAL_GL_BGRA : LOCAL_GL_RGBA;
tp->set_dataformat(dFormat);
tp->set_dataformat((1 << 16 | tp->dataformat()));
tp->set_width(width);
tp->set_height(height);
tp->set_stride(stride);
if (packData) {
uint8_t* grallocData = nullptr;
if (BAD_VALUE == buffer->lock(GRALLOC_USAGE_SW_READ_OFTEN |
GRALLOC_USAGE_SW_WRITE_NEVER,
reinterpret_cast<void**>(&grallocData)))
{
return false;
}
// Do not return before buffer->unlock();
auto compressedData =
MakeUnique<char[]>(LZ4::maxCompressedSize(sourceSize));
int compressedSize = LZ4::compress((char*)grallocData,
sourceSize,
compressedData.get());
if (compressedSize > 0) {
tp->set_data(compressedData.get(), compressedSize);
} else {
buffer->unlock();
return false;
}
buffer->unlock();
}
return true;
}
private:
uint64_t mLayerRef;
GLenum mTarget;
GLuint mName;
const LayerRenderState &mState;
bool mIsMask;
UniquePtr<Packet> mPacket;
};
#endif
class DebugGLTextureData final: public DebugGLData {
public:
DebugGLTextureData(GLContext* cx,
@@ -947,13 +852,6 @@ private:
bool aFlipY,
bool aIsMask,
UniquePtr<Packet> aPacket);
#ifdef MOZ_WIDGET_GONK
static bool SendGraphicBuffer(GLContext* aGLContext,
void* aLayerRef,
TextureSourceOGL* aSource,
const TexturedEffect* aEffect,
bool aIsMask);
#endif
static void SetAndSendTexture(GLContext* aGLContext,
void* aLayerRef,
TextureSourceOGL* aSource,
@@ -1110,51 +1008,6 @@ SenderHelper::SendTextureSource(GLContext* aGLContext,
}
#ifdef MOZ_WIDGET_GONK
bool
SenderHelper::SendGraphicBuffer(GLContext* aGLContext,
void* aLayerRef,
TextureSourceOGL* aSource,
const TexturedEffect* aEffect,
bool aIsMask) {
GLuint texID = GetTextureID(aGLContext, aSource);
if (HasTextureIdBeenSent(texID)) {
return false;
}
if (!aEffect->mState.mSurface.get()) {
return false;
}
// Expose packet creation here, so we could dump primary texture effect attributes.
auto packet = MakeUnique<layerscope::Packet>();
layerscope::TexturePacket* texturePacket = packet->mutable_texture();
texturePacket->set_mpremultiplied(aEffect->mPremultiplied);
DumpFilter(texturePacket, aEffect->mSamplingFilter);
DumpRect(texturePacket->mutable_mtexturecoords(), aEffect->mTextureCoords);
GLenum target = aSource->GetTextureTarget();
mozilla::UniquePtr<DebugGLGraphicBuffer> package =
MakeUnique<DebugGLGraphicBuffer>(aLayerRef, target, texID, aEffect->mState, aIsMask, Move(packet));
// The texure content in this TexureHost is not altered,
// we don't need to send it again.
bool changed = gLayerScopeManager.GetContentMonitor()->IsChangedOrNew(
aEffect->mState.mTexture);
if (!package->TryPack(changed)) {
return false;
}
// Transfer ownership to SocketManager.
gLayerScopeManager.GetSocketManager()->AppendDebugData(package.release());
sSentTextureIds.push_back(texID);
gLayerScopeManager.CurrentSession().mTexIDs.push_back(texID);
gLayerScopeManager.GetContentMonitor()->ClearChangedHost(aEffect->mState.mTexture);
return true;
}
#endif
void
SenderHelper::SetAndSendTexture(GLContext* aGLContext,
void* aLayerRef,
@@ -1180,12 +1033,6 @@ SenderHelper::SendTexturedEffect(GLContext* aGLContext,
return;
}
#ifdef MOZ_WIDGET_GONK
if (SendGraphicBuffer(aGLContext, aLayerRef, source, aEffect, false)) {
return;
}
#endif
// Fallback texture sending path.
SetAndSendTexture(aGLContext, aLayerRef, source, aEffect);
}

View File

@@ -366,8 +366,6 @@ AppendToString(std::stringstream& aStream, ImageFormat format,
aStream << "ImageFormat::PLANAR_YCBCR"; break;
case ImageFormat::GRALLOC_PLANAR_YCBCR:
aStream << "ImageFormat::GRALLOC_PLANAR_YCBCR"; break;
case ImageFormat::GONK_CAMERA_IMAGE:
aStream << "ImageFormat::GONK_CAMERA_IMAGE"; break;
case ImageFormat::SHARED_RGB:
aStream << "ImageFormat::SHARED_RGB"; break;
case ImageFormat::CAIRO_SURFACE:

View File

@@ -5,21 +5,12 @@
#include "LayersTypes.h"
#ifdef MOZ_WIDGET_GONK
#include <ui/GraphicBuffer.h>
#endif
namespace mozilla {
namespace layers {
LayerRenderState::LayerRenderState()
: mFlags(LayerRenderStateFlags::LAYER_RENDER_STATE_DEFAULT)
, mHasOwnOffset(false)
#ifdef MOZ_WIDGET_GONK
, mSurface(nullptr)
, mOverlayId(INVALID_OVERLAY)
, mTexture(nullptr)
#endif
{
}
@@ -27,12 +18,6 @@ LayerRenderState::LayerRenderState(const LayerRenderState& aOther)
: mFlags(aOther.mFlags)
, mHasOwnOffset(aOther.mHasOwnOffset)
, mOffset(aOther.mOffset)
#ifdef MOZ_WIDGET_GONK
, mSurface(aOther.mSurface)
, mOverlayId(aOther.mOverlayId)
, mSize(aOther.mSize)
, mTexture(aOther.mTexture)
#endif
{
}
@@ -40,19 +25,5 @@ LayerRenderState::~LayerRenderState()
{
}
#ifdef MOZ_WIDGET_GONK
LayerRenderState::LayerRenderState(android::GraphicBuffer* aSurface,
const gfx::IntSize& aSize,
LayerRenderStateFlags aFlags,
TextureHost* aTexture)
: mFlags(aFlags)
, mHasOwnOffset(false)
, mSurface(aSurface)
, mOverlayId(INVALID_OVERLAY)
, mSize(aSize)
, mTexture(aTexture)
{}
#endif
} // namespace layers
} // namespace mozilla

View File

@@ -8,11 +8,6 @@
#include <stdint.h> // for uint32_t
#ifdef MOZ_WIDGET_GONK
#include <utils/RefBase.h>
#include "mozilla/layers/GonkNativeHandle.h"
#endif
#include "Units.h"
#include "mozilla/gfx/Point.h" // for IntPoint
#include "mozilla/TypedEnumBits.h"
@@ -86,8 +81,6 @@ enum class LayerRenderStateFlags : int8_t {
};
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(LayerRenderStateFlags)
// The 'ifdef MOZ_WIDGET_GONK' sadness here is because we don't want to include
// android::sp unless we have to.
struct LayerRenderState {
// Constructors and destructor are defined in LayersTypes.cpp so we don't
// have to pull in a definition for GraphicBuffer.h here. In KK at least,
@@ -97,36 +90,6 @@ struct LayerRenderState {
LayerRenderState(const LayerRenderState& aOther);
~LayerRenderState();
#ifdef MOZ_WIDGET_GONK
LayerRenderState(android::GraphicBuffer* aSurface,
const gfx::IntSize& aSize,
LayerRenderStateFlags aFlags,
TextureHost* aTexture);
bool OriginBottomLeft() const
{ return bool(mFlags & LayerRenderStateFlags::ORIGIN_BOTTOM_LEFT); }
bool BufferRotated() const
{ return bool(mFlags & LayerRenderStateFlags::BUFFER_ROTATION); }
bool FormatRBSwapped() const
{ return bool(mFlags & LayerRenderStateFlags::FORMAT_RB_SWAP); }
void SetOverlayId(const int32_t& aId)
{ mOverlayId = aId; }
void SetSidebandStream(const GonkNativeHandle& aStream)
{
mSidebandStream = aStream;
}
android::GraphicBuffer* GetGrallocBuffer() const
{ return mSurface.get(); }
const GonkNativeHandle& GetSidebandStream()
{ return mSidebandStream; }
#endif
void SetOffset(const nsIntPoint& aOffset)
{
mOffset = aOffset;
@@ -139,17 +102,6 @@ struct LayerRenderState {
bool mHasOwnOffset;
// the location of the layer's origin on mSurface
nsIntPoint mOffset;
// The 'ifdef MOZ_WIDGET_GONK' sadness here is because we don't want to include
// android::sp unless we have to.
#ifdef MOZ_WIDGET_GONK
// surface to render
android::sp<android::GraphicBuffer> mSurface;
int32_t mOverlayId;
// size of mSurface
gfx::IntSize mSize;
TextureHost* mTexture;
GonkNativeHandle mSidebandStream;
#endif
};
enum class ScaleMode : int8_t {

View File

@@ -406,20 +406,6 @@ ComputeBufferRect(const IntRect& aRequestedRect)
// rendering glitch, and guarantees image rows can be SIMD'd for
// even r5g6b5 surfaces pretty much everywhere.
rect.width = std::max(aRequestedRect.width, 64);
#ifdef MOZ_WIDGET_GONK
// Set a minumum height to guarantee a minumum height of buffers we
// allocate. Some GL implementations fail to render gralloc textures
// with a height 9px-16px. It happens on Adreno 200. Adreno 320 does not
// have this problem. 32 is choosed as alignment of gralloc buffers.
// See Bug 873937.
// Increase the height only when the requested height is more than 0.
// See Bug 895976.
// XXX it might be better to disable it on the gpu that does not have
// the height problem.
if (rect.height > 0) {
rect.height = std::max(aRequestedRect.height, 32);
}
#endif
return rect;
}
@@ -480,7 +466,7 @@ RotatedContentBuffer::BeginPaint(PaintedLayer* aLayer,
}
if (mode == SurfaceMode::SURFACE_COMPONENT_ALPHA) {
#if defined(MOZ_GFX_OPTIMIZE_MOBILE) || defined(MOZ_WIDGET_GONK)
#if defined(MOZ_GFX_OPTIMIZE_MOBILE)
mode = SurfaceMode::SURFACE_SINGLE_CHANNEL_ALPHA;
#else
if (!aLayer->GetParent() ||

View File

@@ -22,10 +22,6 @@
#include "nsRegion.h" // for nsIntRegion
#include "nsTArray.h" // for nsTArray
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
#include <ui/Fence.h>
#endif
namespace mozilla {
struct TileUnit {};

View File

@@ -1,306 +0,0 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "GrallocTextureHostBasic.h"
#include "GrallocImages.h" // for GetDataSourceSurfaceFrom()
#include "mozilla/layers/SharedBufferManagerParent.h"
#if ANDROID_VERSION >= 17
#include <ui/Fence.h>
#endif
namespace mozilla {
namespace layers {
static gfx::SurfaceFormat
HalFormatToSurfaceFormat(int aHalFormat, TextureFlags aFlags)
{
bool swapRB = bool(aFlags & TextureFlags::RB_SWAPPED);
switch (aHalFormat) {
case android::PIXEL_FORMAT_BGRA_8888:
return swapRB ? gfx::SurfaceFormat::R8G8B8A8 : gfx::SurfaceFormat::B8G8R8A8;
case android::PIXEL_FORMAT_RGBA_8888:
return swapRB ? gfx::SurfaceFormat::B8G8R8A8 : gfx::SurfaceFormat::R8G8B8A8;
case android::PIXEL_FORMAT_RGBX_8888:
return swapRB ? gfx::SurfaceFormat::B8G8R8X8 : gfx::SurfaceFormat::R8G8B8X8;
case android::PIXEL_FORMAT_RGB_565:
return gfx::SurfaceFormat::R5G6B5_UINT16;
case HAL_PIXEL_FORMAT_YCbCr_422_SP:
case HAL_PIXEL_FORMAT_YCrCb_420_SP:
case HAL_PIXEL_FORMAT_YCbCr_422_I:
case GrallocImage::HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
case GrallocImage::HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
case HAL_PIXEL_FORMAT_YV12:
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
#endif
// Needs convert to RGB565
return gfx::SurfaceFormat::R5G6B5_UINT16;
default:
if (aHalFormat >= 0x100 && aHalFormat <= 0x1FF) {
// Reserved range for HAL specific formats.
// Needs convert to RGB565
return gfx::SurfaceFormat::R5G6B5_UINT16;
} else {
MOZ_CRASH("GFX: Unhandled HAL pixel format");
return gfx::SurfaceFormat::UNKNOWN; // not reached
}
}
}
static bool
NeedsConvertFromYUVtoRGB565(int aHalFormat)
{
switch (aHalFormat) {
case android::PIXEL_FORMAT_BGRA_8888:
case android::PIXEL_FORMAT_RGBA_8888:
case android::PIXEL_FORMAT_RGBX_8888:
case android::PIXEL_FORMAT_RGB_565:
return false;
case HAL_PIXEL_FORMAT_YCbCr_422_SP:
case HAL_PIXEL_FORMAT_YCrCb_420_SP:
case HAL_PIXEL_FORMAT_YCbCr_422_I:
case GrallocImage::HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
case GrallocImage::HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
case HAL_PIXEL_FORMAT_YV12:
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
#endif
return true;
default:
if (aHalFormat >= 0x100 && aHalFormat <= 0x1FF) {
// Reserved range for HAL specific formats.
return true;
} else {
MOZ_CRASH("GFX: Unhandled HAL pixel format YUV");
return false; // not reached
}
}
}
GrallocTextureHostBasic::GrallocTextureHostBasic(
TextureFlags aFlags,
const SurfaceDescriptorGralloc& aDescriptor)
: TextureHost(aFlags)
, mGrallocHandle(aDescriptor)
, mSize(0, 0)
, mCropSize(0, 0)
, mFormat(gfx::SurfaceFormat::UNKNOWN)
, mIsOpaque(aDescriptor.isOpaque())
{
android::GraphicBuffer* grallocBuffer = GetGraphicBufferFromDesc(mGrallocHandle).get();
MOZ_ASSERT(grallocBuffer);
if (grallocBuffer) {
mFormat =
HalFormatToSurfaceFormat(grallocBuffer->getPixelFormat(),
aFlags & TextureFlags::RB_SWAPPED);
mSize = gfx::IntSize(grallocBuffer->getWidth(), grallocBuffer->getHeight());
mCropSize = mSize;
} else {
printf_stderr("gralloc buffer is nullptr\n");
}
}
bool
GrallocTextureHostBasic::Lock()
{
if (!mCompositor || !IsValid()) {
return false;
}
if (mTextureSource) {
return true;
}
android::sp<android::GraphicBuffer> graphicBuffer =
GetGraphicBufferFromDesc(mGrallocHandle);
MOZ_ASSERT(graphicBuffer.get());
RefPtr<gfx::DataSourceSurface> surf;
if (NeedsConvertFromYUVtoRGB565(graphicBuffer->getPixelFormat())) {
PlanarYCbCrData ycbcrData;
surf = GetDataSourceSurfaceFrom(graphicBuffer,
mCropSize,
ycbcrData);
} else {
uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN;
int32_t rv = graphicBuffer->lock(usage,
reinterpret_cast<void**>(&mMappedBuffer));
if (rv) {
mMappedBuffer = nullptr;
NS_WARNING("Couldn't lock graphic buffer");
return false;
}
surf = gfx::Factory::CreateWrappingDataSourceSurface(
mMappedBuffer,
graphicBuffer->getStride() * gfx::BytesPerPixel(mFormat),
mCropSize,
mFormat);
}
if (surf) {
mTextureSource = mCompositor->CreateDataTextureSource(mFlags);
mTextureSource->Update(surf, nullptr);
return true;
}
mMappedBuffer = nullptr;
return false;
}
bool
GrallocTextureHostBasic::IsValid() const
{
android::GraphicBuffer* graphicBuffer = GetGraphicBufferFromDesc(mGrallocHandle).get();
return graphicBuffer != nullptr;
}
bool
GrallocTextureHostBasic::BindTextureSource(CompositableTextureSourceRef& aTexture)
{
aTexture = mTextureSource;
return !!aTexture;
}
void
GrallocTextureHostBasic::UnbindTextureSource()
{
TextureHost::UnbindTextureSource();
ClearTextureSource();
}
void
GrallocTextureHostBasic::ClearTextureSource()
{
mTextureSource = nullptr;
if (mMappedBuffer) {
android::GraphicBuffer* graphicBuffer = GetGraphicBufferFromDesc(mGrallocHandle).get();
MOZ_ASSERT(graphicBuffer);
mMappedBuffer = nullptr;
graphicBuffer->unlock();
}
}
void
GrallocTextureHostBasic::SetCompositor(Compositor* aCompositor)
{
BasicCompositor* compositor = AssertBasicCompositor(aCompositor);
if (!compositor) {
return;
}
mCompositor = compositor;
if (mTextureSource) {
mTextureSource->SetCompositor(compositor);
}
}
Compositor*
GrallocTextureHostBasic::GetCompositor()
{
return mCompositor;
}
gfx::SurfaceFormat
GrallocTextureHostBasic::GetFormat() const {
return mFormat;
}
void
GrallocTextureHostBasic::WaitAcquireFenceHandleSyncComplete()
{
if (!mAcquireFenceHandle.IsValid()) {
return;
}
#if ANDROID_VERSION >= 17
RefPtr<FenceHandle::FdObj> fdObj = mAcquireFenceHandle.GetAndResetFdObj();
android::sp<android::Fence> fence(
new android::Fence(fdObj->GetAndResetFd()));
// Wait fece complete with timeout.
// If a source of the fence becomes invalid because of error,
// fene complete is not signaled. See Bug 1061435.
int rv = fence->wait(400 /*400 msec*/);
if (rv != android::OK) {
NS_ERROR("failed to wait fence complete");
}
#endif
}
void
GrallocTextureHostBasic::SetCropRect(nsIntRect aCropRect)
{
MOZ_ASSERT(aCropRect.TopLeft() == gfx::IntPoint(0, 0));
MOZ_ASSERT(!aCropRect.IsEmpty());
MOZ_ASSERT(aCropRect.width <= mSize.width);
MOZ_ASSERT(aCropRect.height <= mSize.height);
gfx::IntSize cropSize(aCropRect.width, aCropRect.height);
if (mCropSize == cropSize) {
return;
}
mCropSize = cropSize;
ClearTextureSource();
}
void
GrallocTextureHostBasic::DeallocateSharedData()
{
ClearTextureSource();
if (mGrallocHandle.buffer().type() != MaybeMagicGrallocBufferHandle::Tnull_t) {
MaybeMagicGrallocBufferHandle handle = mGrallocHandle.buffer();
base::ProcessId owner;
if (handle.type() == MaybeMagicGrallocBufferHandle::TGrallocBufferRef) {
owner = handle.get_GrallocBufferRef().mOwner;
}
else {
owner = handle.get_MagicGrallocBufferHandle().mRef.mOwner;
}
SharedBufferManagerParent::DropGrallocBuffer(owner, mGrallocHandle);
}
}
void
GrallocTextureHostBasic::ForgetSharedData()
{
ClearTextureSource();
}
void
GrallocTextureHostBasic::DeallocateDeviceData()
{
ClearTextureSource();
}
LayerRenderState
GrallocTextureHostBasic::GetRenderState()
{
android::GraphicBuffer* graphicBuffer = GetGraphicBufferFromDesc(mGrallocHandle).get();
if (graphicBuffer) {
LayerRenderStateFlags flags = LayerRenderStateFlags::LAYER_RENDER_STATE_DEFAULT;
if (mIsOpaque) {
flags |= LayerRenderStateFlags::OPAQUE;
}
if (mFlags & TextureFlags::ORIGIN_BOTTOM_LEFT) {
flags |= LayerRenderStateFlags::ORIGIN_BOTTOM_LEFT;
}
if (mFlags & TextureFlags::RB_SWAPPED) {
flags |= LayerRenderStateFlags::FORMAT_RB_SWAP;
}
return LayerRenderState(graphicBuffer,
mCropSize,
flags,
this);
}
return LayerRenderState();
}
} // namespace layers
} // namespace mozilla

View File

@@ -1,88 +0,0 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef MOZILLA_GFX_GRALLOCTEXTUREHOST_BASIC_H
#define MOZILLA_GFX_GRALLOCTEXTUREHOST_BASIC_H
#include "mozilla/layers/BasicCompositor.h"
#include "mozilla/layers/ShadowLayerUtilsGralloc.h"
#include "mozilla/layers/TextureHostBasic.h"
namespace mozilla {
namespace layers {
class BasicCompositor;
/**
* A TextureHost for shared gralloc
*
* Most of the logic actually happens in GrallocTextureSourceBasic.
*/
class GrallocTextureHostBasic : public TextureHost
{
public:
GrallocTextureHostBasic(TextureFlags aFlags,
const SurfaceDescriptorGralloc& aDescriptor);
virtual void SetCompositor(Compositor* aCompositor) override;
virtual Compositor* GetCompositor() override;
virtual bool Lock() override;
virtual gfx::SurfaceFormat GetFormat() const override;
virtual bool BindTextureSource(CompositableTextureSourceRef& aTexture) override;
virtual void UnbindTextureSource() override;
virtual already_AddRefed<gfx::DataSourceSurface> GetAsSurface() override
{
return nullptr; // XXX - implement this (for MOZ_DUMP_PAINTING)
}
virtual void WaitAcquireFenceHandleSyncComplete() override;
virtual gfx::IntSize GetSize() const override { return mCropSize; }
virtual void SetCropRect(nsIntRect aCropRect) override;
virtual void DeallocateSharedData() override;
virtual void ForgetSharedData() override;
virtual void DeallocateDeviceData() override;
virtual LayerRenderState GetRenderState() override;
bool IsValid() const;
void ClearTextureSource();
#ifdef MOZ_LAYERS_HAVE_LOG
virtual const char* Name() override { return "GrallocTextureHostBasic"; }
#endif
protected:
RefPtr<BasicCompositor> mCompositor;
RefPtr<DataTextureSource> mTextureSource;
SurfaceDescriptorGralloc mGrallocHandle;
// gralloc buffer size.
gfx::IntSize mSize;
// Size reported by TextureClient, can be different in some cases (video?),
// used by LayerRenderState.
gfx::IntSize mCropSize;
gfx::SurfaceFormat mFormat;
bool mIsOpaque;
/**
* Points to a mapped gralloc buffer when TextureSource is valid.
*/
uint8_t* mMappedBuffer;
};
} // namespace layers
} // namespace mozilla
#endif // MOZILLA_GFX_GRALLOCTEXTUREHOST_BASIC_H

View File

@@ -7,9 +7,6 @@
#ifdef XP_MACOSX
#include "MacIOSurfaceTextureHostBasic.h"
#endif
#ifdef MOZ_WIDGET_GONK
#include "GrallocTextureHostBasic.h"
#endif
using namespace mozilla::gl;
using namespace mozilla::gfx;
@@ -28,13 +25,6 @@ CreateTextureHostBasic(const SurfaceDescriptor& aDesc,
aDesc.get_SurfaceDescriptorMacIOSurface();
return MakeAndAddRef<MacIOSurfaceTextureHostBasic>(aFlags, desc);
}
#endif
#ifdef MOZ_WIDGET_GONK
if (aDesc.type() == SurfaceDescriptor::TSurfaceDescriptorGralloc) {
const SurfaceDescriptorGralloc& desc =
aDesc.get_SurfaceDescriptorGralloc();
return MakeAndAddRef<GrallocTextureHostBasic>(aFlags, desc);
}
#endif
return CreateBackendIndependentTextureHost(aDesc, aDeallocator, aFlags);
}

View File

@@ -17,7 +17,6 @@
#include "mozilla/layers/AsyncCanvasRenderer.h"
#include "mozilla/layers/CompositableForwarder.h"
#include "mozilla/layers/CompositorBridgeChild.h" // for CompositorBridgeChild
#include "mozilla/layers/GrallocTextureClient.h"
#include "mozilla/layers/LayersTypes.h"
#include "mozilla/layers/TextureClient.h" // for TextureClient, etc
#include "mozilla/layers/TextureClientOGL.h"

View File

@@ -238,7 +238,7 @@ ClientLayerManager::BeginTransactionWithTarget(gfxContext* aTarget)
//
// Desktop does not support async zoom yet, so we ignore this for those
// platforms.
#if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GONK) || defined(MOZ_WIDGET_UIKIT)
#if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_UIKIT)
if (mWidget && mWidget->GetOwningTabChild()) {
mCompositorMightResample = AsyncPanZoomEnabled();
}

View File

@@ -150,7 +150,7 @@ ClientTiledPaintedLayer::BeginPaint()
if (!displayPortAncestor || !scrollAncestor) {
// No displayport or scroll ancestor, so we can't do progressive rendering.
#if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GONK)
#if defined(MOZ_WIDGET_ANDROID)
// Both Android and b2g on phones are guaranteed to have a displayport set, so this
// should never happen.
NS_WARNING("Tiled PaintedLayer with no scrollable container ancestor");

View File

@@ -33,10 +33,6 @@
#include "nsISupportsImpl.h" // for Image::Release, etc
#include "nsRect.h" // for mozilla::gfx::IntRect
#ifdef MOZ_WIDGET_GONK
#include "GrallocImages.h"
#endif
namespace mozilla {
namespace layers {
@@ -222,28 +218,6 @@ ImageClientSingle::UpdateImage(ImageContainer* aContainer, uint32_t aContentFlag
for (auto& img : images) {
Image* image = img.mImage;
#ifdef MOZ_WIDGET_GONK
if (image->GetFormat() == ImageFormat::OVERLAY_IMAGE) {
OverlayImage* overlayImage = static_cast<OverlayImage*>(image);
OverlaySource source;
if (overlayImage->GetSidebandStream().IsValid()) {
// Duplicate GonkNativeHandle::NhObj for ipc,
// since ParamTraits<GonkNativeHandle>::Write() absorbs native_handle_t.
RefPtr<GonkNativeHandle::NhObj> nhObj = overlayImage->GetSidebandStream().GetDupNhObj();
GonkNativeHandle handle(nhObj);
if (!handle.IsValid()) {
return false;
}
source.handle() = OverlayHandle(handle);
} else {
source.handle() = OverlayHandle(overlayImage->GetOverlayId());
}
source.size() = overlayImage->GetSize();
GetForwarder()->UseOverlaySource(this, source, image->GetPictureRect());
continue;
}
#endif
RefPtr<TextureClient> texture = image->GetTextureClient(GetForwarder());
const bool hasTextureClient = !!texture;

View File

@@ -53,11 +53,6 @@
#include "mozilla/layers/MacIOSurfaceTextureClientOGL.h"
#endif
#ifdef MOZ_WIDGET_GONK
#include <cutils/properties.h>
#include "mozilla/layers/GrallocTextureClient.h"
#endif
#if 0
#define RECYCLE_LOG(...) printf_stderr(__VA_ARGS__)
#else
@@ -726,13 +721,6 @@ TextureClient::WaitForBufferOwnership(bool aWaitReleaseFence)
if (mFenceHandleWaiter) {
mFenceHandleWaiter->WaitComplete();
}
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION < 21
if (aWaitReleaseFence && mReleaseFenceHandle.IsValid()) {
mData->WaitForFence(&mReleaseFenceHandle);
mReleaseFenceHandle = FenceHandle();
}
#endif
}
// static
@@ -1131,13 +1119,6 @@ TextureClient::CreateForDrawing(TextureForwarder* aAllocator,
#endif
#endif
#ifdef MOZ_WIDGET_GONK
if (!data && aSize.width <= aMaxTextureSize && aSize.height <= aMaxTextureSize) {
data = GrallocTextureData::CreateForDrawing(aSize, aFormat, moz2DBackend,
aAllocator);
}
#endif
#ifdef XP_MACOSX
if (!data && gfxPrefs::UseIOSurfaceTextures()) {
data = MacIOSurfaceTextureData::Create(aSize, aFormat, moz2DBackend);

View File

@@ -42,17 +42,12 @@ namespace mozilla {
#define GFX_DEBUG_TRACK_CLIENTS_IN_POOL 1
#endif
namespace gl {
class SharedSurface_Gralloc;
}
namespace layers {
class AsyncTransactionWaiter;
class BufferTextureData;
class CompositableForwarder;
class KnowsCompositor;
class GrallocTextureData;
class LayersIPCChannel;
class CompositableClient;
struct PlanarYCbCrData;
@@ -306,8 +301,6 @@ public:
}
#endif
virtual GrallocTextureData* AsGrallocTextureData() { return nullptr; }
virtual BufferTextureData* AsBufferTextureData() { return nullptr; }
};
@@ -652,15 +645,8 @@ public:
bool NeedsFenceHandle()
{
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
if (!mData) {
return false;
}
return !!mData->AsGrallocTextureData();
#else
return false;
#endif
}
void WaitFenceHandleOnImageBridge(Mutex& aMutex);
void ClearWaitFenceHandleOnImageBridge(Mutex& aMutex);
@@ -731,7 +717,6 @@ private:
void Finalize() {}
friend class AtomicRefCountedWithFinalize<TextureClient>;
friend class gl::SharedSurface_Gralloc;
protected:
/**
* Should only be called *once* per texture, in TextureClient::InitIPDLActor.

View File

@@ -13,11 +13,6 @@
#include "nsThreadUtils.h"
#include "SharedSurface.h"
#ifdef MOZ_WIDGET_GONK
#include "mozilla/layers/GrallocTextureClient.h"
#include "SharedSurfaceGralloc.h"
#endif
using namespace mozilla::gl;
namespace mozilla {
@@ -73,67 +68,6 @@ SharedSurfaceTextureClient::Create(UniquePtr<gl::SharedSurface> surf, gl::Surfac
return MakeAndAddRef<SharedSurfaceTextureClient>(data, flags, aAllocator);
}
void
SharedSurfaceTextureClient::SetReleaseFenceHandle(const FenceHandle& aReleaseFenceHandle)
{
#ifdef MOZ_WIDGET_GONK
gl::SharedSurface_Gralloc* surf = nullptr;
if (Surf()->mType == gl::SharedSurfaceType::Gralloc) {
surf = gl::SharedSurface_Gralloc::Cast(Surf());
}
if (surf && surf->GetTextureClient()) {
surf->GetTextureClient()->SetReleaseFenceHandle(aReleaseFenceHandle);
return;
}
#endif
TextureClient::SetReleaseFenceHandle(aReleaseFenceHandle);
}
FenceHandle
SharedSurfaceTextureClient::GetAndResetReleaseFenceHandle()
{
#ifdef MOZ_WIDGET_GONK
gl::SharedSurface_Gralloc* surf = nullptr;
if (Surf()->mType == gl::SharedSurfaceType::Gralloc) {
surf = gl::SharedSurface_Gralloc::Cast(Surf());
}
if (surf && surf->GetTextureClient()) {
return surf->GetTextureClient()->GetAndResetReleaseFenceHandle();
}
#endif
return TextureClient::GetAndResetReleaseFenceHandle();
}
void
SharedSurfaceTextureClient::SetAcquireFenceHandle(const FenceHandle& aAcquireFenceHandle)
{
#ifdef MOZ_WIDGET_GONK
gl::SharedSurface_Gralloc* surf = nullptr;
if (Surf()->mType == gl::SharedSurfaceType::Gralloc) {
surf = gl::SharedSurface_Gralloc::Cast(Surf());
}
if (surf && surf->GetTextureClient()) {
return surf->GetTextureClient()->SetAcquireFenceHandle(aAcquireFenceHandle);
}
#endif
TextureClient::SetAcquireFenceHandle(aAcquireFenceHandle);
}
const FenceHandle&
SharedSurfaceTextureClient::GetAcquireFenceHandle() const
{
#ifdef MOZ_WIDGET_GONK
gl::SharedSurface_Gralloc* surf = nullptr;
if (Surf()->mType == gl::SharedSurfaceType::Gralloc) {
surf = gl::SharedSurface_Gralloc::Cast(Surf());
}
if (surf && surf->GetTextureClient()) {
return surf->GetTextureClient()->GetAcquireFenceHandle();
}
#endif
return TextureClient::GetAcquireFenceHandle();
}
SharedSurfaceTextureClient::~SharedSurfaceTextureClient()
{
// XXX - Things break when using the proper destruction handshake with

View File

@@ -66,14 +66,6 @@ public:
Create(UniquePtr<gl::SharedSurface> surf, gl::SurfaceFactory* factory,
LayersIPCChannel* aAllocator, TextureFlags aFlags);
virtual void SetReleaseFenceHandle(const FenceHandle& aReleaseFenceHandle) override;
virtual FenceHandle GetAndResetReleaseFenceHandle() override;
virtual void SetAcquireFenceHandle(const FenceHandle& aAcquireFenceHandle) override;
virtual const FenceHandle& GetAcquireFenceHandle() const override;
gl::SharedSurface* Surf() const {
return static_cast<const SharedSurfaceTextureData*>(GetInternalData())->Surf();
}

View File

@@ -308,7 +308,7 @@ ClientTiledLayerBuffer::GetContentType(SurfaceMode* aMode) const
SurfaceMode mode = mPaintedLayer.GetSurfaceMode();
if (mode == SurfaceMode::SURFACE_COMPONENT_ALPHA) {
#if defined(MOZ_GFX_OPTIMIZE_MOBILE) || defined(MOZ_WIDGET_GONK)
#if defined(MOZ_GFX_OPTIMIZE_MOBILE)
mode = SurfaceMode::SURFACE_SINGLE_CHANNEL_ALPHA;
#else
if (!mPaintedLayer.GetParent() ||
@@ -319,7 +319,7 @@ ClientTiledLayerBuffer::GetContentType(SurfaceMode* aMode) const
}
#endif
} else if (mode == SurfaceMode::SURFACE_OPAQUE) {
#if defined(MOZ_GFX_OPTIMIZE_MOBILE) || defined(MOZ_WIDGET_GONK)
#if defined(MOZ_GFX_OPTIMIZE_MOBILE)
if (IsLowPrecision()) {
// If we're in low-res mode, drawing can sample from outside the visible
// region. Make sure that we only sample transparency if that happens.

View File

@@ -703,15 +703,6 @@ LayerRenderState
ImageHostOverlay::GetRenderState()
{
LayerRenderState state;
#ifdef MOZ_WIDGET_GONK
if (mOverlay.handle().type() == OverlayHandle::Tint32_t) {
state.SetOverlayId(mOverlay.handle().get_int32_t());
} else if (mOverlay.handle().type() == OverlayHandle::TGonkNativeHandle) {
state.SetSidebandStream(mOverlay.handle().get_GonkNativeHandle());
}
state.mSize.width = mPictureRect.Width();
state.mSize.height = mPictureRect.Height();
#endif
return state;
}

View File

@@ -58,16 +58,12 @@
#include <android/log.h>
#include <android/native_window.h>
#endif
#if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GONK)
#if defined(MOZ_WIDGET_ANDROID)
#include "opengl/CompositorOGL.h"
#include "GLContextEGL.h"
#include "GLContextProvider.h"
#include "ScopedGLHelpers.h"
#endif
#ifdef MOZ_WIDGET_GONK
#include "nsScreenManagerGonk.h"
#include "nsWindow.h"
#endif
#include "GeckoProfiler.h"
#include "TextRenderer.h" // for TextRenderer
#include "mozilla/layers/CompositorBridgeParent.h"
@@ -481,7 +477,7 @@ LayerManagerComposite::UpdateAndRender()
}
Render(invalid, opaque);
#if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GONK)
#if defined(MOZ_WIDGET_ANDROID)
RenderToPresentationSurface();
#endif
mGeometryChanged = false;
@@ -1006,7 +1002,7 @@ LayerManagerComposite::Render(const nsIntRegion& aInvalidRegion, const nsIntRegi
RecordFrame();
}
#if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GONK)
#if defined(MOZ_WIDGET_ANDROID)
class ScopedCompositorProjMatrix {
public:
ScopedCompositorProjMatrix(CompositorOGL* aCompositor, const Matrix4x4& aProjMatrix):
@@ -1113,40 +1109,6 @@ LayerManagerComposite::RenderToPresentationSurface()
const IntSize windowSize(ANativeWindow_getWidth(window),
ANativeWindow_getHeight(window));
#elif defined(MOZ_WIDGET_GONK)
CompositorOGL* compositor = mCompositor->AsCompositorOGL();
nsScreenGonk* screen = static_cast<nsWindow*>(mCompositor->GetWidget()->RealWidget())->GetScreen();
if (!screen->IsPrimaryScreen()) {
// Only primary screen support mirroring
return;
}
nsWindow* mirrorScreenWidget = screen->GetMirroringWidget();
if (!mirrorScreenWidget) {
// No mirroring
return;
}
nsScreenGonk* mirrorScreen = mirrorScreenWidget->GetScreen();
if (!mirrorScreen->GetTopWindows().IsEmpty()) {
return;
}
EGLSurface surface = mirrorScreen->GetEGLSurface();
if (surface == LOCAL_EGL_NO_SURFACE) {
// Create GLContext
RefPtr<GLContext> gl = gl::GLContextProvider::CreateForWindow(mirrorScreenWidget, false);
mirrorScreenWidget->SetNativeData(NS_NATIVE_OPENGL_CONTEXT,
reinterpret_cast<uintptr_t>(gl.get()));
surface = mirrorScreen->GetEGLSurface();
if (surface == LOCAL_EGL_NO_SURFACE) {
// Failed to create EGLSurface
return;
}
}
GLContext* gl = compositor->gl();
GLContextEGL* egl = GLContextEGL::Cast(gl);
const IntSize windowSize = mirrorScreen->GetNaturalBounds().Size().ToUnknownSize();
#endif
if ((windowSize.width <= 0) || (windowSize.height <= 0)) {
@@ -1213,15 +1175,6 @@ LayerManagerComposite::RenderToPresentationSurface()
RootLayer()->RenderLayer(clipRect);
mCompositor->EndFrame();
#ifdef MOZ_WIDGET_GONK
mCompositor->SetDispAcquireFence(mRoot); // Call after EndFrame()
RefPtr<Composer2D> composer2D;
composer2D = mCompositor->GetWidget()->GetComposer2D();
if (composer2D) {
composer2D->Render(mirrorScreenWidget);
}
#endif
}
#endif

View File

@@ -326,7 +326,7 @@ private:
* Render the current layer tree to the active target.
*/
void Render(const nsIntRegion& aInvalidRegion, const nsIntRegion& aOpaqueRegion);
#if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GONK)
#if defined(MOZ_WIDGET_ANDROID)
void RenderToPresentationSurface();
#endif

View File

@@ -35,11 +35,6 @@
#include "../d3d11/CompositorD3D11.h"
#endif
#ifdef MOZ_WIDGET_GONK
#include "../opengl/GrallocTextureClient.h"
#include "../opengl/GrallocTextureHost.h"
#endif
#ifdef MOZ_X11
#include "mozilla/layers/X11TextureHost.h"
#endif
@@ -241,7 +236,6 @@ TextureHost::Create(const SurfaceDescriptor& aDesc,
case SurfaceDescriptor::TSurfaceDescriptorSharedGLTexture:
return CreateTextureHostOGL(aDesc, aDeallocator, aFlags);
case SurfaceDescriptor::TSurfaceDescriptorGralloc:
case SurfaceDescriptor::TSurfaceDescriptorMacIOSurface:
if (aBackend == LayersBackend::LAYERS_OPENGL) {
return CreateTextureHostOGL(aDesc, aDeallocator, aFlags);
@@ -386,9 +380,8 @@ TextureHost::NotifyNotUsed()
}
// Do not need to call NotifyNotUsed() if TextureHost does not have
// TextureFlags::RECYCLE flag and TextureHost is not GrallocTextureHostOGL.
if (!(GetFlags() & TextureFlags::RECYCLE) &&
!AsGrallocTextureHostOGL()) {
// TextureFlags::RECYCLE flag.
if (!(GetFlags() & TextureFlags::RECYCLE)) {
return;
}
@@ -397,13 +390,11 @@ TextureHost::NotifyNotUsed()
// - TextureHost does not have Compositor.
// - Compositor is BasicCompositor.
// - TextureHost has intermediate buffer.
// - TextureHost is GrallocTextureHostOGL. Fence object is used to detect
// end of buffer usage.
if (!compositor ||
compositor->IsDestroyed() ||
compositor->AsBasicCompositor() ||
HasIntermediateBuffer() ||
AsGrallocTextureHostOGL()) {
HasIntermediateBuffer()) {
static_cast<TextureParent*>(mActor)->NotifyNotUsed(mFwdTransactionId);
return;
}

View File

@@ -44,7 +44,6 @@ class Compositor;
class CompositableParentManager;
class ReadLockDescriptor;
class CompositorBridgeParent;
class GrallocTextureHostOGL;
class SurfaceDescriptor;
class HostIPCAllocator;
class ISurfaceAllocator;
@@ -622,8 +621,6 @@ public:
virtual BufferTextureHost* AsBufferTextureHost() { return nullptr; }
virtual GrallocTextureHostOGL* AsGrallocTextureHostOGL() { return nullptr; }
protected:
void ReadUnlock();

View File

@@ -28,10 +28,6 @@
#include "nsRegion.h" // for nsIntRegion
#include "nscore.h" // for nsACString
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
#include <ui/Fence.h>
#endif
namespace mozilla {
namespace layers {

View File

@@ -72,12 +72,6 @@ public:
const ThebesBufferData& aThebesBufferData,
const nsIntRegion& aUpdatedRegion) = 0;
#ifdef MOZ_WIDGET_GONK
virtual void UseOverlaySource(CompositableClient* aCompositabl,
const OverlaySource& aOverlay,
const gfx::IntRect& aPictureRect) = 0;
#endif
virtual void Destroy(CompositableChild* aCompositable);
virtual bool DestroyInTransaction(PTextureChild* aTexture, bool synchronously) = 0;

View File

@@ -16,7 +16,6 @@
#include "mozilla/layers/CompositorTypes.h"
#include "mozilla/layers/ContentHost.h" // for ContentHostBase
#include "mozilla/layers/ImageBridgeParent.h" // for ImageBridgeParent
#include "mozilla/layers/SharedBufferManagerParent.h"
#include "mozilla/layers/LayerManagerComposite.h"
#include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor
#include "mozilla/layers/LayersTypes.h" // for MOZ_LAYERS_LOG
@@ -61,7 +60,7 @@ ScheduleComposition(CompositableHost* aCompositable)
return true;
}
#if defined(DEBUG) || defined(MOZ_WIDGET_GONK)
#if defined(DEBUG)
static bool ValidatePictureRect(const mozilla::gfx::IntSize& aSize,
const nsIntRect& aPictureRect)
{
@@ -246,16 +245,6 @@ CompositableParentManager::ReceiveCompositableUpdate(const CompositableOperation
}
break;
}
#ifdef MOZ_WIDGET_GONK
case CompositableOperationDetail::TOpUseOverlaySource: {
const OpUseOverlaySource& op = aEdit.detail().get_OpUseOverlaySource();
if (!ValidatePictureRect(op.overlay().size(), op.picture())) {
return false;
}
compositable->UseOverlaySource(op.overlay(), op.picture());
break;
}
#endif
default: {
MOZ_ASSERT(false, "bad type");
}

View File

@@ -14,10 +14,6 @@
#include <math.h>
#include "GeckoProfiler.h"
#ifdef MOZ_WIDGET_GONK
#include "mozilla/layers/GrallocTextureHost.h"
#endif
#define TEST_STEPS 1000
#define DURATION_THRESHOLD 30
#define THRESHOLD_ABORT_COUNT 5
@@ -275,92 +271,6 @@ public:
}
};
#ifdef MOZ_WIDGET_GONK
class TrivialGrallocQuadBench : public BenchTest {
public:
TrivialGrallocQuadBench()
: BenchTest("Travial Gralloc Quad (10s 256x256 quads)")
{}
uint32_t* mBuf;
android::sp<android::GraphicBuffer> mGralloc;
RefPtr<TextureSource> mTexture;
virtual void Setup(Compositor* aCompositor, size_t aStep) {
mBuf = nullptr;
int w = 256;
int h = 256;
int32_t format = android::PIXEL_FORMAT_RGBA_8888;;
mGralloc = new android::GraphicBuffer(w, h,
format,
android::GraphicBuffer::USAGE_SW_READ_OFTEN |
android::GraphicBuffer::USAGE_SW_WRITE_OFTEN |
android::GraphicBuffer::USAGE_HW_TEXTURE);
mTexture = new mozilla::layers::GrallocTextureSourceOGL((CompositorOGL*)aCompositor, mGralloc.get(), SurfaceFormat::B8G8R8A8);
}
void DrawFrame(Compositor* aCompositor, const gfx::Rect& aScreenRect, size_t aStep) {
EffectChain effects;
effects.mPrimaryEffect = CreateEffect(aStep);
DrawFrameTrivialQuad(aCompositor, aScreenRect, aStep, effects);
}
virtual void Teardown(Compositor* aCompositor) {
mGralloc = nullptr;
mTexture = nullptr;
free(mBuf);
}
virtual already_AddRefed<Effect> CreateEffect(size_t i) {
return CreateTexturedEffect(SurfaceFormat::B8G8R8A8, mTexture,
SamplingFilter::POINT);
}
};
class StressGrallocQuadBench : public BenchTest {
public:
StressGrallocQuadBench()
: BenchTest("Stress Gralloc Quad (10s 256x256 quads)")
{}
uint32_t* mBuf;
android::sp<android::GraphicBuffer> mGralloc;
RefPtr<TextureSource> mTexture;
virtual void Setup(Compositor* aCompositor, size_t aStep) {
mBuf = nullptr;
int w = 256;
int h = 256;
int32_t format = android::PIXEL_FORMAT_RGBA_8888;;
mGralloc = new android::GraphicBuffer(w, h,
format,
android::GraphicBuffer::USAGE_SW_READ_OFTEN |
android::GraphicBuffer::USAGE_SW_WRITE_OFTEN |
android::GraphicBuffer::USAGE_HW_TEXTURE);
mTexture = new mozilla::layers::GrallocTextureSourceOGL((CompositorOGL*)aCompositor, mGralloc.get(), SurfaceFormat::B8G8R8A8);
}
void DrawFrame(Compositor* aCompositor, const gfx::Rect& aScreenRect, size_t aStep) {
EffectChain effects;
effects.mPrimaryEffect = CreateEffect(aStep);
DrawFrameStressQuad(aCompositor, aScreenRect, aStep, effects);
}
virtual void Teardown(Compositor* aCompositor) {
mGralloc = nullptr;
mTexture = nullptr;
free(mBuf);
}
virtual already_AddRefed<Effect> CreateEffect(size_t i) {
return CreateTexturedEffect(SurfaceFormat::B8G8R8A8, mTexture,
SamplingFilter::POINT);
}
};
#endif
static void RunCompositorBench(Compositor* aCompositor, const gfx::Rect& aScreenRect)
{
std::vector<BenchTest*> tests;
@@ -371,10 +281,6 @@ static void RunCompositorBench(Compositor* aCompositor, const gfx::Rect& aScreen
tests.push_back(new EffectSolidColorStressBench());
tests.push_back(new TrivialTexturedQuadBench());
tests.push_back(new StressTexturedQuadBench());
#ifdef MOZ_WIDGET_GONK
tests.push_back(new TrivialGrallocQuadBench());
tests.push_back(new StressGrallocQuadBench());
#endif
for (size_t i = 0; i < tests.size(); i++) {
BenchTest* test = tests[i];

View File

@@ -85,11 +85,6 @@
# include "mozilla/widget/CompositorWidgetParent.h"
#endif
#ifdef MOZ_WIDGET_GONK
#include "GeckoTouchDispatcher.h"
#include "nsScreenManagerGonk.h"
#endif
#include "LayerScope.h"
namespace mozilla {
@@ -349,24 +344,9 @@ CompositorVsyncScheduler::CompositorVsyncScheduler(CompositorBridgeParent* aComp
, mCurrentCompositeTask(nullptr)
, mSetNeedsCompositeMonitor("SetNeedsCompositeMonitor")
, mSetNeedsCompositeTask(nullptr)
#ifdef MOZ_WIDGET_GONK
#if ANDROID_VERSION >= 19
, mDisplayEnabled(false)
, mSetDisplayMonitor("SetDisplayMonitor")
, mSetDisplayTask(nullptr)
#endif
#endif
{
MOZ_ASSERT(NS_IsMainThread() || XRE_GetProcessType() == GeckoProcessType_GPU);
mVsyncObserver = new Observer(this);
#ifdef MOZ_WIDGET_GONK
GeckoTouchDispatcher::GetInstance()->SetCompositorVsyncScheduler(this);
#if ANDROID_VERSION >= 19
RefPtr<nsScreenManagerGonk> screenManager = nsScreenManagerGonk::GetInstance();
screenManager->SetCompositorVsyncScheduler(this);
#endif
#endif
// mAsapScheduling is set on the main thread during init,
// but is only accessed after on the compositor thread.
@@ -382,54 +362,6 @@ CompositorVsyncScheduler::~CompositorVsyncScheduler()
mCompositorBridgeParent = nullptr;
}
#ifdef MOZ_WIDGET_GONK
#if ANDROID_VERSION >= 19
void
CompositorVsyncScheduler::SetDisplay(bool aDisplayEnable)
{
// SetDisplay() is usually called from nsScreenManager at main thread. Post
// to compositor thread if needs.
if (!CompositorThreadHolder::IsInCompositorThread()) {
MOZ_ASSERT(NS_IsMainThread());
MonitorAutoLock lock(mSetDisplayMonitor);
RefPtr<CancelableRunnable> task =
NewCancelableRunnableMethod<bool>(this, &CompositorVsyncScheduler::SetDisplay, aDisplayEnable);
mSetDisplayTask = task;
ScheduleTask(task.forget(), 0);
return;
} else {
MonitorAutoLock lock(mSetDisplayMonitor);
mSetDisplayTask = nullptr;
}
if (mDisplayEnabled == aDisplayEnable) {
return;
}
mDisplayEnabled = aDisplayEnable;
if (!mDisplayEnabled) {
CancelCurrentSetNeedsCompositeTask();
CancelCurrentCompositeTask();
}
}
void
CompositorVsyncScheduler::CancelSetDisplayTask()
{
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
MonitorAutoLock lock(mSetDisplayMonitor);
if (mSetDisplayTask) {
mSetDisplayTask->Cancel();
mSetDisplayTask = nullptr;
}
// CancelSetDisplayTask is only be called in clean-up process, so
// mDisplayEnabled could be false there.
mDisplayEnabled = false;
}
#endif //ANDROID_VERSION >= 19
#endif //MOZ_WIDGET_GONK
void
CompositorVsyncScheduler::Destroy()
{
@@ -442,11 +374,6 @@ CompositorVsyncScheduler::Destroy()
mVsyncObserver->Destroy();
mVsyncObserver = nullptr;
#ifdef MOZ_WIDGET_GONK
#if ANDROID_VERSION >= 19
CancelSetDisplayTask();
#endif
#endif
CancelCurrentSetNeedsCompositeTask();
CancelCurrentCompositeTask();
}
@@ -521,15 +448,6 @@ CompositorVsyncScheduler::SetNeedsComposite()
mSetNeedsCompositeTask = nullptr;
}
#ifdef MOZ_WIDGET_GONK
#if ANDROID_VERSION >= 19
// Skip composition when display off.
if (!mDisplayEnabled) {
return;
}
#endif
#endif
mNeedsComposite++;
if (!mIsObservingVsync && mNeedsComposite) {
ObserveVsync();
@@ -652,9 +570,6 @@ CompositorVsyncScheduler::UnobserveVsync()
void
CompositorVsyncScheduler::DispatchTouchEvents(TimeStamp aVsyncTimestamp)
{
#ifdef MOZ_WIDGET_GONK
GeckoTouchDispatcher::GetInstance()->NotifyVsync(aVsyncTimestamp);
#endif
}
void

View File

@@ -95,19 +95,6 @@ public:
explicit CompositorVsyncScheduler(CompositorBridgeParent* aCompositorBridgeParent,
widget::CompositorWidget* aWidget);
#ifdef MOZ_WIDGET_GONK
// emulator-ics never trigger the display on/off, so compositor will always
// skip composition request at that device. Only check the display status
// with kk device and upon.
#if ANDROID_VERSION >= 19
// SetDisplay() and CancelSetDisplayTask() are used for the display on/off.
// It will clear all composition related task and flag, and skip another
// composition task during the display off. That could prevent the problem
// that compositor might show the old content at the first frame of display on.
void SetDisplay(bool aDisplayEnable);
#endif
#endif
bool NotifyVsync(TimeStamp aVsyncTimestamp);
void SetNeedsComposite();
void OnForceComposeToTarget();
@@ -144,11 +131,6 @@ private:
void DispatchTouchEvents(TimeStamp aVsyncTimestamp);
void DispatchVREvents(TimeStamp aVsyncTimestamp);
void CancelCurrentSetNeedsCompositeTask();
#ifdef MOZ_WIDGET_GONK
#if ANDROID_VERSION >= 19
void CancelSetDisplayTask();
#endif
#endif
class Observer final : public VsyncObserver
{
@@ -183,14 +165,6 @@ private:
mozilla::Monitor mSetNeedsCompositeMonitor;
RefPtr<CancelableRunnable> mSetNeedsCompositeTask;
#ifdef MOZ_WIDGET_GONK
#if ANDROID_VERSION >= 19
bool mDisplayEnabled;
mozilla::Monitor mSetDisplayMonitor;
RefPtr<CancelableRunnable> mSetDisplayTask;
#endif
#endif
};
class CompositorBridgeParentBase : public PCompositorBridgeParent,

View File

@@ -5,12 +5,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
#pragma GCC visibility push(default)
#include "sync/sync.h" // for sync_merge
#pragma GCC visibility pop
#endif
#include "FenceUtils.h"
using namespace mozilla::layers;
@@ -24,23 +18,12 @@ ParamTraits<FenceHandle>::Write(Message* aMsg,
FenceHandle handle = aParam;
MOZ_ASSERT(handle.IsValid());
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
RefPtr<FenceHandle::FdObj> fence = handle.GetAndResetFdObj();
aMsg->WriteFileDescriptor(base::FileDescriptor(fence->GetAndResetFd(), true));
#endif
}
bool
ParamTraits<FenceHandle>::Read(const Message* aMsg,
PickleIterator* aIter, paramType* aResult)
{
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
base::FileDescriptor fd;
if (aMsg->ReadFileDescriptor(aIter, &fd)) {
aResult->Merge(FenceHandle(new FenceHandle::FdObj(fd.fd)));
}
#endif
return true;
}
@@ -63,22 +46,6 @@ FenceHandle::FenceHandle(FdObj* aFdObj)
void
FenceHandle::Merge(const FenceHandle& aFenceHandle)
{
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
if (!aFenceHandle.IsValid()) {
return;
}
if (!IsValid()) {
mFence = aFenceHandle.mFence;
} else {
int result = sync_merge("FenceHandle", mFence->mFd, aFenceHandle.mFence->mFd);
if (result == -1) {
mFence = aFenceHandle.mFence;
} else {
mFence = new FdObj(result);
}
}
#endif
}
void

View File

@@ -8,88 +8,15 @@
#ifndef IPC_GonkNativeHandle_h
#define IPC_GonkNativeHandle_h
#ifdef MOZ_WIDGET_GONK
#include <cutils/native_handle.h>
#endif
#include "mozilla/RefPtr.h" // for RefPtr
#include "nsISupportsImpl.h"
namespace mozilla {
namespace layers {
#ifdef MOZ_WIDGET_GONK
// GonkNativeHandle wraps android's native_handle_t and is used to support
// android's sideband stream.
// The sideband stream is a device-specific mechanism for passing buffers
// to hwcomposer. It is used to render TV streams and DRM protected streams.
// The native_handle_t represents device-specific kernel objects on android.
class GonkNativeHandle {
public:
class NhObj {
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(NhObj)
friend class GonkNativeHandle;
public:
NhObj()
: mHandle(nullptr) {}
explicit NhObj(native_handle_t* aHandle)
: mHandle(aHandle) {}
native_handle_t* GetAndResetNativeHandle()
{
native_handle_t* handle = mHandle;
mHandle = nullptr;
return handle;
}
private:
virtual ~NhObj() {
if (mHandle) {
native_handle_close(mHandle);
native_handle_delete(mHandle);
}
}
native_handle_t* mHandle;
};
GonkNativeHandle();
explicit GonkNativeHandle(NhObj* aNhObj);
bool operator==(const GonkNativeHandle& aOther) const {
return mNhObj.get() == aOther.mNhObj.get();
}
bool IsValid() const
{
return mNhObj && mNhObj->mHandle;
}
void TransferToAnother(GonkNativeHandle& aHandle);
already_AddRefed<NhObj> GetAndResetNhObj();
already_AddRefed<NhObj> GetDupNhObj();
static already_AddRefed<NhObj> CreateDupNhObj(native_handle_t* aHandle);
// Return non owning handle.
native_handle_t* GetRawNativeHandle() const
{
if (mNhObj) {
return mNhObj->mHandle;
}
return nullptr;
}
private:
RefPtr<NhObj> mNhObj;
};
#else
struct GonkNativeHandle {
bool operator==(const GonkNativeHandle&) const { return false; }
};
#endif
} // namespace layers
} // namespace mozilla

View File

@@ -14,22 +14,12 @@
namespace IPC {
#ifdef MOZ_WIDGET_GONK
template <>
struct ParamTraits<mozilla::layers::GonkNativeHandle> {
typedef mozilla::layers::GonkNativeHandle paramType;
static void Write(Message* aMsg, const paramType& aParam);
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult);
};
#else
template <>
struct ParamTraits<mozilla::layers::GonkNativeHandle> {
typedef mozilla::layers::GonkNativeHandle paramType;
static void Write(Message*, const paramType&) {}
static bool Read(const Message*, PickleIterator*, paramType*) { return false; }
};
#endif
} // namespace IPC

View File

@@ -17,18 +17,6 @@
#include "mozilla/layers/LayersMessages.h" // for ShmemSection
#include "LayersTypes.h"
/*
* FIXME [bjacob] *** PURE CRAZYNESS WARNING ***
* (I think that this doesn't apply anymore.)
*
* This #define is actually needed here, because subclasses of ISurfaceAllocator,
* namely ShadowLayerForwarder, will or will not override AllocGrallocBuffer
* depending on whether MOZ_HAVE_SURFACEDESCRIPTORGRALLOC is defined.
*/
#ifdef MOZ_WIDGET_GONK
#define MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
#endif
namespace mozilla {
namespace ipc {
class Shmem;

View File

@@ -219,24 +219,6 @@ ImageBridgeChild::UseComponentAlphaTextures(CompositableClient* aCompositable,
);
}
#ifdef MOZ_WIDGET_GONK
void
ImageBridgeChild::UseOverlaySource(CompositableClient* aCompositable,
const OverlaySource& aOverlay,
const nsIntRect& aPictureRect)
{
MOZ_ASSERT(aCompositable);
MOZ_ASSERT(aCompositable->IsConnected());
CompositableOperation op(
nullptr,
aCompositable->GetIPDLActor(),
OpUseOverlaySource(aOverlay, aPictureRect));
mTxn->AddEdit(op);
}
#endif
void
ImageBridgeChild::HoldUntilCompositableRefReleasedIfNecessary(TextureClient* aClient)
{
@@ -280,17 +262,7 @@ ImageBridgeChild::HoldUntilFenceHandleDelivery(TextureClient* aClient, uint64_t
// XXX Re-enable fence handling
return;
#ifdef MOZ_WIDGET_GONK
if (!aClient) {
return;
}
MutexAutoLock lock(mWaitingFenceHandleMutex);
aClient->SetLastFwdTransactionId(aTransactionId);
aClient->WaitFenceHandleOnImageBridge(mWaitingFenceHandleMutex);
mTexturesWaitingFenceHandle.Put(aClient->GetSerial(), aClient);
#else
NS_RUNTIMEABORT("not reached");
#endif
}
void
@@ -299,17 +271,7 @@ ImageBridgeChild::DeliverFenceToNonRecycle(uint64_t aTextureId, FenceHandle& aRe
// XXX Re-enable fence handling
return;
#ifdef MOZ_WIDGET_GONK
MutexAutoLock lock(mWaitingFenceHandleMutex);
TextureClient* client = mTexturesWaitingFenceHandle.Get(aTextureId).get();
if (!client) {
return;
}
MOZ_ASSERT(aTextureId == client->GetSerial());
client->SetReleaseFenceHandle(aReleaseFenceHandle);
#else
NS_RUNTIMEABORT("not reached");
#endif
}
void
@@ -318,30 +280,7 @@ ImageBridgeChild::NotifyNotUsedToNonRecycle(uint64_t aTextureId, uint64_t aTrans
// XXX Re-enable fence handling
return;
#ifdef MOZ_WIDGET_GONK
MutexAutoLock lock(mWaitingFenceHandleMutex);
RefPtr<TextureClient> client = mTexturesWaitingFenceHandle.Get(aTextureId);
if (!client) {
return;
}
if (aTransactionId < client->GetLastFwdTransactionId()) {
return;
}
MOZ_ASSERT(aTextureId == client->GetSerial());
client->ClearWaitFenceHandleOnImageBridge(mWaitingFenceHandleMutex);
mTexturesWaitingFenceHandle.Remove(aTextureId);
// Release TextureClient on allocator's message loop.
RefPtr<TextureClientReleaseTask> task =
MakeAndAddRef<TextureClientReleaseTask>(client);
RefPtr<LayersIPCChannel> allocator = client->GetAllocator();
client = nullptr;
allocator->GetMessageLoop()->PostTask(task.forget());
#else
NS_RUNTIMEABORT("not reached");
#endif
}
void
@@ -350,13 +289,7 @@ ImageBridgeChild::CancelWaitFenceHandle(TextureClient* aClient)
// XXX Re-enable fence handling
return;
#ifdef MOZ_WIDGET_GONK
MutexAutoLock lock(mWaitingFenceHandleMutex);
aClient->ClearWaitFenceHandleOnImageBridge(mWaitingFenceHandleMutex);
mTexturesWaitingFenceHandle.Remove(aClient->GetSerial());
#else
NS_RUNTIMEABORT("not reached");
#endif
}
void
@@ -516,9 +449,6 @@ ImageBridgeChild::ImageBridgeChild()
: mCanSend(false)
, mCalledClose(false)
, mFwdTransactionId(0)
#ifdef MOZ_WIDGET_GONK
, mWaitingFenceHandleMutex("ImageBridgeChild::mWaitingFenceHandleMutex")
#endif
{
MOZ_ASSERT(NS_IsMainThread());
@@ -722,18 +652,11 @@ ImageBridgeChild::FlushAllImagesSync(SynchronousTask* aTask,
ImageContainer* aContainer,
RefPtr<AsyncTransactionWaiter> aWaiter)
{
#ifdef MOZ_WIDGET_GONK
MOZ_ASSERT(aWaiter);
#else
MOZ_ASSERT(!aWaiter);
#endif
AutoCompleteTask complete(aTask);
if (!CanSend()) {
#ifdef MOZ_WIDGET_GONK
aWaiter->DecrementWaitCount();
#endif
return;
}
@@ -744,13 +667,6 @@ ImageBridgeChild::FlushAllImagesSync(SynchronousTask* aTask,
}
aClient->FlushAllImages(aWaiter);
EndTransaction();
// This decrement is balanced by the increment in FlushAllImages.
// If any AsyncTransactionTrackers were created by FlushAllImages and attached
// to aWaiter, aWaiter will not complete until those trackers all complete.
// Otherwise, aWaiter will be ready to complete now.
#ifdef MOZ_WIDGET_GONK
aWaiter->DecrementWaitCount();
#endif
}
void
@@ -767,11 +683,6 @@ ImageBridgeChild::FlushAllImages(ImageClient* aClient, ImageContainer* aContaine
SynchronousTask task("FlushAllImages Lock");
RefPtr<AsyncTransactionWaiter> waiter;
#ifdef MOZ_WIDGET_GONK
waiter = new AsyncTransactionWaiter();
// This increment is balanced by the decrement in FlushAllImagesSync
waiter->IncrementWaitCount();
#endif
// RefPtrs on arguments are not needed since this dispatches synchronously.
RefPtr<Runnable> runnable = WrapRunnable(
@@ -784,10 +695,6 @@ ImageBridgeChild::FlushAllImages(ImageClient* aClient, ImageContainer* aContaine
GetMessageLoop()->PostTask(runnable.forget());
task.Wait();
#ifdef MOZ_WIDGET_GONK
waiter->WaitComplete();
#endif
}
void
@@ -844,9 +751,6 @@ ImageBridgeChild::EndTransaction()
void
ImageBridgeChild::SendImageBridgeThreadId()
{
#ifdef MOZ_WIDGET_GONK
PImageBridgeChild::SendImageBridgeThreadId(gettid());
#endif
}
bool

View File

@@ -279,11 +279,6 @@ public:
virtual void UseComponentAlphaTextures(CompositableClient* aCompositable,
TextureClient* aClientOnBlack,
TextureClient* aClientOnWhite) override;
#ifdef MOZ_WIDGET_GONK
virtual void UseOverlaySource(CompositableClient* aCompositable,
const OverlaySource& aOverlay,
const nsIntRect& aPictureRect) override;
#endif
void Destroy(CompositableChild* aCompositable) override;
@@ -415,11 +410,6 @@ private:
nsDataHashtable<nsUint64HashKey, RefPtr<TextureClient> > mTexturesWaitingRecycled;
AsyncTransactionTrackersHolder mTrackersHolder;
#ifdef MOZ_WIDGET_GONK
Mutex mWaitingFenceHandleMutex;
nsDataHashtable<nsUint64HashKey, RefPtr<TextureClient> > mTexturesWaitingFenceHandle;
#endif
};
} // namespace layers

View File

@@ -132,9 +132,6 @@ ImageBridgeParent::RecvImageBridgeThreadId(const PlatformThreadId& aThreadId)
return false;
}
mSetChildThreadPriority = true;
#ifdef MOZ_WIDGET_GONK
hal::SetThreadPriority(aThreadId, hal::THREAD_PRIORITY_COMPOSITOR);
#endif
return true;
}

View File

@@ -52,8 +52,6 @@ using mozilla::layout::RenderFrameParent;
namespace mozilla {
namespace layers {
class PGrallocBufferParent;
//--------------------------------------------------
// Convenience accessors
static ShadowLayerParent*

View File

@@ -4,8 +4,6 @@
using struct gfxPoint from "gfxPoint.h";
using nsIntRegion from "nsRegion.h";
using struct mozilla::layers::MagicGrallocBufferHandle from "gfxipc/ShadowLayerUtils.h";
using struct mozilla::layers::GrallocBufferRef from "gfxipc/ShadowLayerUtils.h";
using struct mozilla::layers::SurfaceDescriptorX11 from "gfxipc/ShadowLayerUtils.h";
using mozilla::StereoMode from "ImageTypes.h";
using mozilla::YUVColorSpace from "ImageTypes.h";
@@ -31,12 +29,6 @@ struct OverlaySource {
IntSize size;
};
union MaybeMagicGrallocBufferHandle {
MagicGrallocBufferHandle;
GrallocBufferRef;
null_t;
};
struct SurfaceDescriptorD3D9 {
// IDirect3DTexture9*
uintptr_t texture;
@@ -94,11 +86,6 @@ struct SurfaceDescriptorSharedGLTexture {
bool hasAlpha;
};
struct SurfaceDescriptorGralloc {
MaybeMagicGrallocBufferHandle buffer;
bool isOpaque;
};
struct SurfaceDescriptorGPUVideo {
uint64_t handle;
};
@@ -146,7 +133,6 @@ union SurfaceDescriptor {
SurfaceTextureDescriptor;
EGLImageDescriptor;
SurfaceDescriptorMacIOSurface;
SurfaceDescriptorGralloc;
SurfaceDescriptorSharedGLTexture;
SurfaceDescriptorGPUVideo;
null_t;

View File

@@ -1,29 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=8 et :
*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
include LayersSurfaces;
include ProtocolTypes;
include "mozilla/GfxMessageUtils.h";
namespace mozilla {
namespace layers {
/**
* This is a dedicated protocol to track/allocate/deallocate gralloc buffers.
*/
sync protocol PSharedBufferManager {
parent:
sync AllocateGrallocBuffer(IntSize size, uint32_t format, uint32_t usage)
returns (MaybeMagicGrallocBufferHandle handle);
both:
async DropGrallocBuffer(MaybeMagicGrallocBufferHandle handle);
};
} // namespace layers
} // namespace mozilla

View File

@@ -28,21 +28,6 @@ struct SurfaceDescriptorX11 {
} // namespace mozilla
#endif
#if defined(MOZ_WIDGET_GONK)
# include "mozilla/layers/ShadowLayerUtilsGralloc.h"
#else
namespace mozilla { namespace layers {
struct MagicGrallocBufferHandle {
bool operator==(const MagicGrallocBufferHandle&) const { return false; }
};
struct GrallocBufferRef {
bool operator==(const GrallocBufferRef&) const { return false; }
};
} // namespace layers
} // namespace mozilla
#endif
namespace IPC {
#if !defined(MOZ_HAVE_SURFACEDESCRIPTORX11)
@@ -54,22 +39,6 @@ struct ParamTraits<mozilla::layers::SurfaceDescriptorX11> {
};
#endif // !defined(MOZ_HAVE_XSURFACEDESCRIPTORX11)
#if !defined(MOZ_HAVE_SURFACEDESCRIPTORGRALLOC)
template <>
struct ParamTraits<mozilla::layers::MagicGrallocBufferHandle> {
typedef mozilla::layers::MagicGrallocBufferHandle paramType;
static void Write(Message*, const paramType&) {}
static bool Read(const Message*, PickleIterator*, paramType*) { return false; }
};
template <>
struct ParamTraits<mozilla::layers::GrallocBufferRef> {
typedef mozilla::layers::GrallocBufferRef paramType;
static void Write(Message*, const paramType&) {}
static bool Read(const Message*, PickleIterator*, paramType*) { return false; }
};
#endif // !defined(MOZ_HAVE_XSURFACEDESCRIPTORGRALLOC)
template <>
struct ParamTraits<mozilla::ScreenRotation>
: public ContiguousEnumSerializer<

View File

@@ -1,253 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=8 et :
*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/DebugOnly.h"
#include "mozilla/gfx/Point.h"
#include "mozilla/layers/LayerTransactionChild.h"
#include "mozilla/layers/ShadowLayers.h"
#include "mozilla/layers/LayerManagerComposite.h"
#include "mozilla/layers/CompositorTypes.h"
#include "mozilla/layers/TextureHost.h"
#include "mozilla/layers/SharedBufferManagerChild.h"
#include "mozilla/layers/SharedBufferManagerParent.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/Unused.h"
#include "nsXULAppAPI.h"
#include "ShadowLayerUtilsGralloc.h"
#include "nsIMemoryReporter.h"
#include "gfxPlatform.h"
#include "gfx2DGlue.h"
#include "GLContext.h"
#include "GeckoProfiler.h"
#include "cutils/properties.h"
#include "MainThreadUtils.h"
using namespace android;
using namespace mozilla::layers;
using namespace mozilla::gl;
using base::FileDescriptor;
namespace IPC {
void
ParamTraits<GrallocBufferRef>::Write(Message* aMsg,
const paramType& aParam)
{
aMsg->WriteInt(aParam.mOwner);
aMsg->WriteInt64(aParam.mKey);
}
bool
ParamTraits<GrallocBufferRef>::Read(const Message* aMsg, PickleIterator* aIter,
paramType* aParam)
{
int owner;
int64_t index;
if (!aMsg->ReadInt(aIter, &owner) ||
!aMsg->ReadInt64(aIter, &index)) {
printf_stderr("ParamTraits<GrallocBufferRef>::Read() failed to read a message\n");
return false;
}
aParam->mOwner = owner;
aParam->mKey = index;
return true;
}
void
ParamTraits<MagicGrallocBufferHandle>::Write(Message* aMsg,
const paramType& aParam)
{
#if ANDROID_VERSION >= 19
sp<GraphicBuffer> flattenable = aParam.mGraphicBuffer;
#else
Flattenable *flattenable = aParam.mGraphicBuffer.get();
#endif
size_t nbytes = flattenable->getFlattenedSize();
size_t nfds = flattenable->getFdCount();
char data[nbytes];
int fds[nfds];
#if ANDROID_VERSION >= 19
// Make a copy of "data" and "fds" for flatten() to avoid casting problem
void *pdata = (void *)data;
int *pfds = fds;
flattenable->flatten(pdata, nbytes, pfds, nfds);
// In Kitkat, flatten() will change the value of nbytes and nfds, which dues
// to multiple parcelable object consumption. The actual size and fd count
// which returned by getFlattenedSize() and getFdCount() are not changed.
// So we change nbytes and nfds back by call corresponding calls.
nbytes = flattenable->getFlattenedSize();
nfds = flattenable->getFdCount();
#else
flattenable->flatten(data, nbytes, fds, nfds);
#endif
aMsg->WriteInt(aParam.mRef.mOwner);
aMsg->WriteInt64(aParam.mRef.mKey);
aMsg->WriteSize(nbytes);
aMsg->WriteBytes(data, nbytes);
for (size_t n = 0; n < nfds; ++n) {
// These buffers can't die in transit because they're created
// synchonously and the parent-side buffer can only be dropped if
// there's a crash.
aMsg->WriteFileDescriptor(FileDescriptor(fds[n], false));
}
}
bool
ParamTraits<MagicGrallocBufferHandle>::Read(const Message* aMsg,
PickleIterator* aIter, paramType* aResult)
{
MOZ_ASSERT(!aResult->mGraphicBuffer.get());
MOZ_ASSERT(aResult->mRef.mOwner == 0);
MOZ_ASSERT(aResult->mRef.mKey == -1);
size_t nbytes;
int owner;
int64_t index;
if (!aMsg->ReadInt(aIter, &owner) ||
!aMsg->ReadInt64(aIter, &index) ||
!aMsg->ReadSize(aIter, &nbytes)) {
printf_stderr("ParamTraits<MagicGrallocBufferHandle>::Read() failed to read a message\n");
return false;
}
auto data = mozilla::MakeUnique<char[]>(nbytes);
if (!aMsg->ReadBytesInto(aIter, data.get(), nbytes)) {
printf_stderr("ParamTraits<MagicGrallocBufferHandle>::Read() failed to read a message\n");
return false;
}
size_t nfds = aMsg->num_fds();
int fds[nfds];
for (size_t n = 0; n < nfds; ++n) {
FileDescriptor fd;
if (!aMsg->ReadFileDescriptor(aIter, &fd)) {
printf_stderr("ParamTraits<MagicGrallocBufferHandle>::Read() failed to read file descriptors\n");
return false;
}
// If the GraphicBuffer was shared cross-process, SCM_RIGHTS does
// the right thing and dup's the fd. If it's shared cross-thread,
// SCM_RIGHTS doesn't dup the fd.
// But in shared cross-thread, dup fd is not necessary because we get
// a pointer to the GraphicBuffer directly from SharedBufferManagerParent
// and don't create a new GraphicBuffer around the fd.
fds[n] = fd.fd;
}
aResult->mRef.mOwner = owner;
aResult->mRef.mKey = index;
if (XRE_IsParentProcess()) {
// If we are in chrome process, we can just get GraphicBuffer directly from
// SharedBufferManagerParent.
aResult->mGraphicBuffer = SharedBufferManagerParent::GetGraphicBuffer(aResult->mRef);
} else {
// Deserialize GraphicBuffer
#if ANDROID_VERSION >= 19
sp<GraphicBuffer> buffer(new GraphicBuffer());
const void* datap = (const void*)data.get();
const int* fdsp = &fds[0];
if (NO_ERROR != buffer->unflatten(datap, nbytes, fdsp, nfds)) {
buffer = nullptr;
}
#else
sp<GraphicBuffer> buffer(new GraphicBuffer());
Flattenable *flattenable = buffer.get();
if (NO_ERROR != flattenable->unflatten(data.get(), nbytes, fds, nfds)) {
buffer = nullptr;
}
#endif
if (buffer.get()) {
aResult->mGraphicBuffer = buffer;
}
}
if (!aResult->mGraphicBuffer.get()) {
printf_stderr("ParamTraits<MagicGrallocBufferHandle>::Read() failed to get gralloc buffer\n");
return false;
}
return true;
}
} // namespace IPC
namespace mozilla {
namespace layers {
MagicGrallocBufferHandle::MagicGrallocBufferHandle(const sp<GraphicBuffer>& aGraphicBuffer, GrallocBufferRef ref)
: mGraphicBuffer(aGraphicBuffer)
, mRef(ref)
{
}
//-----------------------------------------------------------------------------
// Parent process
/*static*/ bool
LayerManagerComposite::SupportsDirectTexturing()
{
return true;
}
/*static*/ void
LayerManagerComposite::PlatformSyncBeforeReplyUpdate()
{
// Nothing to be done for gralloc.
}
//-----------------------------------------------------------------------------
// Both processes
/*static*/ sp<GraphicBuffer>
GetGraphicBufferFrom(MaybeMagicGrallocBufferHandle aHandle)
{
if (aHandle.type() != MaybeMagicGrallocBufferHandle::TMagicGrallocBufferHandle) {
if (aHandle.type() == MaybeMagicGrallocBufferHandle::TGrallocBufferRef) {
if (XRE_IsParentProcess()) {
return SharedBufferManagerParent::GetGraphicBuffer(aHandle.get_GrallocBufferRef());
}
return SharedBufferManagerChild::GetSingleton()->GetGraphicBuffer(aHandle.get_GrallocBufferRef().mKey);
}
} else {
MagicGrallocBufferHandle realHandle = aHandle.get_MagicGrallocBufferHandle();
return realHandle.mGraphicBuffer;
}
return nullptr;
}
android::sp<android::GraphicBuffer>
GetGraphicBufferFromDesc(SurfaceDescriptor aDesc)
{
MaybeMagicGrallocBufferHandle handle;
if (aDesc.type() == SurfaceDescriptor::TSurfaceDescriptorGralloc) {
handle = aDesc.get_SurfaceDescriptorGralloc().buffer();
}
return GetGraphicBufferFrom(handle);
}
/*static*/ void
ShadowLayerForwarder::PlatformSyncBeforeUpdate()
{
// Nothing to be done for gralloc.
}
} // namespace layers
} // namespace mozilla

View File

@@ -1,95 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=8 et :
*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_layers_ShadowLayerUtilsGralloc_h
#define mozilla_layers_ShadowLayerUtilsGralloc_h
#include <unistd.h>
#include <ui/GraphicBuffer.h>
#include "base/process.h"
#include "ipc/IPCMessageUtils.h"
#define MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
#define MOZ_HAVE_PLATFORM_SPECIFIC_LAYER_BUFFERS
namespace mozilla {
namespace layers {
class MaybeMagicGrallocBufferHandle;
class SurfaceDescriptor;
struct GrallocBufferRef {
base::ProcessId mOwner;
int64_t mKey;
GrallocBufferRef()
: mOwner(0)
, mKey(-1)
{
}
bool operator== (const GrallocBufferRef rhs) const{
return mOwner == rhs.mOwner && mKey == rhs.mKey;
}
};
/**
* This class exists to share the underlying GraphicBuffer resources
* from one thread context to another. This requires going through
* slow paths in the kernel so can be somewhat expensive.
*
* This is not just platform-specific, but also
* gralloc-implementation-specific.
*/
struct MagicGrallocBufferHandle {
typedef android::GraphicBuffer GraphicBuffer;
MagicGrallocBufferHandle() {}
MagicGrallocBufferHandle(const android::sp<GraphicBuffer>& aGraphicBuffer, GrallocBufferRef ref);
// Default copy ctor and operator= are OK
bool operator==(const MagicGrallocBufferHandle& aOther) const {
return mGraphicBuffer == aOther.mGraphicBuffer;
}
android::sp<GraphicBuffer> mGraphicBuffer;
GrallocBufferRef mRef;
};
/**
* Util function to find GraphicBuffer from SurfaceDescriptor, caller of this function should check origin
* to make sure not corrupt others buffer
*/
android::sp<android::GraphicBuffer> GetGraphicBufferFrom(MaybeMagicGrallocBufferHandle aHandle);
android::sp<android::GraphicBuffer> GetGraphicBufferFromDesc(SurfaceDescriptor aDesc);
} // namespace layers
} // namespace mozilla
namespace IPC {
template <>
struct ParamTraits<mozilla::layers::MagicGrallocBufferHandle> {
typedef mozilla::layers::MagicGrallocBufferHandle paramType;
static void Write(Message* aMsg, const paramType& aParam);
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult);
};
template<>
struct ParamTraits<mozilla::layers::GrallocBufferRef> {
typedef mozilla::layers::GrallocBufferRef paramType;
static void Write(Message* aMsg, const paramType& aParam);
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult);
};
} // namespace IPC
#endif // mozilla_layers_ShadowLayerUtilsGralloc_h

View File

@@ -29,7 +29,6 @@
#include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor, etc
#include "mozilla/layers/LayersTypes.h" // for MOZ_LAYERS_LOG
#include "mozilla/layers/LayerTransactionChild.h"
#include "mozilla/layers/SharedBufferManagerChild.h"
#include "mozilla/layers/PCompositableChild.h"
#include "mozilla/layers/PTextureChild.h"
#include "ShadowLayerUtils.h"
@@ -357,24 +356,6 @@ ShadowLayerForwarder::UseTiledLayerBuffer(CompositableClient* aCompositable,
{
MOZ_ASSERT(aCompositable && aCompositable->IsConnected());
#ifdef MOZ_WIDGET_GONK
// GrallocTextureData alwasys requests fence delivery if ANDROID_VERSION >= 17.
const InfallibleTArray<TileDescriptor>& tileDescriptors = aTileLayerDescriptor.tiles();
for (size_t i = 0; i < tileDescriptors.Length(); i++) {
const TileDescriptor& tileDesc = tileDescriptors[i];
if (tileDesc.type() != TileDescriptor::TTexturedTileDescriptor) {
continue;
}
const TexturedTileDescriptor& texturedDesc = tileDesc.get_TexturedTileDescriptor();
RefPtr<TextureClient> texture = TextureClient::AsTextureClient(texturedDesc.textureChild());
mClientLayerManager->GetCompositorBridgeChild()->HoldUntilCompositableRefReleasedIfNecessary(texture);
if (texturedDesc.textureOnWhite().type() == MaybeTexture::TPTextureChild) {
texture = TextureClient::AsTextureClient(texturedDesc.textureOnWhite().get_PTextureChild());
mClientLayerManager->GetCompositorBridgeChild()->HoldUntilCompositableRefReleasedIfNecessary(texture);
}
}
#endif
mTxn->AddNoSwapPaint(CompositableOperation(nullptr, aCompositable->GetIPDLActor(),
OpUseTiledLayerBuffer(aTileLayerDescriptor)));
}
@@ -463,20 +444,6 @@ ShadowLayerForwarder::UseComponentAlphaTextures(CompositableClient* aCompositabl
);
}
#ifdef MOZ_WIDGET_GONK
void
ShadowLayerForwarder::UseOverlaySource(CompositableClient* aCompositable,
const OverlaySource& aOverlay,
const nsIntRect& aPictureRect)
{
MOZ_ASSERT(aCompositable);
MOZ_ASSERT(aCompositable->IsConnected());
mTxn->AddEdit(CompositableOperation(nullptr, aCompositable->GetIPDLActor(),
OpUseOverlaySource(aOverlay, aPictureRect)));
}
#endif
static bool
AddOpDestroy(Transaction* aTxn, const OpDestroy& op, bool synchronously)
{

View File

@@ -274,11 +274,6 @@ public:
virtual void UseComponentAlphaTextures(CompositableClient* aCompositable,
TextureClient* aClientOnBlack,
TextureClient* aClientOnWhite) override;
#ifdef MOZ_WIDGET_GONK
virtual void UseOverlaySource(CompositableClient* aCompositable,
const OverlaySource& aOverlay,
const nsIntRect& aPictureRect) override;
#endif
/**
* Used for debugging to tell the compositor how long this frame took to paint.

View File

@@ -1,352 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=8 et :
*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "base/task.h" // for NewRunnableFunction, etc
#include "base/thread.h" // for Thread
#include "mozilla/gfx/Logging.h" // for gfxDebug
#include "mozilla/layers/SharedBufferManagerChild.h"
#include "mozilla/layers/SharedBufferManagerParent.h"
#include "mozilla/Sprintf.h" // for SprintfLiteral
#include "mozilla/StaticPtr.h" // for StaticRefPtr
#include "mozilla/ReentrantMonitor.h" // for ReentrantMonitor, etc
#include "nsThreadUtils.h" // for NS_IsMainThread
#ifdef MOZ_WIDGET_GONK
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "SBMChild", ## args)
#endif
namespace mozilla {
namespace layers {
using namespace mozilla::gfx;
// Singleton
SharedBufferManagerChild* SharedBufferManagerChild::sSharedBufferManagerChildSingleton = nullptr;
SharedBufferManagerParent* SharedBufferManagerChild::sSharedBufferManagerParentSingleton = nullptr;
base::Thread* SharedBufferManagerChild::sSharedBufferManagerChildThread = nullptr;
SharedBufferManagerChild::SharedBufferManagerChild()
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
: mBufferMutex("BufferMonitor")
#endif
{
}
static bool
InSharedBufferManagerChildThread()
{
return SharedBufferManagerChild::sSharedBufferManagerChildThread->thread_id() == PlatformThread::CurrentId();
}
// dispatched function
static void
DeleteSharedBufferManagerSync(ReentrantMonitor *aBarrier, bool *aDone)
{
ReentrantMonitorAutoEnter autoMon(*aBarrier);
MOZ_ASSERT(InSharedBufferManagerChildThread(),
"Should be in SharedBufferManagerChild thread.");
SharedBufferManagerChild::sSharedBufferManagerChildSingleton = nullptr;
SharedBufferManagerChild::sSharedBufferManagerParentSingleton = nullptr;
*aDone = true;
aBarrier->NotifyAll();
}
// dispatched function
static void
ConnectSharedBufferManager(SharedBufferManagerChild *child, SharedBufferManagerParent *parent)
{
MessageLoop *parentMsgLoop = parent->GetMessageLoop();
ipc::MessageChannel *parentChannel = parent->GetIPCChannel();
child->Open(parentChannel, parentMsgLoop, mozilla::ipc::ChildSide);
}
base::Thread*
SharedBufferManagerChild::GetThread() const
{
return sSharedBufferManagerChildThread;
}
SharedBufferManagerChild*
SharedBufferManagerChild::GetSingleton()
{
return sSharedBufferManagerChildSingleton;
}
bool
SharedBufferManagerChild::IsCreated()
{
return GetSingleton() != nullptr;
}
void
SharedBufferManagerChild::StartUp()
{
NS_ASSERTION(NS_IsMainThread(), "Should be on the main Thread!");
SharedBufferManagerChild::StartUpOnThread(new base::Thread("BufferMgrChild"));
}
static void
ConnectSharedBufferManagerInChildProcess(mozilla::ipc::Transport* aTransport,
base::ProcessId aOtherPid)
{
// Bind the IPC channel to the shared buffer manager thread.
SharedBufferManagerChild::sSharedBufferManagerChildSingleton->Open(aTransport,
aOtherPid,
XRE_GetIOMessageLoop(),
ipc::ChildSide);
}
PSharedBufferManagerChild*
SharedBufferManagerChild::StartUpInChildProcess(Transport* aTransport,
base::ProcessId aOtherPid)
{
NS_ASSERTION(NS_IsMainThread(), "Should be on the main Thread!");
sSharedBufferManagerChildThread = new base::Thread("BufferMgrChild");
if (!sSharedBufferManagerChildThread->Start()) {
return nullptr;
}
sSharedBufferManagerChildSingleton = new SharedBufferManagerChild();
sSharedBufferManagerChildSingleton->GetMessageLoop()->PostTask(
NewRunnableFunction(ConnectSharedBufferManagerInChildProcess,
aTransport, aOtherPid));
return sSharedBufferManagerChildSingleton;
}
void
SharedBufferManagerChild::ShutDown()
{
NS_ASSERTION(NS_IsMainThread(), "Should be on the main Thread!");
if (IsCreated()) {
SharedBufferManagerChild::DestroyManager();
delete sSharedBufferManagerChildThread;
sSharedBufferManagerChildThread = nullptr;
}
}
bool
SharedBufferManagerChild::StartUpOnThread(base::Thread* aThread)
{
MOZ_ASSERT(aThread, "SharedBufferManager needs a thread.");
if (sSharedBufferManagerChildSingleton != nullptr) {
return false;
}
sSharedBufferManagerChildThread = aThread;
if (!aThread->IsRunning()) {
aThread->Start();
}
sSharedBufferManagerChildSingleton = new SharedBufferManagerChild();
char thrname[128];
SprintfLiteral(thrname, "BufMgrParent#%d", base::Process::Current().pid());
sSharedBufferManagerParentSingleton = new SharedBufferManagerParent(
base::Process::Current().pid(), new base::Thread(thrname));
sSharedBufferManagerChildSingleton->ConnectAsync(sSharedBufferManagerParentSingleton);
return true;
}
void
SharedBufferManagerChild::DestroyManager()
{
MOZ_ASSERT(!InSharedBufferManagerChildThread(),
"This method must not be called in this thread.");
// ...because we are about to dispatch synchronous messages to the
// BufferManagerChild thread.
if (!IsCreated()) {
return;
}
ReentrantMonitor barrier("BufferManagerDestroyTask lock");
ReentrantMonitorAutoEnter autoMon(barrier);
bool done = false;
sSharedBufferManagerChildSingleton->GetMessageLoop()->PostTask(
NewRunnableFunction(&DeleteSharedBufferManagerSync, &barrier, &done));
while (!done) {
barrier.Wait();
}
}
MessageLoop *
SharedBufferManagerChild::GetMessageLoop() const
{
return sSharedBufferManagerChildThread != nullptr ?
sSharedBufferManagerChildThread->message_loop() :
nullptr;
}
void
SharedBufferManagerChild::ConnectAsync(SharedBufferManagerParent* aParent)
{
GetMessageLoop()->PostTask(NewRunnableFunction(&ConnectSharedBufferManager,
this, aParent));
}
// dispatched function
void
SharedBufferManagerChild::AllocGrallocBufferSync(const GrallocParam& aParam,
Monitor* aBarrier,
bool* aDone)
{
MonitorAutoLock autoMon(*aBarrier);
sSharedBufferManagerChildSingleton->AllocGrallocBufferNow(aParam.size,
aParam.format,
aParam.usage,
aParam.buffer);
*aDone = true;
aBarrier->NotifyAll();
}
// dispatched function
void
SharedBufferManagerChild::DeallocGrallocBufferSync(const mozilla::layers::MaybeMagicGrallocBufferHandle& aBuffer)
{
SharedBufferManagerChild::sSharedBufferManagerChildSingleton->
DeallocGrallocBufferNow(aBuffer);
}
bool
SharedBufferManagerChild::AllocGrallocBuffer(const gfx::IntSize& aSize,
const uint32_t& aFormat,
const uint32_t& aUsage,
mozilla::layers::MaybeMagicGrallocBufferHandle* aBuffer)
{
if (aSize.width <= 0 || aSize.height <= 0) {
gfxDebug() << "Asking for gralloc of invalid size " << aSize.width << "x" << aSize.height;
return false;
}
if (InSharedBufferManagerChildThread()) {
return SharedBufferManagerChild::AllocGrallocBufferNow(aSize, aFormat, aUsage, aBuffer);
}
Monitor barrier("AllocSurfaceDescriptorGralloc Lock");
MonitorAutoLock autoMon(barrier);
bool done = false;
GetMessageLoop()->PostTask(
NewRunnableFunction(&AllocGrallocBufferSync,
GrallocParam(aSize, aFormat, aUsage, aBuffer), &barrier, &done));
while (!done) {
barrier.Wait();
}
return true;
}
bool
SharedBufferManagerChild::AllocGrallocBufferNow(const IntSize& aSize,
const uint32_t& aFormat,
const uint32_t& aUsage,
mozilla::layers::MaybeMagicGrallocBufferHandle* aHandle)
{
// These are protected functions, we can just assert and ask the caller to test
MOZ_ASSERT(aSize.width >= 0 && aSize.height >= 0);
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
mozilla::layers::MaybeMagicGrallocBufferHandle handle;
if (!SendAllocateGrallocBuffer(aSize, aFormat, aUsage, &handle)) {
return false;
}
if (handle.type() != mozilla::layers::MaybeMagicGrallocBufferHandle::TMagicGrallocBufferHandle) {
return false;
}
*aHandle = handle.get_MagicGrallocBufferHandle().mRef;
{
MutexAutoLock lock(mBufferMutex);
MOZ_ASSERT(mBuffers.count(handle.get_MagicGrallocBufferHandle().mRef.mKey)==0);
mBuffers[handle.get_MagicGrallocBufferHandle().mRef.mKey] = handle.get_MagicGrallocBufferHandle().mGraphicBuffer;
}
return true;
#else
NS_RUNTIMEABORT("No GrallocBuffer for you");
return true;
#endif
}
void
SharedBufferManagerChild::DeallocGrallocBuffer(const mozilla::layers::MaybeMagicGrallocBufferHandle& aBuffer)
{
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
NS_ASSERTION(aBuffer.type() != mozilla::layers::MaybeMagicGrallocBufferHandle::TMagicGrallocBufferHandle, "We shouldn't try to do IPC with real buffer");
if (aBuffer.type() != mozilla::layers::MaybeMagicGrallocBufferHandle::TGrallocBufferRef) {
return;
}
#endif
if (InSharedBufferManagerChildThread()) {
return SharedBufferManagerChild::DeallocGrallocBufferNow(aBuffer);
}
GetMessageLoop()->PostTask(NewRunnableFunction(&DeallocGrallocBufferSync, aBuffer));
}
void
SharedBufferManagerChild::DeallocGrallocBufferNow(const mozilla::layers::MaybeMagicGrallocBufferHandle& aBuffer)
{
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
NS_ASSERTION(aBuffer.type() != mozilla::layers::MaybeMagicGrallocBufferHandle::TMagicGrallocBufferHandle, "We shouldn't try to do IPC with real buffer");
{
MutexAutoLock lock(mBufferMutex);
mBuffers.erase(aBuffer.get_GrallocBufferRef().mKey);
}
SendDropGrallocBuffer(aBuffer);
#else
NS_RUNTIMEABORT("No GrallocBuffer for you");
#endif
}
void
SharedBufferManagerChild::DropGrallocBuffer(const mozilla::layers::MaybeMagicGrallocBufferHandle& aHandle)
{
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
int64_t bufferKey = -1;
if (aHandle.type() == mozilla::layers::MaybeMagicGrallocBufferHandle::TMagicGrallocBufferHandle) {
bufferKey = aHandle.get_MagicGrallocBufferHandle().mRef.mKey;
} else if (aHandle.type() == mozilla::layers::MaybeMagicGrallocBufferHandle::TGrallocBufferRef) {
bufferKey = aHandle.get_GrallocBufferRef().mKey;
} else {
return;
}
{
MutexAutoLock lock(mBufferMutex);
mBuffers.erase(bufferKey);
}
#endif
}
bool SharedBufferManagerChild::RecvDropGrallocBuffer(const mozilla::layers::MaybeMagicGrallocBufferHandle& aHandle)
{
DropGrallocBuffer(aHandle);
return true;
}
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
android::sp<android::GraphicBuffer>
SharedBufferManagerChild::GetGraphicBuffer(int64_t key)
{
MutexAutoLock lock(mBufferMutex);
if (mBuffers.count(key) == 0) {
printf_stderr("SharedBufferManagerChild::GetGraphicBuffer -- invalid key");
return nullptr;
}
return mBuffers[key];
}
#endif
} /* namespace layers */
} /* namespace mozilla */

View File

@@ -1,168 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set sw=2 ts=8 et tw=80 : */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef SharedBufferManagerCHILD_H_
#define SharedBufferManagerCHILD_H_
#include "mozilla/layers/PSharedBufferManagerChild.h"
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
#include "mozilla/Mutex.h"
#endif
namespace base {
class Thread;
} // namespace base
namespace mozilla {
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
class Mutex;
#endif
namespace layers {
class SharedBufferManagerParent;
struct GrallocParam {
gfx::IntSize size;
uint32_t format;
uint32_t usage;
mozilla::layers::MaybeMagicGrallocBufferHandle* buffer;
GrallocParam(const gfx::IntSize& aSize,
const uint32_t& aFormat,
const uint32_t& aUsage,
mozilla::layers::MaybeMagicGrallocBufferHandle* aBuffer)
: size(aSize)
, format(aFormat)
, usage(aUsage)
, buffer(aBuffer)
{}
};
class SharedBufferManagerChild : public PSharedBufferManagerChild {
public:
SharedBufferManagerChild();
/**
* Creates the gralloc buffer manager with a dedicated thread for SharedBufferManagerChild.
*
* We may want to use a specific thread in the future. In this case, use
* CreateWithThread instead.
*/
static void StartUp();
static PSharedBufferManagerChild*
StartUpInChildProcess(Transport* aTransport, ProcessId aOtherProcess);
/**
* Creates the SharedBufferManagerChild manager protocol.
*/
static bool StartUpOnThread(base::Thread* aThread);
/**
* Destroys The SharedBufferManager protocol.
*
* The actual destruction happens synchronously on the SharedBufferManagerChild thread
* which means that if this function is called from another thread, the current
* thread will be paused until the destruction is done.
*/
static void DestroyManager();
/**
* Destroys the grallob buffer manager calling DestroyManager, and destroys the
* SharedBufferManager's thread.
*
* If you don't want to destroy the thread, call DestroyManager directly
* instead.
*/
static void ShutDown();
/**
* returns the singleton instance.
*
* can be called from any thread.
*/
static SharedBufferManagerChild* GetSingleton();
/**
* Dispatches a task to the SharedBufferManagerChild thread to do the connection
*/
void ConnectAsync(SharedBufferManagerParent* aParent);
/**
* Allocate GrallocBuffer remotely.
*/
bool
AllocGrallocBuffer(const gfx::IntSize&, const uint32_t&, const uint32_t&, mozilla::layers::MaybeMagicGrallocBufferHandle*);
/**
* Deallocate a remotely allocated gralloc buffer.
* As gralloc buffer life cycle controlled by sp, this just break the sharing status of the underlying buffer
* and decrease the reference count on both side.
*/
void
DeallocGrallocBuffer(const mozilla::layers::MaybeMagicGrallocBufferHandle& aBuffer);
void
DropGrallocBuffer(const mozilla::layers::MaybeMagicGrallocBufferHandle& aHandle);
virtual bool RecvDropGrallocBuffer(const mozilla::layers::MaybeMagicGrallocBufferHandle& aHandle);
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
android::sp<android::GraphicBuffer> GetGraphicBuffer(int64_t key);
#endif
base::Thread* GetThread() const;
MessageLoop* GetMessageLoop() const;
static bool IsCreated();
static base::Thread* sSharedBufferManagerChildThread;
static SharedBufferManagerChild* sSharedBufferManagerChildSingleton;
static SharedBufferManagerParent* sSharedBufferManagerParentSingleton; // Only available in Chrome process
protected:
/**
* Part of the allocation of gralloc SurfaceDescriptor that is
* executed on the SharedBufferManagerChild thread after invoking
* AllocSurfaceDescriptorGralloc.
*
* Must be called from the SharedBufferManagerChild thread.
*/
bool
AllocGrallocBufferNow(const gfx::IntSize& aSize,
const uint32_t& aFormat,
const uint32_t& aUsage,
mozilla::layers::MaybeMagicGrallocBufferHandle* aBuffer);
// Dispatched function
static void
AllocGrallocBufferSync(const GrallocParam& aParam,
Monitor* aBarrier,
bool* aDone);
/**
* Part of the deallocation of gralloc SurfaceDescriptor that is
* executed on the SharedBufferManagerChild thread after invoking
* DeallocSurfaceDescriptorGralloc.
*
* Must be called from the SharedBufferManagerChild thread.
*/
void
DeallocGrallocBufferNow(const mozilla::layers::MaybeMagicGrallocBufferHandle& handle);
// dispatched function
static void
DeallocGrallocBufferSync(const mozilla::layers::MaybeMagicGrallocBufferHandle& handle);
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
std::map<int64_t, android::sp<android::GraphicBuffer> > mBuffers;
Mutex mBufferMutex;
#endif
};
} /* namespace layers */
} /* namespace mozilla */
#endif /* SharedBufferManagerCHILD_H_*/

View File

@@ -1,364 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set sw=2 ts=8 et tw=80 : */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/layers/SharedBufferManagerParent.h"
#include "base/message_loop.h" // for MessageLoop
#include "base/process.h" // for ProcessId
#include "base/task.h" // for CancelableTask, DeleteTask, etc
#include "base/thread.h"
#include "mozilla/Sprintf.h" // for SprintfLiteral
#include "mozilla/ipc/MessageChannel.h" // for MessageChannel, etc
#include "mozilla/ipc/ProtocolUtils.h"
#include "mozilla/ipc/Transport.h" // for Transport
#include "mozilla/Sprintf.h"
#include "mozilla/UniquePtr.h" // for UniquePtr
#include "mozilla/Unused.h"
#include "nsIMemoryReporter.h"
#ifdef MOZ_WIDGET_GONK
#include "mozilla/LinuxUtils.h"
#include "ui/PixelFormat.h"
#endif
#include "nsPrintfCString.h"
#include "nsThreadUtils.h"
using namespace mozilla::ipc;
#ifdef MOZ_WIDGET_GONK
using namespace android;
#endif
using std::map;
namespace mozilla {
namespace layers {
map<base::ProcessId, SharedBufferManagerParent* > SharedBufferManagerParent::sManagers;
StaticAutoPtr<Monitor> SharedBufferManagerParent::sManagerMonitor;
uint64_t SharedBufferManagerParent::sBufferKey(0);
#ifdef MOZ_WIDGET_GONK
class GrallocReporter final : public nsIMemoryReporter
{
public:
NS_DECL_ISUPPORTS
NS_IMETHOD CollectReports(nsIHandleReportCallback* aHandleReport,
nsISupports* aData, bool aAnonymize) override
{
if (SharedBufferManagerParent::sManagerMonitor) {
SharedBufferManagerParent::sManagerMonitor->Lock();
}
map<base::ProcessId, SharedBufferManagerParent*>::iterator it;
for (it = SharedBufferManagerParent::sManagers.begin(); it != SharedBufferManagerParent::sManagers.end(); it++) {
base::ProcessId pid = it->first;
SharedBufferManagerParent *mgr = it->second;
if (!mgr) {
printf_stderr("GrallocReporter::CollectReports(): mgr is nullptr");
continue;
}
nsAutoCString pidName;
LinuxUtils::GetThreadName(pid, pidName);
MutexAutoLock lock(mgr->mLock);
std::map<int64_t, android::sp<android::GraphicBuffer> >::iterator buf_it;
for (buf_it = mgr->mBuffers.begin(); buf_it != mgr->mBuffers.end(); buf_it++) {
android::sp<android::GraphicBuffer> gb = buf_it->second;
int bpp = android::bytesPerPixel(gb->getPixelFormat());
int stride = gb->getStride();
int height = gb->getHeight();
int amount = bpp > 0
? (stride * height * bpp)
// Special case for BSP specific formats (mainly YUV formats, count it as normal YUV buffer).
: (stride * height * 3 / 2);
nsPrintfCString gpath("gralloc/%s (pid=%d)/buffer(width=%d, height=%d, bpp=%d, stride=%d)",
pidName.get(), pid, gb->getWidth(), height, bpp, stride);
aHandleReport->Callback(
EmptyCString(), gpath, KIND_OTHER, UNITS_BYTES, amount,
NS_LITERAL_CSTRING(
"Special RAM that can be shared between processes and directly accessed by "
"both the CPU and GPU. Gralloc memory is usually a relatively precious "
"resource, with much less available than generic RAM. When it's exhausted, "
"graphics performance can suffer. This value can be incorrect because of race "
"conditions."),
aData);
}
}
if (SharedBufferManagerParent::sManagerMonitor) {
SharedBufferManagerParent::sManagerMonitor->Unlock();
}
return NS_OK;
}
protected:
~GrallocReporter() {}
};
NS_IMPL_ISUPPORTS(GrallocReporter, nsIMemoryReporter)
#endif
void InitGralloc() {
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
#ifdef MOZ_WIDGET_GONK
RegisterStrongMemoryReporter(new GrallocReporter());
#endif
}
/**
* Task that deletes SharedBufferManagerParent on a specified thread.
*/
class DeleteSharedBufferManagerParentTask : public Runnable
{
public:
explicit DeleteSharedBufferManagerParentTask(UniquePtr<SharedBufferManagerParent> aSharedBufferManager)
: mSharedBufferManager(Move(aSharedBufferManager)) {
}
NS_IMETHOD Run() override { return NS_OK; }
private:
UniquePtr<SharedBufferManagerParent> mSharedBufferManager;
};
SharedBufferManagerParent::SharedBufferManagerParent(base::ProcessId aOwner, base::Thread* aThread)
: mThread(aThread)
, mDestroyed(false)
, mLock("SharedBufferManagerParent.mLock")
{
MOZ_ASSERT(NS_IsMainThread());
if (!sManagerMonitor) {
sManagerMonitor = new Monitor("Manager Monitor");
}
MonitorAutoLock lock(*sManagerMonitor.get());
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread");
if (!aThread->IsRunning()) {
aThread->Start();
}
if (sManagers.count(aOwner) != 0) {
printf_stderr("SharedBufferManagerParent already exists.");
}
mOwner = aOwner;
sManagers[aOwner] = this;
}
SharedBufferManagerParent::~SharedBufferManagerParent()
{
MonitorAutoLock lock(*sManagerMonitor.get());
sManagers.erase(mOwner);
delete mThread;
}
void
SharedBufferManagerParent::ActorDestroy(ActorDestroyReason aWhy)
{
MutexAutoLock lock(mLock);
mDestroyed = true;
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
mBuffers.clear();
#endif
RefPtr<DeleteSharedBufferManagerParentTask> task =
new DeleteSharedBufferManagerParentTask(UniquePtr<SharedBufferManagerParent>(this));
NS_DispatchToMainThread(task.forget());
}
static void
ConnectSharedBufferManagerInParentProcess(SharedBufferManagerParent* aManager,
Transport* aTransport,
base::ProcessId aOtherPid)
{
aManager->Open(aTransport, aOtherPid, XRE_GetIOMessageLoop(), ipc::ParentSide);
}
PSharedBufferManagerParent* SharedBufferManagerParent::Create(Transport* aTransport,
ProcessId aOtherPid)
{
base::Thread* thread = nullptr;
char thrname[128];
SprintfLiteral(thrname, "BufMgrParent#%d", aOtherPid);
thread = new base::Thread(thrname);
SharedBufferManagerParent* manager = new SharedBufferManagerParent(aOtherPid, thread);
if (!thread->IsRunning()) {
thread->Start();
}
thread->message_loop()->PostTask(NewRunnableFunction(ConnectSharedBufferManagerInParentProcess,
manager, aTransport, aOtherPid));
return manager;
}
bool SharedBufferManagerParent::RecvAllocateGrallocBuffer(const IntSize& aSize, const uint32_t& aFormat, const uint32_t& aUsage, mozilla::layers::MaybeMagicGrallocBufferHandle* aHandle)
{
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
*aHandle = null_t();
if (aFormat == 0 || aUsage == 0) {
printf_stderr("SharedBufferManagerParent::RecvAllocateGrallocBuffer -- format and usage must be non-zero");
return false;
}
if (aSize.width <= 0 || aSize.height <= 0) {
printf_stderr("SharedBufferManagerParent::RecvAllocateGrallocBuffer -- requested gralloc buffer size is invalid");
return false;
}
// If the requested size is too big (i.e. exceeds the commonly used max GL texture size)
// then we risk OOMing the parent process. It's better to just deny the allocation and
// kill the child process, which is what the following code does.
// TODO: actually use GL_MAX_TEXTURE_SIZE instead of hardcoding 4096
if (aSize.width > 4096 || aSize.height > 4096) {
printf_stderr("SharedBufferManagerParent::RecvAllocateGrallocBuffer -- requested gralloc buffer is too big.");
return false;
}
sp<GraphicBuffer> outgoingBuffer = new GraphicBuffer(aSize.width, aSize.height, aFormat, aUsage);
if (!outgoingBuffer.get() || outgoingBuffer->initCheck() != NO_ERROR) {
printf_stderr("SharedBufferManagerParent::RecvAllocateGrallocBuffer -- gralloc buffer allocation failed");
return true;
}
int64_t bufferKey;
{
MonitorAutoLock lock(*sManagerMonitor.get());
bufferKey = ++sBufferKey;
}
GrallocBufferRef ref;
ref.mOwner = mOwner;
ref.mKey = bufferKey;
*aHandle = MagicGrallocBufferHandle(outgoingBuffer, ref);
{
MutexAutoLock lock(mLock);
mBuffers[bufferKey] = outgoingBuffer;
}
#endif
return true;
}
bool SharedBufferManagerParent::RecvDropGrallocBuffer(const mozilla::layers::MaybeMagicGrallocBufferHandle& handle)
{
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
NS_ASSERTION(handle.type() == MaybeMagicGrallocBufferHandle::TGrallocBufferRef, "We shouldn't interact with the real buffer!");
int64_t bufferKey = handle.get_GrallocBufferRef().mKey;
sp<GraphicBuffer> buf = GetGraphicBuffer(bufferKey);
MOZ_ASSERT(buf.get());
MutexAutoLock lock(mLock);
NS_ASSERTION(mBuffers.count(bufferKey) == 1, "No such buffer");
mBuffers.erase(bufferKey);
if(!buf.get()) {
printf_stderr("SharedBufferManagerParent::RecvDropGrallocBuffer -- invalid buffer key.");
return true;
}
#endif
return true;
}
/*static*/
void SharedBufferManagerParent::DropGrallocBufferSync(SharedBufferManagerParent* mgr, mozilla::layers::SurfaceDescriptor aDesc)
{
mgr->DropGrallocBufferImpl(aDesc);
}
/*static*/
void SharedBufferManagerParent::DropGrallocBuffer(ProcessId id, mozilla::layers::SurfaceDescriptor aDesc)
{
if (aDesc.type() != SurfaceDescriptor::TSurfaceDescriptorGralloc) {
return;
}
MonitorAutoLock lock(*sManagerMonitor.get());
SharedBufferManagerParent* mgr = SharedBufferManagerParent::GetInstance(id);
if (!mgr) {
return;
}
MutexAutoLock mgrlock(mgr->mLock);
if (mgr->mDestroyed) {
return;
}
if (PlatformThread::CurrentId() == mgr->mThread->thread_id()) {
MOZ_CRASH("GFX: SharedBufferManagerParent::DropGrallocBuffer should not be called on SharedBufferManagerParent thread");
} else {
mgr->mThread->message_loop()->PostTask(
NewRunnableFunction(&DropGrallocBufferSync, mgr, aDesc));
}
return;
}
void SharedBufferManagerParent::DropGrallocBufferImpl(mozilla::layers::SurfaceDescriptor aDesc)
{
MutexAutoLock lock(mLock);
if (mDestroyed) {
return;
}
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
int64_t key = -1;
MaybeMagicGrallocBufferHandle handle;
if (aDesc.type() == SurfaceDescriptor::TSurfaceDescriptorGralloc) {
handle = aDesc.get_SurfaceDescriptorGralloc().buffer();
} else {
return;
}
if (handle.type() == MaybeMagicGrallocBufferHandle::TGrallocBufferRef) {
key = handle.get_GrallocBufferRef().mKey;
} else if (handle.type() == MaybeMagicGrallocBufferHandle::TMagicGrallocBufferHandle) {
key = handle.get_MagicGrallocBufferHandle().mRef.mKey;
}
NS_ASSERTION(key != -1, "Invalid buffer key");
NS_ASSERTION(mBuffers.count(key) == 1, "No such buffer");
mBuffers.erase(key);
mozilla::Unused << SendDropGrallocBuffer(handle);
#endif
}
MessageLoop* SharedBufferManagerParent::GetMessageLoop()
{
return mThread->message_loop();
}
SharedBufferManagerParent* SharedBufferManagerParent::GetInstance(ProcessId id)
{
NS_ASSERTION(sManagers.count(id) == 1, "No BufferManager for the process");
if (sManagers.count(id) == 1) {
return sManagers[id];
} else {
return nullptr;
}
}
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
android::sp<android::GraphicBuffer>
SharedBufferManagerParent::GetGraphicBuffer(int64_t key)
{
MutexAutoLock lock(mLock);
if (mBuffers.count(key) == 1) {
return mBuffers[key];
} else {
// The buffer can be dropped, or invalid
printf_stderr("SharedBufferManagerParent::GetGraphicBuffer -- invalid key");
return nullptr;
}
}
android::sp<android::GraphicBuffer>
SharedBufferManagerParent::GetGraphicBuffer(GrallocBufferRef aRef)
{
MonitorAutoLock lock(*sManagerMonitor.get());
SharedBufferManagerParent* parent = GetInstance(aRef.mOwner);
if (!parent) {
return nullptr;
}
return parent->GetGraphicBuffer(aRef.mKey);
}
#endif
} /* namespace layers */
} /* namespace mozilla */

View File

@@ -1,110 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set sw=2 ts=8 et tw=80 : */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef SharedBufferManagerPARENT_H_
#define SharedBufferManagerPARENT_H_
#include "mozilla/Atomics.h" // for Atomic
#include "mozilla/layers/PSharedBufferManagerParent.h"
#include "mozilla/StaticPtr.h"
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
#include "mozilla/ipc/ProtocolUtils.h"
#include "mozilla/Mutex.h" // for Mutex
namespace android {
class GraphicBuffer;
}
#endif
namespace base {
class Thread;
} // namespace base
namespace mozilla {
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
class Mutex;
#endif
namespace layers {
class SharedBufferManagerParent : public PSharedBufferManagerParent
{
friend class GrallocReporter;
public:
/**
* Create a SharedBufferManagerParent for child process, and link to the child side before leaving
*/
static PSharedBufferManagerParent* Create(Transport* aTransport, ProcessId aOtherProcess);
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
android::sp<android::GraphicBuffer> GetGraphicBuffer(int64_t key);
static android::sp<android::GraphicBuffer> GetGraphicBuffer(GrallocBufferRef aRef);
#endif
/**
* Create a SharedBufferManagerParent but do not open the link
*/
SharedBufferManagerParent(ProcessId aOwner, base::Thread* aThread);
virtual ~SharedBufferManagerParent();
/**
* When the IPC channel down or something bad make this Manager die, clear all the buffer reference!
*/
virtual void ActorDestroy(ActorDestroyReason aWhy) override;
virtual bool RecvAllocateGrallocBuffer(const IntSize&, const uint32_t&, const uint32_t&, mozilla::layers::MaybeMagicGrallocBufferHandle*) override;
virtual bool RecvDropGrallocBuffer(const mozilla::layers::MaybeMagicGrallocBufferHandle& handle) override;
/**
* Break the buffer's sharing state, decrease buffer reference for both side
*/
static void DropGrallocBuffer(ProcessId id, mozilla::layers::SurfaceDescriptor aDesc);
MessageLoop* GetMessageLoop();
protected:
/**
* Break the buffer's sharing state, decrease buffer reference for both side
*
* Must be called from SharedBufferManagerParent's thread
*/
void DropGrallocBufferImpl(mozilla::layers::SurfaceDescriptor aDesc);
// dispatched function
static void DropGrallocBufferSync(SharedBufferManagerParent* mgr, mozilla::layers::SurfaceDescriptor aDesc);
/**
* Function for find the buffer owner, most buffer passing on IPC contains only owner/key pair.
* Use these function to access the real buffer.
* Caller needs to hold sManagerMonitor.
*/
static SharedBufferManagerParent* GetInstance(ProcessId id);
/**
* All living SharedBufferManager instances used to find the buffer owner, and parent->child IPCs
*/
static std::map<base::ProcessId, SharedBufferManagerParent*> sManagers;
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
/**
* Buffers owned by this SharedBufferManager pair
*/
std::map<int64_t, android::sp<android::GraphicBuffer> > mBuffers;
#endif
base::ProcessId mOwner;
base::Thread* mThread;
bool mDestroyed;
Mutex mLock;
static uint64_t sBufferKey;
static StaticAutoPtr<Monitor> sManagerMonitor;
};
} /* namespace layers */
} /* namespace mozilla */
#endif /* SharedBufferManagerPARENT_H_ */

View File

@@ -26,7 +26,6 @@ EXPORTS += [
'FrameMetrics.h',
'GLImages.h',
'GPUVideoImage.h',
'GrallocImages.h',
'ImageContainer.h',
'ImageLayers.h',
'ImageTypes.h',
@@ -186,8 +185,6 @@ EXPORTS.mozilla.layers += [
'ipc/RemoteContentController.h',
'ipc/ShadowLayerChild.h',
'ipc/ShadowLayers.h',
'ipc/SharedBufferManagerChild.h',
'ipc/SharedBufferManagerParent.h',
'ipc/SharedPlanarYCbCrImage.h',
'ipc/SharedRGBImage.h',
'ipc/TextureForwarder.h',
@@ -197,8 +194,6 @@ EXPORTS.mozilla.layers += [
'LayersTypes.h',
'opengl/CompositingRenderTargetOGL.h',
'opengl/CompositorOGL.h',
'opengl/GrallocTextureClient.h',
'opengl/GrallocTextureHost.h',
'opengl/MacIOSurfaceTextureClientOGL.h',
'opengl/MacIOSurfaceTextureHostOGL.h',
'opengl/TextureClientOGL.h',
@@ -243,34 +238,6 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
'MacIOSurfaceImage.cpp',
]
# NB: Gralloc is available on other platforms that use the android GL
# libraries, but only Gonk is able to use it reliably because Gecko
# has full system permissions there.
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
EXPORTS.mozilla.layers += [
'basic/GrallocTextureHostBasic.h',
'ipc/ShadowLayerUtilsGralloc.h',
]
UNIFIED_SOURCES += [
'basic/GrallocTextureHostBasic.cpp',
'GrallocImages.cpp',
'opengl/EGLImageHelpers.cpp',
'opengl/GrallocTextureClient.cpp',
'opengl/GrallocTextureHost.cpp',
]
LOCAL_INCLUDES += ['/widget/gonk']
if CONFIG['ANDROID_VERSION'] >= '21':
LOCAL_INCLUDES += [
'%' + '%s/%s' % (CONFIG['ANDROID_SOURCE'], d) for d in [
'system/core/libsync/include'
]
]
SOURCES += [
'ipc/GonkNativeHandle.cpp',
'ipc/GonkNativeHandleUtils.cpp',
'ipc/ShadowLayerUtilsGralloc.cpp',
]
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
UNIFIED_SOURCES += [
'apz/src/AndroidAPZ.cpp',
@@ -386,8 +353,6 @@ UNIFIED_SOURCES += [
'ipc/ShadowLayerChild.cpp',
'ipc/ShadowLayerParent.cpp',
'ipc/ShadowLayers.cpp',
'ipc/SharedBufferManagerChild.cpp',
'ipc/SharedBufferManagerParent.cpp',
'ipc/SharedPlanarYCbCrImage.cpp',
'ipc/SharedRGBImage.cpp',
'ipc/VideoBridgeChild.cpp',
@@ -447,7 +412,6 @@ IPDL_SOURCES = [
'ipc/PImageContainer.ipdl',
'ipc/PLayer.ipdl',
'ipc/PLayerTransaction.ipdl',
'ipc/PSharedBufferManager.ipdl',
'ipc/PTexture.ipdl',
'ipc/PVideoBridge.ipdl',
]
@@ -469,22 +433,6 @@ if CONFIG['MOZ_DEBUG']:
if CONFIG['MOZ_ENABLE_D3D10_LAYER']:
DEFINES['MOZ_ENABLE_D3D10_LAYER'] = True
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
if CONFIG['ANDROID_VERSION'] >= '17':
includes = [
'frameworks/av/include/media/stagefright',
'frameworks/native/include/media/openmax',
]
else:
includes = [
'frameworks/base/include/media/stagefright',
'frameworks/base/include/media/stagefright/openmax',
]
LOCAL_INCLUDES += [
'%' + '%s/%s' % (CONFIG['ANDROID_SOURCE'], d) for d in includes
]
if CONFIG['ENABLE_TESTS']:
DIRS += ['apz/test/gtest']

View File

@@ -148,12 +148,6 @@ CompositorOGL::CreateContext()
NS_WARNING("Failed to create CompositorOGL context");
}
#ifdef MOZ_WIDGET_GONK
MOZ_ASSERT(widget);
widget->SetNativeData(
NS_NATIVE_OPENGL_CONTEXT, reinterpret_cast<uintptr_t>(context.get()));
#endif
return context.forget();
}
@@ -179,11 +173,6 @@ CompositorOGL::CleanupResources()
if (!mGLContext)
return;
#ifdef MOZ_WIDGET_GONK
mWidget->RealWidget()->SetNativeData(
NS_NATIVE_OPENGL_CONTEXT, reinterpret_cast<uintptr_t>(nullptr));
#endif
RefPtr<GLContext> ctx = mGLContext->GetSharedContext();
if (!ctx) {
ctx = mGLContext;
@@ -1778,11 +1767,7 @@ GLuint
CompositorOGL::GetTemporaryTexture(GLenum aTarget, GLenum aUnit)
{
if (!mTexturePool) {
#ifdef MOZ_WIDGET_GONK
mTexturePool = new PerFrameTexturePoolOGL(gl());
#else
mTexturePool = new PerUnitTexturePoolOGL(gl());
#endif
}
return mTexturePool->GetTexture(aTarget, aUnit);
}

View File

@@ -33,10 +33,6 @@
#include "nsXULAppAPI.h" // for XRE_GetProcessType
#include "nscore.h" // for NS_IMETHOD
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 21
#include "nsTHashtable.h" // for nsTHashtable
#endif
class nsIWidget;
namespace mozilla {
@@ -52,10 +48,6 @@ struct Effect;
struct EffectChain;
class GLBlitTextureImageHelper;
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 21
class ImageHostOverlay;
#endif
/**
* Interface for pools of temporary gl textures for the compositor.
* The textures are fully owned by the pool, so the latter is responsible
@@ -259,25 +251,15 @@ public:
virtual bool HasImageHostOverlays() override
{
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 21
return mImageHostOverlays.Count() > 0;
#else
return false;
#endif
}
virtual void AddImageHostOverlay(ImageHostOverlay* aOverlay) override
{
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 21
mImageHostOverlays.PutEntry(aOverlay);
#endif
}
virtual void RemoveImageHostOverlay(ImageHostOverlay* aOverlay) override
{
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 21
mImageHostOverlays.RemoveEntry(aOverlay);
#endif
}
GLContext* gl() const { return mGLContext; }
@@ -509,11 +491,6 @@ private:
gfx::IntSize mViewportSize;
ShaderProgramOGL *mCurrentProgram;
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 21
nsTHashtable<nsPtrHashKey<ImageHostOverlay> > mImageHostOverlays;
#endif
};
} // namespace layers

View File

@@ -1,460 +0,0 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// * This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifdef MOZ_WIDGET_GONK
#include "mozilla/gfx/2D.h"
#include "mozilla/layers/AsyncTransactionTracker.h" // for AsyncTransactionTracker
#include "mozilla/layers/GrallocTextureClient.h"
#include "mozilla/layers/TextureForwarder.h"
#include "mozilla/layers/ISurfaceAllocator.h"
#include "mozilla/layers/ShadowLayerUtilsGralloc.h"
#include "mozilla/layers/SharedBufferManagerChild.h"
#include "gfx2DGlue.h"
#include "gfxPrefs.h" // for gfxPrefs
#include "SharedSurfaceGralloc.h"
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
#include <ui/Fence.h>
#endif
namespace mozilla {
namespace layers {
using namespace mozilla::gfx;
using namespace android;
static bool
DisableGralloc(SurfaceFormat aFormat, const gfx::IntSize& aSizeHint)
{
if (gfxPrefs::DisableGralloc()) {
return true;
}
if (aFormat == gfx::SurfaceFormat::A8) {
return true;
}
return false;
}
gfx::SurfaceFormat
SurfaceFormatForPixelFormat(android::PixelFormat aFormat)
{
switch (aFormat) {
case PIXEL_FORMAT_RGBA_8888:
return gfx::SurfaceFormat::R8G8B8A8;
case PIXEL_FORMAT_BGRA_8888:
return gfx::SurfaceFormat::B8G8R8A8;
case PIXEL_FORMAT_RGBX_8888:
return gfx::SurfaceFormat::R8G8B8X8;
case PIXEL_FORMAT_RGB_565:
return gfx::SurfaceFormat::R5G6B5_UINT16;
case HAL_PIXEL_FORMAT_YV12:
return gfx::SurfaceFormat::YUV;
default:
return gfx::SurfaceFormat::UNKNOWN;
}
}
bool
IsGrallocRBSwapped(gfx::SurfaceFormat aFormat) {
switch (aFormat) {
case gfx::SurfaceFormat::B8G8R8A8:
case gfx::SurfaceFormat::B8G8R8X8:
return true;
default:
return false;
}
}
uint32_t GetAndroidFormat(gfx::SurfaceFormat aFormat)
{
switch (aFormat) {
case gfx::SurfaceFormat::R8G8B8A8:
case gfx::SurfaceFormat::B8G8R8A8:
return android::PIXEL_FORMAT_RGBA_8888;
case gfx::SurfaceFormat::R8G8B8X8:
case gfx::SurfaceFormat::B8G8R8X8:
return android::PIXEL_FORMAT_RGBX_8888;
case gfx::SurfaceFormat::R5G6B5_UINT16:
return android::PIXEL_FORMAT_RGB_565;
case gfx::SurfaceFormat::YUV:
return HAL_PIXEL_FORMAT_YV12;
case gfx::SurfaceFormat::A8:
NS_WARNING("gralloc does not support SurfaceFormat::A8");
default:
NS_WARNING("Unsupported surface format");
return android::PIXEL_FORMAT_UNKNOWN;
}
}
GrallocTextureData::GrallocTextureData(MaybeMagicGrallocBufferHandle aGrallocHandle,
gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
gfx::BackendType aMoz2DBackend)
: mSize(aSize)
, mFormat(aFormat)
, mMoz2DBackend(aMoz2DBackend)
, mGrallocHandle(aGrallocHandle)
, mMappedBuffer(nullptr)
, mMediaBuffer(nullptr)
{
mGraphicBuffer = GetGraphicBufferFrom(aGrallocHandle);
MOZ_COUNT_CTOR(GrallocTextureData);
}
GrallocTextureData::~GrallocTextureData()
{
MOZ_COUNT_DTOR(GrallocTextureData);
}
void
GrallocTextureData::Deallocate(LayersIPCChannel* aAllocator)
{
MOZ_ASSERT(aAllocator);
if (aAllocator && aAllocator->IPCOpen()) {
SharedBufferManagerChild::GetSingleton()->DeallocGrallocBuffer(mGrallocHandle);
}
mGrallocHandle = null_t();
mGraphicBuffer = nullptr;
}
void
GrallocTextureData::Forget(LayersIPCChannel* aAllocator)
{
MOZ_ASSERT(aAllocator);
if (aAllocator && aAllocator->IPCOpen()) {
SharedBufferManagerChild::GetSingleton()->DropGrallocBuffer(mGrallocHandle);
}
mGrallocHandle = null_t();
mGraphicBuffer = nullptr;
}
void
GrallocTextureData::FillInfo(TextureData::Info& aInfo) const
{
aInfo.size = mSize;
aInfo.format = mFormat;
aInfo.hasIntermediateBuffer = false;
aInfo.hasSynchronization = true;
aInfo.supportsMoz2D = true;
aInfo.canExposeMappedData = true;
}
bool
GrallocTextureData::Serialize(SurfaceDescriptor& aOutDescriptor)
{
aOutDescriptor = SurfaceDescriptorGralloc(mGrallocHandle, gfx::IsOpaque(mFormat));
return true;
}
void
GrallocTextureData::WaitForFence(FenceHandle* aFence)
{
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION < 21 && ANDROID_VERSION >= 17
if (aFence && aFence->IsValid()) {
RefPtr<FenceHandle::FdObj> fdObj = aFence->GetAndResetFdObj();
android::sp<Fence> fence = new Fence(fdObj->GetAndResetFd());
#if ANDROID_VERSION == 17
fence->waitForever(1000, "GrallocTextureData::Lock");
// 1000 is what Android uses. It is a warning timeout in ms.
// This timeout was removed in ANDROID_VERSION 18.
#else
fence->waitForever("GrallocTextureData::Lock");
#endif
}
#endif
}
bool
GrallocTextureData::Lock(OpenMode aMode, FenceHandle* aReleaseFence)
{
MOZ_ASSERT(!mMappedBuffer);
uint32_t usage = 0;
if (aMode & OpenMode::OPEN_READ) {
usage |= GRALLOC_USAGE_SW_READ_OFTEN;
}
if (aMode & OpenMode::OPEN_WRITE) {
usage |= GRALLOC_USAGE_SW_WRITE_OFTEN;
}
void** mappedBufferPtr = reinterpret_cast<void**>(&mMappedBuffer);
int32_t rv = 0;
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 21
if (aReleaseFence) {
RefPtr<FenceHandle::FdObj> fdObj = aReleaseFence->GetAndResetFdObj();
rv = mGraphicBuffer->lockAsync(usage, mappedBufferPtr,
fdObj->GetAndResetFd());
} else {
rv = mGraphicBuffer->lock(usage, mappedBufferPtr);
}
#else
// older versions of android don't have lockAsync
WaitForFence(aReleaseFence);
rv = mGraphicBuffer->lock(usage, mappedBufferPtr);
#endif
if (rv) {
mMappedBuffer = nullptr;
NS_WARNING("Couldn't lock graphic buffer");
return false;
}
return true;
}
void
GrallocTextureData::Unlock()
{
MOZ_ASSERT(mMappedBuffer);
mMappedBuffer = nullptr;
mGraphicBuffer->unlock();
}
already_AddRefed<gfx::DrawTarget>
GrallocTextureData::BorrowDrawTarget()
{
MOZ_ASSERT(mMappedBuffer);
if (!mMappedBuffer) {
return nullptr;
}
long byteStride = mGraphicBuffer->getStride() * BytesPerPixel(mFormat);
return gfxPlatform::CreateDrawTargetForData(mMappedBuffer, mSize,
byteStride, mFormat);
}
bool
GrallocTextureData::BorrowMappedData(MappedTextureData& aMap)
{
if (mFormat == gfx::SurfaceFormat::YUV || !mMappedBuffer) {
return false;
}
aMap.data = mMappedBuffer;
aMap.size = mSize;
aMap.stride = mGraphicBuffer->getStride() * BytesPerPixel(mFormat);
aMap.format = mFormat;
return true;
}
bool
GrallocTextureData::UpdateFromSurface(gfx::SourceSurface* aSurface)
{
MOZ_ASSERT(mMappedBuffer, "Calling TextureClient::BorrowDrawTarget without locking :(");
if (!mMappedBuffer) {
return false;
}
RefPtr<DataSourceSurface> srcSurf = aSurface->GetDataSurface();
if (!srcSurf) {
gfxCriticalError() << "Failed to GetDataSurface in UpdateFromSurface (GTC).";
return false;
}
gfx::SurfaceFormat format = SurfaceFormatForPixelFormat(mGraphicBuffer->getPixelFormat());
if (mSize != srcSurf->GetSize() || mFormat != srcSurf->GetFormat()) {
gfxCriticalError() << "Attempt to update texture client from a surface with a different size or format! This: " << mSize << " " << format << " Other: " << srcSurf->GetSize() << " " << srcSurf->GetFormat();
return false;
}
long pixelStride = mGraphicBuffer->getStride();
long byteStride = pixelStride * BytesPerPixel(format);
DataSourceSurface::MappedSurface sourceMap;
if (!srcSurf->Map(DataSourceSurface::READ, &sourceMap)) {
gfxCriticalError() << "Failed to map source surface for UpdateFromSurface (GTC).";
return false;
}
for (int y = 0; y < srcSurf->GetSize().height; y++) {
memcpy(mMappedBuffer + byteStride * y,
sourceMap.mData + sourceMap.mStride * y,
srcSurf->GetSize().width * BytesPerPixel(srcSurf->GetFormat()));
}
srcSurf->Unmap();
return true;
}
// static
GrallocTextureData*
GrallocTextureData::Create(gfx::IntSize aSize, AndroidFormat aAndroidFormat,
gfx::BackendType aMoz2dBackend, uint32_t aUsage,
LayersIPCChannel* aAllocator)
{
if (!aAllocator || !aAllocator->IPCOpen()) {
return nullptr;
}
gfx::SurfaceFormat format;
switch (aAndroidFormat) {
case android::PIXEL_FORMAT_RGBA_8888:
format = gfx::SurfaceFormat::B8G8R8A8;
break;
case android::PIXEL_FORMAT_BGRA_8888:
format = gfx::SurfaceFormat::B8G8R8A8;
break;
case android::PIXEL_FORMAT_RGBX_8888:
format = gfx::SurfaceFormat::B8G8R8X8;
break;
case android::PIXEL_FORMAT_RGB_565:
format = gfx::SurfaceFormat::R5G6B5_UINT16;
break;
case HAL_PIXEL_FORMAT_YV12:
format = gfx::SurfaceFormat::YUV;
break;
default:
format = gfx::SurfaceFormat::UNKNOWN;
}
if (DisableGralloc(format, aSize)) {
return nullptr;
}
MaybeMagicGrallocBufferHandle handle;
if (!SharedBufferManagerChild::GetSingleton()->AllocGrallocBuffer(aSize, aAndroidFormat, aUsage, &handle)) {
return nullptr;
}
sp<GraphicBuffer> graphicBuffer = GetGraphicBufferFrom(handle);
if (!graphicBuffer.get()) {
return nullptr;
}
if (graphicBuffer->initCheck() != NO_ERROR) {
return nullptr;
}
return new GrallocTextureData(handle, aSize, format, aMoz2dBackend);
}
// static
GrallocTextureData*
GrallocTextureData::CreateForDrawing(gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
gfx::BackendType aMoz2dBackend,
LayersIPCChannel* aAllocator)
{
if (DisableGralloc(aFormat, aSize)) {
return nullptr;
}
#if ANDROID_VERSION <= 15
// Adreno 200 has a problem of drawing gralloc buffer width less than 64 and
// drawing gralloc buffer with a height 9px-16px.
// See Bug 983971.
// We only have this restriction in TextureClients that we'll use for drawing
// (not with WebGL for instance). Not sure why that's OK, but we have tests that
// rely on being able to create 32x32 webgl canvases with gralloc, so moving
// this check in DisableGralloc will break them.
if (aSize.width < 64 || aSize.height < 32) {
return nullptr;
}
#endif
uint32_t usage = android::GraphicBuffer::USAGE_SW_READ_OFTEN |
android::GraphicBuffer::USAGE_SW_WRITE_OFTEN |
android::GraphicBuffer::USAGE_HW_TEXTURE;
auto data = GrallocTextureData::Create(aSize, GetAndroidFormat(aFormat),
aMoz2dBackend, usage, aAllocator);
if (!data) {
return nullptr;
}
DebugOnly<gfx::SurfaceFormat> grallocFormat =
SurfaceFormatForPixelFormat(data->mGraphicBuffer->getPixelFormat());
// mFormat may be different from the format the graphic buffer reports if we
// swap the R and B channels but we should always have at least the same bytes
// per pixel!
MOZ_ASSERT(BytesPerPixel(data->mFormat) == BytesPerPixel(grallocFormat));
return data;
}
TextureFlags
GrallocTextureData::GetTextureFlags() const
{
if (IsGrallocRBSwapped(mFormat)) {
return TextureFlags::RB_SWAPPED;
}
return TextureFlags::NO_FLAGS;
}
// static
GrallocTextureData*
GrallocTextureData::CreateForYCbCr(gfx::IntSize aYSize, gfx::IntSize aCbCrSize,
LayersIPCChannel* aAllocator)
{
MOZ_ASSERT(aYSize.width == aCbCrSize.width * 2);
MOZ_ASSERT(aYSize.height == aCbCrSize.height * 2);
return GrallocTextureData::Create(aYSize, HAL_PIXEL_FORMAT_YV12,
gfx::BackendType::NONE,
android::GraphicBuffer::USAGE_SW_READ_OFTEN,
aAllocator);
}
// static
GrallocTextureData*
GrallocTextureData::CreateForGLRendering(gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
LayersIPCChannel* aAllocator)
{
if (aFormat == gfx::SurfaceFormat::YUV) {
return nullptr;
}
uint32_t usage = android::GraphicBuffer::USAGE_HW_RENDER |
android::GraphicBuffer::USAGE_HW_TEXTURE;
return GrallocTextureData::Create(aSize, GetAndroidFormat(aFormat),
gfx::BackendType::NONE, usage, aAllocator);
}
// static
already_AddRefed<TextureClient>
GrallocTextureData::TextureClientFromSharedSurface(gl::SharedSurface* abstractSurf,
TextureFlags flags)
{
auto surf = gl::SharedSurface_Gralloc::Cast(abstractSurf);
RefPtr<TextureClient> ret = surf->GetTextureClient();
TextureFlags mask = TextureFlags::ORIGIN_BOTTOM_LEFT |
TextureFlags::RB_SWAPPED |
TextureFlags::NON_PREMULTIPLIED;
TextureFlags required = flags & mask;
TextureFlags present = ret->GetFlags() & mask;
if (present != required) {
printf_stderr("Present flags: 0x%x. Required: 0x%x.\n",
(uint32_t)present,
(uint32_t)required);
MOZ_CRASH("Flag requirement mismatch.");
}
return ret.forget();
}
TextureData*
GrallocTextureData::CreateSimilar(LayersIPCChannel* aAllocator,
LayersBackend aLayersBackend,
TextureFlags aFlags,
TextureAllocationFlags aAllocFlags) const
{
if (mFormat == gfx::SurfaceFormat::YUV) {
return GrallocTextureData::CreateForYCbCr(mSize, mSize*2, aAllocator);
} else {
return GrallocTextureData::CreateForDrawing(mSize, mFormat, mMoz2DBackend, aAllocator);
}
}
} // namesapace layers
} // namesapace mozilla
#endif // MOZ_WIDGET_GONK

View File

@@ -1,129 +0,0 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// * This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef MOZILLA_GFX_GRALLOCTEXTURECLIENT_H
#define MOZILLA_GFX_GRALLOCTEXTURECLIENT_H
#ifdef MOZ_WIDGET_GONK
#include "mozilla/layers/TextureClient.h"
#include "mozilla/layers/FenceUtils.h" // for FenceHandle
#include "mozilla/layers/ShadowLayerUtilsGralloc.h"
#include <ui/GraphicBuffer.h>
namespace android {
class MediaBuffer;
};
namespace mozilla {
namespace gl {
class SharedSurface;
}
namespace layers {
/// A TextureData implementation based on android::GraphicBuffer (also referred to
/// as "gralloc").
///
/// Gralloc lets us map texture data in memory (accessible through pointers)
/// and also use it directly as an OpenGL texture without the cost of texture
/// uploads.
/// Gralloc buffers can also be shared accros processes.
///
/// More info about Gralloc here: https://wiki.mozilla.org/Platform/GFX/Gralloc
///
/// This is only used in Firefox OS
class GrallocTextureData : public TextureData {
public:
typedef uint32_t AndroidFormat;
virtual bool Serialize(SurfaceDescriptor& aOutDescriptor) override;
virtual bool Lock(OpenMode aMode, FenceHandle* aFence) override;
virtual void Unlock() override;
virtual void FillInfo(TextureData::Info& aInfo) const override;
virtual already_AddRefed<gfx::DrawTarget> BorrowDrawTarget() override;
virtual bool BorrowMappedData(MappedTextureData& aMap) override;
virtual void Deallocate(LayersIPCChannel*) override;
virtual void Forget(LayersIPCChannel*) override;
static GrallocTextureData* CreateForDrawing(gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
gfx::BackendType aMoz2dBackend,
LayersIPCChannel* aAllocator);
static GrallocTextureData* CreateForYCbCr(gfx::IntSize aYSize, gfx::IntSize aCbCrSize,
LayersIPCChannel* aAllocator);
static GrallocTextureData* CreateForGLRendering(gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
LayersIPCChannel* aAllocator);
static GrallocTextureData* Create(gfx::IntSize aSize, AndroidFormat aFormat,
gfx::BackendType aMoz2DBackend, uint32_t aUsage,
LayersIPCChannel* aAllocator);
static already_AddRefed<TextureClient>
TextureClientFromSharedSurface(gl::SharedSurface* abstractSurf, TextureFlags flags);
virtual TextureData*
CreateSimilar(LayersIPCChannel* aAllocator,
LayersBackend aLayersBackend,
TextureFlags aFlags = TextureFlags::DEFAULT,
TextureAllocationFlags aAllocFlags = ALLOC_DEFAULT) const override;
// use TextureClient's default implementation
virtual bool UpdateFromSurface(gfx::SourceSurface* aSurface) override;
/// Hold android::MediaBuffer.
/// MediaBuffer needs to be add refed to keep MediaBuffer alive while the texture
/// is in use.
///
/// TODO - ideally we should be able to put the MediaBuffer in the texture's
/// constructor and not expose these methods.
void SetMediaBuffer(android::MediaBuffer* aMediaBuffer) { mMediaBuffer = aMediaBuffer; }
android::MediaBuffer* GetMediaBuffer() { return mMediaBuffer; }
android::sp<android::GraphicBuffer> GetGraphicBuffer() { return mGraphicBuffer; }
virtual void WaitForFence(FenceHandle* aFence) override;
~GrallocTextureData();
virtual TextureFlags GetTextureFlags() const override;
virtual GrallocTextureData* AsGrallocTextureData() { return this; }
protected:
GrallocTextureData(MaybeMagicGrallocBufferHandle aGrallocHandle,
gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
gfx::BackendType aMoz2DBackend);
gfx::IntSize mSize;
gfx::SurfaceFormat mFormat;
gfx::BackendType mMoz2DBackend;
MaybeMagicGrallocBufferHandle mGrallocHandle;
android::sp<android::GraphicBuffer> mGraphicBuffer;
// Points to a mapped gralloc buffer between calls to lock and unlock.
// Should be null outside of the lock-unlock pair.
uint8_t* mMappedBuffer;
android::MediaBuffer* mMediaBuffer;
};
gfx::SurfaceFormat SurfaceFormatForPixelFormat(android::PixelFormat aFormat);
} // namespace layers
} // namespace mozilla
#endif // MOZ_WIDGET_GONK
#endif

View File

@@ -1,480 +0,0 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// * This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "base/process.h"
#include "GLContext.h"
#include "gfx2DGlue.h"
#include <ui/GraphicBuffer.h>
#include "GrallocImages.h" // for GrallocImage
#include "GLLibraryEGL.h" // for GLLibraryEGL
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/DataSurfaceHelpers.h"
#include "mozilla/layers/GrallocTextureHost.h"
#include "mozilla/layers/SharedBufferManagerParent.h"
#include "EGLImageHelpers.h"
#include "GLReadTexImageHelper.h"
namespace mozilla {
namespace layers {
using namespace android;
using namespace mozilla::gl;
static gfx::SurfaceFormat
SurfaceFormatForAndroidPixelFormat(android::PixelFormat aFormat,
TextureFlags aFlags)
{
bool swapRB = bool(aFlags & TextureFlags::RB_SWAPPED);
switch (aFormat) {
case android::PIXEL_FORMAT_BGRA_8888:
return swapRB ? gfx::SurfaceFormat::R8G8B8A8 : gfx::SurfaceFormat::B8G8R8A8;
case android::PIXEL_FORMAT_RGBA_8888:
return swapRB ? gfx::SurfaceFormat::B8G8R8A8 : gfx::SurfaceFormat::R8G8B8A8;
case android::PIXEL_FORMAT_RGBX_8888:
return swapRB ? gfx::SurfaceFormat::B8G8R8X8 : gfx::SurfaceFormat::R8G8B8X8;
case android::PIXEL_FORMAT_RGB_565:
return gfx::SurfaceFormat::R5G6B5_UINT16;
case HAL_PIXEL_FORMAT_YCbCr_422_SP:
case HAL_PIXEL_FORMAT_YCrCb_420_SP:
case HAL_PIXEL_FORMAT_YCbCr_422_I:
case GrallocImage::HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
case GrallocImage::HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
case HAL_PIXEL_FORMAT_YV12:
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
#endif
return gfx::SurfaceFormat::R8G8B8A8; // yup, use SurfaceFormat::R8G8B8A8 even though it's a YUV texture. This is an external texture.
default:
if (aFormat >= 0x100 && aFormat <= 0x1FF) {
// Reserved range for HAL specific formats.
return gfx::SurfaceFormat::R8G8B8A8;
} else {
// This is not super-unreachable, there's a bunch of hypothetical pixel
// formats we don't deal with.
// We only want to abort in debug builds here, since if we crash here
// we'll take down the compositor process and thus the phone. This seems
// like undesirable behaviour. We'd rather have a subtle artifact.
printf_stderr(" xxxxx unknow android format %i\n", (int)aFormat);
MOZ_ASSERT(false, "Unknown Android pixel format.");
return gfx::SurfaceFormat::UNKNOWN;
}
}
}
static GLenum
TextureTargetForAndroidPixelFormat(android::PixelFormat aFormat)
{
switch (aFormat) {
case HAL_PIXEL_FORMAT_YCbCr_422_SP:
case HAL_PIXEL_FORMAT_YCrCb_420_SP:
case HAL_PIXEL_FORMAT_YCbCr_422_I:
case GrallocImage::HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
case GrallocImage::HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
case HAL_PIXEL_FORMAT_YV12:
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
#endif
return LOCAL_GL_TEXTURE_EXTERNAL;
case android::PIXEL_FORMAT_BGRA_8888:
case android::PIXEL_FORMAT_RGBA_8888:
case android::PIXEL_FORMAT_RGBX_8888:
case android::PIXEL_FORMAT_RGB_565:
return LOCAL_GL_TEXTURE_2D;
default:
if (aFormat >= 0x100 && aFormat <= 0x1FF) {
// Reserved range for HAL specific formats.
return LOCAL_GL_TEXTURE_EXTERNAL;
} else {
// This is not super-unreachable, there's a bunch of hypothetical pixel
// formats we don't deal with.
// We only want to abort in debug builds here, since if we crash here
// we'll take down the compositor process and thus the phone. This seems
// like undesirable behaviour. We'd rather have a subtle artifact.
MOZ_ASSERT(false, "Unknown Android pixel format.");
return LOCAL_GL_TEXTURE_EXTERNAL;
}
}
}
GrallocTextureHostOGL::GrallocTextureHostOGL(TextureFlags aFlags,
const SurfaceDescriptorGralloc& aDescriptor)
: TextureHost(aFlags)
, mGrallocHandle(aDescriptor)
, mSize(0, 0)
, mCropSize(0, 0)
, mFormat(gfx::SurfaceFormat::UNKNOWN)
, mEGLImage(EGL_NO_IMAGE)
, mIsOpaque(aDescriptor.isOpaque())
{
android::GraphicBuffer* graphicBuffer = GetGraphicBufferFromDesc(mGrallocHandle).get();
MOZ_ASSERT(graphicBuffer);
if (graphicBuffer) {
mFormat =
SurfaceFormatForAndroidPixelFormat(graphicBuffer->getPixelFormat(),
aFlags & TextureFlags::RB_SWAPPED);
mSize = gfx::IntSize(graphicBuffer->getWidth(), graphicBuffer->getHeight());
mCropSize = mSize;
} else {
printf_stderr("gralloc buffer is nullptr\n");
}
}
GrallocTextureHostOGL::~GrallocTextureHostOGL()
{
DestroyEGLImage();
}
void
GrallocTextureHostOGL::SetCompositor(Compositor* aCompositor)
{
mCompositor = AssertGLCompositor(aCompositor);
if (mGLTextureSource) {
mGLTextureSource->SetCompositor(mCompositor);
}
if (mCompositor && aCompositor != mCompositor) {
DestroyEGLImage();
}
}
bool
GrallocTextureHostOGL::Lock()
{
return IsValid();
}
void
GrallocTextureHostOGL::Unlock()
{
// Unlock is done internally by binding the texture to another gralloc buffer
}
bool
GrallocTextureHostOGL::IsValid() const
{
android::GraphicBuffer* graphicBuffer = GetGraphicBufferFromDesc(mGrallocHandle).get();
return graphicBuffer != nullptr;
}
gfx::SurfaceFormat
GrallocTextureHostOGL::GetFormat() const
{
return mFormat;
}
void
GrallocTextureHostOGL::DeallocateSharedData()
{
if (mGLTextureSource) {
mGLTextureSource = nullptr;
}
DestroyEGLImage();
if (mGrallocHandle.buffer().type() != MaybeMagicGrallocBufferHandle::Tnull_t) {
MaybeMagicGrallocBufferHandle handle = mGrallocHandle.buffer();
base::ProcessId owner;
if (handle.type() == MaybeMagicGrallocBufferHandle::TGrallocBufferRef) {
owner = handle.get_GrallocBufferRef().mOwner;
}
else {
owner = handle.get_MagicGrallocBufferHandle().mRef.mOwner;
}
SharedBufferManagerParent::DropGrallocBuffer(owner, mGrallocHandle);
}
}
void
GrallocTextureHostOGL::ForgetSharedData()
{
if (mGLTextureSource) {
mGLTextureSource = nullptr;
}
}
void
GrallocTextureHostOGL::DeallocateDeviceData()
{
if (mGLTextureSource) {
mGLTextureSource = nullptr;
}
DestroyEGLImage();
}
LayerRenderState
GrallocTextureHostOGL::GetRenderState()
{
android::GraphicBuffer* graphicBuffer = GetGraphicBufferFromDesc(mGrallocHandle).get();
if (graphicBuffer) {
LayerRenderStateFlags flags = LayerRenderStateFlags::LAYER_RENDER_STATE_DEFAULT;
if (mIsOpaque) {
flags |= LayerRenderStateFlags::OPAQUE;
}
if (mFlags & TextureFlags::ORIGIN_BOTTOM_LEFT) {
flags |= LayerRenderStateFlags::ORIGIN_BOTTOM_LEFT;
}
if (mFlags & TextureFlags::RB_SWAPPED) {
flags |= LayerRenderStateFlags::FORMAT_RB_SWAP;
}
return LayerRenderState(graphicBuffer,
mCropSize,
flags,
this);
}
return LayerRenderState();
}
already_AddRefed<gfx::DataSourceSurface>
GrallocTextureHostOGL::GetAsSurface() {
android::GraphicBuffer* graphicBuffer = GetGraphicBufferFromDesc(mGrallocHandle).get();
if (!graphicBuffer) {
return nullptr;
}
uint8_t* grallocData;
int32_t rv = graphicBuffer->lock(GRALLOC_USAGE_SW_READ_OFTEN, reinterpret_cast<void**>(&grallocData));
if (rv) {
return nullptr;
}
RefPtr<gfx::DataSourceSurface> grallocTempSurf =
gfx::Factory::CreateWrappingDataSourceSurface(grallocData,
graphicBuffer->getStride() * android::bytesPerPixel(graphicBuffer->getPixelFormat()),
GetSize(), GetFormat());
if (!grallocTempSurf) {
graphicBuffer->unlock();
return nullptr;
}
RefPtr<gfx::DataSourceSurface> surf = CreateDataSourceSurfaceByCloning(grallocTempSurf);
graphicBuffer->unlock();
return surf.forget();
}
void
GrallocTextureHostOGL::UnbindTextureSource()
{
TextureHost::UnbindTextureSource();
// Clear the reference to the TextureSource (if any), because we know that
// another TextureHost is being bound to the TextureSource. This means that
// we will have to re-do gl->fEGLImageTargetTexture2D next time we go through
// BindTextureSource (otherwise we would have skipped it).
// Note that this doesn't "unlock" the gralloc buffer or force it to be
// detached, Although decreasing the refcount of the TextureSource may lead
// to the gl handle being destroyed, which would unlock the gralloc buffer.
// That said, this method is called before another TextureHost attaches to the
// TextureSource, which has the effect of unlocking the gralloc buffer. So when
// this is called we know we are going to be unlocked soon.
mGLTextureSource = nullptr;
}
GLenum GetTextureTarget(gl::GLContext* aGL, android::PixelFormat aFormat) {
MOZ_ASSERT(aGL);
if (aGL->Renderer() == gl::GLRenderer::SGX530 ||
aGL->Renderer() == gl::GLRenderer::SGX540) {
// SGX has a quirk that only TEXTURE_EXTERNAL works and any other value will
// result in black pixels when trying to draw from bound textures.
// Unfortunately, using TEXTURE_EXTERNAL on Adreno has a terrible effect on
// performance.
// See Bug 950050.
return LOCAL_GL_TEXTURE_EXTERNAL;
} else {
return TextureTargetForAndroidPixelFormat(aFormat);
}
}
void
GrallocTextureHostOGL::DestroyEGLImage()
{
// Only called when we want to get rid of the gralloc buffer, usually
// around the end of life of the TextureHost.
if (mEGLImage != EGL_NO_IMAGE && GetGLContext()) {
EGLImageDestroy(GetGLContext(), mEGLImage);
mEGLImage = EGL_NO_IMAGE;
}
}
void
GrallocTextureHostOGL::PrepareTextureSource(CompositableTextureSourceRef& aTextureSource)
{
// This happens during the layers transaction.
// All of the gralloc magic goes here. The only thing that happens externally
// and that is good to keep in mind is that when the TextureSource is deleted,
// it destroys its gl texture handle which is important for genlock.
// If this TextureHost's mGLTextureSource member is non-null, it means we are
// still bound to the TextureSource, in which case we can skip the driver
// overhead of binding the texture again (fEGLImageTargetTexture2D)
// As a result, if the TextureHost is used with several CompositableHosts,
// it will be bound to only one TextureSource, and we'll do the driver work
// only once, which is great. This means that all of the compositables that
// use this TextureHost will keep a reference to this TextureSource at least
// for the duration of this frame.
// If the compositable already has a TextureSource (the aTextureSource parameter),
// that is compatible and is not in use by several compositable, we try to
// attach to it. This has the effect of unlocking the previous TextureHost that
// we attached to the TextureSource (the previous frame)
// If the TextureSource used by the compositable is also used by other
// compositables (see NumCompositableRefs), we have to create a new TextureSource,
// because otherwise we would be modifying the content of every layer that uses
// the TextureSource in question, even thoug they don't use this TextureHost.
android::GraphicBuffer* graphicBuffer = GetGraphicBufferFromDesc(mGrallocHandle).get();
MOZ_ASSERT(graphicBuffer);
if (!graphicBuffer) {
mGLTextureSource = nullptr;
return;
}
if (mGLTextureSource && !mGLTextureSource->IsValid()) {
mGLTextureSource = nullptr;
}
if (mGLTextureSource) {
// We are already attached to a TextureSource, nothing to do except tell
// the compositable to use it.
aTextureSource = mGLTextureSource.get();
return;
}
gl::GLContext* gl = GetGLContext();
if (!gl || !gl->MakeCurrent()) {
mGLTextureSource = nullptr;
return;
}
if (mEGLImage == EGL_NO_IMAGE) {
gfx::IntSize cropSize(0, 0);
if (mCropSize != mSize) {
cropSize = mCropSize;
}
// Should only happen the first time.
mEGLImage = EGLImageCreateFromNativeBuffer(gl, graphicBuffer->getNativeBuffer(), cropSize);
}
GLenum textureTarget = GetTextureTarget(gl, graphicBuffer->getPixelFormat());
GLTextureSource* glSource = aTextureSource.get() ?
aTextureSource->AsSourceOGL()->AsGLTextureSource() : nullptr;
bool shouldCreateTextureSource = !glSource || !glSource->IsValid()
|| glSource->NumCompositableRefs() > 1
|| glSource->GetTextureTarget() != textureTarget;
if (shouldCreateTextureSource) {
GLuint textureHandle;
gl->fGenTextures(1, &textureHandle);
gl->fBindTexture(textureTarget, textureHandle);
gl->fTexParameteri(textureTarget, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
gl->fTexParameteri(textureTarget, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
gl->fEGLImageTargetTexture2D(textureTarget, mEGLImage);
mGLTextureSource = new GLTextureSource(mCompositor, textureHandle, textureTarget,
mSize, mFormat);
aTextureSource = mGLTextureSource.get();
} else {
gl->fBindTexture(textureTarget, glSource->GetTextureHandle());
gl->fEGLImageTargetTexture2D(textureTarget, mEGLImage);
glSource->SetSize(mSize);
glSource->SetFormat(mFormat);
mGLTextureSource = glSource;
}
}
void
GrallocTextureHostOGL::WaitAcquireFenceHandleSyncComplete()
{
if (!mAcquireFenceHandle.IsValid()) {
return;
}
RefPtr<FenceHandle::FdObj> fence = mAcquireFenceHandle.GetAndResetFdObj();
int fenceFd = fence->GetAndResetFd();
EGLint attribs[] = {
LOCAL_EGL_SYNC_NATIVE_FENCE_FD_ANDROID, fenceFd,
LOCAL_EGL_NONE
};
EGLSync sync = sEGLLibrary.fCreateSync(EGL_DISPLAY(),
LOCAL_EGL_SYNC_NATIVE_FENCE_ANDROID,
attribs);
if (!sync) {
NS_WARNING("failed to create native fence sync");
return;
}
// Wait sync complete with timeout.
// If a source of the fence becomes invalid because of error,
// fene complete is not signaled. See Bug 1061435.
EGLint status = sEGLLibrary.fClientWaitSync(EGL_DISPLAY(),
sync,
0,
400000000 /*400 msec*/);
if (status != LOCAL_EGL_CONDITION_SATISFIED) {
NS_ERROR("failed to wait native fence sync");
}
MOZ_ALWAYS_TRUE( sEGLLibrary.fDestroySync(EGL_DISPLAY(), sync) );
}
void
GrallocTextureHostOGL::SetCropRect(nsIntRect aCropRect)
{
MOZ_ASSERT(aCropRect.TopLeft() == gfx::IntPoint(0, 0));
MOZ_ASSERT(!aCropRect.IsEmpty());
MOZ_ASSERT(aCropRect.width <= mSize.width);
MOZ_ASSERT(aCropRect.height <= mSize.height);
gfx::IntSize cropSize(aCropRect.width, aCropRect.height);
if (mCropSize == cropSize) {
return;
}
mCropSize = cropSize;
mGLTextureSource = nullptr;
}
bool
GrallocTextureHostOGL::BindTextureSource(CompositableTextureSourceRef& aTextureSource)
{
// This happens at composition time.
// If mGLTextureSource is null it means PrepareTextureSource failed.
if (!mGLTextureSource) {
return false;
}
// If Prepare didn't fail, we expect our TextureSource to be the same as aTextureSource,
// otherwise it means something has fiddled with the TextureSource between Prepare and
// now.
MOZ_ASSERT(mGLTextureSource == aTextureSource);
aTextureSource = mGLTextureSource.get();
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
// Wait until it's ready.
WaitAcquireFenceHandleSyncComplete();
#endif
return true;
}
FenceHandle
GrallocTextureHostOGL::GetCompositorReleaseFence()
{
if (!mCompositor) {
return FenceHandle();
}
return mCompositor->GetReleaseFence();
}
} // namepsace layers
} // namepsace mozilla

View File

@@ -1,98 +0,0 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// * This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef MOZILLA_GFX_GRALLOCTEXTUREHOST_H
#define MOZILLA_GFX_GRALLOCTEXTUREHOST_H
#ifdef MOZ_WIDGET_GONK
#include "mozilla/layers/CompositorOGL.h"
#include "mozilla/layers/TextureHostOGL.h"
#include "mozilla/layers/ShadowLayerUtilsGralloc.h"
#include <ui/GraphicBuffer.h>
namespace mozilla {
namespace layers {
class GrallocTextureHostOGL : public TextureHost
{
friend class GrallocBufferActor;
public:
GrallocTextureHostOGL(TextureFlags aFlags,
const SurfaceDescriptorGralloc& aDescriptor);
virtual ~GrallocTextureHostOGL();
virtual bool Lock() override;
virtual void Unlock() override;
virtual void SetCompositor(Compositor* aCompositor) override;
virtual Compositor* GetCompositor() override { return mCompositor; }
virtual void DeallocateSharedData() override;
virtual void ForgetSharedData() override;
virtual void DeallocateDeviceData() override;
virtual gfx::SurfaceFormat GetFormat() const;
virtual gfx::IntSize GetSize() const override { return mCropSize; }
virtual LayerRenderState GetRenderState() override;
virtual void PrepareTextureSource(CompositableTextureSourceRef& aTextureSource) override;
virtual bool BindTextureSource(CompositableTextureSourceRef& aTextureSource) override;
virtual void UnbindTextureSource() override;
virtual already_AddRefed<gfx::DataSourceSurface> GetAsSurface() override;
virtual void WaitAcquireFenceHandleSyncComplete() override;
virtual void SetCropRect(nsIntRect aCropRect) override;
bool IsValid() const;
virtual const char* Name() override { return "GrallocTextureHostOGL"; }
gl::GLContext* GetGLContext() const { return mCompositor ? mCompositor->gl() : nullptr; }
virtual bool NeedsFenceHandle() override
{
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
return true;
#else
return false;
#endif
}
virtual FenceHandle GetCompositorReleaseFence() override;
virtual GrallocTextureHostOGL* AsGrallocTextureHostOGL() override { return this; }
private:
void DestroyEGLImage();
SurfaceDescriptorGralloc mGrallocHandle;
RefPtr<GLTextureSource> mGLTextureSource;
RefPtr<CompositorOGL> mCompositor;
// Size reported by the GraphicBuffer
gfx::IntSize mSize;
// Size reported by TextureClient, can be different in some cases (video?),
// used by LayerRenderState.
gfx::IntSize mCropSize;
gfx::SurfaceFormat mFormat;
EGLImage mEGLImage;
bool mIsOpaque;
};
} // namespace layers
} // namespace mozilla
#endif
#endif

View File

@@ -15,18 +15,12 @@
#include "mozilla/gfx/BaseSize.h" // for BaseSize
#include "mozilla/gfx/Logging.h" // for gfxCriticalError
#include "mozilla/layers/ISurfaceAllocator.h"
#include "mozilla/layers/GrallocTextureHost.h"
#include "nsRegion.h" // for nsIntRegion
#include "AndroidSurfaceTexture.h"
#include "GfxTexturesReporter.h" // for GfxTexturesReporter
#include "GLBlitTextureImageHelper.h"
#include "GeckoProfiler.h"
#ifdef MOZ_WIDGET_GONK
# include "GrallocImages.h" // for GrallocImage
# include "EGLImageHelpers.h"
#endif
#ifdef XP_MACOSX
#include "mozilla/layers/MacIOSurfaceTextureHostOGL.h"
#endif
@@ -85,15 +79,6 @@ CreateTextureHostOGL(const SurfaceDescriptor& aDesc,
}
#endif
#ifdef MOZ_WIDGET_GONK
case SurfaceDescriptor::TSurfaceDescriptorGralloc: {
const SurfaceDescriptorGralloc& desc =
aDesc.get_SurfaceDescriptorGralloc();
result = new GrallocTextureHostOGL(aFlags, desc);
break;
}
#endif
#ifdef GL_PROVIDER_GLX
case SurfaceDescriptor::TSurfaceDescriptorX11: {
const auto& desc = aDesc.get_SurfaceDescriptorX11();

View File

@@ -492,7 +492,7 @@ if CONFIG['MOZ_ENABLE_SKIA_GPU']:
'skia/src/gpu/GrResourceCache.cpp',
'skia/src/image/SkImage_Gpu.cpp',
]
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gonk'):
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android'):
UNIFIED_SOURCES += [
'skia/src/ports/SkDebug_android.cpp',
'skia/src/ports/SkOSFile_posix.cpp',
@@ -650,7 +650,7 @@ LOCAL_INCLUDES += [
'skia/src/utils/win',
]
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gonk'):
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android'):
DEFINES['SK_FONTHOST_CAIRO_STANDALONE'] = 0
if CONFIG['MOZ_WIDGET_TOOLKIT'] in {
@@ -659,7 +659,6 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] in {
'gtk2',
'gtk3',
'uikit',
'gonk',
}:
DEFINES['SK_FONTHOST_DOES_NOT_USE_FONTMGR'] = 1
@@ -730,7 +729,7 @@ if CONFIG['CLANG_CXX'] or CONFIG['CLANG_CL']:
'-Wno-unused-private-field',
]
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('gtk2', 'gtk3', 'android', 'gonk'):
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('gtk2', 'gtk3', 'android'):
CXXFLAGS += CONFIG['MOZ_CAIRO_CFLAGS']
CXXFLAGS += CONFIG['CAIRO_FT_CFLAGS']

View File

@@ -25,12 +25,6 @@
#include "cairo.h"
#include "VsyncSource.h"
#ifdef MOZ_WIDGET_GONK
#include <cutils/properties.h>
#include "mozilla/layers/CompositorBridgeParent.h"
#include "HwcComposer2D.h"
#endif
#include "ft2build.h"
#include FT_FREETYPE_H
#include FT_MODULE_H
@@ -105,12 +99,6 @@ gfxAndroidPlatform::gfxAndroidPlatform()
if (gfxPrefs::AndroidRGB16Force()) {
mOffscreenFormat = SurfaceFormat::R5G6B5_UINT16;
}
#ifdef MOZ_WIDGET_GONK
char propQemu[PROPERTY_VALUE_MAX];
property_get("ro.kernel.qemu", propQemu, "");
mIsInGonkEmulator = !strncmp(propQemu, "1", 1);
#endif
}
gfxAndroidPlatform::~gfxAndroidPlatform()
@@ -179,15 +167,9 @@ gfxAndroidPlatform::GetCommonFallbackFonts(uint32_t aCh, uint32_t aNextCh,
static const char kMotoyaLMaru[] = "MotoyaLMaru";
static const char kNotoSansCJKJP[] = "Noto Sans CJK JP";
static const char kNotoColorEmoji[] = "Noto Color Emoji";
#ifdef MOZ_WIDGET_GONK
static const char kFirefoxEmoji[] = "Firefox Emoji";
#endif
if (aNextCh == 0xfe0fu) {
// if char is followed by VS16, try for a color emoji glyph
#ifdef MOZ_WIDGET_GONK
aFontList.AppendElement(kFirefoxEmoji);
#endif
aFontList.AppendElement(kNotoColorEmoji);
}
@@ -195,9 +177,6 @@ gfxAndroidPlatform::GetCommonFallbackFonts(uint32_t aCh, uint32_t aNextCh,
uint32_t p = aCh >> 16;
if (p == 1) { // try color emoji font, unless VS15 (text style) present
if (aNextCh != 0xfe0fu && aNextCh != 0xfe0eu) {
#ifdef MOZ_WIDGET_GONK
aFontList.AppendElement(kFirefoxEmoji);
#endif
aFontList.AppendElement(kNotoColorEmoji);
}
}
@@ -328,12 +307,6 @@ gfxAndroidPlatform::FontHintingEnabled()
return false;
#endif // MOZ_WIDGET_ANDROID
#ifdef MOZ_WIDGET_GONK
// On B2G, the UX preference is currently to keep hinting disabled
// for all text (see bug 829523).
return false;
#endif
// Currently, we don't have any other targets, but if/when we do,
// decide how to handle them here.
@@ -354,104 +327,12 @@ gfxAndroidPlatform::RequiresLinearZoom()
return true;
#endif
#ifdef MOZ_WIDGET_GONK
// On B2G, we need linear zoom for the browser, but otherwise prefer
// the improved glyph spacing that results from respecting the device
// pixel resolution for glyph layout (see bug 816614).
return XRE_IsContentProcess() &&
ContentChild::GetSingleton()->IsForBrowser();
#endif
NS_NOTREACHED("oops, what platform is this?");
return gfxPlatform::RequiresLinearZoom();
}
#ifdef MOZ_WIDGET_GONK
class GonkVsyncSource final : public VsyncSource
{
public:
GonkVsyncSource()
{
}
virtual Display& GetGlobalDisplay() override
{
return mGlobalDisplay;
}
class GonkDisplay final : public VsyncSource::Display
{
public:
GonkDisplay() : mVsyncEnabled(false)
{
}
~GonkDisplay()
{
MOZ_ASSERT(NS_IsMainThread());
}
virtual void Shutdown() override
{
MOZ_ASSERT(NS_IsMainThread());
DisableVsync();
}
virtual void EnableVsync() override
{
MOZ_ASSERT(NS_IsMainThread());
if (IsVsyncEnabled()) {
return;
}
mVsyncEnabled = HwcComposer2D::GetInstance()->EnableVsync(true);
}
virtual void DisableVsync() override
{
MOZ_ASSERT(NS_IsMainThread());
if (!IsVsyncEnabled()) {
return;
}
mVsyncEnabled = HwcComposer2D::GetInstance()->EnableVsync(false);
}
virtual bool IsVsyncEnabled() override
{
MOZ_ASSERT(NS_IsMainThread());
return mVsyncEnabled;
}
private:
bool mVsyncEnabled;
}; // GonkDisplay
private:
virtual ~GonkVsyncSource()
{
}
GonkDisplay mGlobalDisplay;
}; // GonkVsyncSource
#endif
already_AddRefed<mozilla::gfx::VsyncSource>
gfxAndroidPlatform::CreateHardwareVsyncSource()
{
// Only enable true hardware vsync on kit-kat and L device. Jelly Bean has
// inaccurate hardware vsync so disable on JB. Android pre-JB doesn't have
// hardware vsync.
// L is android version 21, L-MR1 is 22, kit-kat is 19, 20 is kit-kat for
// wearables.
#if defined(MOZ_WIDGET_GONK) && (ANDROID_VERSION == 19 || ANDROID_VERSION >= 21)
RefPtr<GonkVsyncSource> vsyncSource = new GonkVsyncSource();
VsyncSource::Display& display = vsyncSource->GetGlobalDisplay();
display.EnableVsync();
if (!display.IsVsyncEnabled()) {
NS_WARNING("Error enabling gonk vsync. Falling back to software vsync");
return gfxPlatform::CreateHardwareVsyncSource();
}
display.DisableVsync();
return vsyncSource.forget();
#else
return gfxPlatform::CreateHardwareVsyncSource();
#endif
}

View File

@@ -68,10 +68,6 @@ public:
virtual already_AddRefed<mozilla::gfx::VsyncSource> CreateHardwareVsyncSource() override;
#ifdef MOZ_WIDGET_GONK
virtual bool IsInGonkEmulator() const { return mIsInGonkEmulator; }
#endif
virtual bool SupportsApzTouchInput() const override {
return true;
}
@@ -83,10 +79,6 @@ protected:
private:
gfxImageFormat mOffscreenFormat;
#ifdef MOZ_WIDGET_GONK
bool mIsInGonkEmulator;
#endif
};
#endif /* GFX_PLATFORM_ANDROID_H */

View File

@@ -1234,13 +1234,6 @@ gfxFT2FontList::FindFonts()
NS_RUNTIMEABORT("Could not read the system fonts directory");
}
#ifdef MOZ_WIDGET_GONK
// Look for fonts in /system/fonts/hidden and preload them to the
// user-font cache as data: URIs
root.AppendLiteral("/hidden");
FindFontsInDir(root, mFontNameCache.get(), FT2FontFamily::kHidden);
#endif
// Look for fonts stored in omnijar, unless we're on a low-memory
// device where we don't want to spend the RAM to decompress them.
// (Prefs may disable this, or force-enable it even with low memory.)
@@ -1564,9 +1557,7 @@ gfxFontFamily*
gfxFT2FontList::GetDefaultFontForPlatform(const gfxFontStyle* aStyle)
{
gfxFontFamily *ff = nullptr;
#ifdef MOZ_WIDGET_GONK
ff = FindFamily(NS_LITERAL_STRING("Fira Sans"));
#elif defined(MOZ_WIDGET_ANDROID)
#if defined(MOZ_WIDGET_ANDROID)
ff = FindFamily(NS_LITERAL_STRING("Roboto"));
if (!ff) {
ff = FindFamily(NS_LITERAL_STRING("Droid Sans"));

View File

@@ -6,7 +6,6 @@
#include "mozilla/layers/CompositorBridgeChild.h"
#include "mozilla/layers/CompositorThread.h"
#include "mozilla/layers/ImageBridgeChild.h"
#include "mozilla/layers/SharedBufferManagerChild.h"
#include "mozilla/layers/ISurfaceAllocator.h" // for GfxMemoryImageReporter
#include "mozilla/gfx/gfxVars.h"
#include "mozilla/gfx/GPUProcessManager.h"
@@ -97,10 +96,6 @@
#include "TexturePoolOGL.h"
#endif
#ifdef MOZ_WIDGET_GONK
#include "mozilla/layers/GrallocTextureHost.h"
#endif
#ifdef USE_SKIA
# ifdef __GNUC__
# pragma GCC diagnostic push
@@ -147,9 +142,6 @@ class mozilla::gl::SkiaGLGlue : public GenericAtomicRefCounted {
namespace mozilla {
namespace layers {
#ifdef MOZ_WIDGET_GONK
void InitGralloc();
#endif
void ShutdownTileCache();
} // namespace layers
} // namespace mozilla
@@ -753,10 +745,6 @@ gfxPlatform::Init()
TexturePoolOGL::Init();
#endif
#ifdef MOZ_WIDGET_GONK
mozilla::layers::InitGralloc();
#endif
Preferences::RegisterCallbackAndCall(RecordingPrefChanged, "gfx.2d.recording", nullptr);
CreateCMSOutputProfile();
@@ -919,9 +907,6 @@ gfxPlatform::InitLayersIPC()
if (XRE_IsParentProcess())
{
layers::CompositorThreadHolder::Start();
#ifdef MOZ_WIDGET_GONK
SharedBufferManagerChild::StartUp();
#endif
}
}
@@ -945,10 +930,6 @@ gfxPlatform::ShutdownLayersIPC()
layers::CompositorBridgeChild::ShutDown();
layers::ImageBridgeChild::ShutDown();
#ifdef MOZ_WIDGET_GONK
layers::SharedBufferManagerChild::ShutDown();
#endif
// This has to happen after shutting down the child protocols.
layers::CompositorThreadHolder::Shutdown();
} else {
@@ -1216,18 +1197,6 @@ gfxPlatform::ComputeTileSize()
// but I think everything should at least support 1024
w = h = clamped(int32_t(RoundUpPow2(screenSize.width)) / 4, 256, 1024);
}
#ifdef MOZ_WIDGET_GONK
android::sp<android::GraphicBuffer> alloc =
new android::GraphicBuffer(w, h, android::PIXEL_FORMAT_RGBA_8888,
android::GraphicBuffer::USAGE_SW_READ_OFTEN |
android::GraphicBuffer::USAGE_SW_WRITE_OFTEN |
android::GraphicBuffer::USAGE_HW_TEXTURE);
if (alloc.get()) {
w = alloc->getStride(); // We want the tiles to be gralloc stride aligned.
}
#endif
}
// Don't allow changing the tile size after we've set it.
@@ -1393,11 +1362,6 @@ gfxPlatform::PurgeSkiaGPUCache()
bool
gfxPlatform::HasEnoughTotalSystemMemoryForSkiaGL()
{
#ifdef MOZ_WIDGET_GONK
if (mTotalSystemMemory < 250*1024*1024) {
return false;
}
#endif
return true;
}

View File

@@ -74,23 +74,6 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
'gfxFT2Utils.cpp',
'PrintTargetPDF.cpp',
]
elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
EXPORTS += [
'gfxAndroidPlatform.h',
'gfxFT2FontBase.h',
'gfxFT2Fonts.h',
]
EXPORTS.mozilla.gfx += [
'PrintTargetPDF.h',
]
SOURCES += [
'gfxAndroidPlatform.cpp',
'gfxFT2FontBase.cpp',
'gfxFT2FontList.cpp',
'gfxFT2Fonts.cpp',
'gfxFT2Utils.cpp',
'PrintTargetPDF.cpp',
]
elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
EXPORTS += [
'gfxPlatformMac.h',
@@ -261,10 +244,7 @@ LOCAL_INCLUDES += [
'/dom/xml',
]
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
LOCAL_INCLUDES += ['/widget/gonk']
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gtk2', 'gtk3', 'gonk'):
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gtk2', 'gtk3'):
DEFINES['MOZ_ENABLE_FREETYPE'] = True
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
@@ -277,7 +257,7 @@ CXXFLAGS += CONFIG['TK_CFLAGS']
CFLAGS += CONFIG['MOZ_CAIRO_CFLAGS']
CFLAGS += CONFIG['TK_CFLAGS']
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gonk'):
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android'):
CXXFLAGS += CONFIG['CAIRO_FT_CFLAGS']
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('gtk2', 'gtk3'):

View File

@@ -18,7 +18,6 @@
#include "mozilla/layers/ImageBridgeChild.h"
#include "mozilla/layers/CompositorBridgeParent.h"
#include "mozilla/layers/SharedBufferManagerChild.h"
#include "prlink.h"