2013-05-01 09:03:25 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; 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 "ClientCanvasLayer.h"
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "GLContext.h" // for GLContext
|
|
|
|
#include "GLScreenBuffer.h" // for GLScreenBuffer
|
2013-08-22 11:11:51 +04:00
|
|
|
#include "GeckoProfiler.h" // for PROFILER_LABEL
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "SharedSurfaceEGL.h" // for SurfaceFactory_EGLImage
|
|
|
|
#include "SharedSurfaceGL.h" // for SurfaceFactory_GLTexture, etc
|
|
|
|
#include "SurfaceStream.h" // for SurfaceStream, etc
|
|
|
|
#include "SurfaceTypes.h" // for SurfaceStreamType
|
|
|
|
#include "ClientLayerManager.h" // for ClientLayerManager, etc
|
|
|
|
#include "mozilla/gfx/Point.h" // for IntSize
|
|
|
|
#include "mozilla/layers/CompositorTypes.h"
|
|
|
|
#include "mozilla/layers/LayersTypes.h"
|
|
|
|
#include "nsCOMPtr.h" // for already_AddRefed
|
|
|
|
#include "nsISupportsImpl.h" // for Layer::AddRef, etc
|
|
|
|
#include "nsRect.h" // for nsIntRect
|
|
|
|
#include "nsXULAppAPI.h" // for XRE_GetProcessType, etc
|
2013-05-27 18:12:13 +04:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
#include "SharedSurfaceGralloc.h"
|
|
|
|
#endif
|
2013-07-18 07:24:15 +04:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
#include "SharedSurfaceIO.h"
|
|
|
|
#endif
|
2013-05-01 09:03:25 +04:00
|
|
|
|
2013-12-09 06:53:26 +04:00
|
|
|
using namespace mozilla::gfx;
|
2013-05-01 09:03:25 +04:00
|
|
|
using namespace mozilla::gl;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
void
|
|
|
|
ClientCanvasLayer::Initialize(const Data& aData)
|
|
|
|
{
|
|
|
|
CopyableCanvasLayer::Initialize(aData);
|
2014-02-15 01:55:58 +04:00
|
|
|
|
2013-05-01 09:03:25 +04:00
|
|
|
mCanvasClient = nullptr;
|
|
|
|
|
|
|
|
if (mGLContext) {
|
|
|
|
GLScreenBuffer* screen = mGLContext->Screen();
|
2014-02-15 01:55:58 +04:00
|
|
|
|
|
|
|
SurfaceCaps caps = screen->Caps();
|
|
|
|
if (mStream) {
|
|
|
|
// The screen caps are irrelevant if we're using a separate stream
|
|
|
|
caps = GetContentFlags() & CONTENT_OPAQUE ? SurfaceCaps::ForRGB() : SurfaceCaps::ForRGBA();
|
|
|
|
}
|
|
|
|
|
2013-05-01 09:03:25 +04:00
|
|
|
SurfaceStreamType streamType =
|
|
|
|
SurfaceStream::ChooseGLStreamType(SurfaceStream::OffMainThread,
|
|
|
|
screen->PreserveBuffer());
|
|
|
|
SurfaceFactory_GL* factory = nullptr;
|
|
|
|
if (!mForceReadback) {
|
2014-02-15 01:55:58 +04:00
|
|
|
if (ClientManager()->AsShadowForwarder()->GetCompositorBackendType() == mozilla::layers::LAYERS_OPENGL) {
|
2014-01-10 22:55:24 +04:00
|
|
|
if (mGLContext->GetContextType() == GLContextType::EGL) {
|
2013-05-01 09:03:25 +04:00
|
|
|
bool isCrossProcess = !(XRE_GetProcessType() == GeckoProcessType_Default);
|
|
|
|
|
|
|
|
if (!isCrossProcess) {
|
|
|
|
// [Basic/OGL Layers, OMTC] WebGL layer init.
|
2014-02-15 01:55:58 +04:00
|
|
|
factory = SurfaceFactory_EGLImage::Create(mGLContext, caps);
|
2013-05-01 09:03:25 +04:00
|
|
|
} else {
|
|
|
|
// [Basic/OGL Layers, OOPC] WebGL layer init. (Out Of Process Compositing)
|
2013-05-27 18:12:13 +04:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2014-02-15 01:55:58 +04:00
|
|
|
factory = new SurfaceFactory_Gralloc(mGLContext, caps, ClientManager()->AsShadowForwarder());
|
2013-05-27 18:12:13 +04:00
|
|
|
#else
|
|
|
|
// we could do readback here maybe
|
|
|
|
NS_NOTREACHED("isCrossProcess but not on native B2G!");
|
|
|
|
#endif
|
2013-05-01 09:03:25 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// [Basic Layers, OMTC] WebGL layer init.
|
|
|
|
// Well, this *should* work...
|
2013-07-18 07:24:15 +04:00
|
|
|
#ifdef XP_MACOSX
|
2014-02-15 01:55:58 +04:00
|
|
|
factory = new SurfaceFactory_IOSurface(mGLContext, caps);
|
2013-07-18 07:24:15 +04:00
|
|
|
#else
|
2014-02-15 01:55:58 +04:00
|
|
|
factory = new SurfaceFactory_GLTexture(mGLContext, nullptr, caps);
|
2013-07-18 07:24:15 +04:00
|
|
|
#endif
|
2013-05-01 09:03:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (factory) {
|
2014-02-15 01:55:58 +04:00
|
|
|
if (mStream) {
|
|
|
|
// We're using a stream other than the one in the default screen
|
|
|
|
mFactory = factory;
|
|
|
|
|
|
|
|
gfx::IntSize size = gfx::IntSize(aData.mSize.width, aData.mSize.height);
|
|
|
|
mTextureSurface = SharedSurface_GLTexture::Create(mGLContext, mGLContext,
|
|
|
|
mGLContext->GetGLFormats(),
|
|
|
|
size, caps.alpha, aData.mTexID);
|
|
|
|
SharedSurface* producer = mStream->SwapProducer(mFactory, size);
|
|
|
|
if (!producer) {
|
|
|
|
// Fallback to basic factory
|
|
|
|
delete mFactory;
|
|
|
|
mFactory = new SurfaceFactory_Basic(mGLContext, caps);
|
|
|
|
producer = mStream->SwapProducer(mFactory, size);
|
|
|
|
MOZ_ASSERT(producer, "Failed to create initial canvas surface with basic factory");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
screen->Morph(factory, streamType);
|
|
|
|
}
|
2013-05-01 09:03:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ClientCanvasLayer::RenderLayer()
|
|
|
|
{
|
|
|
|
PROFILER_LABEL("ClientCanvasLayer", "Paint");
|
|
|
|
if (!IsDirty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GetMaskLayer()) {
|
|
|
|
ToClientLayer(GetMaskLayer())->RenderLayer();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mCanvasClient) {
|
2013-08-03 21:30:28 +04:00
|
|
|
TextureFlags flags = TEXTURE_IMMEDIATE_UPLOAD;
|
2013-05-01 09:03:25 +04:00
|
|
|
if (mNeedsYFlip) {
|
2013-08-06 21:36:35 +04:00
|
|
|
flags |= TEXTURE_NEEDS_Y_FLIP;
|
2013-05-01 09:03:25 +04:00
|
|
|
}
|
2013-05-27 18:12:13 +04:00
|
|
|
|
2013-08-20 03:39:56 +04:00
|
|
|
if (!mGLContext) {
|
2013-09-26 21:06:12 +04:00
|
|
|
// We don't support locking for buffer surfaces currently
|
|
|
|
flags |= TEXTURE_IMMEDIATE_UPLOAD;
|
2013-10-03 00:52:04 +04:00
|
|
|
} else {
|
|
|
|
// GLContext's SurfaceStream handles ownership itself,
|
|
|
|
// and doesn't require layers to do any deallocation.
|
|
|
|
flags |= TEXTURE_DEALLOCATE_CLIENT;
|
2013-05-27 18:12:13 +04:00
|
|
|
}
|
2013-08-02 05:12:15 +04:00
|
|
|
mCanvasClient = CanvasClient::CreateCanvasClient(GetCanvasClientType(),
|
2013-11-27 19:19:34 +04:00
|
|
|
ClientManager()->AsShadowForwarder(), flags);
|
2013-05-01 09:03:25 +04:00
|
|
|
if (!mCanvasClient) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (HasShadow()) {
|
|
|
|
mCanvasClient->Connect();
|
2013-11-27 19:19:34 +04:00
|
|
|
ClientManager()->AsShadowForwarder()->Attach(mCanvasClient, this);
|
2013-05-01 09:03:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FirePreTransactionCallback();
|
|
|
|
mCanvasClient->Update(gfx::IntSize(mBounds.width, mBounds.height), this);
|
|
|
|
|
|
|
|
FireDidTransactionCallback();
|
|
|
|
|
|
|
|
ClientManager()->Hold(this);
|
|
|
|
mCanvasClient->Updated();
|
2013-08-03 21:29:48 +04:00
|
|
|
mCanvasClient->OnTransaction();
|
2013-05-01 09:03:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<CanvasLayer>
|
|
|
|
ClientLayerManager::CreateCanvasLayer()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
|
|
|
|
nsRefPtr<ClientCanvasLayer> layer =
|
|
|
|
new ClientCanvasLayer(this);
|
|
|
|
CREATE_SHADOW(Canvas);
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|