gfx/layers/wr/WebRenderMessageUtils.h
author Ryan Hunt <rhunt@eqrion.net>
Thu, 09 Mar 2017 16:58:33 -0500
changeset 347292 5de79be2222a9fc5d133a24ebaa7752517defc08
parent 347279 6374644ff317f40c9ddb43483fc70c45a121021b
child 355148 765939ca757ddeca3dae3a653c60973be3f6721c
permissions -rw-r--r--
Bug 1345975 - Rename WrLayoutSize to WrSize r=kats MozReview-Commit-ID: JY9YyoypFym

/* -*- 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.mNamespace);
    WriteParam(aMsg, aParam.mHandle);
  }

  static bool
  Read(const Message* aMsg, PickleIterator* aIter, mozilla::wr::ImageKey* aResult)
  {
    return ReadParam(aMsg, aIter, &aResult->mNamespace)
        && ReadParam(aMsg, aIter, &aResult->mHandle);
  }
};

template<>
struct ParamTraits<mozilla::wr::FontKey>
{
  static void
  Write(Message* aMsg, const mozilla::wr::FontKey& aParam)
  {
    WriteParam(aMsg, aParam.mNamespace);
    WriteParam(aMsg, aParam.mHandle);
  }

  static bool
  Read(const Message* aMsg, PickleIterator* aIter, mozilla::wr::FontKey* aResult)
  {
    return ReadParam(aMsg, aIter, &aResult->mNamespace)
        && ReadParam(aMsg, aIter, &aResult->mHandle);
  }
};

template<>
struct ParamTraits<mozilla::wr::PipelineId>
{
  static void
  Write(Message* aMsg, const mozilla::wr::PipelineId& aParam)
  {
    WriteParam(aMsg, aParam.mNamespace);
    WriteParam(aMsg, aParam.mHandle);
  }

  static bool
  Read(const Message* aMsg, PickleIterator* aIter, mozilla::wr::PipelineId* aResult)
  {
    return ReadParam(aMsg, aIter, &aResult->mNamespace)
        && ReadParam(aMsg, aIter, &aResult->mHandle);
  }
};

template<>
struct ParamTraits<WrImageFormat>
  : public ContiguousEnumSerializer<
        WrImageFormat,
        WrImageFormat::Invalid,
        WrImageFormat::Sentinel>
{
};

template<>
struct ParamTraits<WrSize>
{
  static void
  Write(Message* aMsg, const WrSize& aParam)
  {
    WriteParam(aMsg, aParam.width);
    WriteParam(aMsg, aParam.height);
  }

  static bool
  Read(const Message* aMsg, PickleIterator* aIter, WrSize* 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<WrPoint>
{
  static void
  Write(Message* aMsg, const WrPoint& aParam)
  {
    WriteParam(aMsg, aParam.x);
    WriteParam(aMsg, aParam.y);
  }

  static bool
  Read(const Message* aMsg, PickleIterator* aIter, WrPoint* aResult)
  {
    return ReadParam(aMsg, aIter, &aResult->x) &&
           ReadParam(aMsg, aIter, &aResult->y);
  }
};

template<>
struct ParamTraits<WrBuiltDisplayListDescriptor>
{
  static void
  Write(Message* aMsg, const WrBuiltDisplayListDescriptor& aParam)
  {
    WriteParam(aMsg, aParam.display_list_items_size);
  }

  static bool
  Read(const Message* aMsg, PickleIterator* aIter, WrBuiltDisplayListDescriptor* aResult)
  {
    return ReadParam(aMsg, aIter, &aResult->display_list_items_size);
  }
};

template<>
struct ParamTraits<WrAuxiliaryListsDescriptor>
{
  static void
  Write(Message* aMsg, const WrAuxiliaryListsDescriptor& aParam)
  {
    WriteParam(aMsg, aParam.gradient_stops_size);
    WriteParam(aMsg, aParam.complex_clip_regions_size);
    WriteParam(aMsg, aParam.filters_size);
    WriteParam(aMsg, aParam.glyph_instances_size);
  }

  static bool
  Read(const Message* aMsg, PickleIterator* aIter, WrAuxiliaryListsDescriptor* aResult)
  {
    return ReadParam(aMsg, aIter, &aResult->gradient_stops_size)
        && ReadParam(aMsg, aIter, &aResult->complex_clip_regions_size)
        && ReadParam(aMsg, aIter, &aResult->filters_size)
        && ReadParam(aMsg, aIter, &aResult->glyph_instances_size);
  }
};

} // namespace IPC

#endif // GFX_WEBRENDERMESSAGEUTILS_H