Commit bca15907 authored by danakj@chromium.org's avatar danakj@chromium.org

cc: Add CompositorFrame class with IPC param traits for it

Tests:
content_unittests:CCMessagesTest.AllQuads
content_unittests:CCMessagesTest.Resources

BUG=152337
R=piman
NOTRY=true

Review URL: https://chromiumcodereview.appspot.com/11308306

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@170853 0039d316-1c4b-4281-b951-d872f2087c98
parent 673266c4
......@@ -5,7 +5,4 @@ include_rules = [
"+third_party/khronos/GLES2/gl2ext.h",
"+ui/gfx",
"+media",
# TODO(piman): Remove as soon as ui/compositor uses cc directly.
# http://crbug.com/159278
"+third_party/WebKit/Source/Platform/chromium/public/WebCompositorTransferableResourceList.h"
]
......@@ -20,6 +20,10 @@
'checkerboard_draw_quad.cc',
'checkerboard_draw_quad.h',
'completion_event.h',
'compositor_frame.cc',
'compositor_frame.h',
'compositor_frame_ack.cc',
'compositor_frame_ack.h',
'content_layer.cc',
'content_layer.h',
'content_layer_client.h',
......
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/compositor_frame.h"
namespace cc {
CompositorFrame::CompositorFrame() {}
CompositorFrame::~CompositorFrame() {}
} // namespace cc
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CC_COMPOSITOR_FRAME_H_
#define CC_COMPOSITOR_FRAME_H_
#include "cc/cc_export.h"
#include "cc/render_pass.h"
#include "cc/scoped_ptr_vector.h"
#include "cc/transferable_resource.h"
#include "ui/gfx/size.h"
namespace cc {
class CC_EXPORT CompositorFrame {
public:
CompositorFrame();
~CompositorFrame();
gfx::Size size;
TransferableResourceList resource_list;
ScopedPtrVector<RenderPass> render_pass_list;
};
} // namespace cc
#endif // CC_COMPOSITOR_FRAME_H_
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/compositor_frame_ack.h"
namespace cc {
CompositorFrameAck::CompositorFrameAck() {}
CompositorFrameAck::~CompositorFrameAck() {}
} // namespace cc
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CC_COMPOSITOR_FRAME_ACK_H_
#define CC_COMPOSITOR_FRAME_ACK_H_
#include "cc/cc_export.h"
#include "cc/transferable_resource.h"
namespace cc {
class CC_EXPORT CompositorFrameAck {
public:
CompositorFrameAck();
~CompositorFrameAck();
TransferableResourceList resources;
};
} // namespace cc
#endif // CC_COMPOSITOR_FRAME_ACK_H_
......@@ -10,11 +10,10 @@
#include "cc/cc_export.h"
#include "ui/gfx/size.h"
#include "third_party/khronos/GLES2/gl2.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorTransferableResourceList.h"
namespace cc {
struct Mailbox {
struct CC_EXPORT Mailbox {
Mailbox();
bool isZero() const;
void setName(const GLbyte* name);
......@@ -33,8 +32,7 @@ struct CC_EXPORT TransferableResource {
typedef std::vector<TransferableResource> TransferableResourceArray;
struct CC_EXPORT TransferableResourceList :
public NON_EXPORTED_BASE(WebKit::WebCompositorTransferableResourceList) {
struct CC_EXPORT TransferableResourceList {
TransferableResourceList();
~TransferableResourceList();
......
......@@ -4,6 +4,7 @@
#include "content/common/cc_messages.h"
#include "cc/compositor_frame.h"
#include "content/public/common/common_param_traits.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebData.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperations.h"
......@@ -574,4 +575,67 @@ void ParamTraits<cc::RenderPass>::Log(
l->append("])");
}
void ParamTraits<cc::Mailbox>::Write(Message* m, const param_type& p) {
m->WriteBytes(p.name, sizeof(p.name));
}
bool ParamTraits<cc::Mailbox>::Read(const Message* m,
PickleIterator* iter,
param_type* p) {
const char* bytes = NULL;
if (!m->ReadBytes(iter, &bytes, sizeof(p->name)))
return false;
DCHECK(bytes);
memcpy(p->name, bytes, sizeof(p->name));
return true;
}
void ParamTraits<cc::Mailbox>::Log(const param_type& p, std::string* l) {
for (size_t i = 0; i < sizeof(p.name); ++i)
*l += base::StringPrintf("%02x", p.name[i]);
}
void ParamTraits<cc::CompositorFrame>::Write(Message* m, const param_type& p) {
WriteParam(m, p.size);
WriteParam(m, p.resource_list);
WriteParam(m, p.render_pass_list.size());
for (size_t i = 0; i < p.render_pass_list.size(); ++i)
WriteParam(m, *p.render_pass_list[i]);
}
bool ParamTraits<cc::CompositorFrame>::Read(const Message* m,
PickleIterator* iter,
param_type* p) {
const static size_t kMaxRenderPasses = 10000;
size_t num_render_passes;
if (!ReadParam(m, iter, &p->size) ||
!ReadParam(m, iter, &p->resource_list) ||
!ReadParam(m, iter, &num_render_passes) ||
num_render_passes > kMaxRenderPasses)
return false;
for (size_t i = 0; i < num_render_passes; ++i) {
scoped_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create();
if (!ReadParam(m, iter, render_pass.get()))
return false;
p->render_pass_list.append(render_pass.Pass());
}
return true;
}
void ParamTraits<cc::CompositorFrame>::Log(const param_type& p,
std::string* l) {
l->append("CompositorFrame(");
LogParam(p.size, l);
l->append(", ");
LogParam(p.resource_list, l);
l->append(", [");
for (size_t i = 0; i < p.render_pass_list.size(); ++i) {
if (i)
l->append(", ");
LogParam(*p.render_pass_list[i], l);
}
l->append("])");
}
} // namespace IPC
......@@ -5,6 +5,7 @@
// IPC Messages sent between compositor instances.
#include "cc/checkerboard_draw_quad.h"
#include "cc/compositor_frame_ack.h"
#include "cc/debug_border_draw_quad.h"
#include "cc/draw_quad.h"
#include "cc/io_surface_draw_quad.h"
......@@ -15,6 +16,7 @@
#include "cc/stream_video_draw_quad.h"
#include "cc/texture_draw_quad.h"
#include "cc/tile_draw_quad.h"
#include "cc/transferable_resource.h"
#include "cc/video_layer_impl.h"
#include "cc/yuv_video_draw_quad.h"
#include "content/common/content_export.h"
......@@ -24,6 +26,10 @@
#ifndef CONTENT_COMMON_CC_MESSAGES_H_
#define CONTENT_COMMON_CC_MESSAGES_H_
namespace cc {
class CompositorFrame;
}
namespace gfx {
class Transform;
}
......@@ -75,6 +81,22 @@ struct CONTENT_EXPORT ParamTraits<cc::RenderPass> {
static void Log(const param_type& p, std::string* l);
};
template<>
struct CONTENT_EXPORT ParamTraits<cc::Mailbox> {
typedef cc::Mailbox param_type;
static void Write(Message* m, const param_type& p);
static bool Read(const Message* m, PickleIterator* iter, param_type* p);
static void Log(const param_type& p, std::string* l);
};
template<>
struct CONTENT_EXPORT ParamTraits<cc::CompositorFrame> {
typedef cc::CompositorFrame param_type;
static void Write(Message* m, const param_type& p);
static bool Read(const Message* m, PickleIterator* iter, param_type* p);
static void Log(const param_type& p, std::string* l);
};
} // namespace IPC
#endif // CONTENT_COMMON_CC_MESSAGES_H_
......@@ -184,3 +206,19 @@ IPC_STRUCT_TRAITS_BEGIN(cc::SharedQuadState)
IPC_STRUCT_TRAITS_MEMBER(is_clipped)
IPC_STRUCT_TRAITS_MEMBER(opacity)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(cc::TransferableResource)
IPC_STRUCT_TRAITS_MEMBER(id)
IPC_STRUCT_TRAITS_MEMBER(format)
IPC_STRUCT_TRAITS_MEMBER(size)
IPC_STRUCT_TRAITS_MEMBER(mailbox)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(cc::TransferableResourceList)
IPC_STRUCT_TRAITS_MEMBER(sync_point)
IPC_STRUCT_TRAITS_MEMBER(resources)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(cc::CompositorFrameAck)
IPC_STRUCT_TRAITS_MEMBER(resources)
IPC_STRUCT_TRAITS_END()
......@@ -6,10 +6,12 @@
#include <string.h>
#include "cc/compositor_frame.h"
#include "ipc/ipc_message.h"
#include "testing/gtest/include/gtest/gtest.h"
using cc::CheckerboardDrawQuad;
using cc::CompositorFrame;
using cc::DebugBorderDrawQuad;
using cc::DrawQuad;
using cc::IOSurfaceDrawQuad;
......@@ -20,6 +22,7 @@ using cc::SharedQuadState;
using cc::SolidColorDrawQuad;
using cc::TextureDrawQuad;
using cc::TileDrawQuad;
using cc::TransferableResource;
using cc::StreamVideoDrawQuad;
using cc::VideoLayerImpl;
using cc::YUVVideoDrawQuad;
......@@ -27,6 +30,9 @@ using gfx::Transform;
using WebKit::WebFilterOperation;
using WebKit::WebFilterOperations;
namespace content {
namespace {
class CCMessagesTest : public testing::Test {
protected:
void Compare(const RenderPass* a, const RenderPass* b) {
......@@ -168,6 +174,14 @@ class CCMessagesTest : public testing::Test {
EXPECT_EQ(a->v_plane.size.ToString(), b->v_plane.size.ToString());
EXPECT_EQ(a->v_plane.format, b->v_plane.format);
}
void Compare(const TransferableResource& a, const TransferableResource& b) {
EXPECT_EQ(a.id, b.id);
EXPECT_EQ(a.format, b.format);
EXPECT_EQ(a.size.ToString(), b.size.ToString());
for (size_t i = 0; i < arraysize(a.mailbox.name); ++i)
EXPECT_EQ(a.mailbox.name[i], b.mailbox.name[i]);
}
};
TEST_F(CCMessagesTest, AllQuads) {
......@@ -403,13 +417,20 @@ TEST_F(CCMessagesTest, AllQuads) {
EXPECT_EQ(same_shared_quad_state_cmp, same_shared_quad_state_in);
}
IPC::ParamTraits<RenderPass>::Write(&msg, *pass_in);
CompositorFrame frame_in;
frame_in.size = arbitrary_size1;
frame_in.render_pass_list.append(pass_in.Pass());
scoped_ptr<RenderPass> pass_out = RenderPass::Create();
IPC::ParamTraits<CompositorFrame>::Write(&msg, frame_in);
CompositorFrame frame_out;
PickleIterator iter(msg);
EXPECT_TRUE(IPC::ParamTraits<RenderPass>::Read(&msg, &iter, pass_out.get()));
EXPECT_TRUE(IPC::ParamTraits<CompositorFrame>::Read(&msg, &iter, &frame_out));
EXPECT_EQ(arbitrary_size1, frame_out.size);
// Make sure the out and cmp RenderPasses match.
scoped_ptr<RenderPass> pass_out = frame_out.render_pass_list.take(0);
Compare(pass_cmp.get(), pass_out.get());
ASSERT_EQ(3u, pass_out->shared_quad_state_list.size());
ASSERT_EQ(7u, pass_out->quad_list.size());
......@@ -429,3 +450,58 @@ TEST_F(CCMessagesTest, AllQuads) {
EXPECT_EQ(same_shared_quad_state_cmp, same_shared_quad_state_out);
}
}
TEST_F(CCMessagesTest, Resources) {
IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
gfx::Size arbitrary_size(757, 1281);
unsigned int arbitrary_uint = 71234838;
GLbyte arbitrary_mailbox1[64] = {
1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0,
1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0,
1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0,
1, 2, 3, 4
};
GLbyte arbitrary_mailbox2[64] = {
0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0,
0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0,
0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0,
0, 9, 8, 7
};
TransferableResource arbitrary_resource1;
arbitrary_resource1.id = 2178312;
arbitrary_resource1.format = 7;
arbitrary_resource1.size = gfx::Size(37189, 123123);
arbitrary_resource1.mailbox.setName(arbitrary_mailbox1);
TransferableResource arbitrary_resource2;
arbitrary_resource2.id = 789132;
arbitrary_resource2.format = 30;
arbitrary_resource2.size = gfx::Size(89123, 23789);
arbitrary_resource2.mailbox.setName(arbitrary_mailbox2);
CompositorFrame frame_in;
frame_in.size = arbitrary_size;
frame_in.resource_list.sync_point = arbitrary_uint;
frame_in.resource_list.resources.push_back(arbitrary_resource1);
frame_in.resource_list.resources.push_back(arbitrary_resource2);
IPC::ParamTraits<CompositorFrame>::Write(&msg, frame_in);
CompositorFrame frame_out;
PickleIterator iter(msg);
EXPECT_TRUE(IPC::ParamTraits<CompositorFrame>::Read(&msg, &iter, &frame_out));
EXPECT_EQ(arbitrary_size.ToString(), frame_out.size.ToString());
EXPECT_EQ(arbitrary_uint, frame_out.resource_list.sync_point);
EXPECT_EQ(2u, frame_out.resource_list.resources.size());
Compare(arbitrary_resource1, frame_out.resource_list.resources[0]);
Compare(arbitrary_resource2, frame_out.resource_list.resources[1]);
}
} // namespace
} // namespace content
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment