OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gl/gl_image_ozone_native_pixmap.h" | 5 #include "ui/gl/gl_image_ozone_native_pixmap.h" |
6 | 6 |
7 #define FOURCC(a, b, c, d) \ | 7 #define FOURCC(a, b, c, d) \ |
8 ((static_cast<uint32>(a)) | (static_cast<uint32>(b) << 8) | \ | 8 ((static_cast<uint32>(a)) | (static_cast<uint32>(b) << 8) | \ |
9 (static_cast<uint32>(c) << 16) | (static_cast<uint32>(d) << 24)) | 9 (static_cast<uint32>(c) << 16) | (static_cast<uint32>(d) << 24)) |
10 | 10 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 } | 74 } |
75 | 75 |
76 NOTREACHED(); | 76 NOTREACHED(); |
77 return 0; | 77 return 0; |
78 } | 78 } |
79 | 79 |
80 } // namespace | 80 } // namespace |
81 | 81 |
82 GLImageOzoneNativePixmap::GLImageOzoneNativePixmap(const Size& size, | 82 GLImageOzoneNativePixmap::GLImageOzoneNativePixmap(const Size& size, |
83 unsigned internalformat) | 83 unsigned internalformat) |
84 : GLImageEGL(size), internalformat_(internalformat) {} | 84 : gl::GLImageEGL(size), internalformat_(internalformat) {} |
85 | 85 |
86 GLImageOzoneNativePixmap::~GLImageOzoneNativePixmap() { | 86 GLImageOzoneNativePixmap::~GLImageOzoneNativePixmap() { |
87 } | 87 } |
88 | 88 |
89 bool GLImageOzoneNativePixmap::Initialize(ui::NativePixmap* pixmap, | 89 bool GLImageOzoneNativePixmap::Initialize(ui::NativePixmap* pixmap, |
90 BufferFormat format) { | 90 BufferFormat format) { |
91 DCHECK(!pixmap_); | 91 DCHECK(!pixmap_); |
92 if (pixmap->GetEGLClientBuffer()) { | 92 if (pixmap->GetEGLClientBuffer()) { |
93 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; | 93 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; |
94 if (!GLImageEGL::Initialize(EGL_NATIVE_PIXMAP_KHR, | 94 if (!gl::GLImageEGL::Initialize(EGL_NATIVE_PIXMAP_KHR, |
95 pixmap->GetEGLClientBuffer(), attrs)) { | 95 pixmap->GetEGLClientBuffer(), attrs)) { |
96 return false; | 96 return false; |
97 } | 97 } |
98 } else if (pixmap->GetDmaBufFd() >= 0) { | 98 } else if (pixmap->GetDmaBufFd() >= 0) { |
99 if (!ValidInternalFormat(internalformat_)) { | 99 if (!ValidInternalFormat(internalformat_)) { |
100 LOG(ERROR) << "Invalid internalformat: " << internalformat_; | 100 LOG(ERROR) << "Invalid internalformat: " << internalformat_; |
101 return false; | 101 return false; |
102 } | 102 } |
103 | 103 |
104 if (!ValidFormat(format)) { | 104 if (!ValidFormat(format)) { |
105 LOG(ERROR) << "Invalid format: " << static_cast<int>(format); | 105 LOG(ERROR) << "Invalid format: " << static_cast<int>(format); |
106 return false; | 106 return false; |
107 } | 107 } |
108 | 108 |
109 // Note: If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT | 109 // Note: If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT |
110 // target, the EGL will take a reference to the dma_buf. | 110 // target, the EGL will take a reference to the dma_buf. |
111 EGLint attrs[] = {EGL_WIDTH, | 111 EGLint attrs[] = {EGL_WIDTH, |
112 size_.width(), | 112 size_.width(), |
113 EGL_HEIGHT, | 113 EGL_HEIGHT, |
114 size_.height(), | 114 size_.height(), |
115 EGL_LINUX_DRM_FOURCC_EXT, | 115 EGL_LINUX_DRM_FOURCC_EXT, |
116 FourCC(format), | 116 FourCC(format), |
117 EGL_DMA_BUF_PLANE0_FD_EXT, | 117 EGL_DMA_BUF_PLANE0_FD_EXT, |
118 pixmap->GetDmaBufFd(), | 118 pixmap->GetDmaBufFd(), |
119 EGL_DMA_BUF_PLANE0_OFFSET_EXT, | 119 EGL_DMA_BUF_PLANE0_OFFSET_EXT, |
120 0, | 120 0, |
121 EGL_DMA_BUF_PLANE0_PITCH_EXT, | 121 EGL_DMA_BUF_PLANE0_PITCH_EXT, |
122 pixmap->GetDmaBufPitch(), | 122 pixmap->GetDmaBufPitch(), |
123 EGL_NONE}; | 123 EGL_NONE}; |
124 if (!GLImageEGL::Initialize(EGL_LINUX_DMA_BUF_EXT, | 124 if (!gl::GLImageEGL::Initialize(EGL_LINUX_DMA_BUF_EXT, |
125 static_cast<EGLClientBuffer>(nullptr), attrs)) { | 125 static_cast<EGLClientBuffer>(nullptr), |
| 126 attrs)) { |
126 return false; | 127 return false; |
127 } | 128 } |
128 } | 129 } |
129 | 130 |
130 pixmap_ = pixmap; | 131 pixmap_ = pixmap; |
131 return true; | 132 return true; |
132 } | 133 } |
133 | 134 |
134 unsigned GLImageOzoneNativePixmap::GetInternalFormat() { | 135 unsigned GLImageOzoneNativePixmap::GetInternalFormat() { |
135 return internalformat_; | 136 return internalformat_; |
136 } | 137 } |
137 | 138 |
138 void GLImageOzoneNativePixmap::Destroy(bool have_context) { | 139 void GLImageOzoneNativePixmap::Destroy(bool have_context) { |
139 GLImageEGL::Destroy(have_context); | 140 gl::GLImageEGL::Destroy(have_context); |
140 } | 141 } |
141 | 142 |
142 bool GLImageOzoneNativePixmap::ScheduleOverlayPlane(AcceleratedWidget widget, | 143 bool GLImageOzoneNativePixmap::ScheduleOverlayPlane(AcceleratedWidget widget, |
143 int z_order, | 144 int z_order, |
144 OverlayTransform transform, | 145 OverlayTransform transform, |
145 const Rect& bounds_rect, | 146 const Rect& bounds_rect, |
146 const RectF& crop_rect) { | 147 const RectF& crop_rect) { |
147 DCHECK(pixmap_); | 148 DCHECK(pixmap_); |
148 return pixmap_->ScheduleOverlayPlane(widget, z_order, transform, bounds_rect, | 149 return pixmap_->ScheduleOverlayPlane(widget, z_order, transform, bounds_rect, |
149 crop_rect); | 150 crop_rect); |
150 } | 151 } |
151 | 152 |
152 void GLImageOzoneNativePixmap::OnMemoryDump( | 153 void GLImageOzoneNativePixmap::OnMemoryDump( |
153 base::trace_event::ProcessMemoryDump* pmd, | 154 base::trace_event::ProcessMemoryDump* pmd, |
154 uint64_t process_tracing_id, | 155 uint64_t process_tracing_id, |
155 const std::string& dump_name) { | 156 const std::string& dump_name) { |
156 // TODO(ericrk): Implement GLImage OnMemoryDump. crbug.com/514914 | 157 // TODO(ericrk): Implement GLImage OnMemoryDump. crbug.com/514914 |
157 } | 158 } |
158 | 159 |
159 } // namespace gfx | 160 } // namespace gfx |
OLD | NEW |