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

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: address comments 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..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

Powered by Google App Engine
This is Rietveld 408576698