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

Side by Side 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, 4 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 unified diff | Download patch
OLDNEW
(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 namespace {
11
12 class GLImageOzoneNativePixmap : public GLImageEGL {
13 public:
14 static scoped_refptr<GLImageOzoneNativePixmap> Create(
15 const Size& size,
16 scoped_refptr<ui::NativePixmap> pixmap) {
17 scoped_refptr<GLImageOzoneNativePixmap> image =
18 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.
19 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
20 if (!image->Initialize(EGL_NATIVE_PIXMAP_KHR, pixmap->GetEGLClientBuffer(),
21 attrs)) {
22 return nullptr;
23 }
24 image->pixmap_ = pixmap;
25 return image;
26 }
27
28 void Destroy(bool have_context) override {
29 GLImageEGL::Destroy(have_context);
30 pixmap_ = nullptr;
31 }
32
33 bool ScheduleOverlayPlane(AcceleratedWidget widget,
34 int z_order,
35 OverlayTransform transform,
36 const Rect& bounds_rect,
37 const RectF& crop_rect) override {
38 return pixmap_ &&
39 pixmap_->ScheduleOverlayPlane(widget, z_order, transform,
40 bounds_rect, crop_rect);
41 }
42
43 protected:
44 ~GLImageOzoneNativePixmap() override {}
45
46 private:
47 explicit GLImageOzoneNativePixmap(const Size& size) : GLImageEGL(size) {}
48
49 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.
50 scoped_refptr<ui::NativePixmap> pixmap_;
51 };
52
53 class GLImageOzoneNativePixmapDmaBuf : public GLImageLinuxDMABuffer {
54 public:
55 static scoped_refptr<GLImageOzoneNativePixmapDmaBuf> Create(
56 const Size& size,
57 unsigned internalformat,
58 scoped_refptr<ui::NativePixmap> pixmap,
59 GpuMemoryBuffer::Format format) {
60 scoped_refptr<GLImageOzoneNativePixmapDmaBuf> image =
61 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.
62 base::FileDescriptor handle(pixmap->GetDmaBufFd(), false);
63 if (!image->Initialize(handle, format, pixmap->GetDmaBufPitch())) {
64 return nullptr;
65 }
66 image->pixmap_ = pixmap;
67 return image;
68 }
69
70 void Destroy(bool have_context) override {
71 GLImageLinuxDMABuffer::Destroy(have_context);
72 pixmap_ = nullptr;
73 }
74
75 bool ScheduleOverlayPlane(AcceleratedWidget widget,
76 int z_order,
77 OverlayTransform transform,
78 const Rect& bounds_rect,
79 const RectF& crop_rect) override {
80 return pixmap_ &&
81 pixmap_->ScheduleOverlayPlane(widget, z_order, transform,
82 bounds_rect, crop_rect);
83 }
84
85 protected:
86 ~GLImageOzoneNativePixmapDmaBuf() override {}
87
88 private:
89 GLImageOzoneNativePixmapDmaBuf(const Size& size, unsigned internalformat)
90 : GLImageLinuxDMABuffer(size, internalformat) {}
91
92 scoped_refptr<ui::NativePixmap> pixmap_;
93 };
94
95 class GLImageOzoneOverlayOnlyPassThrough : public GLImage {
96 public:
97 GLImageOzoneOverlayOnlyPassThrough(scoped_refptr<ui::NativePixmap> pixmap,
98 const Size& size,
99 unsigned internalformat)
100 : pixmap_(pixmap), size_(size), internalformat_(internalformat) {}
101
102 void Destroy(bool have_context) override { pixmap_ = nullptr; }
103 Size GetSize() override { return size_; }
104 unsigned GetInternalFormat() override { return internalformat_; }
105 bool BindTexImage(unsigned target) override { return true; }
106 void ReleaseTexImage(unsigned target) override {}
107 bool CopyTexSubImage(unsigned target,
108 const Point& offset,
109 const Rect& rect) override {
110 return false;
111 }
112 void WillUseTexImage() override {}
113 void DidUseTexImage() override {}
114 void WillModifyTexImage() override {}
115 void DidModifyTexImage() override {}
116 bool ScheduleOverlayPlane(AcceleratedWidget widget,
117 int z_order,
118 OverlayTransform transform,
119 const Rect& bounds_rect,
120 const RectF& crop_rect) override {
121 return pixmap_ &&
122 pixmap_->ScheduleOverlayPlane(widget, z_order, transform,
123 bounds_rect, crop_rect);
124 }
125
126 protected:
127 ~GLImageOzoneOverlayOnlyPassThrough() override {}
128
129 private:
130 scoped_refptr<ui::NativePixmap> pixmap_;
131 const Size size_;
132 unsigned internalformat_;
133 };
134
135 } // namespace
136
137 scoped_refptr<GLImage> CreateImageForOzoneNativePixmap(
138 scoped_refptr<ui::NativePixmap> pixmap,
139 const Size& size,
140 GpuMemoryBuffer::Format format,
141 unsigned internalformat) {
142 DCHECK(pixmap);
143 if (pixmap->GetEGLClientBuffer()) {
144 return GLImageOzoneNativePixmap::Create(size, pixmap);
145 }
146 if (pixmap->GetDmaBufFd() >= 0) {
147 return GLImageOzoneNativePixmapDmaBuf::Create(size, internalformat, pixmap,
148 format);
149 }
150 return new GLImageOzoneOverlayOnlyPassThrough(pixmap, size, internalformat);
151 }
152
153 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698