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