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 // Whole-tree processing that's likely to be helpful in multiple render models.
6 
7 #ifndef GPU_TOOLS_COMPOSITOR_MODEL_BENCH_RENDER_MODEL_UTILS_H_
8 #define GPU_TOOLS_COMPOSITOR_MODEL_BENCH_RENDER_MODEL_UTILS_H_
9 
10 #include <stdint.h>
11 
12 #include <map>
13 #include <memory>
14 #include <set>
15 #include <vector>
16 
17 #include "base/compiler_specific.h"
18 #include "gpu/tools/compositor_model_bench/render_tree.h"
19 
20 // This is a visitor that runs over the tree structure that was built from the
21 // configuration file. It creates OpenGL textures (random checkerboards) that
22 // match the specifications of the original textures and overwrites the old
23 // texture ID's in the tree, replacing them with the matching new textures.
24 class TextureGenerator : public RenderNodeVisitor {
25  public:
26   typedef std::unique_ptr<uint8_t[]> ImagePtr;
27   typedef std::vector<Tile>::iterator tile_iter;
28 
29   explicit TextureGenerator(RenderNode* root);
30   ~TextureGenerator() override;
31 
32   // RenderNodeVisitor functions look for textures and pass them
33   // off to HandleTexture (which behaves appropriately depending
34   // on which pass we are in.)
35   void BeginVisitRenderNode(RenderNode* node) override;
36   void BeginVisitCCNode(CCNode* node) override;
37 
38  private:
39   enum TextureGenStage {
40     DiscoveryStage,
41     RemappingStage,
42     ImageGenerationStage
43   };
44 
45   void DiscoverInputIDs(RenderNode* root);
46   void GenerateGLTexIDs();
47   void AssignIDMapping();
48   void WriteOutNewIDs(RenderNode* root);
49   void AllocateImageArray();
50   void BuildTextureImages(RenderNode* root);
51   void HandleTexture(int* texID, int width, int height, GLenum format);
52   void GenerateImageForTexture(int texID, int width, int height, GLenum format);
53 
54   TextureGenStage stage_;
55   std::set<int> discovered_ids_;
56   std::unique_ptr<GLuint[]> tex_ids_;
57   std::map<int, int> remapped_ids_;
58   std::unique_ptr<ImagePtr[]> image_data_;
59   int images_generated_;
60   std::set<int> ids_for_completed_textures_;
61 };
62 
63 #endif  // GPU_TOOLS_COMPOSITOR_MODEL_BENCH_RENDER_MODEL_UTILS_H_
64 
65