OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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. |
| 4 |
| 5 // Data structures for representing parts of Chromium's composited layer tree |
| 6 // and a function to load it from the JSON configuration file |
| 7 |
| 8 #ifndef GPU_TOOLS_COMPOSITOR_MODEL_BENCH_RENDER_TREE_H_ |
| 9 #define GPU_TOOLS_COMPOSITOR_MODEL_BENCH_RENDER_TREE_H_ |
| 10 |
| 11 #include <string> |
| 12 #include <vector> |
| 13 |
| 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/gfx/gl/gl_bindings.h" |
| 18 #include "ui/gfx/gl/gl_implementation.h" |
| 19 |
| 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; |
| 24 |
| 25 struct Tile { |
| 26 int x; |
| 27 int y; |
| 28 int texID; |
| 29 }; |
| 30 |
| 31 struct Texture { |
| 32 int texID; |
| 33 int height; |
| 34 int width; |
| 35 GLenum format; |
| 36 }; |
| 37 |
| 38 GLenum TextureFormatFromString(std::string format); |
| 39 const char* TextureFormatName(GLenum format); |
| 40 int FormatBytesPerPixel(GLenum format); |
| 41 |
| 42 class RenderNodeVisitor; |
| 43 |
| 44 class RenderNode { |
| 45 public: |
| 46 RenderNode(); |
| 47 virtual ~RenderNode(); |
| 48 virtual void Accept(RenderNodeVisitor* v); |
| 49 |
| 50 int layerID() { |
| 51 return layerID_; |
| 52 } |
| 53 |
| 54 void set_layerID(int id) { |
| 55 layerID_ = id; |
| 56 } |
| 57 |
| 58 int width() { |
| 59 return width_; |
| 60 } |
| 61 |
| 62 void set_width(int width) { |
| 63 width_ = width; |
| 64 } |
| 65 |
| 66 int height() { |
| 67 return height_; |
| 68 } |
| 69 |
| 70 void set_height(int height) { |
| 71 height_ = height; |
| 72 } |
| 73 |
| 74 bool drawsContent() { |
| 75 return drawsContent_; |
| 76 } |
| 77 |
| 78 void set_drawsContent(bool draws) { |
| 79 drawsContent_ = draws; |
| 80 } |
| 81 |
| 82 void set_targetSurface(int surface) { |
| 83 targetSurface_ = surface; |
| 84 } |
| 85 |
| 86 float* transform() { |
| 87 return transform_; |
| 88 } |
| 89 |
| 90 void set_transform(float* mat) { |
| 91 memcpy(reinterpret_cast<void*>(transform_), |
| 92 reinterpret_cast<void*>(mat), |
| 93 16 * sizeof(transform_[0])); |
| 94 } |
| 95 |
| 96 void add_tile(Tile t) { |
| 97 tiles_.push_back(t); |
| 98 } |
| 99 |
| 100 size_t num_tiles() { |
| 101 return tiles_.size(); |
| 102 } |
| 103 |
| 104 Tile* tile(size_t index) { |
| 105 return &tiles_[index]; |
| 106 } |
| 107 |
| 108 int tile_width() { |
| 109 return tile_width_; |
| 110 } |
| 111 |
| 112 void set_tile_width(int width) { |
| 113 tile_width_ = width; |
| 114 } |
| 115 |
| 116 int tile_height() { |
| 117 return tile_height_; |
| 118 } |
| 119 |
| 120 void set_tile_height(int height) { |
| 121 tile_height_ = height; |
| 122 } |
| 123 |
| 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_; |
| 134 }; |
| 135 |
| 136 class ContentLayerNode : public RenderNode { |
| 137 public: |
| 138 ContentLayerNode(); |
| 139 virtual ~ContentLayerNode(); |
| 140 virtual void Accept(RenderNodeVisitor* v) OVERRIDE; |
| 141 |
| 142 void set_skipsDraw(bool skips) { |
| 143 skipsDraw_ = skips; |
| 144 } |
| 145 |
| 146 void add_child(RenderNode* child) { |
| 147 children_.push_back(child); |
| 148 } |
| 149 |
| 150 private: |
| 151 ScopedVector<RenderNode> children_; |
| 152 bool skipsDraw_; |
| 153 }; |
| 154 |
| 155 class CCNode : public RenderNode { |
| 156 public: |
| 157 CCNode(); |
| 158 virtual ~CCNode(); |
| 159 |
| 160 virtual void Accept(RenderNodeVisitor* v) OVERRIDE; |
| 161 |
| 162 ShaderID vertex_shader() { |
| 163 return vertex_shader_; |
| 164 } |
| 165 |
| 166 void set_vertex_shader(ShaderID shader) { |
| 167 vertex_shader_ = shader; |
| 168 } |
| 169 |
| 170 ShaderID fragment_shader() { |
| 171 return fragment_shader_; |
| 172 } |
| 173 |
| 174 void set_fragment_shader(ShaderID shader) { |
| 175 fragment_shader_ = shader; |
| 176 } |
| 177 |
| 178 void add_texture(Texture t) { |
| 179 textures_.push_back(t); |
| 180 } |
| 181 |
| 182 size_t num_textures() { |
| 183 return textures_.size(); |
| 184 } |
| 185 |
| 186 Texture* texture(size_t index) { |
| 187 return &textures_[index]; |
| 188 } |
| 189 |
| 190 private: |
| 191 ShaderID vertex_shader_; |
| 192 ShaderID fragment_shader_; |
| 193 std::vector<Texture> textures_; |
| 194 }; |
| 195 |
| 196 class RenderNodeVisitor { |
| 197 public: |
| 198 virtual ~RenderNodeVisitor(); |
| 199 |
| 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); |
| 206 }; |
| 207 |
| 208 RenderNode* BuildRenderTreeFromFile(const FilePath& path); |
| 209 |
| 210 #endif // GPU_TOOLS_COMPOSITOR_MODEL_BENCH_RENDER_TREE_H_ |
| 211 |
OLD | NEW |