OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 #ifndef MOJO_GPU_TEXTURE_CACHE_H_ | |
6 #define MOJO_GPU_TEXTURE_CACHE_H_ | |
7 | |
8 #include <GLES2/gl2.h> | |
9 | |
10 #include <deque> | |
11 #include <map> | |
12 | |
13 #include "base/macros.h" | |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/memory/weak_ptr.h" | |
16 #include "mojo/public/cpp/bindings/binding.h" | |
17 #include "mojo/services/surfaces/interfaces/surfaces.mojom.h" | |
18 | |
19 namespace mojo { | |
20 | |
21 class GLContext; | |
22 class GLTexture; | |
23 class Size; | |
24 | |
25 // Represents a cache of textures which can be drawn to and submitted to a | |
26 // surface. | |
27 // Each |texture| in the cache has an associated |resource_id| which must be | |
28 // used when the texture is submitted to a surface via a | |
29 // TransferableResourcePtr. This class must also be hooked up to the surface as | |
30 // a ResourceReturner such that the resources are properly marked as available | |
31 // to be used again. | |
32 class TextureCache : public mojo::ResourceReturner { | |
33 public: | |
34 class TextureInfo { | |
35 public: | |
36 TextureInfo(); | |
37 TextureInfo(scoped_ptr<mojo::GLTexture> texture, uint32_t resource_id); | |
38 ~TextureInfo(); | |
39 scoped_ptr<mojo::GLTexture> TakeTexture() { return texture_.Pass(); } | |
40 uint32_t resource_id() { return resource_id_; } | |
41 | |
42 private: | |
43 scoped_ptr<mojo::GLTexture> texture_; | |
44 uint32_t resource_id_; | |
45 | |
46 DISALLOW_COPY_AND_ASSIGN(TextureInfo); | |
47 }; | |
48 | |
49 // Returns the ResourceReturner to be given to the surface the textures will | |
50 // be uploaded to via |out_resource_returner|. | |
51 TextureCache(base::WeakPtr<mojo::GLContext> gl_context, | |
52 mojo::ResourceReturnerPtr* out_resource_returner); | |
53 ~TextureCache() override; | |
54 | |
55 // Returns a texture for the given size. If no texture is available the | |
56 // scoped_ptr will be empty. | |
57 scoped_ptr<TextureInfo> GetTexture(const mojo::Size& requested_size); | |
58 | |
59 // Notifies the TextureCache to expect the given resource to be returned | |
60 // shortly. | |
61 void NotifyPendingResourceReturn(uint32_t resource_id, | |
62 scoped_ptr<mojo::GLTexture> texture); | |
63 | |
64 private: | |
65 // mojo::ResourceReturner | |
66 void ReturnResources( | |
67 mojo::Array<mojo::ReturnedResourcePtr> resources) override; | |
68 | |
69 base::WeakPtr<mojo::GLContext> gl_context_; | |
70 mojo::Binding<mojo::ResourceReturner> returner_binding_; | |
71 std::deque<uint32_t> available_textures_; | |
72 std::map<uint32_t, scoped_ptr<mojo::GLTexture>> resource_to_texture_map_; | |
73 std::map<uint32_t, GLuint> resource_to_sync_point_map_; | |
74 uint32_t next_resource_id_; | |
75 | |
76 DISALLOW_COPY_AND_ASSIGN(TextureCache); | |
77 }; | |
78 | |
79 } // namespace mojo | |
80 | |
81 #endif // MOJO_GPU_TEXTURE_CACHE_H_ | |
OLD | NEW |