fune/gfx/layers/wr/WebRenderMessageUtils.h
Ryan Hunt b66f280583 Bug 1329739 - Specify a WrMixBlendMode for WebRenderLayer r=kats
--HG--
extra : amend_source : bfa6ad8ee9cc13ab292958040ccd0f8dded15e5f
extra : histedit_source : c33cb15304d3e5806b90f04f690e000d42a5f933
2017-01-19 17:57:18 -06:00

286 lines
6.3 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef GFX_WEBRENDERMESSAGEUTILS_H
#define GFX_WEBRENDERMESSAGEUTILS_H
#include "chrome/common/ipc_message_utils.h"
#include "mozilla/webrender/webrender_ffi.h"
#include "mozilla/webrender/WebRenderTypes.h"
namespace IPC {
template<>
struct ParamTraits<mozilla::wr::ByteBuffer>
{
typedef mozilla::wr::ByteBuffer paramType;
static void
Write(Message* aMsg, const paramType& aParam)
{
WriteParam(aMsg, aParam.mLength);
aMsg->WriteBytes(aParam.mData, aParam.mLength);
}
static bool
Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
{
size_t length;
return ReadParam(aMsg, aIter, &length)
&& aResult->Allocate(length)
&& aMsg->ReadBytesInto(aIter, aResult->mData, length);
}
};
template<>
struct ParamTraits<mozilla::wr::ImageKey>
{
static void
Write(Message* aMsg, const mozilla::wr::ImageKey& aParam)
{
WriteParam(aMsg, aParam.mHandle);
}
static bool
Read(const Message* aMsg, PickleIterator* aIter, mozilla::wr::ImageKey* aResult)
{
return ReadParam(aMsg, aIter, &aResult->mHandle);
}
};
template<>
struct ParamTraits<mozilla::wr::FontKey>
{
static void
Write(Message* aMsg, const mozilla::wr::FontKey& aParam)
{
WriteParam(aMsg, aParam.mHandle);
}
static bool
Read(const Message* aMsg, PickleIterator* aIter, mozilla::wr::FontKey* aResult)
{
return ReadParam(aMsg, aIter, &aResult->mHandle);
}
};
template<>
struct ParamTraits<mozilla::wr::PipelineId>
{
static void
Write(Message* aMsg, const mozilla::wr::PipelineId& aParam)
{
WriteParam(aMsg, aParam.mHandle);
}
static bool
Read(const Message* aMsg, PickleIterator* aIter, mozilla::wr::PipelineId* aResult)
{
return ReadParam(aMsg, aIter, &aResult->mHandle);
}
};
template<>
struct ParamTraits<WrImageFormat>
: public ContiguousEnumSerializer<
WrImageFormat,
WrImageFormat::Invalid,
WrImageFormat::RGBAF32>
{
};
template<>
struct ParamTraits<WrBorderStyle>
: public ContiguousEnumSerializer<
WrBorderStyle,
WrBorderStyle::None,
WrBorderStyle::Outset>
{
};
template<>
struct ParamTraits<WrColor>
{
static void
Write(Message* aMsg, const WrColor& aParam)
{
WriteParam(aMsg, aParam.r);
WriteParam(aMsg, aParam.g);
WriteParam(aMsg, aParam.b);
WriteParam(aMsg, aParam.a);
}
static bool
Read(const Message* aMsg, PickleIterator* aIter, WrColor* aResult)
{
return ReadParam(aMsg, aIter, &aResult->r)
&& ReadParam(aMsg, aIter, &aResult->g)
&& ReadParam(aMsg, aIter, &aResult->b)
&& ReadParam(aMsg, aIter, &aResult->a);
}
};
template<>
struct ParamTraits<WRGlyphInstance>
{
static void
Write(Message* aMsg, const WRGlyphInstance& aParam)
{
WriteParam(aMsg, aParam.index);
WriteParam(aMsg, aParam.x);
WriteParam(aMsg, aParam.y);
}
static bool
Read(const Message* aMsg, PickleIterator* aIter, WRGlyphInstance* aResult)
{
return ReadParam(aMsg, aIter, &aResult->index)
&& ReadParam(aMsg, aIter, &aResult->x)
&& ReadParam(aMsg, aIter, &aResult->y);
}
};
template<>
struct ParamTraits<WrGlyphArray>
{
static void
Write(Message* aMsg, const WrGlyphArray& aParam)
{
WriteParam(aMsg, aParam.color);
size_t length = aParam.glyphs.Length();
WriteParam(aMsg, length);
for (size_t i = 0; i < length; i++) {
WriteParam(aMsg, aParam.glyphs[i]);
}
}
static bool
Read(const Message* aMsg, PickleIterator* aIter, WrGlyphArray* aResult)
{
if (!ReadParam(aMsg, aIter, &aResult->color)) {
return false;
}
size_t length;
if (!ReadParam(aMsg, aIter, &length)) {
return false;
}
aResult->glyphs.SetLength(length);
for (size_t i = 0; i < length; i++) {
if (!ReadParam(aMsg, aIter, &aResult->glyphs[i])) {
return false;
}
}
return true;
}
};
template<>
struct ParamTraits<WrBorderSide>
{
static void
Write(Message* aMsg, const WrBorderSide& aParam)
{
WriteParam(aMsg, aParam.width);
WriteParam(aMsg, aParam.color);
WriteParam(aMsg, aParam.style);
}
static bool
Read(const Message* aMsg, PickleIterator* aIter, WrBorderSide* aResult)
{
return ReadParam(aMsg, aIter, &aResult->width)
&& ReadParam(aMsg, aIter, &aResult->color)
&& ReadParam(aMsg, aIter, &aResult->style);
}
};
template<>
struct ParamTraits<WrLayoutSize>
{
static void
Write(Message* aMsg, const WrLayoutSize& aParam)
{
WriteParam(aMsg, aParam.width);
WriteParam(aMsg, aParam.height);
}
static bool
Read(const Message* aMsg, PickleIterator* aIter, WrLayoutSize* aResult)
{
return ReadParam(aMsg, aIter, &aResult->width)
&& ReadParam(aMsg, aIter, &aResult->height);
}
};
template<>
struct ParamTraits<WrRect>
{
static void
Write(Message* aMsg, const WrRect& aParam)
{
WriteParam(aMsg, aParam.x);
WriteParam(aMsg, aParam.y);
WriteParam(aMsg, aParam.width);
WriteParam(aMsg, aParam.height);
}
static bool
Read(const Message* aMsg, PickleIterator* aIter, WrRect* aResult)
{
return ReadParam(aMsg, aIter, &aResult->x)
&& ReadParam(aMsg, aIter, &aResult->y)
&& ReadParam(aMsg, aIter, &aResult->width)
&& ReadParam(aMsg, aIter, &aResult->height);
}
};
template<>
struct ParamTraits<WrImageMask>
{
static void
Write(Message* aMsg, const WrImageMask& aParam)
{
WriteParam(aMsg, aParam.image);
WriteParam(aMsg, aParam.rect);
WriteParam(aMsg, aParam.repeat);
}
static bool
Read(const Message* aMsg, PickleIterator* aIter, WrImageMask* aResult)
{
return ReadParam(aMsg, aIter, &aResult->image)
&& ReadParam(aMsg, aIter, &aResult->rect)
&& ReadParam(aMsg, aIter, &aResult->repeat);
}
};
template<>
struct ParamTraits<WrTextureFilter>
: public ContiguousEnumSerializer<
WrTextureFilter,
WrTextureFilter::Linear,
WrTextureFilter::Sentinel>
{
};
template<>
struct ParamTraits<WrMixBlendMode>
: public ContiguousEnumSerializer<
WrMixBlendMode,
WrMixBlendMode::Normal,
WrMixBlendMode::Sentinel>
{
};
} // namespace IPC
#endif // GFX_WEBRENDERMESSAGEUTILS_H