2013-11-28 20:11:49 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* 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"
|
|
|
|
|
|
|
|
#include "Composer2D.h"
|
|
|
|
#include "Effects.h"
|
|
|
|
#include "mozilla/TimeStamp.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
2014-02-10 05:45:15 -08:00
|
|
|
#include "mozilla/Endian.h"
|
2013-11-28 20:11:49 -08:00
|
|
|
#include "TexturePoolOGL.h"
|
2014-07-02 16:17:00 -07:00
|
|
|
#include "mozilla/layers/CompositorOGL.h"
|
|
|
|
#include "mozilla/layers/LayerManagerComposite.h"
|
2013-11-28 20:11:49 -08:00
|
|
|
#include "mozilla/layers/TextureHostOGL.h"
|
|
|
|
|
|
|
|
#include "gfxColor.h"
|
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "gfxUtils.h"
|
2014-02-28 09:59:38 -08:00
|
|
|
#include "gfxPrefs.h"
|
2013-11-28 20:11:49 -08:00
|
|
|
#include "nsIWidget.h"
|
|
|
|
|
|
|
|
#include "GLContext.h"
|
|
|
|
#include "GLContextProvider.h"
|
2014-01-02 07:17:22 -08:00
|
|
|
#include "GLReadTexImageHelper.h"
|
2013-11-28 20:11:49 -08:00
|
|
|
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIConsoleService.h"
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include "mozilla/LinkedList.h"
|
2014-02-10 05:45:15 -08:00
|
|
|
#include "mozilla/Base64.h"
|
|
|
|
#include "mozilla/SHA1.h"
|
|
|
|
#include "mozilla/StaticPtr.h"
|
2013-11-28 20:11:49 -08:00
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsISocketTransport.h"
|
|
|
|
#include "nsIServerSocket.h"
|
2014-02-10 05:45:15 -08:00
|
|
|
#include "nsReadLine.h"
|
2013-11-28 20:11:49 -08:00
|
|
|
#include "nsNetCID.h"
|
|
|
|
#include "nsIOutputStream.h"
|
2014-02-10 05:45:15 -08:00
|
|
|
#include "nsIAsyncInputStream.h"
|
2013-11-28 20:11:49 -08:00
|
|
|
#include "nsIEventTarget.h"
|
|
|
|
#include "nsProxyRelease.h"
|
|
|
|
|
2014-04-07 01:58:03 -07:00
|
|
|
// Undo the damage done by mozzconf.h
|
|
|
|
#undef compress
|
|
|
|
#include "mozilla/Compression.h"
|
|
|
|
|
2014-07-09 20:16:00 -07:00
|
|
|
// Protocol buffer (generated automatically)
|
|
|
|
#include "protobuf/LayerScopePacket.pb.h"
|
2013-11-28 20:11:49 -08:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
using namespace mozilla::Compression;
|
|
|
|
using namespace mozilla::gfx;
|
|
|
|
using namespace mozilla::gl;
|
|
|
|
using namespace mozilla;
|
2014-07-09 20:16:00 -07:00
|
|
|
using namespace layerscope;
|
2013-11-28 20:11:49 -08:00
|
|
|
|
|
|
|
class DebugDataSender;
|
2014-02-10 05:45:15 -08:00
|
|
|
class DebugGLData;
|
2013-11-28 20:11:49 -08:00
|
|
|
|
2014-02-10 05:45:15 -08:00
|
|
|
/* This class handle websocket protocol which included
|
|
|
|
* handshake and data frame's header
|
|
|
|
*/
|
|
|
|
class LayerScopeWebSocketHandler : public nsIInputStreamCallback {
|
|
|
|
public:
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
|
|
|
|
enum SocketStateType {
|
|
|
|
NoHandshake,
|
|
|
|
HandshakeSuccess,
|
|
|
|
HandshakeFailed
|
|
|
|
};
|
|
|
|
|
|
|
|
LayerScopeWebSocketHandler()
|
|
|
|
: mState(NoHandshake)
|
|
|
|
{ }
|
|
|
|
|
2014-06-23 11:49:07 -07:00
|
|
|
private:
|
2014-02-10 05:45:15 -08:00
|
|
|
virtual ~LayerScopeWebSocketHandler()
|
|
|
|
{
|
|
|
|
if (mTransport) {
|
|
|
|
mTransport->Close(NS_OK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-23 11:49:07 -07:00
|
|
|
public:
|
2014-02-10 05:45:15 -08:00
|
|
|
void OpenStream(nsISocketTransport* aTransport) {
|
|
|
|
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);
|
|
|
|
mInputStream->AsyncWait(this, 0, 0, NS_GetCurrentThread());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WriteToStream(void *ptr, uint32_t size) {
|
|
|
|
if (mState == NoHandshake) {
|
|
|
|
// Not yet handshake, just return true in case of
|
|
|
|
// LayerScope remove this handle
|
|
|
|
return true;
|
|
|
|
} else if (mState == HandshakeFailed) {
|
|
|
|
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 (size <= 125) {
|
|
|
|
wsHeaderSize = 2;
|
|
|
|
wsHeader[1] = size;
|
|
|
|
} else if (size < 65536) {
|
|
|
|
wsHeaderSize = 4;
|
|
|
|
wsHeader[1] = 0x7E;
|
|
|
|
NetworkEndian::writeUint16(wsHeader + 2, size);
|
|
|
|
} else {
|
|
|
|
wsHeaderSize = 10;
|
|
|
|
wsHeader[1] = 0x7F;
|
|
|
|
NetworkEndian::writeUint64(wsHeader + 2, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 < size) {
|
|
|
|
uint32_t cnt;
|
|
|
|
rv = mOutputStream->Write(reinterpret_cast<char*>(ptr) + written,
|
|
|
|
size - written, &cnt);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
written += cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIInputStreamCallback
|
|
|
|
NS_IMETHODIMP OnInputStreamReady(nsIAsyncInputStream *stream) MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
nsTArray<nsCString> protocolString;
|
|
|
|
ReadInputStreamData(protocolString);
|
|
|
|
|
|
|
|
if (WebSocketHandshake(protocolString)) {
|
|
|
|
mState = HandshakeSuccess;
|
|
|
|
} else {
|
|
|
|
mState = HandshakeFailed;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
void ReadInputStreamData(nsTArray<nsCString>& aProtocolString)
|
|
|
|
{
|
|
|
|
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 WebSocketHandshake(nsTArray<nsCString>& aProtocolString)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-05-21 20:48:51 -07:00
|
|
|
if (!(version.EqualsLiteral("7") ||
|
|
|
|
version.EqualsLiteral("8") ||
|
|
|
|
version.EqualsLiteral("13"))) {
|
2014-02-10 05:45:15 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(protocol.EqualsIgnoreCase("binary"))) {
|
|
|
|
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());
|
2014-07-10 19:10:17 -07:00
|
|
|
uint8_t digest[SHA1Sum::kHashSize]; // SHA1 digests are 20 bytes long.
|
2014-02-10 05:45:15 -08:00
|
|
|
sha1.finish(digest);
|
2014-07-10 19:10:17 -07:00
|
|
|
nsCString newString(reinterpret_cast<char*>(digest), SHA1Sum::kHashSize);
|
2014-02-10 05:45:15 -08:00
|
|
|
Base64Encode(newString, res);
|
|
|
|
|
|
|
|
nsCString response("HTTP/1.1 101 Switching Protocols\r\n");
|
2014-05-21 20:48:51 -07:00
|
|
|
response.AppendLiteral("Upgrade: websocket\r\n");
|
|
|
|
response.AppendLiteral("Connection: Upgrade\r\n");
|
2014-02-10 05:45:15 -08:00
|
|
|
response.Append(nsCString("Sec-WebSocket-Accept: ") + res + nsCString("\r\n"));
|
2014-05-21 20:48:51 -07:00
|
|
|
response.AppendLiteral("Sec-WebSocket-Protocol: binary\r\n\r\n");
|
2014-02-10 05:45:15 -08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIOutputStream> mOutputStream;
|
|
|
|
nsCOMPtr<nsIAsyncInputStream> mInputStream;
|
|
|
|
nsCOMPtr<nsISocketTransport> mTransport;
|
|
|
|
SocketStateType mState;
|
|
|
|
};
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(LayerScopeWebSocketHandler, nsIInputStreamCallback);
|
2014-02-10 05:45:15 -08:00
|
|
|
|
|
|
|
class LayerScopeWebSocketManager {
|
|
|
|
public:
|
|
|
|
LayerScopeWebSocketManager();
|
|
|
|
~LayerScopeWebSocketManager();
|
|
|
|
|
|
|
|
void AddConnection(nsISocketTransport *aTransport)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aTransport);
|
|
|
|
nsRefPtr<LayerScopeWebSocketHandler> temp = new LayerScopeWebSocketHandler();
|
|
|
|
temp->OpenStream(aTransport);
|
|
|
|
mHandlers.AppendElement(temp.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveConnection(uint32_t aIndex)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aIndex < mHandlers.Length());
|
|
|
|
mHandlers.RemoveElementAt(aIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveAllConnections()
|
|
|
|
{
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
return (mHandlers.Length() != 0) ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppendDebugData(DebugGLData *aDebugData);
|
2014-07-02 16:17:00 -07:00
|
|
|
void CleanDebugData();
|
2014-02-10 05:45:15 -08:00
|
|
|
void DispatchDebugData();
|
|
|
|
private:
|
|
|
|
nsTArray<nsRefPtr<LayerScopeWebSocketHandler> > mHandlers;
|
|
|
|
nsCOMPtr<nsIThread> mDebugSenderThread;
|
2014-03-17 17:23:03 -07:00
|
|
|
nsRefPtr<DebugDataSender> mCurrentSender;
|
2014-02-10 05:45:15 -08:00
|
|
|
nsCOMPtr<nsIServerSocket> mServerSocket;
|
|
|
|
};
|
|
|
|
|
2014-07-02 16:17:00 -07:00
|
|
|
// Static class to create and destory LayerScopeWebSocketManager object
|
|
|
|
class WebSocketHelper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static void CreateServerSocket()
|
|
|
|
{
|
|
|
|
// Create Web Server Socket (which has to be on the main thread)
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
if (!sWebSocketManager) {
|
|
|
|
sWebSocketManager = new LayerScopeWebSocketManager();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DestroyServerSocket()
|
|
|
|
{
|
|
|
|
// Destroy Web Server Socket
|
|
|
|
if (sWebSocketManager) {
|
|
|
|
sWebSocketManager->RemoveAllConnections();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static LayerScopeWebSocketManager* GetSocketManager()
|
|
|
|
{
|
2014-07-09 20:16:00 -07:00
|
|
|
return sWebSocketManager;
|
2014-07-02 16:17:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static StaticAutoPtr<LayerScopeWebSocketManager> sWebSocketManager;
|
|
|
|
};
|
|
|
|
|
|
|
|
StaticAutoPtr<LayerScopeWebSocketManager> WebSocketHelper::sWebSocketManager;
|
2013-11-28 20:11:49 -08:00
|
|
|
|
2014-07-09 20:16:00 -07:00
|
|
|
/*
|
|
|
|
* DebugGLData is the base class of
|
|
|
|
* 1. DebugGLFrameStatusData (Frame start/end packet)
|
|
|
|
* 2. DebugGLColorData (Color data packet)
|
|
|
|
* 3. DebugGLTextureData (Texture data packet)
|
|
|
|
*/
|
|
|
|
class DebugGLData: public LinkedListElement<DebugGLData> {
|
2013-11-28 20:11:49 -08:00
|
|
|
public:
|
2014-08-19 21:55:14 -07:00
|
|
|
explicit DebugGLData(Packet::DataType aDataType)
|
2014-07-09 20:16:00 -07:00
|
|
|
: mDataType(aDataType)
|
|
|
|
{ }
|
2013-11-28 20:11:49 -08:00
|
|
|
|
|
|
|
virtual ~DebugGLData() { }
|
|
|
|
|
2014-07-09 20:16:00 -07:00
|
|
|
Packet::DataType GetDataType() const { return mDataType; }
|
2013-11-28 20:11:49 -08:00
|
|
|
|
2014-07-09 20:16:00 -07:00
|
|
|
virtual bool Write() = 0;
|
2013-11-28 20:11:49 -08:00
|
|
|
|
2014-07-09 20:16:00 -07:00
|
|
|
static bool WriteToStream(Packet& aPacket) {
|
|
|
|
if (!WebSocketHelper::GetSocketManager())
|
|
|
|
return true;
|
2013-11-28 20:11:49 -08:00
|
|
|
|
2014-07-09 20:16:00 -07:00
|
|
|
uint32_t size = aPacket.ByteSize();
|
2014-07-27 13:32:00 -07:00
|
|
|
auto data = MakeUnique<uint8_t[]>(size);
|
2014-07-21 12:12:00 -07:00
|
|
|
aPacket.SerializeToArray(data.get(), size);
|
|
|
|
return WebSocketHelper::GetSocketManager()->WriteAll(data.get(), size);
|
2014-07-09 20:16:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Packet::DataType mDataType;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DebugGLFrameStatusData : public DebugGLData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DebugGLFrameStatusData(Packet::DataType aDataType,
|
|
|
|
int64_t aValue)
|
|
|
|
: DebugGLData(aDataType),
|
|
|
|
mFrameStamp(aValue)
|
2013-11-28 20:11:49 -08:00
|
|
|
{ }
|
|
|
|
|
2014-08-19 21:55:14 -07:00
|
|
|
explicit DebugGLFrameStatusData(Packet::DataType aDataType)
|
2014-07-09 20:16:00 -07:00
|
|
|
: DebugGLData(aDataType),
|
|
|
|
mFrameStamp(0)
|
|
|
|
{ }
|
2013-11-28 20:11:49 -08:00
|
|
|
|
2014-07-09 20:16:00 -07:00
|
|
|
int64_t GetFrameStamp() const { return mFrameStamp; }
|
2013-11-28 20:11:49 -08:00
|
|
|
|
2014-07-09 20:16:00 -07:00
|
|
|
virtual bool Write() MOZ_OVERRIDE {
|
|
|
|
Packet packet;
|
|
|
|
packet.set_type(mDataType);
|
2013-11-28 20:11:49 -08:00
|
|
|
|
2014-07-27 13:32:00 -07:00
|
|
|
FramePacket* fp = packet.mutable_frame();
|
|
|
|
fp->set_value(static_cast<uint64_t>(mFrameStamp));
|
2013-11-28 20:11:49 -08:00
|
|
|
|
2014-07-09 20:16:00 -07:00
|
|
|
if (!WriteToStream(packet))
|
|
|
|
return false;
|
|
|
|
return true;
|
2013-11-28 20:11:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-07-09 20:16:00 -07:00
|
|
|
int64_t mFrameStamp;
|
2013-11-28 20:11:49 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
class DebugGLTextureData : public DebugGLData {
|
|
|
|
public:
|
2014-07-02 16:17:00 -07:00
|
|
|
DebugGLTextureData(GLContext* cx,
|
|
|
|
void* layerRef,
|
|
|
|
GLenum target,
|
|
|
|
GLuint name,
|
|
|
|
DataSourceSurface* img)
|
2014-07-09 20:16:00 -07:00
|
|
|
: DebugGLData(Packet::TEXTURE),
|
2013-11-28 20:11:49 -08:00
|
|
|
mLayerRef(layerRef),
|
|
|
|
mTarget(target),
|
|
|
|
mName(name),
|
2014-07-09 20:16:00 -07:00
|
|
|
mContextAddress(reinterpret_cast<intptr_t>(cx)),
|
2014-07-02 16:17:00 -07:00
|
|
|
mDatasize(0)
|
|
|
|
{
|
|
|
|
// pre-packing
|
|
|
|
// DataSourceSurface may have locked buffer,
|
|
|
|
// so we should compress now, and then it could
|
|
|
|
// be unlocked outside.
|
|
|
|
pack(img);
|
|
|
|
}
|
2013-11-28 20:11:49 -08:00
|
|
|
|
2014-07-09 20:16:00 -07:00
|
|
|
const void* GetLayerRef() const { return mLayerRef; }
|
2013-11-28 20:11:49 -08:00
|
|
|
GLuint GetName() const { return mName; }
|
|
|
|
GLenum GetTextureTarget() const { return mTarget; }
|
2014-07-09 20:16:00 -07:00
|
|
|
intptr_t GetContextAddress() const { return mContextAddress; }
|
|
|
|
uint32_t GetDataSize() const { return mDatasize; }
|
2013-11-28 20:11:49 -08:00
|
|
|
|
2014-07-09 20:16:00 -07:00
|
|
|
virtual bool Write() MOZ_OVERRIDE {
|
|
|
|
if (!WriteToStream(mPacket))
|
2013-11-28 20:11:49 -08:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-02 16:17:00 -07:00
|
|
|
private:
|
|
|
|
void pack(DataSourceSurface* aImage) {
|
2014-07-09 20:16:00 -07:00
|
|
|
mPacket.set_type(mDataType);
|
|
|
|
|
2014-07-27 13:32:00 -07:00
|
|
|
TexturePacket* tp = mPacket.mutable_texture();
|
2014-07-09 20:16:00 -07:00
|
|
|
tp->set_layerref(reinterpret_cast<uint64_t>(mLayerRef));
|
|
|
|
tp->set_name(mName);
|
|
|
|
tp->set_target(mTarget);
|
|
|
|
tp->set_dataformat(LOCAL_GL_RGBA);
|
|
|
|
tp->set_glcontext(static_cast<uint64_t>(mContextAddress));
|
2014-07-02 16:17:00 -07:00
|
|
|
|
|
|
|
if (aImage) {
|
2014-07-09 20:16:00 -07: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-27 13:32:00 -07:00
|
|
|
auto compresseddata = MakeUnique<char[]>(LZ4::maxCompressedSize(mDatasize));
|
2014-07-21 12:12:00 -07:00
|
|
|
if (compresseddata) {
|
2014-07-02 16:17:00 -07:00
|
|
|
int ndatasize = LZ4::compress((char*)aImage->GetData(),
|
2014-07-09 20:16:00 -07:00
|
|
|
mDatasize,
|
2014-07-21 12:12:00 -07:00
|
|
|
compresseddata.get());
|
2014-07-02 16:17:00 -07:00
|
|
|
if (ndatasize > 0) {
|
|
|
|
mDatasize = ndatasize;
|
2014-07-09 20:16:00 -07:00
|
|
|
tp->set_dataformat((1 << 16 | tp->dataformat()));
|
2014-07-21 12:12:00 -07:00
|
|
|
tp->set_data(compresseddata.get(), mDatasize);
|
2014-07-02 16:17:00 -07:00
|
|
|
} else {
|
|
|
|
NS_WARNING("Compress data failed");
|
2014-07-09 20:16:00 -07:00
|
|
|
tp->set_data(aImage->GetData(), mDatasize);
|
2014-07-02 16:17:00 -07:00
|
|
|
}
|
|
|
|
} else {
|
2014-07-09 20:16:00 -07:00
|
|
|
NS_WARNING("Couldn't new compressed data.");
|
|
|
|
tp->set_data(aImage->GetData(), mDatasize);
|
2014-07-02 16:17:00 -07:00
|
|
|
}
|
|
|
|
} else {
|
2014-07-09 20:16:00 -07:00
|
|
|
tp->set_width(0);
|
|
|
|
tp->set_height(0);
|
|
|
|
tp->set_stride(0);
|
2014-07-02 16:17:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-28 20:11:49 -08:00
|
|
|
protected:
|
|
|
|
void* mLayerRef;
|
|
|
|
GLenum mTarget;
|
|
|
|
GLuint mName;
|
2014-07-09 20:16:00 -07:00
|
|
|
intptr_t mContextAddress;
|
|
|
|
uint32_t mDatasize;
|
2014-07-02 16:17:00 -07:00
|
|
|
|
|
|
|
// Packet data
|
2014-07-09 20:16:00 -07:00
|
|
|
Packet mPacket;
|
2013-11-28 20:11:49 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
class DebugGLColorData : public DebugGLData {
|
|
|
|
public:
|
2014-07-09 20:16:00 -07:00
|
|
|
DebugGLColorData(void* layerRef,
|
|
|
|
const gfxRGBA& color,
|
|
|
|
int width,
|
|
|
|
int height)
|
|
|
|
: DebugGLData(Packet::COLOR),
|
2014-06-24 12:42:00 -07:00
|
|
|
mLayerRef(layerRef),
|
2013-11-28 20:11:49 -08:00
|
|
|
mColor(color.Packed()),
|
|
|
|
mSize(width, height)
|
|
|
|
{ }
|
|
|
|
|
2014-07-09 20:16:00 -07:00
|
|
|
const void* GetLayerRef() const { return mLayerRef; }
|
2013-11-28 20:11:49 -08:00
|
|
|
uint32_t GetColor() const { return mColor; }
|
|
|
|
const nsIntSize& GetSize() const { return mSize; }
|
|
|
|
|
2014-07-09 20:16:00 -07:00
|
|
|
virtual bool Write() MOZ_OVERRIDE {
|
|
|
|
Packet packet;
|
|
|
|
packet.set_type(mDataType);
|
2013-11-28 20:11:49 -08:00
|
|
|
|
2014-07-27 13:32:00 -07:00
|
|
|
ColorPacket* cp = packet.mutable_color();
|
2014-07-09 20:16:00 -07:00
|
|
|
cp->set_layerref(reinterpret_cast<uint64_t>(mLayerRef));
|
|
|
|
cp->set_color(mColor);
|
|
|
|
cp->set_width(mSize.width);
|
|
|
|
cp->set_height(mSize.height);
|
2013-11-28 20:11:49 -08:00
|
|
|
|
2014-07-09 20:16:00 -07:00
|
|
|
if (!WriteToStream(packet))
|
|
|
|
return false;
|
|
|
|
return true;
|
2013-11-28 20:11:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-07-27 13:32:00 -07:00
|
|
|
void* mLayerRef;
|
2013-11-28 20:11:49 -08:00
|
|
|
uint32_t mColor;
|
|
|
|
nsIntSize mSize;
|
|
|
|
};
|
|
|
|
|
2014-07-27 13:32:00 -07:00
|
|
|
class DebugGLLayersData : public DebugGLData {
|
|
|
|
public:
|
2014-08-19 21:55:14 -07:00
|
|
|
explicit DebugGLLayersData(UniquePtr<Packet> aPacket)
|
2014-07-27 13:32:00 -07:00
|
|
|
: DebugGLData(Packet::LAYERS),
|
|
|
|
mPacket(Move(aPacket))
|
|
|
|
{ }
|
|
|
|
|
|
|
|
virtual bool Write() MOZ_OVERRIDE {
|
|
|
|
mPacket->set_type(mDataType);
|
|
|
|
|
|
|
|
if (!WriteToStream(*mPacket))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
UniquePtr<Packet> mPacket;
|
|
|
|
};
|
|
|
|
|
2013-11-28 20:11:49 -08:00
|
|
|
class DebugListener : public nsIServerSocketListener
|
|
|
|
{
|
2014-06-23 11:49:07 -07:00
|
|
|
virtual ~DebugListener() { }
|
|
|
|
|
2013-11-28 20:11:49 -08:00
|
|
|
public:
|
|
|
|
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
|
|
|
|
DebugListener() { }
|
|
|
|
|
|
|
|
/* nsIServerSocketListener */
|
|
|
|
|
|
|
|
NS_IMETHODIMP OnSocketAccepted(nsIServerSocket *aServ,
|
|
|
|
nsISocketTransport *aTransport)
|
|
|
|
{
|
2014-07-02 16:17:00 -07:00
|
|
|
if (!WebSocketHelper::GetSocketManager())
|
2014-02-10 05:45:15 -08:00
|
|
|
return NS_OK;
|
|
|
|
|
2013-11-28 20:11:49 -08:00
|
|
|
printf_stderr("*** LayerScope: Accepted connection\n");
|
2014-07-02 16:17:00 -07:00
|
|
|
WebSocketHelper::GetSocketManager()->AddConnection(aTransport);
|
2013-11-28 20:11:49 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP OnStopListening(nsIServerSocket *aServ,
|
|
|
|
nsresult aStatus)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(DebugListener, nsIServerSocketListener);
|
2013-11-28 20:11:49 -08:00
|
|
|
|
|
|
|
|
|
|
|
class DebugDataSender : public nsIRunnable
|
|
|
|
{
|
2014-06-23 11:49:07 -07:00
|
|
|
virtual ~DebugDataSender() {
|
|
|
|
Cleanup();
|
|
|
|
}
|
|
|
|
|
2013-11-28 20:11:49 -08:00
|
|
|
public:
|
|
|
|
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
|
2014-07-02 16:17:00 -07:00
|
|
|
DebugDataSender() { }
|
2013-11-28 20:11:49 -08:00
|
|
|
|
|
|
|
void Append(DebugGLData *d) {
|
2014-07-02 16:17:00 -07:00
|
|
|
mList.insertBack(d);
|
2013-11-28 20:11:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Cleanup() {
|
2014-07-02 16:17:00 -07:00
|
|
|
if (mList.isEmpty())
|
2013-11-28 20:11:49 -08:00
|
|
|
return;
|
|
|
|
|
|
|
|
DebugGLData *d;
|
2014-07-02 16:17:00 -07:00
|
|
|
while ((d = mList.popFirst()) != nullptr)
|
2013-11-28 20:11:49 -08:00
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* nsIRunnable impl; send the data */
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run() {
|
|
|
|
DebugGLData *d;
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2014-07-02 16:17:00 -07:00
|
|
|
while ((d = mList.popFirst()) != nullptr) {
|
2014-07-21 12:12:00 -07:00
|
|
|
UniquePtr<DebugGLData> cleaner(d);
|
2013-11-28 20:11:49 -08:00
|
|
|
if (!d->Write()) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Cleanup();
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
2014-07-02 16:17:00 -07:00
|
|
|
WebSocketHelper::DestroyServerSocket();
|
2013-11-28 20:11:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-07-02 16:17:00 -07:00
|
|
|
LinkedList<DebugGLData> mList;
|
2013-11-28 20:11:49 -08:00
|
|
|
};
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(DebugDataSender, nsIRunnable);
|
2013-11-28 20:11:49 -08:00
|
|
|
|
2014-07-02 16:17:00 -07:00
|
|
|
/*
|
|
|
|
* LayerScope SendXXX Structure
|
|
|
|
* 1. SendLayer
|
|
|
|
* 2. SendEffectChain
|
|
|
|
* 1. SendTexturedEffect
|
|
|
|
* -> SendTextureSource
|
|
|
|
* 2. SendYCbCrEffect
|
|
|
|
* -> SendTextureSource
|
|
|
|
* 3. SendColor
|
|
|
|
*/
|
|
|
|
class SenderHelper
|
2013-11-28 20:11:49 -08:00
|
|
|
{
|
2014-07-02 16:17:00 -07:00
|
|
|
// Sender public APIs
|
|
|
|
public:
|
|
|
|
static void SendLayer(LayerComposite* aLayer,
|
|
|
|
int aWidth,
|
|
|
|
int aHeight);
|
2013-11-28 20:11:49 -08:00
|
|
|
|
2014-07-02 16:17:00 -07:00
|
|
|
static void SendEffectChain(gl::GLContext* aGLContext,
|
|
|
|
const EffectChain& aEffectChain,
|
|
|
|
int aWidth = 0,
|
|
|
|
int aHeight = 0);
|
|
|
|
|
|
|
|
// Sender private functions
|
|
|
|
private:
|
|
|
|
static void SendColor(void* aLayerRef,
|
|
|
|
const gfxRGBA& aColor,
|
|
|
|
int aWidth,
|
|
|
|
int aHeight);
|
|
|
|
static void SendTextureSource(GLContext* aGLContext,
|
|
|
|
void* aLayerRef,
|
|
|
|
TextureSourceOGL* aSource,
|
|
|
|
bool aFlipY);
|
|
|
|
static void SendTexturedEffect(GLContext* aGLContext,
|
|
|
|
void* aLayerRef,
|
|
|
|
const TexturedEffect* aEffect);
|
|
|
|
static void SendYCbCrEffect(GLContext* aGLContext,
|
|
|
|
void* aLayerRef,
|
|
|
|
const EffectYCbCr* aEffect);
|
|
|
|
};
|
2013-11-28 20:11:49 -08:00
|
|
|
|
|
|
|
|
2014-07-02 16:17:00 -07:00
|
|
|
// ----------------------------------------------
|
|
|
|
// SenderHelper implementation
|
|
|
|
// ----------------------------------------------
|
2013-11-28 20:11:49 -08:00
|
|
|
void
|
2014-07-02 16:17:00 -07:00
|
|
|
SenderHelper::SendLayer(LayerComposite* aLayer,
|
|
|
|
int aWidth,
|
|
|
|
int aHeight)
|
2013-11-28 20:11:49 -08:00
|
|
|
{
|
2014-07-02 16:17:00 -07:00
|
|
|
MOZ_ASSERT(aLayer && aLayer->GetLayer());
|
|
|
|
if (!aLayer || !aLayer->GetLayer()) {
|
2013-11-28 20:11:49 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-02 16:17:00 -07:00
|
|
|
switch (aLayer->GetLayer()->GetType()) {
|
|
|
|
case Layer::TYPE_COLOR: {
|
|
|
|
EffectChain effect;
|
|
|
|
aLayer->GenEffectChain(effect);
|
|
|
|
SenderHelper::SendEffectChain(nullptr, effect, aWidth, aHeight);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Layer::TYPE_IMAGE:
|
|
|
|
case Layer::TYPE_CANVAS:
|
2014-09-26 10:07:06 -07:00
|
|
|
case Layer::TYPE_PAINTED: {
|
2014-07-02 16:17:00 -07:00
|
|
|
// Get CompositableHost and Compositor
|
|
|
|
CompositableHost* compHost = aLayer->GetCompositableHost();
|
|
|
|
Compositor* comp = compHost->GetCompositor();
|
|
|
|
// Send EffectChain only for CompositorOGL
|
|
|
|
if (LayersBackend::LAYERS_OPENGL == comp->GetBackendType()) {
|
|
|
|
CompositorOGL* compOGL = static_cast<CompositorOGL*>(comp);
|
|
|
|
EffectChain effect;
|
|
|
|
// Generate primary effect (lock and gen)
|
|
|
|
AutoLockCompositableHost lock(compHost);
|
|
|
|
aLayer->GenEffectChain(effect);
|
|
|
|
SenderHelper::SendEffectChain(compOGL->gl(), effect);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Layer::TYPE_CONTAINER:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-11-28 20:11:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-07-02 16:17:00 -07:00
|
|
|
SenderHelper::SendColor(void* aLayerRef,
|
|
|
|
const gfxRGBA& aColor,
|
|
|
|
int aWidth,
|
|
|
|
int aHeight)
|
2013-11-28 20:11:49 -08:00
|
|
|
{
|
2014-07-02 16:17:00 -07:00
|
|
|
WebSocketHelper::GetSocketManager()->AppendDebugData(
|
|
|
|
new DebugGLColorData(aLayerRef, aColor, aWidth, aHeight));
|
2013-11-28 20:11:49 -08:00
|
|
|
}
|
|
|
|
|
2014-07-02 16:17:00 -07:00
|
|
|
void
|
|
|
|
SenderHelper::SendTextureSource(GLContext* aGLContext,
|
|
|
|
void* aLayerRef,
|
|
|
|
TextureSourceOGL* aSource,
|
|
|
|
bool aFlipY)
|
2013-11-28 20:11:49 -08:00
|
|
|
{
|
2014-07-02 16:17:00 -07:00
|
|
|
MOZ_ASSERT(aGLContext);
|
|
|
|
if (!aGLContext) {
|
2013-11-28 20:11:49 -08:00
|
|
|
return;
|
2014-07-02 16:17:00 -07:00
|
|
|
}
|
2013-11-28 20:11:49 -08:00
|
|
|
|
|
|
|
GLenum textureTarget = aSource->GetTextureTarget();
|
2013-11-07 22:22:05 -08:00
|
|
|
ShaderConfigOGL config = ShaderConfigFromTargetAndFormat(textureTarget,
|
|
|
|
aSource->GetFormat());
|
|
|
|
int shaderConfig = config.mFeatures;
|
2013-11-28 20:11:49 -08:00
|
|
|
|
2014-03-12 17:37:17 -07:00
|
|
|
aSource->BindTexture(LOCAL_GL_TEXTURE0, gfx::Filter::LINEAR);
|
2013-11-28 20:11:49 -08:00
|
|
|
|
|
|
|
GLuint textureId = 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, &textureId);
|
|
|
|
} else if (textureTarget == LOCAL_GL_TEXTURE_EXTERNAL) {
|
|
|
|
aGLContext->GetUIntegerv(LOCAL_GL_TEXTURE_BINDING_EXTERNAL, &textureId);
|
|
|
|
} else if (textureTarget == LOCAL_GL_TEXTURE_RECTANGLE) {
|
|
|
|
aGLContext->GetUIntegerv(LOCAL_GL_TEXTURE_BINDING_RECTANGLE, &textureId);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::IntSize size = aSource->GetSize();
|
|
|
|
|
|
|
|
// By sending 0 to ReadTextureImage rely upon aSource->BindTexture binding
|
|
|
|
// texture correctly. textureId is used for tracking in DebugGLTextureData.
|
2014-03-11 08:14:50 -07:00
|
|
|
RefPtr<DataSourceSurface> img =
|
2014-01-02 07:17:22 -08:00
|
|
|
aGLContext->ReadTexImageHelper()->ReadTexImage(0, textureTarget,
|
2014-03-11 08:14:50 -07:00
|
|
|
size,
|
2013-11-07 22:22:05 -08:00
|
|
|
shaderConfig, aFlipY);
|
2013-11-28 20:11:49 -08:00
|
|
|
|
2014-07-02 16:17:00 -07:00
|
|
|
WebSocketHelper::GetSocketManager()->AppendDebugData(
|
2013-11-28 20:11:49 -08:00
|
|
|
new DebugGLTextureData(aGLContext, aLayerRef, textureTarget,
|
|
|
|
textureId, img));
|
|
|
|
}
|
|
|
|
|
2014-07-02 16:17:00 -07:00
|
|
|
void
|
|
|
|
SenderHelper::SendTexturedEffect(GLContext* aGLContext,
|
|
|
|
void* aLayerRef,
|
|
|
|
const TexturedEffect* aEffect)
|
2013-11-28 20:11:49 -08:00
|
|
|
{
|
|
|
|
TextureSourceOGL* source = aEffect->mTexture->AsSourceOGL();
|
|
|
|
if (!source)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool flipY = false;
|
|
|
|
SendTextureSource(aGLContext, aLayerRef, source, flipY);
|
|
|
|
}
|
|
|
|
|
2014-07-02 16:17:00 -07:00
|
|
|
void
|
|
|
|
SenderHelper::SendYCbCrEffect(GLContext* aGLContext,
|
|
|
|
void* aLayerRef,
|
|
|
|
const EffectYCbCr* aEffect)
|
2013-11-28 20:11:49 -08:00
|
|
|
{
|
|
|
|
TextureSource* sourceYCbCr = aEffect->mTexture;
|
|
|
|
if (!sourceYCbCr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const int Y = 0, Cb = 1, Cr = 2;
|
|
|
|
TextureSourceOGL* sourceY = sourceYCbCr->GetSubSource(Y)->AsSourceOGL();
|
|
|
|
TextureSourceOGL* sourceCb = sourceYCbCr->GetSubSource(Cb)->AsSourceOGL();
|
|
|
|
TextureSourceOGL* sourceCr = sourceYCbCr->GetSubSource(Cr)->AsSourceOGL();
|
|
|
|
|
|
|
|
bool flipY = false;
|
|
|
|
SendTextureSource(aGLContext, aLayerRef, sourceY, flipY);
|
|
|
|
SendTextureSource(aGLContext, aLayerRef, sourceCb, flipY);
|
|
|
|
SendTextureSource(aGLContext, aLayerRef, sourceCr, flipY);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-07-02 16:17:00 -07:00
|
|
|
SenderHelper::SendEffectChain(GLContext* aGLContext,
|
|
|
|
const EffectChain& aEffectChain,
|
|
|
|
int aWidth,
|
|
|
|
int aHeight)
|
2013-11-28 20:11:49 -08:00
|
|
|
{
|
|
|
|
const Effect* primaryEffect = aEffectChain.mPrimaryEffect;
|
|
|
|
switch (primaryEffect->mType) {
|
2014-07-02 16:17:00 -07: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);
|
|
|
|
gfxRGBA color(solidColorEffect->mColor.r,
|
|
|
|
solidColorEffect->mColor.g,
|
|
|
|
solidColorEffect->mColor.b,
|
|
|
|
solidColorEffect->mColor.a);
|
|
|
|
SendColor(aEffectChain.mLayerRef, color, aWidth, aHeight);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EffectTypes::COMPONENT_ALPHA:
|
|
|
|
case EffectTypes::RENDER_TARGET:
|
|
|
|
default:
|
|
|
|
break;
|
2013-11-28 20:11:49 -08:00
|
|
|
}
|
|
|
|
|
2014-04-25 19:34:06 -07:00
|
|
|
//const Effect* secondaryEffect = aEffectChain.mSecondaryEffects[EffectTypes::MASK];
|
2013-11-28 20:11:49 -08:00
|
|
|
// TODO:
|
|
|
|
}
|
|
|
|
|
2014-07-02 16:17:00 -07:00
|
|
|
// ----------------------------------------------
|
|
|
|
// LayerScopeWebSocketManager implementation
|
|
|
|
// ----------------------------------------------
|
2014-02-10 05:45:15 -08:00
|
|
|
LayerScopeWebSocketManager::LayerScopeWebSocketManager()
|
|
|
|
{
|
|
|
|
NS_NewThread(getter_AddRefs(mDebugSenderThread));
|
|
|
|
|
|
|
|
mServerSocket = do_CreateInstance(NS_SERVERSOCKET_CONTRACTID);
|
2014-02-28 09:59:38 -08:00
|
|
|
int port = gfxPrefs::LayerScopePort();
|
2014-02-10 05:45:15 -08:00
|
|
|
mServerSocket->Init(port, false, -1);
|
|
|
|
mServerSocket->AsyncListen(new DebugListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
LayerScopeWebSocketManager::~LayerScopeWebSocketManager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-07-02 16:17:00 -07:00
|
|
|
void
|
|
|
|
LayerScopeWebSocketManager::AppendDebugData(DebugGLData *aDebugData)
|
2014-02-10 05:45:15 -08:00
|
|
|
{
|
|
|
|
if (!mCurrentSender) {
|
|
|
|
mCurrentSender = new DebugDataSender();
|
|
|
|
}
|
|
|
|
|
|
|
|
mCurrentSender->Append(aDebugData);
|
|
|
|
}
|
|
|
|
|
2014-07-02 16:17:00 -07:00
|
|
|
void
|
|
|
|
LayerScopeWebSocketManager::CleanDebugData()
|
|
|
|
{
|
|
|
|
if (mCurrentSender) {
|
|
|
|
mCurrentSender->Cleanup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LayerScopeWebSocketManager::DispatchDebugData()
|
2014-02-10 05:45:15 -08:00
|
|
|
{
|
|
|
|
mDebugSenderThread->Dispatch(mCurrentSender, NS_DISPATCH_NORMAL);
|
|
|
|
mCurrentSender = nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-02 16:17:00 -07:00
|
|
|
|
|
|
|
// ----------------------------------------------
|
|
|
|
// LayerScope implementation
|
|
|
|
// ----------------------------------------------
|
|
|
|
void
|
|
|
|
LayerScope::Init()
|
|
|
|
{
|
|
|
|
if (!gfxPrefs::LayerScopeEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note: The server socket has to be created on the main thread
|
|
|
|
WebSocketHelper::CreateServerSocket();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LayerScope::DeInit()
|
|
|
|
{
|
|
|
|
// Destroy Web Server Socket
|
|
|
|
WebSocketHelper::DestroyServerSocket();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LayerScope::SendEffectChain(gl::GLContext* aGLContext,
|
|
|
|
const EffectChain& aEffectChain,
|
|
|
|
int aWidth,
|
|
|
|
int aHeight)
|
|
|
|
{
|
|
|
|
// Protect this public function
|
|
|
|
if (!CheckSendable()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SenderHelper::SendEffectChain(aGLContext, aEffectChain, aWidth, aHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LayerScope::SendLayer(LayerComposite* aLayer,
|
|
|
|
int aWidth,
|
|
|
|
int aHeight)
|
|
|
|
{
|
|
|
|
// Protect this public function
|
|
|
|
if (!CheckSendable()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SenderHelper::SendLayer(aLayer, aWidth, aHeight);
|
|
|
|
}
|
|
|
|
|
2014-07-27 13:32:00 -07:00
|
|
|
void
|
|
|
|
LayerScope::SendLayerDump(UniquePtr<Packet> aPacket)
|
|
|
|
{
|
|
|
|
// Protect this public function
|
|
|
|
if (!CheckSendable()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
WebSocketHelper::GetSocketManager()->AppendDebugData(
|
|
|
|
new DebugGLLayersData(Move(aPacket)));
|
|
|
|
}
|
|
|
|
|
2014-07-02 16:17:00 -07:00
|
|
|
bool
|
|
|
|
LayerScope::CheckSendable()
|
|
|
|
{
|
|
|
|
if (!WebSocketHelper::GetSocketManager()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!WebSocketHelper::GetSocketManager()->IsConnected()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LayerScope::CleanLayer()
|
|
|
|
{
|
|
|
|
if (CheckSendable()) {
|
|
|
|
WebSocketHelper::GetSocketManager()->CleanDebugData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebSocketHelper::GetSocketManager()->AppendDebugData(
|
2014-07-09 20:16:00 -07:00
|
|
|
new DebugGLFrameStatusData(Packet::FRAMESTART, aFrameStamp));
|
2014-07-02 16:17:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LayerScopeAutoFrame::EndFrame()
|
|
|
|
{
|
|
|
|
if (!LayerScope::CheckSendable()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebSocketHelper::GetSocketManager()->AppendDebugData(
|
2014-07-09 20:16:00 -07:00
|
|
|
new DebugGLFrameStatusData(Packet::FRAMEEND));
|
2014-07-02 16:17:00 -07:00
|
|
|
WebSocketHelper::GetSocketManager()->DispatchDebugData();
|
|
|
|
}
|
|
|
|
|
2013-11-28 20:11:49 -08:00
|
|
|
} /* layers */
|
|
|
|
} /* mozilla */
|