Chromium Code Reviews| Index: ui/gl/gl_image_ozone_native_pixmap.cc |
| diff --git a/ui/gl/gl_image_ozone_native_pixmap.cc b/ui/gl/gl_image_ozone_native_pixmap.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6370d1ea7d55ae5051232f616b1d67b0e8091e03 |
| --- /dev/null |
| +++ b/ui/gl/gl_image_ozone_native_pixmap.cc |
| @@ -0,0 +1,153 @@ |
| +// 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. |
| + |
| +#include "ui/gl/gl_image_ozone_native_pixmap.h" |
| + |
| +#include "ui/gl/gl_image_linux_dma_buffer.h" |
| + |
| +namespace gfx { |
| +namespace { |
| + |
| +class GLImageOzoneNativePixmap : public GLImageEGL { |
| + public: |
| + static scoped_refptr<GLImageOzoneNativePixmap> Create( |
| + const Size& size, |
| + scoped_refptr<ui::NativePixmap> pixmap) { |
| + scoped_refptr<GLImageOzoneNativePixmap> image = |
| + new GLImageOzoneNativePixmap(size); |
|
piman
2015/07/24 21:56:26
nit: you can pass pixmap to the constructor here
dshwang
2015/07/25 05:28:15
Done.
|
| + EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; |
| + if (!image->Initialize(EGL_NATIVE_PIXMAP_KHR, pixmap->GetEGLClientBuffer(), |
| + attrs)) { |
| + return nullptr; |
| + } |
| + image->pixmap_ = pixmap; |
| + return image; |
| + } |
| + |
| + void Destroy(bool have_context) override { |
| + GLImageEGL::Destroy(have_context); |
| + pixmap_ = nullptr; |
| + } |
| + |
| + bool ScheduleOverlayPlane(AcceleratedWidget widget, |
| + int z_order, |
| + OverlayTransform transform, |
| + const Rect& bounds_rect, |
| + const RectF& crop_rect) override { |
| + return pixmap_ && |
| + pixmap_->ScheduleOverlayPlane(widget, z_order, transform, |
| + bounds_rect, crop_rect); |
| + } |
| + |
| + protected: |
| + ~GLImageOzoneNativePixmap() override {} |
| + |
| + private: |
| + explicit GLImageOzoneNativePixmap(const Size& size) : GLImageEGL(size) {} |
| + |
| + using GLImageEGL::Initialize; |
|
piman
2015/07/24 21:56:26
nit: You shouldn't need this any more because you
dshwang
2015/07/25 05:28:15
Done.
|
| + scoped_refptr<ui::NativePixmap> pixmap_; |
| +}; |
| + |
| +class GLImageOzoneNativePixmapDmaBuf : public GLImageLinuxDMABuffer { |
| + public: |
| + static scoped_refptr<GLImageOzoneNativePixmapDmaBuf> Create( |
| + const Size& size, |
| + unsigned internalformat, |
| + scoped_refptr<ui::NativePixmap> pixmap, |
| + GpuMemoryBuffer::Format format) { |
| + scoped_refptr<GLImageOzoneNativePixmapDmaBuf> image = |
| + new GLImageOzoneNativePixmapDmaBuf(size, internalformat); |
|
piman
2015/07/24 21:56:26
nit: same here, you can pass pixmap to the constru
dshwang
2015/07/25 05:28:15
Done.
|
| + base::FileDescriptor handle(pixmap->GetDmaBufFd(), false); |
| + if (!image->Initialize(handle, format, pixmap->GetDmaBufPitch())) { |
| + return nullptr; |
| + } |
| + image->pixmap_ = pixmap; |
| + return image; |
| + } |
| + |
| + void Destroy(bool have_context) override { |
| + GLImageLinuxDMABuffer::Destroy(have_context); |
| + pixmap_ = nullptr; |
| + } |
| + |
| + bool ScheduleOverlayPlane(AcceleratedWidget widget, |
| + int z_order, |
| + OverlayTransform transform, |
| + const Rect& bounds_rect, |
| + const RectF& crop_rect) override { |
| + return pixmap_ && |
| + pixmap_->ScheduleOverlayPlane(widget, z_order, transform, |
| + bounds_rect, crop_rect); |
| + } |
| + |
| + protected: |
| + ~GLImageOzoneNativePixmapDmaBuf() override {} |
| + |
| + private: |
| + GLImageOzoneNativePixmapDmaBuf(const Size& size, unsigned internalformat) |
| + : GLImageLinuxDMABuffer(size, internalformat) {} |
| + |
| + scoped_refptr<ui::NativePixmap> pixmap_; |
| +}; |
| + |
| +class GLImageOzoneOverlayOnlyPassThrough : public GLImage { |
| + public: |
| + GLImageOzoneOverlayOnlyPassThrough(scoped_refptr<ui::NativePixmap> pixmap, |
| + const Size& size, |
| + unsigned internalformat) |
| + : pixmap_(pixmap), size_(size), internalformat_(internalformat) {} |
| + |
| + void Destroy(bool have_context) override { pixmap_ = nullptr; } |
| + Size GetSize() override { return size_; } |
| + unsigned GetInternalFormat() override { return internalformat_; } |
| + bool BindTexImage(unsigned target) override { return true; } |
| + void ReleaseTexImage(unsigned target) override {} |
| + bool CopyTexSubImage(unsigned target, |
| + const Point& offset, |
| + const Rect& rect) override { |
| + return false; |
| + } |
| + void WillUseTexImage() override {} |
| + void DidUseTexImage() override {} |
| + void WillModifyTexImage() override {} |
| + void DidModifyTexImage() override {} |
| + bool ScheduleOverlayPlane(AcceleratedWidget widget, |
| + int z_order, |
| + OverlayTransform transform, |
| + const Rect& bounds_rect, |
| + const RectF& crop_rect) override { |
| + return pixmap_ && |
| + pixmap_->ScheduleOverlayPlane(widget, z_order, transform, |
| + bounds_rect, crop_rect); |
| + } |
| + |
| + protected: |
| + ~GLImageOzoneOverlayOnlyPassThrough() override {} |
| + |
| + private: |
| + scoped_refptr<ui::NativePixmap> pixmap_; |
| + const Size size_; |
| + unsigned internalformat_; |
| +}; |
| + |
| +} // namespace |
| + |
| +scoped_refptr<GLImage> CreateImageForOzoneNativePixmap( |
| + scoped_refptr<ui::NativePixmap> pixmap, |
| + const Size& size, |
| + GpuMemoryBuffer::Format format, |
| + unsigned internalformat) { |
| + DCHECK(pixmap); |
| + if (pixmap->GetEGLClientBuffer()) { |
| + return GLImageOzoneNativePixmap::Create(size, pixmap); |
| + } |
| + if (pixmap->GetDmaBufFd() >= 0) { |
| + return GLImageOzoneNativePixmapDmaBuf::Create(size, internalformat, pixmap, |
| + format); |
| + } |
| + return new GLImageOzoneOverlayOnlyPassThrough(pixmap, size, internalformat); |
| +} |
| + |
| +} // namespace gfx |