summaryrefslogtreecommitdiff
path: root/chromium/ui/ozone/common/native_pixmap_egl_binding.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/ui/ozone/common/native_pixmap_egl_binding.cc')
-rw-r--r--chromium/ui/ozone/common/native_pixmap_egl_binding.cc42
1 files changed, 42 insertions, 0 deletions
diff --git a/chromium/ui/ozone/common/native_pixmap_egl_binding.cc b/chromium/ui/ozone/common/native_pixmap_egl_binding.cc
new file mode 100644
index 00000000000..4ce29fe5eda
--- /dev/null
+++ b/chromium/ui/ozone/common/native_pixmap_egl_binding.cc
@@ -0,0 +1,42 @@
+// Copyright 2022 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/ozone/common/native_pixmap_egl_binding.h"
+
+#include "base/logging.h"
+#include "base/memory/scoped_refptr.h"
+#include "ui/gl/gl_image_native_pixmap.h"
+
+namespace ui {
+
+NativePixmapEGLBinding::NativePixmapEGLBinding() = default;
+NativePixmapEGLBinding::~NativePixmapEGLBinding() = default;
+
+// static
+std::unique_ptr<NativePixmapGLBinding> NativePixmapEGLBinding::Create(
+ scoped_refptr<gfx::NativePixmap> pixmap,
+ gfx::BufferFormat plane_format,
+ gfx::BufferPlane plane,
+ gfx::Size plane_size,
+ const gfx::ColorSpace& color_space,
+ GLenum target,
+ GLuint texture_id) {
+ auto gl_image = base::MakeRefCounted<gl::GLImageNativePixmap>(
+ plane_size, plane_format, plane);
+ if (color_space.IsValid())
+ gl_image->SetColorSpace(color_space);
+ if (!gl_image->Initialize(std::move(pixmap))) {
+ LOG(ERROR) << "Unable to initialize GL image from pixmap";
+ return nullptr;
+ }
+
+ auto binding = std::make_unique<NativePixmapEGLBinding>();
+ if (!binding->BindTexture(std::move(gl_image), target, texture_id)) {
+ return nullptr;
+ }
+
+ return binding;
+}
+
+} // namespace ui