2015-01-16 10:00:25 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim:set ts=4 sw=4 sts=4 et: */
|
2013-11-29 08:11:49 +04:00
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
/* This must occur *after* layers/PLayers.h to avoid typedefs conflicts. */
|
|
|
|
#include "LayerScope.h"
|
|
|
|
|
2015-01-15 01:24:09 +03:00
|
|
|
#include "nsAppRunner.h"
|
2013-11-29 08:11:49 +04:00
|
|
|
#include "Effects.h"
|
2016-05-22 23:31:11 +03:00
|
|
|
#include "mozilla/EndianUtils.h"
|
2015-01-29 22:02:00 +03:00
|
|
|
#include "mozilla/MathAlgorithms.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
#include "mozilla/TimeStamp.h"
|
|
|
|
|
2013-11-29 08:11:49 +04:00
|
|
|
#include "TexturePoolOGL.h"
|
2014-07-03 03:17:00 +04:00
|
|
|
#include "mozilla/layers/CompositorOGL.h"
|
2016-05-16 09:40:13 +03:00
|
|
|
#include "mozilla/layers/CompositorThread.h"
|
2014-07-03 03:17:00 +04:00
|
|
|
#include "mozilla/layers/LayerManagerComposite.h"
|
2013-11-29 08:11:49 +04:00
|
|
|
#include "mozilla/layers/TextureHostOGL.h"
|
|
|
|
|
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "gfxUtils.h"
|
2014-02-28 21:59:38 +04:00
|
|
|
#include "gfxPrefs.h"
|
2013-11-29 08:11:49 +04:00
|
|
|
#include "nsIWidget.h"
|
|
|
|
|
|
|
|
#include "GLContext.h"
|
|
|
|
#include "GLContextProvider.h"
|
2014-01-02 19:17:22 +04:00
|
|
|
#include "GLReadTexImageHelper.h"
|
2013-11-29 08:11:49 +04:00
|
|
|
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIConsoleService.h"
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include "mozilla/LinkedList.h"
|
2014-02-10 17:45:15 +04:00
|
|
|
#include "mozilla/Base64.h"
|
|
|
|
#include "mozilla/SHA1.h"
|
|
|
|
#include "mozilla/StaticPtr.h"
|
2013-11-29 08:11:49 +04:00
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsISocketTransport.h"
|
|
|
|
#include "nsIServerSocket.h"
|
2014-02-10 17:45:15 +04:00
|
|
|
#include "nsReadLine.h"
|
2013-11-29 08:11:49 +04:00
|
|
|
#include "nsNetCID.h"
|
|
|
|
#include "nsIOutputStream.h"
|
2014-02-10 17:45:15 +04:00
|
|
|
#include "nsIAsyncInputStream.h"
|
2013-11-29 08:11:49 +04:00
|
|
|
#include "nsIEventTarget.h"
|
|
|
|
#include "nsProxyRelease.h"
|
2015-04-14 09:57:42 +03:00
|
|
|
#include <list>
|
2013-11-29 08:11:49 +04:00
|
|
|
|
2014-04-07 12:58:03 +04:00
|
|
|
// Undo the damage done by mozzconf.h
|
|
|
|
#undef compress
|
|
|
|
#include "mozilla/Compression.h"
|
|
|
|
|
2014-07-10 07:16:00 +04:00
|
|
|
// Protocol buffer (generated automatically)
|
|
|
|
#include "protobuf/LayerScopePacket.pb.h"
|
2013-11-29 08:11:49 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
using namespace mozilla::Compression;
|
|
|
|
using namespace mozilla::gfx;
|
|
|
|
using namespace mozilla::gl;
|
|
|
|
using namespace mozilla;
|
2014-07-10 07:16:00 +04:00
|
|
|
using namespace layerscope;
|
2013-11-29 08:11:49 +04:00
|
|
|
|
|
|
|
class DebugDataSender;
|
2014-02-10 17:45:15 +04:00
|
|
|
class DebugGLData;
|
2013-11-29 08:11:49 +04:00
|
|
|
|
2015-01-29 22:02:00 +03:00
|
|
|
/*
|
|
|
|
* Manage Websocket connections
|
|
|
|
*/
|
2014-02-10 17:45:15 +04:00
|
|
|
class LayerScopeWebSocketManager {
|
|
|
|
public:
|
|
|
|
LayerScopeWebSocketManager();
|
|
|
|
~LayerScopeWebSocketManager();
|
|
|
|
|
|
|
|
void RemoveAllConnections()
|
|
|
|
{
|
2015-08-03 23:22:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
MutexAutoLock lock(mHandlerMutex);
|
2014-02-10 17:45:15 +04:00
|
|
|
mHandlers.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WriteAll(void *ptr, uint32_t size)
|
|
|
|
{
|
|
|
|
for (int32_t i = mHandlers.Length() - 1; i >= 0; --i) {
|
|
|
|
if (!mHandlers[i]->WriteToStream(ptr, size)) {
|
|
|
|
// Send failed, remove this handler
|
|
|
|
RemoveConnection(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsConnected()
|
|
|
|
{
|
2015-08-03 23:22:00 +03:00
|
|
|
// This funtion can be called in both main thread and compositor thread.
|
|
|
|
MutexAutoLock lock(mHandlerMutex);
|
2014-02-10 17:45:15 +04:00
|
|
|
return (mHandlers.Length() != 0) ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppendDebugData(DebugGLData *aDebugData);
|
2014-07-03 03:17:00 +04:00
|
|
|
void CleanDebugData();
|
2014-02-10 17:45:15 +04:00
|
|
|
void DispatchDebugData();
|
2015-08-03 23:22:00 +03:00
|
|
|
|
2014-02-10 17:45:15 +04:00
|
|
|
private:
|
2015-08-03 23:22:00 +03:00
|
|
|
void AddConnection(nsISocketTransport *aTransport)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aTransport);
|
|
|
|
|
|
|
|
MutexAutoLock lock(mHandlerMutex);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SocketHandler> temp = new SocketHandler();
|
2015-08-03 23:22:00 +03:00
|
|
|
temp->OpenStream(aTransport);
|
|
|
|
mHandlers.AppendElement(temp.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveConnection(uint32_t aIndex)
|
|
|
|
{
|
2015-08-24 09:00:00 +03:00
|
|
|
// TBD: RemoveConnection is executed on the compositor thread and
|
|
|
|
// AddConntection is executed on the main thread, which might be
|
|
|
|
// a problem if a user disconnect and connect readlly quickly at
|
|
|
|
// viewer side.
|
|
|
|
|
|
|
|
// We should dispatch RemoveConnection onto main thead.
|
2015-08-03 23:22:00 +03:00
|
|
|
MOZ_ASSERT(aIndex < mHandlers.Length());
|
|
|
|
|
|
|
|
MutexAutoLock lock(mHandlerMutex);
|
|
|
|
mHandlers.RemoveElementAt(aIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend class SocketListener;
|
|
|
|
class SocketListener : public nsIServerSocketListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
|
|
|
|
SocketListener() { }
|
|
|
|
|
|
|
|
/* nsIServerSocketListener */
|
2016-08-08 03:54:47 +03:00
|
|
|
NS_IMETHOD OnSocketAccepted(nsIServerSocket *aServ,
|
|
|
|
nsISocketTransport *aTransport) override;
|
|
|
|
NS_IMETHOD OnStopListening(nsIServerSocket *aServ,
|
|
|
|
nsresult aStatus) override
|
2015-08-03 23:22:00 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
virtual ~SocketListener() { }
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This class handle websocket protocol which included
|
|
|
|
* handshake and data frame's header
|
|
|
|
*/
|
|
|
|
class SocketHandler : public nsIInputStreamCallback {
|
|
|
|
public:
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
|
|
|
|
SocketHandler()
|
|
|
|
: mState(NoHandshake)
|
|
|
|
, mConnected(false)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
void OpenStream(nsISocketTransport* aTransport);
|
|
|
|
bool WriteToStream(void *aPtr, uint32_t aSize);
|
|
|
|
|
|
|
|
// nsIInputStreamCallback
|
2016-08-08 03:54:47 +03:00
|
|
|
NS_IMETHOD OnInputStreamReady(nsIAsyncInputStream *aStream) override;
|
2015-08-03 23:22:00 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~SocketHandler() { CloseConnection(); }
|
|
|
|
|
|
|
|
void ReadInputStreamData(nsTArray<nsCString>& aProtocolString);
|
|
|
|
bool WebSocketHandshake(nsTArray<nsCString>& aProtocolString);
|
|
|
|
void ApplyMask(uint32_t aMask, uint8_t *aData, uint64_t aLen);
|
|
|
|
bool HandleDataFrame(uint8_t *aData, uint32_t aSize);
|
|
|
|
void CloseConnection();
|
|
|
|
|
|
|
|
nsresult HandleSocketMessage(nsIAsyncInputStream *aStream);
|
|
|
|
nsresult ProcessInput(uint8_t *aBuffer, uint32_t aCount);
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum SocketStateType {
|
|
|
|
NoHandshake,
|
|
|
|
HandshakeSuccess,
|
|
|
|
HandshakeFailed
|
|
|
|
};
|
|
|
|
SocketStateType mState;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIOutputStream> mOutputStream;
|
|
|
|
nsCOMPtr<nsIAsyncInputStream> mInputStream;
|
|
|
|
nsCOMPtr<nsISocketTransport> mTransport;
|
|
|
|
bool mConnected;
|
|
|
|
};
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<SocketHandler> > mHandlers;
|
2015-08-03 23:22:00 +03:00
|
|
|
nsCOMPtr<nsIThread> mDebugSenderThread;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DebugDataSender> mCurrentSender;
|
2015-08-03 23:22:00 +03:00
|
|
|
nsCOMPtr<nsIServerSocket> mServerSocket;
|
|
|
|
|
|
|
|
// Keep mHandlers accessing thread safe.
|
|
|
|
Mutex mHandlerMutex;
|
2014-02-10 17:45:15 +04:00
|
|
|
};
|
|
|
|
|
2015-08-03 23:22:00 +03:00
|
|
|
NS_IMPL_ISUPPORTS(LayerScopeWebSocketManager::SocketListener,
|
|
|
|
nsIServerSocketListener);
|
|
|
|
NS_IMPL_ISUPPORTS(LayerScopeWebSocketManager::SocketHandler,
|
|
|
|
nsIInputStreamCallback);
|
|
|
|
|
2015-06-02 13:21:00 +03:00
|
|
|
class DrawSession {
|
|
|
|
public:
|
|
|
|
DrawSession()
|
|
|
|
: mOffsetX(0.0)
|
|
|
|
, mOffsetY(0.0)
|
|
|
|
, mRects(0)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
float mOffsetX;
|
|
|
|
float mOffsetY;
|
|
|
|
gfx::Matrix4x4 mMVMatrix;
|
|
|
|
size_t mRects;
|
|
|
|
gfx::Rect mLayerRects[4];
|
2015-08-03 09:11:00 +03:00
|
|
|
gfx::Rect mTextureRects[4];
|
|
|
|
std::list<GLuint> mTexIDs;
|
2015-06-02 13:21:00 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class ContentMonitor {
|
|
|
|
public:
|
|
|
|
using THArray = nsTArray<const TextureHost *>;
|
|
|
|
|
|
|
|
// Notify the content of a TextureHost was changed.
|
|
|
|
void SetChangedHost(const TextureHost* host) {
|
|
|
|
if (THArray::NoIndex == mChangedHosts.IndexOf(host)) {
|
|
|
|
mChangedHosts.AppendElement(host);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear changed flag of a host.
|
|
|
|
void ClearChangedHost(const TextureHost* host) {
|
|
|
|
if (THArray::NoIndex != mChangedHosts.IndexOf(host)) {
|
|
|
|
mChangedHosts.RemoveElement(host);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return true iff host is a new one or the content of it had been changed.
|
|
|
|
bool IsChangedOrNew(const TextureHost* host) {
|
|
|
|
if (THArray::NoIndex == mSeenHosts.IndexOf(host)) {
|
|
|
|
mSeenHosts.AppendElement(host);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (decltype(mChangedHosts)::NoIndex != mChangedHosts.IndexOf(host)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Empty() {
|
|
|
|
mSeenHosts.SetLength(0);
|
|
|
|
mChangedHosts.SetLength(0);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
THArray mSeenHosts;
|
|
|
|
THArray mChangedHosts;
|
|
|
|
};
|
|
|
|
|
2015-08-03 23:22:00 +03:00
|
|
|
/*
|
|
|
|
* Hold all singleton objects used by LayerScope.
|
|
|
|
*/
|
2015-06-02 13:21:00 +03:00
|
|
|
class LayerScopeManager
|
2014-07-03 03:17:00 +04:00
|
|
|
{
|
|
|
|
public:
|
2015-06-02 13:21:00 +03:00
|
|
|
void CreateServerSocket()
|
2014-07-03 03:17:00 +04:00
|
|
|
{
|
2015-06-02 13:21:00 +03:00
|
|
|
// WebSocketManager must be created on the main thread.
|
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
mWebSocketManager = mozilla::MakeUnique<LayerScopeWebSocketManager>();
|
|
|
|
} else {
|
|
|
|
// Dispatch creation to main thread, and make sure we
|
|
|
|
// dispatch this only once after booting
|
|
|
|
static bool dispatched = false;
|
|
|
|
if (dispatched) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DebugOnly<nsresult> rv =
|
|
|
|
NS_DispatchToMainThread(new CreateServerSocketRunnable(this));
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv),
|
|
|
|
"Failed to dispatch WebSocket Creation to main thread");
|
|
|
|
dispatched = true;
|
2014-07-03 03:17:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-02 13:21:00 +03:00
|
|
|
void DestroyServerSocket()
|
2014-07-03 03:17:00 +04:00
|
|
|
{
|
|
|
|
// Destroy Web Server Socket
|
2015-06-02 13:21:00 +03:00
|
|
|
if (mWebSocketManager) {
|
|
|
|
mWebSocketManager->RemoveAllConnections();
|
2014-07-03 03:17:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-02 13:21:00 +03:00
|
|
|
LayerScopeWebSocketManager* GetSocketManager()
|
|
|
|
{
|
|
|
|
return mWebSocketManager.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
ContentMonitor* GetContentMonitor()
|
2014-07-03 03:17:00 +04:00
|
|
|
{
|
2015-06-02 13:21:00 +03:00
|
|
|
if (!mContentMonitor.get()) {
|
|
|
|
mContentMonitor = mozilla::MakeUnique<ContentMonitor>();
|
|
|
|
}
|
|
|
|
|
|
|
|
return mContentMonitor.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NewDrawSession() {
|
|
|
|
mSession = mozilla::MakeUnique<DrawSession>();
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawSession& CurrentSession() {
|
|
|
|
return *mSession;
|
2014-07-03 03:17:00 +04:00
|
|
|
}
|
|
|
|
|
2015-08-03 09:11:00 +03:00
|
|
|
void SetPixelScale(double scale) {
|
|
|
|
mScale = scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
double GetPixelScale() const {
|
|
|
|
return mScale;
|
|
|
|
}
|
|
|
|
|
|
|
|
LayerScopeManager()
|
|
|
|
: mScale(1.0)
|
|
|
|
{
|
|
|
|
}
|
2014-07-03 03:17:00 +04:00
|
|
|
private:
|
2015-06-02 13:21:00 +03:00
|
|
|
friend class CreateServerSocketRunnable;
|
2016-04-26 03:23:21 +03:00
|
|
|
class CreateServerSocketRunnable : public Runnable
|
2015-06-02 13:21:00 +03:00
|
|
|
{
|
|
|
|
public:
|
2017-06-12 22:34:10 +03:00
|
|
|
explicit CreateServerSocketRunnable(LayerScopeManager* aLayerScopeManager)
|
|
|
|
: Runnable("layers::LayerScopeManager::CreateServerSocketRunnable")
|
|
|
|
, mLayerScopeManager(aLayerScopeManager)
|
|
|
|
{
|
2015-06-02 13:21:00 +03:00
|
|
|
}
|
2016-08-08 05:18:10 +03:00
|
|
|
NS_IMETHOD Run() override {
|
2015-06-02 13:21:00 +03:00
|
|
|
mLayerScopeManager->mWebSocketManager =
|
|
|
|
mozilla::MakeUnique<LayerScopeWebSocketManager>();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
LayerScopeManager* mLayerScopeManager;
|
|
|
|
};
|
|
|
|
|
|
|
|
mozilla::UniquePtr<LayerScopeWebSocketManager> mWebSocketManager;
|
|
|
|
mozilla::UniquePtr<DrawSession> mSession;
|
|
|
|
mozilla::UniquePtr<ContentMonitor> mContentMonitor;
|
2015-08-03 09:11:00 +03:00
|
|
|
double mScale;
|
2014-07-03 03:17:00 +04:00
|
|
|
};
|
|
|
|
|
2015-06-02 13:21:00 +03:00
|
|
|
LayerScopeManager gLayerScopeManager;
|
2013-11-29 08:11:49 +04:00
|
|
|
|
2015-10-20 03:05:00 +03:00
|
|
|
/*
|
|
|
|
* The static helper functions that set data into the packet
|
|
|
|
* 1. DumpRect
|
|
|
|
* 2. DumpFilter
|
|
|
|
*/
|
|
|
|
template<typename T>
|
|
|
|
static void DumpRect(T* aPacketRect, const Rect& aRect)
|
|
|
|
{
|
|
|
|
aPacketRect->set_x(aRect.x);
|
|
|
|
aPacketRect->set_y(aRect.y);
|
2017-08-14 15:29:28 +03:00
|
|
|
aPacketRect->set_w(aRect.Width());
|
|
|
|
aPacketRect->set_h(aRect.Height());
|
2015-10-20 03:05:00 +03:00
|
|
|
}
|
|
|
|
|
2016-05-25 19:01:18 +03:00
|
|
|
static void DumpFilter(TexturePacket* aTexturePacket,
|
|
|
|
const SamplingFilter aSamplingFilter)
|
2015-10-20 03:05:00 +03:00
|
|
|
{
|
2016-05-25 19:01:18 +03:00
|
|
|
switch (aSamplingFilter) {
|
|
|
|
case SamplingFilter::GOOD:
|
2015-10-20 03:05:00 +03:00
|
|
|
aTexturePacket->set_mfilter(TexturePacket::GOOD);
|
|
|
|
break;
|
2016-05-25 19:01:18 +03:00
|
|
|
case SamplingFilter::LINEAR:
|
2015-10-20 03:05:00 +03:00
|
|
|
aTexturePacket->set_mfilter(TexturePacket::LINEAR);
|
|
|
|
break;
|
2016-05-25 19:01:18 +03:00
|
|
|
case SamplingFilter::POINT:
|
2015-10-20 03:05:00 +03:00
|
|
|
aTexturePacket->set_mfilter(TexturePacket::POINT);
|
|
|
|
break;
|
|
|
|
default:
|
2016-05-25 19:01:18 +03:00
|
|
|
MOZ_ASSERT(false, "Can't dump unexpected mSamplingFilter to texture packet!");
|
2015-10-20 03:05:00 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-10 07:16:00 +04:00
|
|
|
/*
|
|
|
|
* DebugGLData is the base class of
|
|
|
|
* 1. DebugGLFrameStatusData (Frame start/end packet)
|
|
|
|
* 2. DebugGLColorData (Color data packet)
|
|
|
|
* 3. DebugGLTextureData (Texture data packet)
|
2015-01-16 10:00:25 +03:00
|
|
|
* 4. DebugGLLayersData (Layers Tree data packet)
|
|
|
|
* 5. DebugGLMetaData (Meta data packet)
|
2014-07-10 07:16:00 +04:00
|
|
|
*/
|
|
|
|
class DebugGLData: public LinkedListElement<DebugGLData> {
|
2013-11-29 08:11:49 +04:00
|
|
|
public:
|
2014-08-20 08:55:14 +04:00
|
|
|
explicit DebugGLData(Packet::DataType aDataType)
|
2014-07-10 07:16:00 +04:00
|
|
|
: mDataType(aDataType)
|
|
|
|
{ }
|
2013-11-29 08:11:49 +04:00
|
|
|
|
|
|
|
virtual ~DebugGLData() { }
|
|
|
|
|
2014-07-10 07:16:00 +04:00
|
|
|
virtual bool Write() = 0;
|
2013-11-29 08:11:49 +04:00
|
|
|
|
2015-05-22 12:36:00 +03:00
|
|
|
protected:
|
2014-07-10 07:16:00 +04:00
|
|
|
static bool WriteToStream(Packet& aPacket) {
|
2015-06-02 13:21:00 +03:00
|
|
|
if (!gLayerScopeManager.GetSocketManager())
|
2014-07-10 07:16:00 +04:00
|
|
|
return true;
|
2013-11-29 08:11:49 +04:00
|
|
|
|
2014-07-10 07:16:00 +04:00
|
|
|
uint32_t size = aPacket.ByteSize();
|
2014-07-28 00:32:00 +04:00
|
|
|
auto data = MakeUnique<uint8_t[]>(size);
|
2014-07-21 23:12:00 +04:00
|
|
|
aPacket.SerializeToArray(data.get(), size);
|
2015-06-02 13:21:00 +03:00
|
|
|
return gLayerScopeManager.GetSocketManager()->WriteAll(data.get(), size);
|
2014-07-10 07:16:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Packet::DataType mDataType;
|
|
|
|
};
|
|
|
|
|
2015-05-22 12:36:00 +03:00
|
|
|
class DebugGLFrameStatusData final: public DebugGLData
|
2014-07-10 07:16:00 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
DebugGLFrameStatusData(Packet::DataType aDataType,
|
|
|
|
int64_t aValue)
|
|
|
|
: DebugGLData(aDataType),
|
|
|
|
mFrameStamp(aValue)
|
2013-11-29 08:11:49 +04:00
|
|
|
{ }
|
|
|
|
|
2014-08-20 08:55:14 +04:00
|
|
|
explicit DebugGLFrameStatusData(Packet::DataType aDataType)
|
2014-07-10 07:16:00 +04:00
|
|
|
: DebugGLData(aDataType),
|
|
|
|
mFrameStamp(0)
|
|
|
|
{ }
|
2013-11-29 08:11:49 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool Write() override {
|
2014-07-10 07:16:00 +04:00
|
|
|
Packet packet;
|
|
|
|
packet.set_type(mDataType);
|
2013-11-29 08:11:49 +04:00
|
|
|
|
2014-07-28 00:32:00 +04:00
|
|
|
FramePacket* fp = packet.mutable_frame();
|
|
|
|
fp->set_value(static_cast<uint64_t>(mFrameStamp));
|
2013-11-29 08:11:49 +04:00
|
|
|
|
2015-08-03 09:11:00 +03:00
|
|
|
fp->set_scale(gLayerScopeManager.GetPixelScale());
|
|
|
|
|
2015-05-22 12:36:00 +03:00
|
|
|
return WriteToStream(packet);
|
2013-11-29 08:11:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-07-10 07:16:00 +04:00
|
|
|
int64_t mFrameStamp;
|
2013-11-29 08:11:49 +04:00
|
|
|
};
|
|
|
|
|
2015-05-22 12:36:00 +03:00
|
|
|
class DebugGLTextureData final: public DebugGLData {
|
2013-11-29 08:11:49 +04:00
|
|
|
public:
|
2014-07-03 03:17:00 +04:00
|
|
|
DebugGLTextureData(GLContext* cx,
|
|
|
|
void* layerRef,
|
|
|
|
GLenum target,
|
|
|
|
GLuint name,
|
2015-09-30 00:32:00 +03:00
|
|
|
DataSourceSurface* img,
|
2015-10-20 03:05:00 +03:00
|
|
|
bool aIsMask,
|
|
|
|
UniquePtr<Packet> aPacket)
|
2014-07-10 07:16:00 +04:00
|
|
|
: DebugGLData(Packet::TEXTURE),
|
2015-05-22 12:36:00 +03:00
|
|
|
mLayerRef(reinterpret_cast<uint64_t>(layerRef)),
|
2013-11-29 08:11:49 +04:00
|
|
|
mTarget(target),
|
|
|
|
mName(name),
|
2014-07-10 07:16:00 +04:00
|
|
|
mContextAddress(reinterpret_cast<intptr_t>(cx)),
|
2015-09-30 00:32:00 +03:00
|
|
|
mDatasize(0),
|
2015-10-20 03:05:00 +03:00
|
|
|
mIsMask(aIsMask),
|
|
|
|
mPacket(Move(aPacket))
|
2014-07-03 03:17:00 +04:00
|
|
|
{
|
|
|
|
// pre-packing
|
|
|
|
// DataSourceSurface may have locked buffer,
|
|
|
|
// so we should compress now, and then it could
|
|
|
|
// be unlocked outside.
|
|
|
|
pack(img);
|
|
|
|
}
|
2013-11-29 08:11:49 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool Write() override {
|
2015-10-20 03:05:00 +03:00
|
|
|
return WriteToStream(*mPacket);
|
2013-11-29 08:11:49 +04:00
|
|
|
}
|
|
|
|
|
2014-07-03 03:17:00 +04:00
|
|
|
private:
|
|
|
|
void pack(DataSourceSurface* aImage) {
|
2015-10-20 03:05:00 +03:00
|
|
|
mPacket->set_type(mDataType);
|
2014-07-10 07:16:00 +04:00
|
|
|
|
2015-10-20 03:05:00 +03:00
|
|
|
TexturePacket* tp = mPacket->mutable_texture();
|
2015-05-22 12:36:00 +03:00
|
|
|
tp->set_layerref(mLayerRef);
|
2014-07-10 07:16:00 +04:00
|
|
|
tp->set_name(mName);
|
|
|
|
tp->set_target(mTarget);
|
|
|
|
tp->set_dataformat(LOCAL_GL_RGBA);
|
|
|
|
tp->set_glcontext(static_cast<uint64_t>(mContextAddress));
|
2015-09-30 00:32:00 +03:00
|
|
|
tp->set_ismask(mIsMask);
|
2014-07-03 03:17:00 +04:00
|
|
|
|
|
|
|
if (aImage) {
|
2014-07-10 07:16:00 +04:00
|
|
|
tp->set_width(aImage->GetSize().width);
|
|
|
|
tp->set_height(aImage->GetSize().height);
|
|
|
|
tp->set_stride(aImage->Stride());
|
|
|
|
|
|
|
|
mDatasize = aImage->GetSize().height * aImage->Stride();
|
|
|
|
|
2014-07-28 00:32:00 +04:00
|
|
|
auto compresseddata = MakeUnique<char[]>(LZ4::maxCompressedSize(mDatasize));
|
2014-07-21 23:12:00 +04:00
|
|
|
if (compresseddata) {
|
2014-07-03 03:17:00 +04:00
|
|
|
int ndatasize = LZ4::compress((char*)aImage->GetData(),
|
2014-07-10 07:16:00 +04:00
|
|
|
mDatasize,
|
2014-07-21 23:12:00 +04:00
|
|
|
compresseddata.get());
|
2014-07-03 03:17:00 +04:00
|
|
|
if (ndatasize > 0) {
|
|
|
|
mDatasize = ndatasize;
|
2014-07-10 07:16:00 +04:00
|
|
|
tp->set_dataformat((1 << 16 | tp->dataformat()));
|
2014-07-21 23:12:00 +04:00
|
|
|
tp->set_data(compresseddata.get(), mDatasize);
|
2014-07-03 03:17:00 +04:00
|
|
|
} else {
|
|
|
|
NS_WARNING("Compress data failed");
|
2014-07-10 07:16:00 +04:00
|
|
|
tp->set_data(aImage->GetData(), mDatasize);
|
2014-07-03 03:17:00 +04:00
|
|
|
}
|
|
|
|
} else {
|
2014-07-10 07:16:00 +04:00
|
|
|
NS_WARNING("Couldn't new compressed data.");
|
|
|
|
tp->set_data(aImage->GetData(), mDatasize);
|
2014-07-03 03:17:00 +04:00
|
|
|
}
|
|
|
|
} else {
|
2014-07-10 07:16:00 +04:00
|
|
|
tp->set_width(0);
|
|
|
|
tp->set_height(0);
|
|
|
|
tp->set_stride(0);
|
2014-07-03 03:17:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-29 08:11:49 +04:00
|
|
|
protected:
|
2015-05-22 12:36:00 +03:00
|
|
|
uint64_t mLayerRef;
|
2013-11-29 08:11:49 +04:00
|
|
|
GLenum mTarget;
|
|
|
|
GLuint mName;
|
2014-07-10 07:16:00 +04:00
|
|
|
intptr_t mContextAddress;
|
|
|
|
uint32_t mDatasize;
|
2015-09-30 00:32:00 +03:00
|
|
|
bool mIsMask;
|
2014-07-03 03:17:00 +04:00
|
|
|
|
|
|
|
// Packet data
|
2015-10-20 03:05:00 +03:00
|
|
|
UniquePtr<Packet> mPacket;
|
2013-11-29 08:11:49 +04:00
|
|
|
};
|
|
|
|
|
2015-05-22 12:36:00 +03:00
|
|
|
class DebugGLColorData final: public DebugGLData {
|
2013-11-29 08:11:49 +04:00
|
|
|
public:
|
2014-07-10 07:16:00 +04:00
|
|
|
DebugGLColorData(void* layerRef,
|
2015-09-25 05:18:03 +03:00
|
|
|
const Color& color,
|
2014-07-10 07:16:00 +04:00
|
|
|
int width,
|
|
|
|
int height)
|
|
|
|
: DebugGLData(Packet::COLOR),
|
2015-05-22 12:36:00 +03:00
|
|
|
mLayerRef(reinterpret_cast<uint64_t>(layerRef)),
|
2015-09-25 05:18:03 +03:00
|
|
|
mColor(color.ToABGR()),
|
2013-11-29 08:11:49 +04:00
|
|
|
mSize(width, height)
|
|
|
|
{ }
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool Write() override {
|
2014-07-10 07:16:00 +04:00
|
|
|
Packet packet;
|
|
|
|
packet.set_type(mDataType);
|
2013-11-29 08:11:49 +04:00
|
|
|
|
2014-07-28 00:32:00 +04:00
|
|
|
ColorPacket* cp = packet.mutable_color();
|
2015-05-22 12:36:00 +03:00
|
|
|
cp->set_layerref(mLayerRef);
|
2014-07-10 07:16:00 +04:00
|
|
|
cp->set_color(mColor);
|
|
|
|
cp->set_width(mSize.width);
|
|
|
|
cp->set_height(mSize.height);
|
2013-11-29 08:11:49 +04:00
|
|
|
|
2015-05-22 12:36:00 +03:00
|
|
|
return WriteToStream(packet);
|
2013-11-29 08:11:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-05-22 12:36:00 +03:00
|
|
|
uint64_t mLayerRef;
|
2013-11-29 08:11:49 +04:00
|
|
|
uint32_t mColor;
|
2015-06-03 14:45:24 +03:00
|
|
|
IntSize mSize;
|
2013-11-29 08:11:49 +04:00
|
|
|
};
|
|
|
|
|
2015-05-22 12:36:00 +03:00
|
|
|
class DebugGLLayersData final: public DebugGLData {
|
2014-07-28 00:32:00 +04:00
|
|
|
public:
|
2014-08-20 08:55:14 +04:00
|
|
|
explicit DebugGLLayersData(UniquePtr<Packet> aPacket)
|
2014-07-28 00:32:00 +04:00
|
|
|
: DebugGLData(Packet::LAYERS),
|
|
|
|
mPacket(Move(aPacket))
|
|
|
|
{ }
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool Write() override {
|
2014-07-28 00:32:00 +04:00
|
|
|
mPacket->set_type(mDataType);
|
2015-05-22 12:36:00 +03:00
|
|
|
return WriteToStream(*mPacket);
|
2014-07-28 00:32:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
UniquePtr<Packet> mPacket;
|
|
|
|
};
|
|
|
|
|
2015-05-22 12:36:00 +03:00
|
|
|
class DebugGLMetaData final: public DebugGLData
|
2015-01-16 10:00:25 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
DebugGLMetaData(Packet::DataType aDataType,
|
|
|
|
bool aValue)
|
|
|
|
: DebugGLData(aDataType),
|
|
|
|
mComposedByHwc(aValue)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
explicit DebugGLMetaData(Packet::DataType aDataType)
|
|
|
|
: DebugGLData(aDataType),
|
|
|
|
mComposedByHwc(false)
|
|
|
|
{ }
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool Write() override {
|
2015-01-16 10:00:25 +03:00
|
|
|
Packet packet;
|
|
|
|
packet.set_type(mDataType);
|
|
|
|
|
|
|
|
MetaPacket* mp = packet.mutable_meta();
|
|
|
|
mp->set_composedbyhwc(mComposedByHwc);
|
|
|
|
|
2015-05-22 12:36:00 +03:00
|
|
|
return WriteToStream(packet);
|
2015-01-16 10:00:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool mComposedByHwc;
|
|
|
|
};
|
|
|
|
|
2015-05-22 12:36:00 +03:00
|
|
|
class DebugGLDrawData final: public DebugGLData {
|
|
|
|
public:
|
|
|
|
DebugGLDrawData(float aOffsetX,
|
|
|
|
float aOffsetY,
|
|
|
|
const gfx::Matrix4x4& aMVMatrix,
|
|
|
|
size_t aRects,
|
|
|
|
const gfx::Rect* aLayerRects,
|
2015-08-03 09:11:00 +03:00
|
|
|
const gfx::Rect* aTextureRects,
|
2017-07-28 20:29:40 +03:00
|
|
|
const std::list<GLuint>& aTexIDs,
|
2015-05-22 12:36:00 +03:00
|
|
|
void* aLayerRef)
|
|
|
|
: DebugGLData(Packet::DRAW),
|
|
|
|
mOffsetX(aOffsetX),
|
|
|
|
mOffsetY(aOffsetY),
|
|
|
|
mMVMatrix(aMVMatrix),
|
|
|
|
mRects(aRects),
|
2015-08-03 09:11:00 +03:00
|
|
|
mTexIDs(aTexIDs),
|
2015-05-22 12:36:00 +03:00
|
|
|
mLayerRef(reinterpret_cast<uint64_t>(aLayerRef))
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < mRects; i++){
|
|
|
|
mLayerRects[i] = aLayerRects[i];
|
2015-08-03 09:11:00 +03:00
|
|
|
mTextureRects[i] = aTextureRects[i];
|
2015-05-22 12:36:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool Write() override {
|
|
|
|
Packet packet;
|
|
|
|
packet.set_type(mDataType);
|
|
|
|
|
|
|
|
DrawPacket* dp = packet.mutable_draw();
|
|
|
|
dp->set_layerref(mLayerRef);
|
|
|
|
|
|
|
|
dp->set_offsetx(mOffsetX);
|
|
|
|
dp->set_offsety(mOffsetY);
|
|
|
|
|
|
|
|
auto element = reinterpret_cast<Float *>(&mMVMatrix);
|
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
dp->add_mvmatrix(*element++);
|
|
|
|
}
|
|
|
|
dp->set_totalrects(mRects);
|
|
|
|
|
|
|
|
MOZ_ASSERT(mRects > 0 && mRects < 4);
|
|
|
|
for (size_t i = 0; i < mRects; i++) {
|
2015-08-03 09:11:00 +03:00
|
|
|
// Vertex
|
2015-10-20 03:05:00 +03:00
|
|
|
DumpRect(dp->add_layerrect(), mLayerRects[i]);
|
2015-08-03 09:11:00 +03:00
|
|
|
// UV
|
2015-10-20 03:05:00 +03:00
|
|
|
DumpRect(dp->add_texturerect(), mTextureRects[i]);
|
2015-08-03 09:11:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for (GLuint texId: mTexIDs) {
|
|
|
|
dp->add_texids(texId);
|
2015-05-22 12:36:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return WriteToStream(packet);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
float mOffsetX;
|
|
|
|
float mOffsetY;
|
|
|
|
gfx::Matrix4x4 mMVMatrix;
|
|
|
|
size_t mRects;
|
|
|
|
gfx::Rect mLayerRects[4];
|
2015-08-03 09:11:00 +03:00
|
|
|
gfx::Rect mTextureRects[4];
|
|
|
|
std::list<GLuint> mTexIDs;
|
2015-05-22 12:36:00 +03:00
|
|
|
uint64_t mLayerRef;
|
|
|
|
};
|
2015-01-16 10:00:25 +03:00
|
|
|
|
2015-08-24 09:00:00 +03:00
|
|
|
class DebugDataSender
|
2013-11-29 08:11:49 +04:00
|
|
|
{
|
|
|
|
public:
|
2015-08-24 09:00:00 +03:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DebugDataSender)
|
2013-11-29 08:11:49 +04:00
|
|
|
|
2015-08-24 09:00:00 +03:00
|
|
|
// Append a DebugData into mList on mThread
|
|
|
|
class AppendTask: public nsIRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2013-11-29 08:11:49 +04:00
|
|
|
|
2015-08-24 09:00:00 +03:00
|
|
|
AppendTask(DebugDataSender *host, DebugGLData *d)
|
|
|
|
: mData(d),
|
|
|
|
mHost(host)
|
|
|
|
{ }
|
2013-11-29 08:11:49 +04:00
|
|
|
|
2016-08-08 03:54:47 +03:00
|
|
|
NS_IMETHOD Run() override {
|
2015-08-24 09:00:00 +03:00
|
|
|
mHost->mList.insertBack(mData);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-11-29 08:11:49 +04:00
|
|
|
|
2015-08-24 09:00:00 +03:00
|
|
|
private:
|
|
|
|
virtual ~AppendTask() { }
|
2013-11-29 08:11:49 +04:00
|
|
|
|
2015-08-24 09:00:00 +03:00
|
|
|
DebugGLData *mData;
|
|
|
|
// Keep a strong reference to DebugDataSender to prevent this object
|
|
|
|
// accessing mHost on mThread, when it's been destroyed on the main
|
|
|
|
// thread.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DebugDataSender> mHost;
|
2015-08-24 09:00:00 +03:00
|
|
|
};
|
2013-11-29 08:11:49 +04:00
|
|
|
|
2015-08-24 09:00:00 +03:00
|
|
|
// Clear all DebugData in mList on mThead.
|
|
|
|
class ClearTask: public nsIRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2015-08-25 00:49:28 +03:00
|
|
|
explicit ClearTask(DebugDataSender *host)
|
2015-08-24 09:00:00 +03:00
|
|
|
: mHost(host)
|
|
|
|
{ }
|
2013-11-29 08:11:49 +04:00
|
|
|
|
2016-08-08 03:54:47 +03:00
|
|
|
NS_IMETHOD Run() override {
|
2015-08-24 09:00:00 +03:00
|
|
|
mHost->RemoveData();
|
|
|
|
return NS_OK;
|
2013-11-29 08:11:49 +04:00
|
|
|
}
|
|
|
|
|
2015-08-24 09:00:00 +03:00
|
|
|
private:
|
|
|
|
virtual ~ClearTask() { }
|
2013-11-29 08:11:49 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DebugDataSender> mHost;
|
2015-08-24 09:00:00 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Send all DebugData in mList via websocket, and then, clean up
|
|
|
|
// mList on mThread.
|
|
|
|
class SendTask: public nsIRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
|
2015-08-25 00:49:28 +03:00
|
|
|
explicit SendTask(DebugDataSender *host)
|
2015-08-24 09:00:00 +03:00
|
|
|
: mHost(host)
|
|
|
|
{ }
|
|
|
|
|
2016-08-08 03:54:47 +03:00
|
|
|
NS_IMETHOD Run() override {
|
2015-08-24 09:00:00 +03:00
|
|
|
// Sendout all appended debug data.
|
|
|
|
DebugGLData *d = nullptr;
|
|
|
|
while ((d = mHost->mList.popFirst()) != nullptr) {
|
|
|
|
UniquePtr<DebugGLData> cleaner(d);
|
|
|
|
if (!d->Write()) {
|
|
|
|
gLayerScopeManager.DestroyServerSocket();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cleanup.
|
|
|
|
mHost->RemoveData();
|
|
|
|
return NS_OK;
|
2013-11-29 08:11:49 +04:00
|
|
|
}
|
2015-08-24 09:00:00 +03:00
|
|
|
private:
|
|
|
|
virtual ~SendTask() { }
|
2013-11-29 08:11:49 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DebugDataSender> mHost;
|
2015-08-24 09:00:00 +03:00
|
|
|
};
|
|
|
|
|
2015-08-25 00:49:28 +03:00
|
|
|
explicit DebugDataSender(nsIThread *thread)
|
2015-08-24 09:00:00 +03:00
|
|
|
: mThread(thread)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
void Append(DebugGLData *d) {
|
|
|
|
mThread->Dispatch(new AppendTask(this, d), NS_DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Cleanup() {
|
|
|
|
mThread->Dispatch(new ClearTask(this), NS_DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Send() {
|
|
|
|
mThread->Dispatch(new SendTask(this), NS_DISPATCH_NORMAL);
|
2013-11-29 08:11:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-08-24 09:00:00 +03:00
|
|
|
virtual ~DebugDataSender() {}
|
|
|
|
void RemoveData() {
|
2017-06-01 23:43:00 +03:00
|
|
|
MOZ_ASSERT(mThread->SerialEventTarget()->IsOnCurrentThread());
|
2015-08-24 09:00:00 +03:00
|
|
|
if (mList.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
DebugGLData *d;
|
|
|
|
while ((d = mList.popFirst()) != nullptr)
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We can only modify or aceess mList on mThread.
|
2014-07-03 03:17:00 +04:00
|
|
|
LinkedList<DebugGLData> mList;
|
2015-08-24 09:00:00 +03:00
|
|
|
nsCOMPtr<nsIThread> mThread;
|
2013-11-29 08:11:49 +04:00
|
|
|
};
|
|
|
|
|
2015-08-24 09:00:00 +03:00
|
|
|
NS_IMPL_ISUPPORTS(DebugDataSender::AppendTask, nsIRunnable);
|
|
|
|
NS_IMPL_ISUPPORTS(DebugDataSender::ClearTask, nsIRunnable);
|
|
|
|
NS_IMPL_ISUPPORTS(DebugDataSender::SendTask, nsIRunnable);
|
2013-11-29 08:11:49 +04:00
|
|
|
|
2014-11-20 04:00:00 +03:00
|
|
|
|
2014-07-03 03:17:00 +04:00
|
|
|
/*
|
|
|
|
* LayerScope SendXXX Structure
|
|
|
|
* 1. SendLayer
|
|
|
|
* 2. SendEffectChain
|
|
|
|
* 1. SendTexturedEffect
|
|
|
|
* -> SendTextureSource
|
2015-09-30 00:19:00 +03:00
|
|
|
* 2. SendMaskEffect
|
2014-07-03 03:17:00 +04:00
|
|
|
* -> SendTextureSource
|
2015-09-30 00:19:00 +03:00
|
|
|
* 3. SendYCbCrEffect
|
|
|
|
* -> SendTextureSource
|
|
|
|
* 4. SendColor
|
2014-07-03 03:17:00 +04:00
|
|
|
*/
|
|
|
|
class SenderHelper
|
2013-11-29 08:11:49 +04:00
|
|
|
{
|
2014-07-03 03:17:00 +04:00
|
|
|
// Sender public APIs
|
|
|
|
public:
|
|
|
|
static void SendLayer(LayerComposite* aLayer,
|
|
|
|
int aWidth,
|
|
|
|
int aHeight);
|
2013-11-29 08:11:49 +04:00
|
|
|
|
2014-07-03 03:17:00 +04:00
|
|
|
static void SendEffectChain(gl::GLContext* aGLContext,
|
|
|
|
const EffectChain& aEffectChain,
|
|
|
|
int aWidth = 0,
|
|
|
|
int aHeight = 0);
|
|
|
|
|
2015-01-29 22:02:00 +03:00
|
|
|
static void SetLayersTreeSendable(bool aSet) {sLayersTreeSendable = aSet;}
|
|
|
|
|
|
|
|
static void SetLayersBufferSendable(bool aSet) {sLayersBufferSendable = aSet;}
|
|
|
|
|
|
|
|
static bool GetLayersTreeSendable() {return sLayersTreeSendable;}
|
|
|
|
|
2015-09-30 00:21:00 +03:00
|
|
|
static void ClearSentTextureIds();
|
2015-04-14 09:57:42 +03:00
|
|
|
|
2014-07-03 03:17:00 +04:00
|
|
|
// Sender private functions
|
|
|
|
private:
|
|
|
|
static void SendColor(void* aLayerRef,
|
2015-09-25 05:18:03 +03:00
|
|
|
const Color& aColor,
|
2014-07-03 03:17:00 +04:00
|
|
|
int aWidth,
|
|
|
|
int aHeight);
|
|
|
|
static void SendTextureSource(GLContext* aGLContext,
|
|
|
|
void* aLayerRef,
|
|
|
|
TextureSourceOGL* aSource,
|
2015-09-30 00:32:00 +03:00
|
|
|
bool aFlipY,
|
2015-10-20 03:05:00 +03:00
|
|
|
bool aIsMask,
|
|
|
|
UniquePtr<Packet> aPacket);
|
|
|
|
static void SetAndSendTexture(GLContext* aGLContext,
|
|
|
|
void* aLayerRef,
|
|
|
|
TextureSourceOGL* aSource,
|
|
|
|
const TexturedEffect* aEffect);
|
2014-07-03 03:17:00 +04:00
|
|
|
static void SendTexturedEffect(GLContext* aGLContext,
|
|
|
|
void* aLayerRef,
|
|
|
|
const TexturedEffect* aEffect);
|
2015-09-30 00:19:00 +03:00
|
|
|
static void SendMaskEffect(GLContext* aGLContext,
|
|
|
|
void* aLayerRef,
|
|
|
|
const EffectMask* aEffect);
|
2014-07-03 03:17:00 +04:00
|
|
|
static void SendYCbCrEffect(GLContext* aGLContext,
|
|
|
|
void* aLayerRef,
|
|
|
|
const EffectYCbCr* aEffect);
|
2015-05-28 09:30:00 +03:00
|
|
|
static GLuint GetTextureID(GLContext* aGLContext,
|
|
|
|
TextureSourceOGL* aSource);
|
2015-09-30 00:21:00 +03:00
|
|
|
static bool HasTextureIdBeenSent(GLuint aTextureId);
|
2015-01-29 22:02:00 +03:00
|
|
|
// Data fields
|
|
|
|
private:
|
|
|
|
static bool sLayersTreeSendable;
|
|
|
|
static bool sLayersBufferSendable;
|
2015-09-30 00:21:00 +03:00
|
|
|
static std::vector<GLuint> sSentTextureIds;
|
2014-07-03 03:17:00 +04:00
|
|
|
};
|
2013-11-29 08:11:49 +04:00
|
|
|
|
2015-01-29 22:02:00 +03:00
|
|
|
bool SenderHelper::sLayersTreeSendable = true;
|
|
|
|
bool SenderHelper::sLayersBufferSendable = true;
|
2015-09-30 00:21:00 +03:00
|
|
|
std::vector<GLuint> SenderHelper::sSentTextureIds;
|
2015-01-29 22:02:00 +03:00
|
|
|
|
2013-11-29 08:11:49 +04:00
|
|
|
|
2014-07-03 03:17:00 +04:00
|
|
|
// ----------------------------------------------
|
|
|
|
// SenderHelper implementation
|
|
|
|
// ----------------------------------------------
|
2015-04-14 09:57:42 +03:00
|
|
|
void
|
2015-09-30 00:21:00 +03:00
|
|
|
SenderHelper::ClearSentTextureIds()
|
2015-04-14 09:57:42 +03:00
|
|
|
{
|
2015-09-30 00:21:00 +03:00
|
|
|
sSentTextureIds.clear();
|
2015-04-14 09:57:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-09-30 00:21:00 +03:00
|
|
|
SenderHelper::HasTextureIdBeenSent(GLuint aTextureId)
|
2015-04-14 09:57:42 +03:00
|
|
|
{
|
2015-09-30 00:21:00 +03:00
|
|
|
return std::find(sSentTextureIds.begin(), sSentTextureIds.end(), aTextureId) != sSentTextureIds.end();
|
2015-04-14 09:57:42 +03:00
|
|
|
}
|
|
|
|
|
2013-11-29 08:11:49 +04:00
|
|
|
void
|
2014-07-03 03:17:00 +04:00
|
|
|
SenderHelper::SendLayer(LayerComposite* aLayer,
|
|
|
|
int aWidth,
|
|
|
|
int aHeight)
|
2013-11-29 08:11:49 +04:00
|
|
|
{
|
2014-07-03 03:17:00 +04:00
|
|
|
MOZ_ASSERT(aLayer && aLayer->GetLayer());
|
|
|
|
if (!aLayer || !aLayer->GetLayer()) {
|
2013-11-29 08:11:49 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-03 03:17:00 +04:00
|
|
|
switch (aLayer->GetLayer()->GetType()) {
|
|
|
|
case Layer::TYPE_COLOR: {
|
|
|
|
EffectChain effect;
|
|
|
|
aLayer->GenEffectChain(effect);
|
2015-10-15 13:03:00 +03:00
|
|
|
|
|
|
|
LayerScope::DrawBegin();
|
|
|
|
LayerScope::DrawEnd(nullptr, effect, aWidth, aHeight);
|
2014-07-03 03:17:00 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Layer::TYPE_IMAGE:
|
|
|
|
case Layer::TYPE_CANVAS:
|
2014-09-26 21:07:06 +04:00
|
|
|
case Layer::TYPE_PAINTED: {
|
2014-07-03 03:17:00 +04:00
|
|
|
// Get CompositableHost and Compositor
|
|
|
|
CompositableHost* compHost = aLayer->GetCompositableHost();
|
2017-03-22 06:32:56 +03:00
|
|
|
TextureSourceProvider* provider = compHost->GetTextureSourceProvider();
|
|
|
|
Compositor* comp = provider->AsCompositor();
|
2014-07-03 03:17:00 +04:00
|
|
|
// Send EffectChain only for CompositorOGL
|
|
|
|
if (LayersBackend::LAYERS_OPENGL == comp->GetBackendType()) {
|
2016-04-14 13:38:42 +03:00
|
|
|
CompositorOGL* compOGL = comp->AsCompositorOGL();
|
2014-07-03 03:17:00 +04:00
|
|
|
EffectChain effect;
|
|
|
|
// Generate primary effect (lock and gen)
|
|
|
|
AutoLockCompositableHost lock(compHost);
|
|
|
|
aLayer->GenEffectChain(effect);
|
2015-10-15 13:03:00 +03:00
|
|
|
|
|
|
|
LayerScope::DrawBegin();
|
|
|
|
LayerScope::DrawEnd(compOGL->gl(), effect, aWidth, aHeight);
|
2014-07-03 03:17:00 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Layer::TYPE_CONTAINER:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-11-29 08:11:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-07-03 03:17:00 +04:00
|
|
|
SenderHelper::SendColor(void* aLayerRef,
|
2015-09-25 05:18:03 +03:00
|
|
|
const Color& aColor,
|
2014-07-03 03:17:00 +04:00
|
|
|
int aWidth,
|
|
|
|
int aHeight)
|
2013-11-29 08:11:49 +04:00
|
|
|
{
|
2015-06-02 13:21:00 +03:00
|
|
|
gLayerScopeManager.GetSocketManager()->AppendDebugData(
|
2014-07-03 03:17:00 +04:00
|
|
|
new DebugGLColorData(aLayerRef, aColor, aWidth, aHeight));
|
2013-11-29 08:11:49 +04:00
|
|
|
}
|
|
|
|
|
2015-05-28 09:30:00 +03:00
|
|
|
GLuint
|
|
|
|
SenderHelper::GetTextureID(GLContext* aGLContext,
|
|
|
|
TextureSourceOGL* aSource) {
|
|
|
|
GLenum textureTarget = aSource->GetTextureTarget();
|
2016-05-25 19:01:18 +03:00
|
|
|
aSource->BindTexture(LOCAL_GL_TEXTURE0, gfx::SamplingFilter::LINEAR);
|
2015-05-28 09:30:00 +03:00
|
|
|
|
|
|
|
GLuint texID = 0;
|
|
|
|
// This is horrid hack. It assumes that aGLContext matches the context
|
|
|
|
// aSource has bound to.
|
|
|
|
if (textureTarget == LOCAL_GL_TEXTURE_2D) {
|
|
|
|
aGLContext->GetUIntegerv(LOCAL_GL_TEXTURE_BINDING_2D, &texID);
|
|
|
|
} else if (textureTarget == LOCAL_GL_TEXTURE_EXTERNAL) {
|
|
|
|
aGLContext->GetUIntegerv(LOCAL_GL_TEXTURE_BINDING_EXTERNAL, &texID);
|
|
|
|
} else if (textureTarget == LOCAL_GL_TEXTURE_RECTANGLE) {
|
|
|
|
aGLContext->GetUIntegerv(LOCAL_GL_TEXTURE_BINDING_RECTANGLE, &texID);
|
|
|
|
}
|
|
|
|
|
|
|
|
return texID;
|
|
|
|
}
|
|
|
|
|
2014-07-03 03:17:00 +04:00
|
|
|
void
|
|
|
|
SenderHelper::SendTextureSource(GLContext* aGLContext,
|
|
|
|
void* aLayerRef,
|
|
|
|
TextureSourceOGL* aSource,
|
2015-09-30 00:32:00 +03:00
|
|
|
bool aFlipY,
|
2015-10-20 03:05:00 +03:00
|
|
|
bool aIsMask,
|
|
|
|
UniquePtr<Packet> aPacket)
|
2013-11-29 08:11:49 +04:00
|
|
|
{
|
2014-07-03 03:17:00 +04:00
|
|
|
MOZ_ASSERT(aGLContext);
|
|
|
|
if (!aGLContext) {
|
2013-11-29 08:11:49 +04:00
|
|
|
return;
|
2014-07-03 03:17:00 +04:00
|
|
|
}
|
2015-09-30 00:21:00 +03:00
|
|
|
GLuint texID = GetTextureID(aGLContext, aSource);
|
|
|
|
if (HasTextureIdBeenSent(texID)) {
|
|
|
|
return;
|
|
|
|
}
|
2013-11-29 08:11:49 +04:00
|
|
|
|
|
|
|
GLenum textureTarget = aSource->GetTextureTarget();
|
2013-11-08 10:22:05 +04:00
|
|
|
ShaderConfigOGL config = ShaderConfigFromTargetAndFormat(textureTarget,
|
|
|
|
aSource->GetFormat());
|
|
|
|
int shaderConfig = config.mFeatures;
|
2013-11-29 08:11:49 +04:00
|
|
|
|
2015-05-28 09:30:00 +03:00
|
|
|
gfx::IntSize size = aSource->GetSize();
|
2013-11-29 08:11:49 +04:00
|
|
|
|
2015-05-28 09:30:00 +03:00
|
|
|
// By sending 0 to ReadTextureImage rely upon aSource->BindTexture binding
|
|
|
|
// texture correctly. texID is used for tracking in DebugGLTextureData.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DataSourceSurface> img =
|
2015-05-28 09:30:00 +03:00
|
|
|
aGLContext->ReadTexImageHelper()->ReadTexImage(0, textureTarget,
|
|
|
|
size,
|
|
|
|
shaderConfig, aFlipY);
|
2015-06-02 13:21:00 +03:00
|
|
|
gLayerScopeManager.GetSocketManager()->AppendDebugData(
|
2015-05-28 09:30:00 +03:00
|
|
|
new DebugGLTextureData(aGLContext, aLayerRef, textureTarget,
|
2015-10-20 03:05:00 +03:00
|
|
|
texID, img, aIsMask, Move(aPacket)));
|
2015-05-28 09:30:00 +03:00
|
|
|
|
2015-09-30 00:21:00 +03:00
|
|
|
sSentTextureIds.push_back(texID);
|
|
|
|
gLayerScopeManager.CurrentSession().mTexIDs.push_back(texID);
|
2015-08-03 09:11:00 +03:00
|
|
|
|
2015-05-28 09:30:00 +03:00
|
|
|
}
|
|
|
|
|
2015-10-20 03:05:00 +03:00
|
|
|
void
|
|
|
|
SenderHelper::SetAndSendTexture(GLContext* aGLContext,
|
|
|
|
void* aLayerRef,
|
|
|
|
TextureSourceOGL* aSource,
|
|
|
|
const TexturedEffect* aEffect)
|
|
|
|
{
|
|
|
|
// 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);
|
2016-05-25 19:01:18 +03:00
|
|
|
DumpFilter(texturePacket, aEffect->mSamplingFilter);
|
2015-10-20 03:05:00 +03:00
|
|
|
DumpRect(texturePacket->mutable_mtexturecoords(), aEffect->mTextureCoords);
|
|
|
|
SendTextureSource(aGLContext, aLayerRef, aSource, false, false, Move(packet));
|
|
|
|
}
|
|
|
|
|
2014-07-03 03:17:00 +04:00
|
|
|
void
|
|
|
|
SenderHelper::SendTexturedEffect(GLContext* aGLContext,
|
|
|
|
void* aLayerRef,
|
|
|
|
const TexturedEffect* aEffect)
|
2013-11-29 08:11:49 +04:00
|
|
|
{
|
|
|
|
TextureSourceOGL* source = aEffect->mTexture->AsSourceOGL();
|
2015-05-28 09:30:00 +03:00
|
|
|
if (!source) {
|
2013-11-29 08:11:49 +04:00
|
|
|
return;
|
2015-05-28 09:30:00 +03:00
|
|
|
}
|
2013-11-29 08:11:49 +04:00
|
|
|
|
2015-06-02 13:21:00 +03:00
|
|
|
// Fallback texture sending path.
|
2015-10-20 03:05:00 +03:00
|
|
|
SetAndSendTexture(aGLContext, aLayerRef, source, aEffect);
|
2013-11-29 08:11:49 +04:00
|
|
|
}
|
|
|
|
|
2015-09-30 00:19:00 +03:00
|
|
|
void
|
|
|
|
SenderHelper::SendMaskEffect(GLContext* aGLContext,
|
|
|
|
void* aLayerRef,
|
|
|
|
const EffectMask* aEffect)
|
|
|
|
{
|
|
|
|
TextureSourceOGL* source = aEffect->mMaskTexture->AsSourceOGL();
|
|
|
|
if (!source) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-20 03:05:00 +03:00
|
|
|
// Expose packet creation here, so we could dump secondary mask effect attributes.
|
|
|
|
auto packet = MakeUnique<layerscope::Packet>();
|
|
|
|
TexturePacket::EffectMask* mask = packet->mutable_texture()->mutable_mask();
|
|
|
|
mask->mutable_msize()->set_w(aEffect->mSize.width);
|
|
|
|
mask->mutable_msize()->set_h(aEffect->mSize.height);
|
|
|
|
auto element = reinterpret_cast<const Float *>(&(aEffect->mMaskTransform));
|
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
mask->mutable_mmasktransform()->add_m(*element++);
|
|
|
|
}
|
|
|
|
|
|
|
|
SendTextureSource(aGLContext, aLayerRef, source, false, true, Move(packet));
|
2015-09-30 00:19:00 +03:00
|
|
|
}
|
|
|
|
|
2014-07-03 03:17:00 +04:00
|
|
|
void
|
|
|
|
SenderHelper::SendYCbCrEffect(GLContext* aGLContext,
|
|
|
|
void* aLayerRef,
|
|
|
|
const EffectYCbCr* aEffect)
|
2013-11-29 08:11:49 +04:00
|
|
|
{
|
|
|
|
TextureSource* sourceYCbCr = aEffect->mTexture;
|
|
|
|
if (!sourceYCbCr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const int Y = 0, Cb = 1, Cr = 2;
|
2015-10-20 03:05:00 +03:00
|
|
|
TextureSourceOGL *sources[] = {
|
|
|
|
sourceYCbCr->GetSubSource(Y)->AsSourceOGL(),
|
|
|
|
sourceYCbCr->GetSubSource(Cb)->AsSourceOGL(),
|
|
|
|
sourceYCbCr->GetSubSource(Cr)->AsSourceOGL()
|
|
|
|
};
|
2013-11-29 08:11:49 +04:00
|
|
|
|
2015-10-20 03:05:00 +03:00
|
|
|
for (auto source: sources) {
|
|
|
|
SetAndSendTexture(aGLContext, aLayerRef, source, aEffect);
|
|
|
|
}
|
2013-11-29 08:11:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-07-03 03:17:00 +04:00
|
|
|
SenderHelper::SendEffectChain(GLContext* aGLContext,
|
|
|
|
const EffectChain& aEffectChain,
|
|
|
|
int aWidth,
|
|
|
|
int aHeight)
|
2013-11-29 08:11:49 +04:00
|
|
|
{
|
2015-01-29 22:02:00 +03:00
|
|
|
if (!sLayersBufferSendable) return;
|
|
|
|
|
2013-11-29 08:11:49 +04:00
|
|
|
const Effect* primaryEffect = aEffectChain.mPrimaryEffect;
|
2015-10-15 13:03:00 +03:00
|
|
|
MOZ_ASSERT(primaryEffect);
|
|
|
|
|
|
|
|
if (!primaryEffect) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-29 08:11:49 +04:00
|
|
|
switch (primaryEffect->mType) {
|
2014-07-03 03:17:00 +04:00
|
|
|
case EffectTypes::RGB: {
|
|
|
|
const TexturedEffect* texturedEffect =
|
|
|
|
static_cast<const TexturedEffect*>(primaryEffect);
|
|
|
|
SendTexturedEffect(aGLContext, aEffectChain.mLayerRef, texturedEffect);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EffectTypes::YCBCR: {
|
|
|
|
const EffectYCbCr* yCbCrEffect =
|
|
|
|
static_cast<const EffectYCbCr*>(primaryEffect);
|
|
|
|
SendYCbCrEffect(aGLContext, aEffectChain.mLayerRef, yCbCrEffect);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EffectTypes::SOLID_COLOR: {
|
|
|
|
const EffectSolidColor* solidColorEffect =
|
|
|
|
static_cast<const EffectSolidColor*>(primaryEffect);
|
2015-09-25 05:18:03 +03:00
|
|
|
SendColor(aEffectChain.mLayerRef, solidColorEffect->mColor,
|
|
|
|
aWidth, aHeight);
|
2014-07-03 03:17:00 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EffectTypes::COMPONENT_ALPHA:
|
|
|
|
case EffectTypes::RENDER_TARGET:
|
|
|
|
default:
|
|
|
|
break;
|
2013-11-29 08:11:49 +04:00
|
|
|
}
|
|
|
|
|
2015-09-30 00:19:00 +03:00
|
|
|
if (aEffectChain.mSecondaryEffects[EffectTypes::MASK]) {
|
|
|
|
const EffectMask* effectMask =
|
|
|
|
static_cast<const EffectMask*>(aEffectChain.mSecondaryEffects[EffectTypes::MASK].get());
|
|
|
|
SendMaskEffect(aGLContext, aEffectChain.mLayerRef, effectMask);
|
|
|
|
}
|
2013-11-29 08:11:49 +04:00
|
|
|
}
|
|
|
|
|
2015-06-02 13:21:00 +03:00
|
|
|
void
|
|
|
|
LayerScope::ContentChanged(TextureHost *host)
|
|
|
|
{
|
|
|
|
if (!CheckSendable()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gLayerScopeManager.GetContentMonitor()->SetChangedHost(host);
|
|
|
|
}
|
|
|
|
|
2015-01-29 22:02:00 +03:00
|
|
|
// ----------------------------------------------
|
2015-08-03 23:22:00 +03:00
|
|
|
// SocketHandler implementation
|
2015-01-29 22:02:00 +03:00
|
|
|
// ----------------------------------------------
|
|
|
|
void
|
2015-08-03 23:22:00 +03:00
|
|
|
LayerScopeWebSocketManager::SocketHandler::OpenStream(nsISocketTransport* aTransport)
|
2015-01-29 22:02:00 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aTransport);
|
|
|
|
|
|
|
|
mTransport = aTransport;
|
|
|
|
mTransport->OpenOutputStream(nsITransport::OPEN_BLOCKING,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
getter_AddRefs(mOutputStream));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIInputStream> debugInputStream;
|
|
|
|
mTransport->OpenInputStream(0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
getter_AddRefs(debugInputStream));
|
|
|
|
mInputStream = do_QueryInterface(debugInputStream);
|
2017-06-01 23:43:00 +03:00
|
|
|
mInputStream->AsyncWait(this, 0, 0, GetCurrentThreadEventTarget());
|
2015-01-29 22:02:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-08-03 23:22:00 +03:00
|
|
|
LayerScopeWebSocketManager::SocketHandler::WriteToStream(void *aPtr,
|
2015-01-29 22:02:00 +03:00
|
|
|
uint32_t aSize)
|
|
|
|
{
|
|
|
|
if (mState == NoHandshake) {
|
|
|
|
// Not yet handshake, just return true in case of
|
|
|
|
// LayerScope remove this handle
|
|
|
|
return true;
|
|
|
|
} else if (mState == HandshakeFailed) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mOutputStream) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate WebSocket header
|
|
|
|
uint8_t wsHeader[10];
|
|
|
|
int wsHeaderSize = 0;
|
|
|
|
const uint8_t opcode = 0x2;
|
|
|
|
wsHeader[0] = 0x80 | (opcode & 0x0f); // FIN + opcode;
|
|
|
|
if (aSize <= 125) {
|
|
|
|
wsHeaderSize = 2;
|
|
|
|
wsHeader[1] = aSize;
|
|
|
|
} else if (aSize < 65536) {
|
|
|
|
wsHeaderSize = 4;
|
|
|
|
wsHeader[1] = 0x7E;
|
|
|
|
NetworkEndian::writeUint16(wsHeader + 2, aSize);
|
|
|
|
} else {
|
|
|
|
wsHeaderSize = 10;
|
|
|
|
wsHeader[1] = 0x7F;
|
|
|
|
NetworkEndian::writeUint64(wsHeader + 2, aSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send WebSocket header
|
|
|
|
nsresult rv;
|
|
|
|
uint32_t cnt;
|
|
|
|
rv = mOutputStream->Write(reinterpret_cast<char*>(wsHeader),
|
|
|
|
wsHeaderSize, &cnt);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
uint32_t written = 0;
|
|
|
|
while (written < aSize) {
|
|
|
|
uint32_t cnt;
|
|
|
|
rv = mOutputStream->Write(reinterpret_cast<char*>(aPtr) + written,
|
|
|
|
aSize - written, &cnt);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
written += cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-08-03 23:22:00 +03:00
|
|
|
LayerScopeWebSocketManager::SocketHandler::OnInputStreamReady(nsIAsyncInputStream *aStream)
|
2015-01-29 22:02:00 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mInputStream);
|
|
|
|
|
|
|
|
if (!mInputStream) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mConnected) {
|
|
|
|
nsTArray<nsCString> protocolString;
|
|
|
|
ReadInputStreamData(protocolString);
|
|
|
|
|
|
|
|
if (WebSocketHandshake(protocolString)) {
|
|
|
|
mState = HandshakeSuccess;
|
|
|
|
mConnected = true;
|
2017-06-01 23:43:00 +03:00
|
|
|
mInputStream->AsyncWait(this, 0, 0, GetCurrentThreadEventTarget());
|
2015-01-29 22:02:00 +03:00
|
|
|
} else {
|
|
|
|
mState = HandshakeFailed;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
} else {
|
|
|
|
return HandleSocketMessage(aStream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-08-03 23:22:00 +03:00
|
|
|
LayerScopeWebSocketManager::SocketHandler::ReadInputStreamData(nsTArray<nsCString>& aProtocolString)
|
2015-01-29 22:02:00 +03:00
|
|
|
{
|
|
|
|
nsLineBuffer<char> lineBuffer;
|
|
|
|
nsCString line;
|
|
|
|
bool more = true;
|
|
|
|
do {
|
|
|
|
NS_ReadLine(mInputStream.get(), &lineBuffer, line, &more);
|
|
|
|
|
|
|
|
if (line.Length() > 0) {
|
|
|
|
aProtocolString.AppendElement(line);
|
|
|
|
}
|
|
|
|
} while (more && line.Length() > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-08-03 23:22:00 +03:00
|
|
|
LayerScopeWebSocketManager::SocketHandler::WebSocketHandshake(nsTArray<nsCString>& aProtocolString)
|
2015-01-29 22:02:00 +03:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
bool isWebSocket = false;
|
|
|
|
nsCString version;
|
|
|
|
nsCString wsKey;
|
|
|
|
nsCString protocol;
|
|
|
|
|
|
|
|
// Validate WebSocket client request.
|
|
|
|
if (aProtocolString.Length() == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Check that the HTTP method is GET
|
|
|
|
const char* HTTP_METHOD = "GET ";
|
|
|
|
if (strncmp(aProtocolString[0].get(), HTTP_METHOD, strlen(HTTP_METHOD)) != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 1; i < aProtocolString.Length(); ++i) {
|
|
|
|
const char* line = aProtocolString[i].get();
|
|
|
|
const char* prop_pos = strchr(line, ':');
|
|
|
|
if (prop_pos != nullptr) {
|
|
|
|
nsCString key(line, prop_pos - line);
|
|
|
|
nsCString value(prop_pos + 2);
|
|
|
|
if (key.EqualsIgnoreCase("upgrade") &&
|
|
|
|
value.EqualsIgnoreCase("websocket")) {
|
|
|
|
isWebSocket = true;
|
|
|
|
} else if (key.EqualsIgnoreCase("sec-websocket-version")) {
|
|
|
|
version = value;
|
|
|
|
} else if (key.EqualsIgnoreCase("sec-websocket-key")) {
|
|
|
|
wsKey = value;
|
|
|
|
} else if (key.EqualsIgnoreCase("sec-websocket-protocol")) {
|
|
|
|
protocol = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isWebSocket) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(version.EqualsLiteral("7") ||
|
|
|
|
version.EqualsLiteral("8") ||
|
|
|
|
version.EqualsLiteral("13"))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(protocol.EqualsIgnoreCase("binary"))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mOutputStream) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Client request is valid. Start to generate and send server response.
|
|
|
|
nsAutoCString guid("258EAFA5-E914-47DA-95CA-C5AB0DC85B11");
|
|
|
|
nsAutoCString res;
|
|
|
|
SHA1Sum sha1;
|
|
|
|
nsCString combined(wsKey + guid);
|
|
|
|
sha1.update(combined.get(), combined.Length());
|
|
|
|
uint8_t digest[SHA1Sum::kHashSize]; // SHA1 digests are 20 bytes long.
|
|
|
|
sha1.finish(digest);
|
|
|
|
nsCString newString(reinterpret_cast<char*>(digest), SHA1Sum::kHashSize);
|
2016-06-06 05:22:14 +03:00
|
|
|
rv = Base64Encode(newString, res);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-01-29 22:02:00 +03:00
|
|
|
nsCString response("HTTP/1.1 101 Switching Protocols\r\n");
|
|
|
|
response.AppendLiteral("Upgrade: websocket\r\n");
|
|
|
|
response.AppendLiteral("Connection: Upgrade\r\n");
|
|
|
|
response.Append(nsCString("Sec-WebSocket-Accept: ") + res + nsCString("\r\n"));
|
|
|
|
response.AppendLiteral("Sec-WebSocket-Protocol: binary\r\n\r\n");
|
|
|
|
uint32_t written = 0;
|
|
|
|
uint32_t size = response.Length();
|
|
|
|
while (written < size) {
|
|
|
|
uint32_t cnt;
|
|
|
|
rv = mOutputStream->Write(const_cast<char*>(response.get()) + written,
|
|
|
|
size - written, &cnt);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
written += cnt;
|
|
|
|
}
|
|
|
|
mOutputStream->Flush();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2015-08-03 23:22:00 +03:00
|
|
|
LayerScopeWebSocketManager::SocketHandler::HandleSocketMessage(nsIAsyncInputStream *aStream)
|
2015-01-29 22:02:00 +03:00
|
|
|
{
|
|
|
|
// The reading and parsing of this input stream is customized for layer viewer.
|
|
|
|
const uint32_t cPacketSize = 1024;
|
|
|
|
char buffer[cPacketSize];
|
|
|
|
uint32_t count = 0;
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
do {
|
|
|
|
rv = mInputStream->Read((char *)buffer, cPacketSize, &count);
|
|
|
|
|
|
|
|
// TODO: combine packets if we have to read more than once
|
|
|
|
|
|
|
|
if (rv == NS_BASE_STREAM_WOULD_BLOCK) {
|
2017-06-01 23:43:00 +03:00
|
|
|
mInputStream->AsyncWait(this, 0, 0, GetCurrentThreadEventTarget());
|
2015-01-29 22:02:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count == 0) {
|
|
|
|
// NS_BASE_STREAM_CLOSED
|
|
|
|
CloseConnection();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = ProcessInput(reinterpret_cast<uint8_t *>(buffer), count);
|
|
|
|
} while (NS_SUCCEEDED(rv) && mInputStream);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2015-08-03 23:22:00 +03:00
|
|
|
LayerScopeWebSocketManager::SocketHandler::ProcessInput(uint8_t *aBuffer,
|
2015-01-29 22:02:00 +03:00
|
|
|
uint32_t aCount)
|
|
|
|
{
|
|
|
|
uint32_t avail = aCount;
|
|
|
|
|
|
|
|
// Decode Websocket data frame
|
|
|
|
if (avail <= 2) {
|
|
|
|
NS_WARNING("Packet size is less than 2 bytes");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// First byte, data type, only care the opcode
|
|
|
|
// rsvBits: aBuffer[0] & 0x70 (0111 0000)
|
|
|
|
uint8_t finBit = aBuffer[0] & 0x80; // 1000 0000
|
|
|
|
uint8_t opcode = aBuffer[0] & 0x0F; // 0000 1111
|
|
|
|
|
|
|
|
if (!finBit) {
|
|
|
|
NS_WARNING("We cannot handle multi-fragments messages in Layerscope websocket parser.");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Second byte, data length
|
|
|
|
uint8_t maskBit = aBuffer[1] & 0x80; // 1000 0000
|
|
|
|
int64_t payloadLength64 = aBuffer[1] & 0x7F; // 0111 1111
|
|
|
|
|
|
|
|
if (!maskBit) {
|
|
|
|
NS_WARNING("Client to Server should set the mask bit");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t framingLength = 2 + 4; // 4 for masks
|
|
|
|
|
|
|
|
if (payloadLength64 < 126) {
|
|
|
|
if (avail < framingLength)
|
|
|
|
return NS_OK;
|
|
|
|
} else if (payloadLength64 == 126) {
|
|
|
|
// 16 bit length field
|
|
|
|
framingLength += 2;
|
|
|
|
if (avail < framingLength) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
payloadLength64 = aBuffer[2] << 8 | aBuffer[3];
|
|
|
|
} else {
|
|
|
|
// 64 bit length
|
|
|
|
framingLength += 8;
|
|
|
|
if (avail < framingLength) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aBuffer[2] & 0x80) {
|
|
|
|
// Section 4.2 says that the most significant bit MUST be
|
|
|
|
// 0. (i.e. this is really a 63 bit value)
|
|
|
|
NS_WARNING("High bit of 64 bit length set");
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// copy this in case it is unaligned
|
|
|
|
payloadLength64 = NetworkEndian::readInt64(aBuffer + 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t *payload = aBuffer + framingLength;
|
|
|
|
avail -= framingLength;
|
|
|
|
|
|
|
|
uint32_t payloadLength = static_cast<uint32_t>(payloadLength64);
|
|
|
|
if (avail < payloadLength) {
|
|
|
|
NS_WARNING("Packet size mismatch the payload length");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply mask
|
|
|
|
uint32_t mask = NetworkEndian::readUint32(payload - 4);
|
|
|
|
ApplyMask(mask, payload, payloadLength);
|
|
|
|
|
|
|
|
if (opcode == 0x8) {
|
|
|
|
// opcode == 0x8 means connection close
|
|
|
|
CloseConnection();
|
|
|
|
return NS_BASE_STREAM_CLOSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!HandleDataFrame(payload, payloadLength)) {
|
|
|
|
NS_WARNING("Cannot decode payload data by the protocol buffer");
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-08-03 23:22:00 +03:00
|
|
|
LayerScopeWebSocketManager::SocketHandler::ApplyMask(uint32_t aMask,
|
2015-01-29 22:02:00 +03:00
|
|
|
uint8_t *aData,
|
|
|
|
uint64_t aLen)
|
|
|
|
{
|
|
|
|
if (!aData || aLen == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Optimally we want to apply the mask 32 bits at a time,
|
|
|
|
// but the buffer might not be alligned. So we first deal with
|
|
|
|
// 0 to 3 bytes of preamble individually
|
|
|
|
while (aLen && (reinterpret_cast<uintptr_t>(aData) & 3)) {
|
|
|
|
*aData ^= aMask >> 24;
|
|
|
|
aMask = RotateLeft(aMask, 8);
|
|
|
|
aData++;
|
|
|
|
aLen--;
|
|
|
|
}
|
|
|
|
|
|
|
|
// perform mask on full words of data
|
|
|
|
uint32_t *iData = reinterpret_cast<uint32_t *>(aData);
|
|
|
|
uint32_t *end = iData + (aLen >> 2);
|
|
|
|
NetworkEndian::writeUint32(&aMask, aMask);
|
|
|
|
for (; iData < end; iData++) {
|
|
|
|
*iData ^= aMask;
|
|
|
|
}
|
|
|
|
aMask = NetworkEndian::readUint32(&aMask);
|
|
|
|
aData = (uint8_t *)iData;
|
|
|
|
aLen = aLen % 4;
|
|
|
|
|
|
|
|
// There maybe up to 3 trailing bytes that need to be dealt with
|
|
|
|
// individually
|
|
|
|
while (aLen) {
|
|
|
|
*aData ^= aMask >> 24;
|
|
|
|
aMask = RotateLeft(aMask, 8);
|
|
|
|
aData++;
|
|
|
|
aLen--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-08-03 23:22:00 +03:00
|
|
|
LayerScopeWebSocketManager::SocketHandler::HandleDataFrame(uint8_t *aData,
|
2015-01-29 22:02:00 +03:00
|
|
|
uint32_t aSize)
|
|
|
|
{
|
|
|
|
// Handle payload data by protocol buffer
|
|
|
|
auto p = MakeUnique<CommandPacket>();
|
|
|
|
p->ParseFromArray(static_cast<void*>(aData), aSize);
|
|
|
|
|
|
|
|
if (!p->has_type()) {
|
|
|
|
MOZ_ASSERT(false, "Protocol buffer decoding failed or cannot recongize it");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (p->type()) {
|
|
|
|
case CommandPacket::LAYERS_TREE:
|
|
|
|
if (p->has_value()) {
|
|
|
|
SenderHelper::SetLayersTreeSendable(p->value());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CommandPacket::LAYERS_BUFFER:
|
|
|
|
if (p->has_value()) {
|
|
|
|
SenderHelper::SetLayersBufferSendable(p->value());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CommandPacket::NO_OP:
|
|
|
|
default:
|
|
|
|
NS_WARNING("Invalid message type");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-08-03 23:22:00 +03:00
|
|
|
LayerScopeWebSocketManager::SocketHandler::CloseConnection()
|
2015-01-29 22:02:00 +03:00
|
|
|
{
|
2015-06-02 13:21:00 +03:00
|
|
|
gLayerScopeManager.GetSocketManager()->CleanDebugData();
|
2015-01-29 22:02:00 +03:00
|
|
|
if (mInputStream) {
|
|
|
|
mInputStream->AsyncWait(nullptr, 0, 0, nullptr);
|
|
|
|
mInputStream = nullptr;
|
|
|
|
}
|
|
|
|
if (mOutputStream) {
|
|
|
|
mOutputStream = nullptr;
|
|
|
|
}
|
|
|
|
if (mTransport) {
|
|
|
|
mTransport->Close(NS_BASE_STREAM_CLOSED);
|
|
|
|
mTransport = nullptr;
|
|
|
|
}
|
|
|
|
mConnected = false;
|
|
|
|
}
|
|
|
|
|
2014-07-03 03:17:00 +04:00
|
|
|
// ----------------------------------------------
|
|
|
|
// LayerScopeWebSocketManager implementation
|
|
|
|
// ----------------------------------------------
|
2014-02-10 17:45:15 +04:00
|
|
|
LayerScopeWebSocketManager::LayerScopeWebSocketManager()
|
2015-08-03 23:22:00 +03:00
|
|
|
: mHandlerMutex("LayerScopeWebSocketManager::mHandlerMutex")
|
2014-02-10 17:45:15 +04:00
|
|
|
{
|
2016-12-21 13:43:50 +03:00
|
|
|
NS_NewNamedThread("LayerScope", getter_AddRefs(mDebugSenderThread));
|
2014-02-10 17:45:15 +04:00
|
|
|
|
|
|
|
mServerSocket = do_CreateInstance(NS_SERVERSOCKET_CONTRACTID);
|
2014-02-28 21:59:38 +04:00
|
|
|
int port = gfxPrefs::LayerScopePort();
|
2014-02-10 17:45:15 +04:00
|
|
|
mServerSocket->Init(port, false, -1);
|
2015-08-03 23:22:00 +03:00
|
|
|
mServerSocket->AsyncListen(new SocketListener);
|
2014-02-10 17:45:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LayerScopeWebSocketManager::~LayerScopeWebSocketManager()
|
|
|
|
{
|
2015-01-29 22:02:00 +03:00
|
|
|
mServerSocket->Close();
|
2014-02-10 17:45:15 +04:00
|
|
|
}
|
|
|
|
|
2014-07-03 03:17:00 +04:00
|
|
|
void
|
|
|
|
LayerScopeWebSocketManager::AppendDebugData(DebugGLData *aDebugData)
|
2014-02-10 17:45:15 +04:00
|
|
|
{
|
|
|
|
if (!mCurrentSender) {
|
2015-08-24 09:00:00 +03:00
|
|
|
mCurrentSender = new DebugDataSender(mDebugSenderThread);
|
2014-02-10 17:45:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mCurrentSender->Append(aDebugData);
|
|
|
|
}
|
|
|
|
|
2014-07-03 03:17:00 +04:00
|
|
|
void
|
|
|
|
LayerScopeWebSocketManager::CleanDebugData()
|
|
|
|
{
|
|
|
|
if (mCurrentSender) {
|
|
|
|
mCurrentSender->Cleanup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LayerScopeWebSocketManager::DispatchDebugData()
|
2014-02-10 17:45:15 +04:00
|
|
|
{
|
2015-08-24 09:00:00 +03:00
|
|
|
MOZ_ASSERT(mCurrentSender.get() != nullptr);
|
|
|
|
|
|
|
|
mCurrentSender->Send();
|
2014-02-10 17:45:15 +04:00
|
|
|
mCurrentSender = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-08-03 23:22:00 +03:00
|
|
|
NS_IMETHODIMP LayerScopeWebSocketManager::SocketListener::OnSocketAccepted(
|
|
|
|
nsIServerSocket *aServ,
|
|
|
|
nsISocketTransport *aTransport)
|
|
|
|
{
|
|
|
|
if (!gLayerScopeManager.GetSocketManager())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
printf_stderr("*** LayerScope: Accepted connection\n");
|
|
|
|
gLayerScopeManager.GetSocketManager()->AddConnection(aTransport);
|
|
|
|
gLayerScopeManager.GetContentMonitor()->Empty();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-07-03 03:17:00 +04:00
|
|
|
|
|
|
|
// ----------------------------------------------
|
|
|
|
// LayerScope implementation
|
|
|
|
// ----------------------------------------------
|
2015-08-03 23:22:00 +03:00
|
|
|
/*static*/
|
2014-07-03 03:17:00 +04:00
|
|
|
void
|
|
|
|
LayerScope::Init()
|
|
|
|
{
|
2016-11-10 21:55:32 +03:00
|
|
|
if (!gfxPrefs::LayerScopeEnabled() || XRE_IsGPUProcess()) {
|
2014-07-03 03:17:00 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-02 13:21:00 +03:00
|
|
|
gLayerScopeManager.CreateServerSocket();
|
2014-07-03 03:17:00 +04:00
|
|
|
}
|
|
|
|
|
2015-08-03 23:22:00 +03:00
|
|
|
/*static*/
|
2015-05-22 12:36:00 +03:00
|
|
|
void
|
|
|
|
LayerScope::DrawBegin()
|
|
|
|
{
|
|
|
|
if (!CheckSendable()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-02 13:21:00 +03:00
|
|
|
gLayerScopeManager.NewDrawSession();
|
2015-05-22 12:36:00 +03:00
|
|
|
}
|
|
|
|
|
2015-08-03 23:22:00 +03:00
|
|
|
/*static*/
|
2015-08-03 09:11:00 +03:00
|
|
|
void
|
|
|
|
LayerScope::SetRenderOffset(float aX, float aY)
|
2015-05-22 12:36:00 +03:00
|
|
|
{
|
|
|
|
if (!CheckSendable()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-02 13:21:00 +03:00
|
|
|
gLayerScopeManager.CurrentSession().mOffsetX = aX;
|
|
|
|
gLayerScopeManager.CurrentSession().mOffsetY = aY;
|
2015-05-22 12:36:00 +03:00
|
|
|
}
|
|
|
|
|
2015-08-03 23:22:00 +03:00
|
|
|
/*static*/
|
2015-08-03 09:11:00 +03:00
|
|
|
void
|
|
|
|
LayerScope::SetLayerTransform(const gfx::Matrix4x4& aMatrix)
|
2015-05-22 12:36:00 +03:00
|
|
|
{
|
|
|
|
if (!CheckSendable()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-02 13:21:00 +03:00
|
|
|
gLayerScopeManager.CurrentSession().mMVMatrix = aMatrix;
|
2015-05-22 12:36:00 +03:00
|
|
|
}
|
|
|
|
|
2015-08-03 23:22:00 +03:00
|
|
|
/*static*/
|
2015-08-03 09:11:00 +03:00
|
|
|
void
|
|
|
|
LayerScope::SetDrawRects(size_t aRects,
|
|
|
|
const gfx::Rect* aLayerRects,
|
|
|
|
const gfx::Rect* aTextureRects)
|
2015-05-22 12:36:00 +03:00
|
|
|
{
|
|
|
|
if (!CheckSendable()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(aRects > 0 && aRects <= 4);
|
|
|
|
MOZ_ASSERT(aLayerRects);
|
|
|
|
|
2015-06-02 13:21:00 +03:00
|
|
|
gLayerScopeManager.CurrentSession().mRects = aRects;
|
2015-05-22 12:36:00 +03:00
|
|
|
|
|
|
|
for (size_t i = 0; i < aRects; i++){
|
2015-06-02 13:21:00 +03:00
|
|
|
gLayerScopeManager.CurrentSession().mLayerRects[i] = aLayerRects[i];
|
2015-08-03 09:11:00 +03:00
|
|
|
gLayerScopeManager.CurrentSession().mTextureRects[i] = aTextureRects[i];
|
2015-05-22 12:36:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-03 23:22:00 +03:00
|
|
|
/*static*/
|
2014-07-03 03:17:00 +04:00
|
|
|
void
|
2015-05-22 12:36:00 +03:00
|
|
|
LayerScope::DrawEnd(gl::GLContext* aGLContext,
|
|
|
|
const EffectChain& aEffectChain,
|
|
|
|
int aWidth,
|
|
|
|
int aHeight)
|
2014-07-03 03:17:00 +04:00
|
|
|
{
|
|
|
|
// Protect this public function
|
|
|
|
if (!CheckSendable()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-05-22 12:36:00 +03:00
|
|
|
|
2015-08-03 09:11:00 +03:00
|
|
|
// 1. Send textures.
|
|
|
|
SenderHelper::SendEffectChain(aGLContext, aEffectChain, aWidth, aHeight);
|
|
|
|
|
|
|
|
// 2. Send parameters of draw call, such as uniforms and attributes of
|
2015-05-22 12:36:00 +03:00
|
|
|
// vertex adnd fragment shader.
|
2015-06-02 13:21:00 +03:00
|
|
|
DrawSession& draws = gLayerScopeManager.CurrentSession();
|
|
|
|
gLayerScopeManager.GetSocketManager()->AppendDebugData(
|
2015-05-22 12:36:00 +03:00
|
|
|
new DebugGLDrawData(draws.mOffsetX, draws.mOffsetY,
|
|
|
|
draws.mMVMatrix, draws.mRects,
|
|
|
|
draws.mLayerRects,
|
2015-08-03 09:11:00 +03:00
|
|
|
draws.mTextureRects,
|
|
|
|
draws.mTexIDs,
|
2015-05-22 12:36:00 +03:00
|
|
|
aEffectChain.mLayerRef));
|
|
|
|
|
2014-07-03 03:17:00 +04:00
|
|
|
}
|
|
|
|
|
2015-08-03 23:22:00 +03:00
|
|
|
/*static*/
|
2014-07-03 03:17:00 +04:00
|
|
|
void
|
|
|
|
LayerScope::SendLayer(LayerComposite* aLayer,
|
|
|
|
int aWidth,
|
|
|
|
int aHeight)
|
|
|
|
{
|
|
|
|
// Protect this public function
|
|
|
|
if (!CheckSendable()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SenderHelper::SendLayer(aLayer, aWidth, aHeight);
|
|
|
|
}
|
|
|
|
|
2015-08-03 23:22:00 +03:00
|
|
|
/*static*/
|
2014-07-28 00:32:00 +04:00
|
|
|
void
|
|
|
|
LayerScope::SendLayerDump(UniquePtr<Packet> aPacket)
|
|
|
|
{
|
|
|
|
// Protect this public function
|
2015-01-29 22:02:00 +03:00
|
|
|
if (!CheckSendable() || !SenderHelper::GetLayersTreeSendable()) {
|
2014-07-28 00:32:00 +04:00
|
|
|
return;
|
|
|
|
}
|
2015-06-02 13:21:00 +03:00
|
|
|
gLayerScopeManager.GetSocketManager()->AppendDebugData(
|
2014-07-28 00:32:00 +04:00
|
|
|
new DebugGLLayersData(Move(aPacket)));
|
|
|
|
}
|
|
|
|
|
2015-08-03 23:22:00 +03:00
|
|
|
/*static*/
|
2014-07-03 03:17:00 +04:00
|
|
|
bool
|
|
|
|
LayerScope::CheckSendable()
|
|
|
|
{
|
2014-11-20 04:00:00 +03:00
|
|
|
// Only compositor threads check LayerScope status
|
2016-05-16 09:40:13 +03:00
|
|
|
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread() || gIsGtest);
|
2014-11-20 04:00:00 +03:00
|
|
|
|
|
|
|
if (!gfxPrefs::LayerScopeEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-06-02 13:21:00 +03:00
|
|
|
if (!gLayerScopeManager.GetSocketManager()) {
|
2014-11-20 04:00:00 +03:00
|
|
|
Init();
|
2014-07-03 03:17:00 +04:00
|
|
|
return false;
|
|
|
|
}
|
2015-06-02 13:21:00 +03:00
|
|
|
if (!gLayerScopeManager.GetSocketManager()->IsConnected()) {
|
2014-07-03 03:17:00 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-08-03 23:22:00 +03:00
|
|
|
/*static*/
|
2014-07-03 03:17:00 +04:00
|
|
|
void
|
|
|
|
LayerScope::CleanLayer()
|
|
|
|
{
|
|
|
|
if (CheckSendable()) {
|
2015-06-02 13:21:00 +03:00
|
|
|
gLayerScopeManager.GetSocketManager()->CleanDebugData();
|
2014-07-03 03:17:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-03 23:22:00 +03:00
|
|
|
/*static*/
|
2015-01-16 10:00:25 +03:00
|
|
|
void
|
|
|
|
LayerScope::SetHWComposed()
|
|
|
|
{
|
|
|
|
if (CheckSendable()) {
|
2015-06-02 13:21:00 +03:00
|
|
|
gLayerScopeManager.GetSocketManager()->AppendDebugData(
|
2015-01-16 10:00:25 +03:00
|
|
|
new DebugGLMetaData(Packet::META, true));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-03 23:22:00 +03:00
|
|
|
/*static*/
|
2015-08-03 09:11:00 +03:00
|
|
|
void
|
|
|
|
LayerScope::SetPixelScale(double devPixelsPerCSSPixel)
|
|
|
|
{
|
|
|
|
gLayerScopeManager.SetPixelScale(devPixelsPerCSSPixel);
|
|
|
|
}
|
2015-08-03 23:22:00 +03:00
|
|
|
|
2014-07-03 03:17:00 +04:00
|
|
|
// ----------------------------------------------
|
|
|
|
// LayerScopeAutoFrame implementation
|
|
|
|
// ----------------------------------------------
|
|
|
|
LayerScopeAutoFrame::LayerScopeAutoFrame(int64_t aFrameStamp)
|
|
|
|
{
|
|
|
|
// Do Begin Frame
|
|
|
|
BeginFrame(aFrameStamp);
|
|
|
|
}
|
|
|
|
|
|
|
|
LayerScopeAutoFrame::~LayerScopeAutoFrame()
|
|
|
|
{
|
|
|
|
// Do End Frame
|
|
|
|
EndFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LayerScopeAutoFrame::BeginFrame(int64_t aFrameStamp)
|
|
|
|
{
|
|
|
|
if (!LayerScope::CheckSendable()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-09-30 00:21:00 +03:00
|
|
|
SenderHelper::ClearSentTextureIds();
|
2014-07-03 03:17:00 +04:00
|
|
|
|
2015-06-02 13:21:00 +03:00
|
|
|
gLayerScopeManager.GetSocketManager()->AppendDebugData(
|
2014-07-10 07:16:00 +04:00
|
|
|
new DebugGLFrameStatusData(Packet::FRAMESTART, aFrameStamp));
|
2014-07-03 03:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LayerScopeAutoFrame::EndFrame()
|
|
|
|
{
|
|
|
|
if (!LayerScope::CheckSendable()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-02 13:21:00 +03:00
|
|
|
gLayerScopeManager.GetSocketManager()->AppendDebugData(
|
2014-07-10 07:16:00 +04:00
|
|
|
new DebugGLFrameStatusData(Packet::FRAMEEND));
|
2015-06-02 13:21:00 +03:00
|
|
|
gLayerScopeManager.GetSocketManager()->DispatchDebugData();
|
2014-07-03 03:17:00 +04:00
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|