Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Unified Diff: ui/gl/gl_image_ozone_native_pixmap.cc

Issue 1258713002: ozone: unify GpuMemoryBufferFactoryOzoneNativePixmap in content/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Re-factor ui/gl/gl_image_ozone_native_pixmap.h/cc so there's only one Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..5dcf5c40a3b041a1a9cb8c75cc43f4242433f9fc
--- /dev/null
+++ b/ui/gl/gl_image_ozone_native_pixmap.cc
@@ -0,0 +1,126 @@
+// 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 {
+
+// static
+scoped_refptr<GLImageOzoneNativePixmap> GLImageOzoneNativePixmap::Create(
+ scoped_refptr<ui::NativePixmap> pixmap,
+ const Size& size,
+ GpuMemoryBuffer::Format format,
+ unsigned internalformat) {
+ DCHECK(pixmap);
+ scoped_refptr<GLImageOzoneNativePixmap> image(
+ new GLImageOzoneNativePixmap(pixmap, size, format, internalformat));
+ if (!image->Initialize()) {
+ return nullptr;
+ }
+ return image;
+}
+
+GLImageOzoneNativePixmap::GLImageOzoneNativePixmap(
+ scoped_refptr<ui::NativePixmap> pixmap,
+ const Size& size,
+ GpuMemoryBuffer::Format format,
+ unsigned internalformat)
+ : pixmap_(pixmap),
+ size_(size),
+ format_(format),
+ internalformat_(internalformat) {}
+
+GLImageOzoneNativePixmap::~GLImageOzoneNativePixmap() {}
+
+bool GLImageOzoneNativePixmap::Initialize() {
+ if (pixmap_->GetEGLClientBuffer()) {
+ scoped_refptr<GLImageEGL> image = new GLImageEGL(size_);
+ EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
+ if (!image->Initialize(EGL_NATIVE_PIXMAP_KHR, pixmap_->GetEGLClientBuffer(),
+ attrs)) {
+ return false;
+ }
+ image_ = image;
+ return true;
+ }
+
+ if (pixmap_->GetDmaBufFd() >= 0) {
+ scoped_refptr<GLImageLinuxDMABuffer> image =
+ new GLImageLinuxDMABuffer(size_, internalformat_);
+ base::FileDescriptor handle(pixmap_->GetDmaBufFd(), false);
+ if (!image->Initialize(handle, format_, pixmap_->GetDmaBufPitch())) {
+ return false;
+ }
+ image_ = image;
+ return true;
+ }
+
+ return true;
+}
+
+void GLImageOzoneNativePixmap::Destroy(bool have_context) {
+ if (image_)
+ image_->Destroy(have_context);
+ pixmap_ = nullptr;
+}
+
+Size GLImageOzoneNativePixmap::GetSize() {
+ return size_;
+}
+
+unsigned GLImageOzoneNativePixmap::GetInternalFormat() {
+ return internalformat_;
+}
+
+bool GLImageOzoneNativePixmap::BindTexImage(unsigned target) {
+ if (image_)
+ return image_->BindTexImage(target);
+ return true;
+}
+
+void GLImageOzoneNativePixmap::ReleaseTexImage(unsigned target) {
+ if (image_)
+ image_->ReleaseTexImage(target);
+}
+
+bool GLImageOzoneNativePixmap::CopyTexSubImage(unsigned target,
+ const Point& offset,
+ const Rect& rect) {
+ if (image_)
+ return image_->CopyTexSubImage(target, offset, rect);
+ return false;
+}
+void GLImageOzoneNativePixmap::WillUseTexImage() {
+ if (image_)
+ image_->WillUseTexImage();
+}
+
+void GLImageOzoneNativePixmap::DidUseTexImage() {
+ if (image_)
+ image_->DidUseTexImage();
+}
+
+void GLImageOzoneNativePixmap::WillModifyTexImage() {
+ if (image_)
+ image_->WillModifyTexImage();
+}
+
+void GLImageOzoneNativePixmap::DidModifyTexImage() {
+ if (image_)
+ image_->DidModifyTexImage();
+}
+
+bool GLImageOzoneNativePixmap::ScheduleOverlayPlane(AcceleratedWidget widget,
+ int z_order,
+ OverlayTransform transform,
+ const Rect& bounds_rect,
+ const RectF& crop_rect) {
+ return pixmap_ &&
+ pixmap_->ScheduleOverlayPlane(widget, z_order, transform, bounds_rect,
+ crop_rect);
+}
+
+} // namespace gfx

Powered by Google App Engine
This is Rietveld 408576698