1 // Copyright 2014 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.
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_TEXTURE_DEFINITION_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_TEXTURE_DEFINITION_H_
11 #include "base/callback.h"
12 #include "base/memory/linked_ptr.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/synchronization/lock.h"
16 #include "gpu/command_buffer/service/gl_utils.h"
17 #include "ui/gl/gl_fence.h"
29 class NativeImageBuffer : public base::RefCountedThreadSafe<NativeImageBuffer> {
31 static scoped_refptr<NativeImageBuffer> Create(GLuint texture_id);
32 virtual void BindToTexture(GLenum target) = 0;
34 void AddClient(gfx::GLImage* client);
35 void RemoveClient(gfx::GLImage* client);
36 bool IsClient(gfx::GLImage* client);
38 void WillRead(gfx::GLImage* client);
39 void WillWrite(gfx::GLImage* client);
40 void DidRead(gfx::GLImage* client);
41 void DidWrite(gfx::GLImage* client);
44 friend class base::RefCountedThreadSafe<NativeImageBuffer>;
45 explicit NativeImageBuffer(scoped_ptr<gfx::GLFence> write_fence);
46 virtual ~NativeImageBuffer();
51 ClientInfo(gfx::GLImage* client);
55 bool needs_wait_before_read;
56 linked_ptr<gfx::GLFence> read_fence;
58 std::list<ClientInfo> client_infos_;
59 scoped_ptr<gfx::GLFence> write_fence_;
60 gfx::GLImage* write_client_;
62 DISALLOW_COPY_AND_ASSIGN(NativeImageBuffer);
65 // An immutable description that can be used to create a texture that shares
66 // the underlying image buffer(s).
67 class TextureDefinition {
69 TextureDefinition(GLenum target,
72 const scoped_refptr<NativeImageBuffer>& image);
73 virtual ~TextureDefinition();
75 Texture* CreateTexture() const;
76 void UpdateTexture(Texture* texture) const;
78 unsigned int version() const { return version_; }
79 bool IsOlderThan(unsigned int version) const {
80 return (version - version_) < 0x80000000;
82 bool Matches(const Texture* texture) const;
84 scoped_refptr<NativeImageBuffer> image() { return image_buffer_; }
88 LevelInfo(GLenum target,
89 GLenum internal_format,
100 GLenum internal_format;
110 typedef std::vector<std::vector<LevelInfo> > LevelInfos;
112 unsigned int version_;
114 scoped_refptr<NativeImageBuffer> image_buffer_;
121 LevelInfos level_infos_;
127 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_DEFINITION_H_