render_tree.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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.
  4. // Data structures for representing parts of Chromium's composited layer tree
  5. // and a function to load it from the JSON configuration file
  6. #ifndef GPU_TOOLS_COMPOSITOR_MODEL_BENCH_RENDER_TREE_H_
  7. #define GPU_TOOLS_COMPOSITOR_MODEL_BENCH_RENDER_TREE_H_
  8. #include <stddef.h>
  9. #include <memory>
  10. #include <string>
  11. #include <vector>
  12. #include "base/compiler_specific.h"
  13. #include "base/memory/ptr_util.h"
  14. #include "gpu/tools/compositor_model_bench/shaders.h"
  15. #include "ui/gl/gl_bindings.h"
  16. #include "ui/gl/gl_implementation.h"
  17. // These are fairly arbitrary values based on how big my actual browser
  18. // window was.
  19. const int WINDOW_WIDTH = 1609;
  20. const int WINDOW_HEIGHT = 993;
  21. struct Tile {
  22. int x;
  23. int y;
  24. int texID;
  25. };
  26. struct Texture {
  27. int texID;
  28. int height;
  29. int width;
  30. GLenum format;
  31. };
  32. GLenum TextureFormatFromString(const std::string& format);
  33. const char* TextureFormatName(GLenum format);
  34. int FormatBytesPerPixel(GLenum format);
  35. class RenderNodeVisitor;
  36. class RenderNode {
  37. public:
  38. RenderNode();
  39. virtual ~RenderNode();
  40. virtual void Accept(RenderNodeVisitor* v);
  41. int layerID() {
  42. return layerID_;
  43. }
  44. void set_layerID(int id) {
  45. layerID_ = id;
  46. }
  47. int width() {
  48. return width_;
  49. }
  50. void set_width(int width) {
  51. width_ = width;
  52. }
  53. int height() {
  54. return height_;
  55. }
  56. void set_height(int height) {
  57. height_ = height;
  58. }
  59. bool drawsContent() {
  60. return drawsContent_;
  61. }
  62. void set_drawsContent(bool draws) {
  63. drawsContent_ = draws;
  64. }
  65. void set_targetSurface(int surface) {
  66. targetSurface_ = surface;
  67. }
  68. float* transform() {
  69. return transform_;
  70. }
  71. void set_transform(float* mat) {
  72. memcpy(reinterpret_cast<void*>(transform_),
  73. reinterpret_cast<void*>(mat),
  74. 16 * sizeof(transform_[0]));
  75. }
  76. void add_tile(Tile t) {
  77. tiles_.push_back(t);
  78. }
  79. size_t num_tiles() {
  80. return tiles_.size();
  81. }
  82. Tile* tile(size_t index) {
  83. return &tiles_[index];
  84. }
  85. int tile_width() {
  86. return tile_width_;
  87. }
  88. void set_tile_width(int width) {
  89. tile_width_ = width;
  90. }
  91. int tile_height() {
  92. return tile_height_;
  93. }
  94. void set_tile_height(int height) {
  95. tile_height_ = height;
  96. }
  97. private:
  98. int layerID_;
  99. int width_;
  100. int height_;
  101. bool drawsContent_;
  102. int targetSurface_;
  103. float transform_[16];
  104. std::vector<Tile> tiles_;
  105. int tile_width_;
  106. int tile_height_;
  107. };
  108. class ContentLayerNode : public RenderNode {
  109. public:
  110. ContentLayerNode();
  111. ~ContentLayerNode() override;
  112. void Accept(RenderNodeVisitor* v) override;
  113. void set_skipsDraw(bool skips) {
  114. skipsDraw_ = skips;
  115. }
  116. void add_child(RenderNode* child) {
  117. children_.push_back(base::WrapUnique(child));
  118. }
  119. private:
  120. std::vector<std::unique_ptr<RenderNode>> children_;
  121. bool skipsDraw_;
  122. };
  123. class CCNode : public RenderNode {
  124. public:
  125. CCNode();
  126. ~CCNode() override;
  127. void Accept(RenderNodeVisitor* v) override;
  128. ShaderID vertex_shader() {
  129. return vertex_shader_;
  130. }
  131. void set_vertex_shader(ShaderID shader) {
  132. vertex_shader_ = shader;
  133. }
  134. ShaderID fragment_shader() {
  135. return fragment_shader_;
  136. }
  137. void set_fragment_shader(ShaderID shader) {
  138. fragment_shader_ = shader;
  139. }
  140. void add_texture(Texture t) {
  141. textures_.push_back(t);
  142. }
  143. size_t num_textures() {
  144. return textures_.size();
  145. }
  146. Texture* texture(size_t index) {
  147. return &textures_[index];
  148. }
  149. private:
  150. ShaderID vertex_shader_;
  151. ShaderID fragment_shader_;
  152. std::vector<Texture> textures_;
  153. };
  154. class RenderNodeVisitor {
  155. public:
  156. virtual ~RenderNodeVisitor();
  157. virtual void BeginVisitRenderNode(RenderNode* v) = 0;
  158. virtual void BeginVisitContentLayerNode(ContentLayerNode* v);
  159. virtual void BeginVisitCCNode(CCNode* v);
  160. virtual void EndVisitRenderNode(RenderNode* v);
  161. virtual void EndVisitContentLayerNode(ContentLayerNode* v);
  162. virtual void EndVisitCCNode(CCNode* v);
  163. };
  164. std::unique_ptr<RenderNode> BuildRenderTreeFromFile(const base::FilePath& path);
  165. #endif // GPU_TOOLS_COMPOSITOR_MODEL_BENCH_RENDER_TREE_H_