OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 #include "ui/gl/gl_image_ozone_native_pixmap.h" |
| 6 |
| 7 #include "ui/gl/gl_image_linux_dma_buffer.h" |
| 8 |
| 9 namespace gfx { |
| 10 |
| 11 // static |
| 12 scoped_refptr<GLImageOzoneNativePixmap> GLImageOzoneNativePixmap::Create( |
| 13 scoped_refptr<ui::NativePixmap> pixmap, |
| 14 const Size& size, |
| 15 GpuMemoryBuffer::Format format, |
| 16 unsigned internalformat) { |
| 17 DCHECK(pixmap); |
| 18 scoped_refptr<GLImageOzoneNativePixmap> image( |
| 19 new GLImageOzoneNativePixmap(pixmap, size, format, internalformat)); |
| 20 if (!image->Initialize()) { |
| 21 return nullptr; |
| 22 } |
| 23 return image; |
| 24 } |
| 25 |
| 26 GLImageOzoneNativePixmap::GLImageOzoneNativePixmap( |
| 27 scoped_refptr<ui::NativePixmap> pixmap, |
| 28 const Size& size, |
| 29 GpuMemoryBuffer::Format format, |
| 30 unsigned internalformat) |
| 31 : pixmap_(pixmap), |
| 32 size_(size), |
| 33 format_(format), |
| 34 internalformat_(internalformat) {} |
| 35 |
| 36 GLImageOzoneNativePixmap::~GLImageOzoneNativePixmap() {} |
| 37 |
| 38 bool GLImageOzoneNativePixmap::Initialize() { |
| 39 if (pixmap_->GetEGLClientBuffer()) { |
| 40 scoped_refptr<GLImageEGL> image = new GLImageEGL(size_); |
| 41 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; |
| 42 if (!image->Initialize(EGL_NATIVE_PIXMAP_KHR, pixmap_->GetEGLClientBuffer(), |
| 43 attrs)) { |
| 44 return false; |
| 45 } |
| 46 image_ = image; |
| 47 return true; |
| 48 } |
| 49 |
| 50 if (pixmap_->GetDmaBufFd() >= 0) { |
| 51 scoped_refptr<GLImageLinuxDMABuffer> image = |
| 52 new GLImageLinuxDMABuffer(size_, internalformat_); |
| 53 base::FileDescriptor handle(pixmap_->GetDmaBufFd(), false); |
| 54 if (!image->Initialize(handle, format_, pixmap_->GetDmaBufPitch())) { |
| 55 return false; |
| 56 } |
| 57 image_ = image; |
| 58 return true; |
| 59 } |
| 60 |
| 61 return true; |
| 62 } |
| 63 |
| 64 void GLImageOzoneNativePixmap::Destroy(bool have_context) { |
| 65 if (image_) |
| 66 image_->Destroy(have_context); |
| 67 pixmap_ = nullptr; |
| 68 } |
| 69 |
| 70 Size GLImageOzoneNativePixmap::GetSize() { |
| 71 return size_; |
| 72 } |
| 73 |
| 74 unsigned GLImageOzoneNativePixmap::GetInternalFormat() { |
| 75 return internalformat_; |
| 76 } |
| 77 |
| 78 bool GLImageOzoneNativePixmap::BindTexImage(unsigned target) { |
| 79 if (image_) |
| 80 return image_->BindTexImage(target); |
| 81 return true; |
| 82 } |
| 83 |
| 84 void GLImageOzoneNativePixmap::ReleaseTexImage(unsigned target) { |
| 85 if (image_) |
| 86 image_->ReleaseTexImage(target); |
| 87 } |
| 88 |
| 89 bool GLImageOzoneNativePixmap::CopyTexSubImage(unsigned target, |
| 90 const Point& offset, |
| 91 const Rect& rect) { |
| 92 if (image_) |
| 93 return image_->CopyTexSubImage(target, offset, rect); |
| 94 return false; |
| 95 } |
| 96 void GLImageOzoneNativePixmap::WillUseTexImage() { |
| 97 if (image_) |
| 98 image_->WillUseTexImage(); |
| 99 } |
| 100 |
| 101 void GLImageOzoneNativePixmap::DidUseTexImage() { |
| 102 if (image_) |
| 103 image_->DidUseTexImage(); |
| 104 } |
| 105 |
| 106 void GLImageOzoneNativePixmap::WillModifyTexImage() { |
| 107 if (image_) |
| 108 image_->WillModifyTexImage(); |
| 109 } |
| 110 |
| 111 void GLImageOzoneNativePixmap::DidModifyTexImage() { |
| 112 if (image_) |
| 113 image_->DidModifyTexImage(); |
| 114 } |
| 115 |
| 116 bool GLImageOzoneNativePixmap::ScheduleOverlayPlane(AcceleratedWidget widget, |
| 117 int z_order, |
| 118 OverlayTransform transform, |
| 119 const Rect& bounds_rect, |
| 120 const RectF& crop_rect) { |
| 121 return pixmap_ && |
| 122 pixmap_->ScheduleOverlayPlane(widget, z_order, transform, bounds_rect, |
| 123 crop_rect); |
| 124 } |
| 125 |
| 126 } // namespace gfx |
OLD | NEW |