0

Choose largest DrawQuad type, no longer dependent on compiler flag

Use template to choose between RenderPassDrawQuad and
StreamVideoDrawQuad for LargestDrawQuad.

BUG=429552

Review URL: https://codereview.chromium.org/698053002

Cr-Commit-Position: refs/heads/master@{#302833}
This commit is contained in:
weiliangc
2014-11-05 10:20:27 -08:00
committed by Commit bot
parent 56aa0fa163
commit fe7b51ef3b
9 changed files with 47 additions and 29 deletions

@ -293,6 +293,7 @@ component("cc") {
"quads/io_surface_draw_quad.cc",
"quads/io_surface_draw_quad.h",
"quads/largest_draw_quad.h",
"quads/largest_draw_quad.cc",
"quads/list_container.cc",
"quads/list_container.h",
"quads/picture_draw_quad.cc",

@ -321,6 +321,7 @@
'quads/io_surface_draw_quad.cc',
'quads/io_surface_draw_quad.h',
'quads/largest_draw_quad.h',
'quads/largest_draw_quad.cc',
'quads/list_container.cc',
'quads/list_container.h',
'quads/picture_draw_quad.cc',

@ -102,13 +102,13 @@ void CompareDrawQuad(DrawQuad* quad,
render_pass->CreateAndAppendSharedQuadState(); \
copy_shared_state->CopyFrom(shared_state);
#define QUAD_DATA \
gfx::Rect quad_rect(30, 40, 50, 60); \
gfx::Rect quad_visible_rect(40, 50, 30, 20); \
gfx::Rect quad_opaque_rect( 60, 55, 10, 10); \
ALLOW_UNUSED_LOCAL(quad_opaque_rect); \
bool needs_blending = true; \
ALLOW_UNUSED_LOCAL(needs_blending);
#define QUAD_DATA \
gfx::Rect quad_rect(30, 40, 50, 60); \
gfx::Rect quad_visible_rect(40, 50, 30, 20); \
gfx::Rect quad_opaque_rect(60, 55, 10, 10); \
ALLOW_UNUSED_LOCAL(quad_opaque_rect); \
bool needs_blending = true; \
ALLOW_UNUSED_LOCAL(needs_blending);
#define SETUP_AND_COPY_QUAD_NEW(Type, quad) \
DrawQuad* copy_new = \
@ -979,14 +979,14 @@ TEST(DrawQuadTest, LargestQuadType) {
break;
}
}
EXPECT_EQ(sizeof(kLargestDrawQuad), largest);
EXPECT_EQ(LargestDrawQuadSize(), largest);
if (!HasFailure())
return;
// On failure, output the size of all quads for debugging.
LOG(ERROR) << "largest " << largest;
LOG(ERROR) << "kLargestDrawQuad " << sizeof(kLargestDrawQuad);
LOG(ERROR) << "kLargestDrawQuad " << LargestDrawQuadSize();
for (int i = 0; i <= DrawQuad::MATERIAL_LAST; ++i) {
switch (static_cast<DrawQuad::Material>(i)) {
case DrawQuad::CHECKERBOARD:

@ -0,0 +1,20 @@
// Copyright 2014 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/quads/largest_draw_quad.h"
#include <algorithm>
#include "cc/quads/render_pass_draw_quad.h"
#include "cc/quads/stream_video_draw_quad.h"
namespace cc {
size_t LargestDrawQuadSize() {
// The largest quad is either a RenderPassDrawQuad or a StreamVideoDrawQuad
// depends on hardware structure.
return std::max(sizeof(RenderPassDrawQuad), sizeof(StreamVideoDrawQuad));
}
} // namespace cc

@ -5,15 +5,12 @@
#ifndef CC_QUADS_LARGEST_DRAW_QUAD_H_
#define CC_QUADS_LARGEST_DRAW_QUAD_H_
namespace cc {
class StreamVideoDrawQuad;
class RenderPassDrawQuad;
#include "base/basictypes.h"
#include "cc/base/cc_export.h"
#if defined(ARCH_CPU_64_BITS)
typedef RenderPassDrawQuad kLargestDrawQuad;
#else
typedef StreamVideoDrawQuad kLargestDrawQuad;
#endif
namespace cc {
CC_EXPORT size_t LargestDrawQuadSize();
} // namespace cc

@ -20,7 +20,7 @@ class DrawQuad;
// pointer will continue to be valid. This class is used to contain
// SharedQuadState or DrawQuad. Since the size of each DrawQuad varies, to hold
// DrawQuads, the allocations size of each element in this class is
// kLargestDrawQuad while BaseElementType is DrawQuad.
// LargestDrawQuadSize while BaseElementType is DrawQuad.
template <class BaseElementType>
class CC_EXPORT ListContainer {
public:

@ -64,7 +64,7 @@ class MockDrawQuad : public DrawQuad {
};
TEST(ListContainerTest, ConstructorCalledInAllocateAndConstruct) {
ListContainer<DrawQuad> list(sizeof(kLargestDrawQuad));
ListContainer<DrawQuad> list(LargestDrawQuadSize());
size_t size = 2;
SimpleDrawQuadConstructMagicNumberOne* dq_1 =
@ -81,7 +81,7 @@ TEST(ListContainerTest, ConstructorCalledInAllocateAndConstruct) {
}
TEST(ListContainerTest, DestructorCalled) {
ListContainer<DrawQuad> list(sizeof(kLargestDrawQuad));
ListContainer<DrawQuad> list(LargestDrawQuadSize());
size_t size = 1;
MockDrawQuad* dq_1 = list.AllocateAndConstruct<MockDrawQuad>();
@ -92,7 +92,7 @@ TEST(ListContainerTest, DestructorCalled) {
}
TEST(ListContainerTest, DestructorCalledOnceWhenClear) {
ListContainer<DrawQuad> list(sizeof(kLargestDrawQuad));
ListContainer<DrawQuad> list(LargestDrawQuadSize());
size_t size = 1;
MockDrawQuad* dq_1 = list.AllocateAndConstruct<MockDrawQuad>();
@ -114,7 +114,7 @@ TEST(ListContainerTest, DestructorCalledOnceWhenClear) {
}
TEST(ListContainerTest, DestructorCalledOnceWhenErase) {
ListContainer<DrawQuad> list(sizeof(kLargestDrawQuad));
ListContainer<DrawQuad> list(LargestDrawQuadSize());
size_t size = 1;
MockDrawQuad* dq_1 = list.AllocateAndConstruct<MockDrawQuad>();
@ -435,7 +435,7 @@ TEST(ListContainerTest, SimpleReverseInsertionSharedQuadState) {
}
TEST(ListContainerTest, SimpleDeletion) {
ListContainer<DrawQuad> list(sizeof(kLargestDrawQuad));
ListContainer<DrawQuad> list(LargestDrawQuadSize());
std::vector<SimpleDrawQuad*> sdq_list;
size_t size = 10;
for (size_t i = 0; i < size; ++i) {
@ -457,7 +457,7 @@ TEST(ListContainerTest, SimpleDeletion) {
}
TEST(ListContainerTest, SimpleIterationAndManipulation) {
ListContainer<DrawQuad> list(sizeof(kLargestDrawQuad));
ListContainer<DrawQuad> list(LargestDrawQuadSize());
std::vector<SimpleDrawQuad*> sdq_list;
size_t size = 10;
for (size_t i = 0; i < size; ++i) {
@ -482,7 +482,7 @@ TEST(ListContainerTest, SimpleIterationAndManipulation) {
}
TEST(ListContainerTest, SimpleManipulationWithIndexSimpleDrawQuad) {
ListContainer<DrawQuad> list(sizeof(kLargestDrawQuad));
ListContainer<DrawQuad> list(LargestDrawQuadSize());
std::vector<SimpleDrawQuad*> dq_list;
size_t size = 10;
for (size_t i = 0; i < size; ++i) {
@ -504,7 +504,7 @@ TEST(ListContainerTest, SimpleManipulationWithIndexSimpleDrawQuad) {
TEST(ListContainerTest,
SimpleManipulationWithIndexMoreThanOneAllocationSimpleDrawQuad) {
ListContainer<DrawQuad> list(sizeof(kLargestDrawQuad), 2);
ListContainer<DrawQuad> list(LargestDrawQuadSize(), 2);
std::vector<SimpleDrawQuad*> dq_list;
size_t size = 10;
for (size_t i = 0; i < size; ++i) {

@ -34,8 +34,7 @@ const size_t kDefaultNumQuadsToReserve = 128;
namespace cc {
QuadList::QuadList(size_t default_size_to_reserve)
: ListContainer<DrawQuad>(sizeof(kLargestDrawQuad),
default_size_to_reserve) {
: ListContainer<DrawQuad>(LargestDrawQuadSize(), default_size_to_reserve) {
}
scoped_ptr<RenderPass> RenderPass::Create() {

@ -379,7 +379,7 @@ static size_t ReserveSizeForRenderPassWrite(const cc::RenderPass& p) {
to_reserve += p.shared_quad_state_list.size() * sizeof(cc::SharedQuadState);
// The largest quad type, verified by a unit test.
to_reserve += p.quad_list.size() * sizeof(cc::kLargestDrawQuad);
to_reserve += p.quad_list.size() * cc::LargestDrawQuadSize();
return to_reserve;
}