1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Data structures for representing parts of Chromium's composited layer tree
6 // and a function to load it from the JSON configuration file
8 #ifndef GPU_TOOLS_COMPOSITOR_MODEL_BENCH_RENDER_TREE_H_
9 #define GPU_TOOLS_COMPOSITOR_MODEL_BENCH_RENDER_TREE_H_
14 #include "base/compiler_specific.h"
15 #include "base/memory/scoped_vector.h"
16 #include "gpu/tools/compositor_model_bench/shaders.h"
17 #include "ui/gl/gl_bindings.h"
18 #include "ui/gl/gl_implementation.h"
20 // These are fairly arbitrary values based on how big my actual browser
22 const int WINDOW_WIDTH
= 1609;
23 const int WINDOW_HEIGHT
= 993;
38 GLenum
TextureFormatFromString(std::string format
);
39 const char* TextureFormatName(GLenum format
);
40 int FormatBytesPerPixel(GLenum format
);
42 class RenderNodeVisitor
;
47 virtual ~RenderNode();
48 virtual void Accept(RenderNodeVisitor
* v
);
54 void set_layerID(int id
) {
62 void set_width(int width
) {
70 void set_height(int height
) {
78 void set_drawsContent(bool draws
) {
79 drawsContent_
= draws
;
82 void set_targetSurface(int surface
) {
83 targetSurface_
= surface
;
90 void set_transform(float* mat
) {
91 memcpy(reinterpret_cast<void*>(transform_
),
92 reinterpret_cast<void*>(mat
),
93 16 * sizeof(transform_
[0]));
96 void add_tile(Tile t
) {
101 return tiles_
.size();
104 Tile
* tile(size_t index
) {
105 return &tiles_
[index
];
112 void set_tile_width(int width
) {
120 void set_tile_height(int height
) {
121 tile_height_
= height
;
130 float transform_
[16];
131 std::vector
<Tile
> tiles_
;
136 class ContentLayerNode
: public RenderNode
{
139 virtual ~ContentLayerNode();
140 virtual void Accept(RenderNodeVisitor
* v
) OVERRIDE
;
142 void set_skipsDraw(bool skips
) {
146 void add_child(RenderNode
* child
) {
147 children_
.push_back(child
);
151 ScopedVector
<RenderNode
> children_
;
155 class CCNode
: public RenderNode
{
160 virtual void Accept(RenderNodeVisitor
* v
) OVERRIDE
;
162 ShaderID
vertex_shader() {
163 return vertex_shader_
;
166 void set_vertex_shader(ShaderID shader
) {
167 vertex_shader_
= shader
;
170 ShaderID
fragment_shader() {
171 return fragment_shader_
;
174 void set_fragment_shader(ShaderID shader
) {
175 fragment_shader_
= shader
;
178 void add_texture(Texture t
) {
179 textures_
.push_back(t
);
182 size_t num_textures() {
183 return textures_
.size();
186 Texture
* texture(size_t index
) {
187 return &textures_
[index
];
191 ShaderID vertex_shader_
;
192 ShaderID fragment_shader_
;
193 std::vector
<Texture
> textures_
;
196 class RenderNodeVisitor
{
198 virtual ~RenderNodeVisitor();
200 virtual void BeginVisitRenderNode(RenderNode
* v
) = 0;
201 virtual void BeginVisitContentLayerNode(ContentLayerNode
* v
);
202 virtual void BeginVisitCCNode(CCNode
* v
);
203 virtual void EndVisitRenderNode(RenderNode
* v
);
204 virtual void EndVisitContentLayerNode(ContentLayerNode
* v
);
205 virtual void EndVisitCCNode(CCNode
* v
);
208 RenderNode
* BuildRenderTreeFromFile(const base::FilePath
& path
);
210 #endif // GPU_TOOLS_COMPOSITOR_MODEL_BENCH_RENDER_TREE_H_