// Copyright 2015 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef MOJO_GPU_TEXTURE_CACHE_H_ #define MOJO_GPU_TEXTURE_CACHE_H_ #include #include #include #include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "mojo/public/cpp/bindings/binding.h" #include "mojo/services/surfaces/interfaces/surfaces.mojom.h" namespace mojo { class GLContext; class GLTexture; class Size; // Represents a cache of textures which can be drawn to and submitted to a // surface. // Each |texture| in the cache has an associated |resource_id| which must be // used when the texture is submitted to a surface via a // TransferableResourcePtr. This class must also be hooked up to the surface as // a ResourceReturner such that the resources are properly marked as available // to be used again. class TextureCache : public mojo::ResourceReturner { public: class TextureInfo { public: TextureInfo(); TextureInfo(scoped_ptr texture, uint32_t resource_id); ~TextureInfo(); scoped_ptr Texture() { return texture_.Pass(); } uint32_t ResourceId() { return resource_id_; } private: scoped_ptr texture_; uint32_t resource_id_; DISALLOW_COPY_AND_ASSIGN(TextureInfo); }; // Returns the ResourceReturner to be given to the surface the textures will // be uploaded to via |out_resource_returner|. TextureCache(base::WeakPtr gl_context, mojo::ResourceReturnerPtr* out_resource_returner); ~TextureCache() override; // Returns a texture for the given size. If no texture is available the // scoped_ptr will be empty. scoped_ptr GetTexture(const mojo::Size& requested_size); // Notifies the TextureCache to expect the given resource to be returned // shortly. void NotifyPendingResourceReturn(uint32_t resource_id, scoped_ptr texture); private: // mojo::ResourceReturner void ReturnResources( mojo::Array resources) override; base::WeakPtr gl_context_; mojo::Binding returner_binding_; std::deque available_textures_; std::map> resource_to_texture_map_; std::map resource_to_sync_point_map_; uint32_t next_resource_id_; DISALLOW_COPY_AND_ASSIGN(TextureCache); }; } // namespace mojo #endif // MOJO_GPU_TEXTURE_CACHE_H_