Home | History | Annotate | Download | only in service
      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.
      4 
      5 #ifndef GPU_COMMAND_BUFFER_SERVICE_TEXTURE_DEFINITION_H_
      6 #define GPU_COMMAND_BUFFER_SERVICE_TEXTURE_DEFINITION_H_
      7 
      8 #include <vector>
      9 
     10 #include "base/memory/ref_counted.h"
     11 #include "gpu/command_buffer/service/gl_utils.h"
     12 
     13 namespace gfx {
     14 class GLImage;
     15 }
     16 
     17 namespace gpu {
     18 namespace gles2 {
     19 
     20 class Texture;
     21 
     22 class NativeImageBuffer : public base::RefCountedThreadSafe<NativeImageBuffer> {
     23  public:
     24   static scoped_refptr<NativeImageBuffer> Create(GLuint texture_id);
     25 
     26   virtual void AddClient(gfx::GLImage* client) = 0;
     27   virtual void RemoveClient(gfx::GLImage* client) = 0;
     28   virtual bool IsClient(gfx::GLImage* client) = 0;
     29   virtual void BindToTexture(GLenum target) = 0;
     30 
     31  protected:
     32   friend class base::RefCountedThreadSafe<NativeImageBuffer>;
     33   NativeImageBuffer() {}
     34   virtual ~NativeImageBuffer() {}
     35 
     36   DISALLOW_COPY_AND_ASSIGN(NativeImageBuffer);
     37 };
     38 
     39 // An immutable description that can be used to create a texture that shares
     40 // the underlying image buffer(s).
     41 class TextureDefinition {
     42  public:
     43   TextureDefinition(GLenum target,
     44                     Texture* texture,
     45                     unsigned int version,
     46                     const scoped_refptr<NativeImageBuffer>& image);
     47   virtual ~TextureDefinition();
     48 
     49   Texture* CreateTexture() const;
     50   void UpdateTexture(Texture* texture) const;
     51 
     52   unsigned int version() const { return version_; }
     53   bool IsOlderThan(unsigned int version) const {
     54     return (version - version_) < 0x80000000;
     55   }
     56   bool Matches(const Texture* texture) const;
     57 
     58   scoped_refptr<NativeImageBuffer> image() { return image_buffer_; }
     59 
     60  private:
     61   struct LevelInfo {
     62     LevelInfo(GLenum target,
     63               GLenum internal_format,
     64               GLsizei width,
     65               GLsizei height,
     66               GLsizei depth,
     67               GLint border,
     68               GLenum format,
     69               GLenum type,
     70               bool cleared);
     71     ~LevelInfo();
     72 
     73     GLenum target;
     74     GLenum internal_format;
     75     GLsizei width;
     76     GLsizei height;
     77     GLsizei depth;
     78     GLint border;
     79     GLenum format;
     80     GLenum type;
     81     bool cleared;
     82   };
     83 
     84   typedef std::vector<std::vector<LevelInfo> > LevelInfos;
     85 
     86   unsigned int version_;
     87   GLenum target_;
     88   scoped_refptr<NativeImageBuffer> image_buffer_;
     89   GLenum min_filter_;
     90   GLenum mag_filter_;
     91   GLenum wrap_s_;
     92   GLenum wrap_t_;
     93   GLenum usage_;
     94   bool immutable_;
     95   LevelInfos level_infos_;
     96 };
     97 
     98 }  // namespage gles2
     99 }  // namespace gpu
    100 
    101 #endif  // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_DEFINITION_H_
    102