Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / gpu / command_buffer / service / texture_definition.h
blob19c953cb1c44eff2a8598c3315312003696a0b3d
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_
8 #include <vector>
10 #include "base/memory/ref_counted.h"
11 #include "gpu/command_buffer/service/gl_utils.h"
12 #include "ui/gfx/geometry/rect.h"
14 namespace gfx {
15 class GLImage;
18 namespace gpu {
19 namespace gles2 {
21 class Texture;
23 class NativeImageBuffer : public base::RefCountedThreadSafe<NativeImageBuffer> {
24 public:
25 static scoped_refptr<NativeImageBuffer> Create(GLuint texture_id);
27 virtual void AddClient(gfx::GLImage* client) = 0;
28 virtual void RemoveClient(gfx::GLImage* client) = 0;
29 virtual bool IsClient(gfx::GLImage* client) = 0;
30 virtual void BindToTexture(GLenum target) const = 0;
32 protected:
33 friend class base::RefCountedThreadSafe<NativeImageBuffer>;
34 NativeImageBuffer() {}
35 virtual ~NativeImageBuffer() {}
37 DISALLOW_COPY_AND_ASSIGN(NativeImageBuffer);
40 class ScopedUpdateTexture {
41 public:
42 ScopedUpdateTexture();
43 ~ScopedUpdateTexture();
45 private:
46 DISALLOW_COPY_AND_ASSIGN(ScopedUpdateTexture);
49 // An immutable description that can be used to create a texture that shares
50 // the underlying image buffer(s).
51 class TextureDefinition {
52 public:
53 static void AvoidEGLTargetTextureReuse();
55 TextureDefinition();
56 TextureDefinition(Texture* texture,
57 unsigned int version,
58 const scoped_refptr<NativeImageBuffer>& image);
59 virtual ~TextureDefinition();
61 Texture* CreateTexture() const;
63 // Must be wrapped with ScopedUpdateTexture.
64 void UpdateTexture(Texture* texture) const;
66 unsigned int version() const { return version_; }
67 bool IsOlderThan(unsigned int version) const {
68 return (version - version_) < 0x80000000;
70 bool Matches(const Texture* texture) const;
72 scoped_refptr<NativeImageBuffer> image() const { return image_buffer_; }
74 private:
75 bool SafeToRenderFrom() const;
76 void UpdateTextureInternal(Texture* texture) const;
78 struct LevelInfo {
79 LevelInfo();
80 LevelInfo(GLenum target,
81 GLenum internal_format,
82 GLsizei width,
83 GLsizei height,
84 GLsizei depth,
85 GLint border,
86 GLenum format,
87 GLenum type,
88 const gfx::Rect& cleared_rect);
89 ~LevelInfo();
91 GLenum target;
92 GLenum internal_format;
93 GLsizei width;
94 GLsizei height;
95 GLsizei depth;
96 GLint border;
97 GLenum format;
98 GLenum type;
99 gfx::Rect cleared_rect;
102 unsigned int version_;
103 GLenum target_;
104 scoped_refptr<NativeImageBuffer> image_buffer_;
105 GLenum min_filter_;
106 GLenum mag_filter_;
107 GLenum wrap_s_;
108 GLenum wrap_t_;
109 GLenum usage_;
110 bool immutable_;
111 bool defined_;
113 // Only support textures with one face and one level.
114 LevelInfo level_info_;
117 } // namespage gles2
118 } // namespace gpu
120 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_DEFINITION_H_