gl_image_memory.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #ifndef UI_GL_GL_IMAGE_MEMORY_H_
  5. #define UI_GL_GL_IMAGE_MEMORY_H_
  6. #include "ui/gl/gl_image.h"
  7. #include <stddef.h>
  8. #include "base/memory/weak_ptr.h"
  9. #include "base/numerics/safe_math.h"
  10. #include "ui/gfx/buffer_types.h"
  11. #include "ui/gl/gl_export.h"
  12. namespace gl {
  13. class GLContext;
  14. class GLSurface;
  15. class GL_EXPORT GLImageMemory : public GLImage {
  16. public:
  17. explicit GLImageMemory(const gfx::Size& size);
  18. GLImageMemory(const GLImageMemory&) = delete;
  19. GLImageMemory& operator=(const GLImageMemory&) = delete;
  20. bool Initialize(const unsigned char* memory,
  21. gfx::BufferFormat format,
  22. size_t stride);
  23. // Safe downcast. Returns |nullptr| on failure.
  24. static GLImageMemory* FromGLImage(GLImage* image);
  25. // Overridden from GLImage:
  26. gfx::Size GetSize() override;
  27. unsigned GetInternalFormat() override;
  28. unsigned GetDataFormat() override;
  29. unsigned GetDataType() override;
  30. BindOrCopy ShouldBindOrCopy() override;
  31. bool BindTexImage(unsigned target) override;
  32. void ReleaseTexImage(unsigned target) override {}
  33. bool CopyTexImage(unsigned target) override;
  34. bool CopyTexSubImage(unsigned target,
  35. const gfx::Point& offset,
  36. const gfx::Rect& rect) override;
  37. void Flush() override {}
  38. Type GetType() const override;
  39. const unsigned char* memory() { return memory_; }
  40. size_t stride() const { return stride_; }
  41. gfx::BufferFormat format() const { return format_; }
  42. protected:
  43. ~GLImageMemory() override;
  44. private:
  45. static bool ValidFormat(gfx::BufferFormat format);
  46. const gfx::Size size_;
  47. const unsigned char* memory_;
  48. gfx::BufferFormat format_;
  49. size_t stride_;
  50. unsigned buffer_ = 0;
  51. // The context/surface from which the |buffer_| is created.
  52. base::WeakPtr<GLContext> original_context_;
  53. base::WeakPtr<GLSurface> original_surface_;
  54. size_t buffer_bytes_ = 0;
  55. int memcpy_tasks_ = 0;
  56. };
  57. } // namespace gl
  58. #endif // UI_GL_GL_IMAGE_MEMORY_H_