Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / gpu / tools / compositor_model_bench / render_tree.h
blob6b43fbe77f90f9d270ad1321c95818499ff572c3
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_
11 #include <string>
12 #include <vector>
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
21 // window was.
22 const int WINDOW_WIDTH = 1609;
23 const int WINDOW_HEIGHT = 993;
25 struct Tile {
26 int x;
27 int y;
28 int texID;
31 struct Texture {
32 int texID;
33 int height;
34 int width;
35 GLenum format;
38 GLenum TextureFormatFromString(std::string format);
39 const char* TextureFormatName(GLenum format);
40 int FormatBytesPerPixel(GLenum format);
42 class RenderNodeVisitor;
44 class RenderNode {
45 public:
46 RenderNode();
47 virtual ~RenderNode();
48 virtual void Accept(RenderNodeVisitor* v);
50 int layerID() {
51 return layerID_;
54 void set_layerID(int id) {
55 layerID_ = id;
58 int width() {
59 return width_;
62 void set_width(int width) {
63 width_ = width;
66 int height() {
67 return height_;
70 void set_height(int height) {
71 height_ = height;
74 bool drawsContent() {
75 return drawsContent_;
78 void set_drawsContent(bool draws) {
79 drawsContent_ = draws;
82 void set_targetSurface(int surface) {
83 targetSurface_ = surface;
86 float* transform() {
87 return transform_;
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) {
97 tiles_.push_back(t);
100 size_t num_tiles() {
101 return tiles_.size();
104 Tile* tile(size_t index) {
105 return &tiles_[index];
108 int tile_width() {
109 return tile_width_;
112 void set_tile_width(int width) {
113 tile_width_ = width;
116 int tile_height() {
117 return tile_height_;
120 void set_tile_height(int height) {
121 tile_height_ = height;
124 private:
125 int layerID_;
126 int width_;
127 int height_;
128 bool drawsContent_;
129 int targetSurface_;
130 float transform_[16];
131 std::vector<Tile> tiles_;
132 int tile_width_;
133 int tile_height_;
136 class ContentLayerNode : public RenderNode {
137 public:
138 ContentLayerNode();
139 ~ContentLayerNode() override;
140 void Accept(RenderNodeVisitor* v) override;
142 void set_skipsDraw(bool skips) {
143 skipsDraw_ = skips;
146 void add_child(RenderNode* child) {
147 children_.push_back(child);
150 private:
151 ScopedVector<RenderNode> children_;
152 bool skipsDraw_;
155 class CCNode : public RenderNode {
156 public:
157 CCNode();
158 ~CCNode() override;
160 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];
190 private:
191 ShaderID vertex_shader_;
192 ShaderID fragment_shader_;
193 std::vector<Texture> textures_;
196 class RenderNodeVisitor {
197 public:
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_