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

Side by Side Diff: ui/gl/gl_image_io_surface.mm

Issue 1870483003: Add command buffer support for GL_RGB CHROMIUM image emulation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase, add more comments. Created 4 years, 8 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gl/gl_image_io_surface.h" 5 #include "ui/gl/gl_image_io_surface.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 return true; 78 return true;
79 default: 79 default:
80 return false; 80 return false;
81 } 81 }
82 } 82 }
83 83
84 bool ValidFormat(BufferFormat format) { 84 bool ValidFormat(BufferFormat format) {
85 switch (format) { 85 switch (format) {
86 case BufferFormat::R_8: 86 case BufferFormat::R_8:
87 case BufferFormat::BGRA_8888: 87 case BufferFormat::BGRA_8888:
88 case BufferFormat::BGRX_8888:
88 case BufferFormat::RGBA_8888: 89 case BufferFormat::RGBA_8888:
89 case BufferFormat::UYVY_422: 90 case BufferFormat::UYVY_422:
90 case BufferFormat::YUV_420_BIPLANAR: 91 case BufferFormat::YUV_420_BIPLANAR:
91 return true; 92 return true;
92 case BufferFormat::ATC: 93 case BufferFormat::ATC:
93 case BufferFormat::ATCIA: 94 case BufferFormat::ATCIA:
94 case BufferFormat::DXT1: 95 case BufferFormat::DXT1:
95 case BufferFormat::DXT5: 96 case BufferFormat::DXT5:
96 case BufferFormat::ETC1: 97 case BufferFormat::ETC1:
97 case BufferFormat::RGBA_4444: 98 case BufferFormat::RGBA_4444:
98 case BufferFormat::RGBX_8888: 99 case BufferFormat::RGBX_8888:
99 case BufferFormat::BGRX_8888:
100 case BufferFormat::YUV_420: 100 case BufferFormat::YUV_420:
101 return false; 101 return false;
102 } 102 }
103 103
104 NOTREACHED(); 104 NOTREACHED();
105 return false; 105 return false;
106 } 106 }
107 107
108 GLenum TextureFormat(BufferFormat format) { 108 GLenum TextureFormat(BufferFormat format) {
109 switch (format) { 109 switch (format) {
110 case BufferFormat::R_8: 110 case BufferFormat::R_8:
111 return GL_RED; 111 return GL_RED;
112 case BufferFormat::BGRA_8888: 112 case BufferFormat::BGRA_8888:
113 case BufferFormat::BGRX_8888:
113 case BufferFormat::RGBA_8888: 114 case BufferFormat::RGBA_8888:
114 return GL_RGBA; 115 return GL_RGBA;
115 case BufferFormat::UYVY_422: 116 case BufferFormat::UYVY_422:
116 return GL_RGB; 117 return GL_RGB;
117 case BufferFormat::YUV_420_BIPLANAR: 118 case BufferFormat::YUV_420_BIPLANAR:
118 return GL_RGB_YCBCR_420V_CHROMIUM; 119 return GL_RGB_YCBCR_420V_CHROMIUM;
119 case BufferFormat::ATC: 120 case BufferFormat::ATC:
120 case BufferFormat::ATCIA: 121 case BufferFormat::ATCIA:
121 case BufferFormat::DXT1: 122 case BufferFormat::DXT1:
122 case BufferFormat::DXT5: 123 case BufferFormat::DXT5:
123 case BufferFormat::ETC1: 124 case BufferFormat::ETC1:
124 case BufferFormat::RGBA_4444: 125 case BufferFormat::RGBA_4444:
125 case BufferFormat::RGBX_8888: 126 case BufferFormat::RGBX_8888:
126 case BufferFormat::BGRX_8888:
127 case BufferFormat::YUV_420: 127 case BufferFormat::YUV_420:
128 NOTREACHED(); 128 NOTREACHED();
129 return 0; 129 return 0;
130 } 130 }
131 131
132 NOTREACHED(); 132 NOTREACHED();
133 return 0; 133 return 0;
134 } 134 }
135 135
136 GLenum DataFormat(BufferFormat format) { 136 GLenum DataFormat(BufferFormat format) {
137 switch (format) { 137 switch (format) {
138 case BufferFormat::R_8: 138 case BufferFormat::R_8:
139 return GL_RED; 139 return GL_RED;
140 case BufferFormat::BGRA_8888: 140 case BufferFormat::BGRA_8888:
141 case BufferFormat::BGRX_8888:
141 case BufferFormat::RGBA_8888: 142 case BufferFormat::RGBA_8888:
142 return GL_BGRA; 143 return GL_BGRA;
143 case BufferFormat::UYVY_422: 144 case BufferFormat::UYVY_422:
144 return GL_YCBCR_422_APPLE; 145 return GL_YCBCR_422_APPLE;
145 case BufferFormat::ATC: 146 case BufferFormat::ATC:
146 case BufferFormat::ATCIA: 147 case BufferFormat::ATCIA:
147 case BufferFormat::DXT1: 148 case BufferFormat::DXT1:
148 case BufferFormat::DXT5: 149 case BufferFormat::DXT5:
149 case BufferFormat::ETC1: 150 case BufferFormat::ETC1:
150 case BufferFormat::RGBA_4444: 151 case BufferFormat::RGBA_4444:
151 case BufferFormat::RGBX_8888: 152 case BufferFormat::RGBX_8888:
152 case BufferFormat::BGRX_8888:
153 case BufferFormat::YUV_420: 153 case BufferFormat::YUV_420:
154 case BufferFormat::YUV_420_BIPLANAR: 154 case BufferFormat::YUV_420_BIPLANAR:
155 NOTREACHED(); 155 NOTREACHED();
156 return 0; 156 return 0;
157 } 157 }
158 158
159 NOTREACHED(); 159 NOTREACHED();
160 return 0; 160 return 0;
161 } 161 }
162 162
163 GLenum DataType(BufferFormat format) { 163 GLenum DataType(BufferFormat format) {
164 switch (format) { 164 switch (format) {
165 case BufferFormat::R_8: 165 case BufferFormat::R_8:
166 return GL_UNSIGNED_BYTE; 166 return GL_UNSIGNED_BYTE;
167 case BufferFormat::BGRA_8888: 167 case BufferFormat::BGRA_8888:
168 case BufferFormat::BGRX_8888:
168 case BufferFormat::RGBA_8888: 169 case BufferFormat::RGBA_8888:
169 return GL_UNSIGNED_INT_8_8_8_8_REV; 170 return GL_UNSIGNED_INT_8_8_8_8_REV;
170 case BufferFormat::UYVY_422: 171 case BufferFormat::UYVY_422:
171 return GL_UNSIGNED_SHORT_8_8_APPLE; 172 return GL_UNSIGNED_SHORT_8_8_APPLE;
172 break; 173 break;
173 case BufferFormat::ATC: 174 case BufferFormat::ATC:
174 case BufferFormat::ATCIA: 175 case BufferFormat::ATCIA:
175 case BufferFormat::DXT1: 176 case BufferFormat::DXT1:
176 case BufferFormat::DXT5: 177 case BufferFormat::DXT5:
177 case BufferFormat::ETC1: 178 case BufferFormat::ETC1:
178 case BufferFormat::RGBA_4444: 179 case BufferFormat::RGBA_4444:
179 case BufferFormat::RGBX_8888: 180 case BufferFormat::RGBX_8888:
180 case BufferFormat::BGRX_8888:
181 case BufferFormat::YUV_420: 181 case BufferFormat::YUV_420:
182 case BufferFormat::YUV_420_BIPLANAR: 182 case BufferFormat::YUV_420_BIPLANAR:
183 NOTREACHED(); 183 NOTREACHED();
184 return 0; 184 return 0;
185 } 185 }
186 186
187 NOTREACHED(); 187 NOTREACHED();
188 return 0; 188 return 0;
189 } 189 }
190 190
191 // When an IOSurface is bound to a texture with internalformat "GL_RGB", many
192 // OpenGL operations are broken. Therefore, never allow an IOSurface to be bound
193 // with GL_RGB. https://crbug.com/595948.
194 GLenum ConvertRequestedInternalFormat(GLenum internalformat) {
195 if (internalformat == GL_RGB)
196 return GL_RGBA;
197 return internalformat;
198 }
199
191 } // namespace 200 } // namespace
192 201
193 class GLImageIOSurface::RGBConverter 202 class GLImageIOSurface::RGBConverter
194 : public base::RefCounted<GLImageIOSurface::RGBConverter> { 203 : public base::RefCounted<GLImageIOSurface::RGBConverter> {
195 public: 204 public:
196 static scoped_refptr<RGBConverter> GetForCurrentContext(); 205 static scoped_refptr<RGBConverter> GetForCurrentContext();
197 bool CopyTexImage(IOSurfaceRef io_surface, const gfx::Size& size); 206 bool CopyTexImage(IOSurfaceRef io_surface, const gfx::Size& size);
198 207
199 private: 208 private:
200 friend class base::RefCounted<RGBConverter>; 209 friend class base::RefCounted<RGBConverter>;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 glUniform2f(size_location_, size.width(), size.height()); 359 glUniform2f(size_location_, size.width(), size.height());
351 gfx::GLHelper::DrawQuad(vertex_buffer_); 360 gfx::GLHelper::DrawQuad(vertex_buffer_);
352 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 361 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
353 GL_TEXTURE_RECTANGLE_ARB, 0, 0); 362 GL_TEXTURE_RECTANGLE_ARB, 0, 0);
354 return true; 363 return true;
355 } 364 }
356 365
357 GLImageIOSurface::GLImageIOSurface(const gfx::Size& size, 366 GLImageIOSurface::GLImageIOSurface(const gfx::Size& size,
358 unsigned internalformat) 367 unsigned internalformat)
359 : size_(size), 368 : size_(size),
360 internalformat_(internalformat), 369 internalformat_(ConvertRequestedInternalFormat(internalformat)),
370 client_internalformat_(internalformat),
361 format_(BufferFormat::RGBA_8888) {} 371 format_(BufferFormat::RGBA_8888) {}
362 372
363 GLImageIOSurface::~GLImageIOSurface() { 373 GLImageIOSurface::~GLImageIOSurface() {
364 DCHECK(thread_checker_.CalledOnValidThread()); 374 DCHECK(thread_checker_.CalledOnValidThread());
365 DCHECK(!io_surface_); 375 DCHECK(!io_surface_);
366 } 376 }
367 377
368 bool GLImageIOSurface::Initialize(IOSurfaceRef io_surface, 378 bool GLImageIOSurface::Initialize(IOSurfaceRef io_surface,
369 gfx::GenericSharedMemoryId io_surface_id, 379 gfx::GenericSharedMemoryId io_surface_id,
370 BufferFormat format) { 380 BufferFormat format) {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, 501 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
492 base::trace_event::MemoryAllocatorDump::kUnitsBytes, 502 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
493 static_cast<uint64_t>(size_bytes)); 503 static_cast<uint64_t>(size_bytes));
494 504
495 auto guid = 505 auto guid =
496 GetGenericSharedMemoryGUIDForTracing(process_tracing_id, io_surface_id_); 506 GetGenericSharedMemoryGUIDForTracing(process_tracing_id, io_surface_id_);
497 pmd->CreateSharedGlobalAllocatorDump(guid); 507 pmd->CreateSharedGlobalAllocatorDump(guid);
498 pmd->AddOwnershipEdge(dump->guid(), guid); 508 pmd->AddOwnershipEdge(dump->guid(), guid);
499 } 509 }
500 510
511 bool GLImageIOSurface::EmulatingRGB() const {
512 return client_internalformat_ == GL_RGB;
513 }
514
501 base::ScopedCFTypeRef<IOSurfaceRef> GLImageIOSurface::io_surface() { 515 base::ScopedCFTypeRef<IOSurfaceRef> GLImageIOSurface::io_surface() {
502 return io_surface_; 516 return io_surface_;
503 } 517 }
504 518
505 base::ScopedCFTypeRef<CVPixelBufferRef> GLImageIOSurface::cv_pixel_buffer() { 519 base::ScopedCFTypeRef<CVPixelBufferRef> GLImageIOSurface::cv_pixel_buffer() {
506 return cv_pixel_buffer_; 520 return cv_pixel_buffer_;
507 } 521 }
508 522
509 // static 523 // static
510 unsigned GLImageIOSurface::GetInternalFormatForTesting( 524 unsigned GLImageIOSurface::GetInternalFormatForTesting(
511 gfx::BufferFormat format) { 525 gfx::BufferFormat format) {
512 DCHECK(ValidFormat(format)); 526 DCHECK(ValidFormat(format));
513 return TextureFormat(format); 527 return TextureFormat(format);
514 } 528 }
515 } // namespace gl 529 } // namespace gl
OLDNEW
« gpu/command_buffer/service/texture_manager.cc ('K') | « ui/gl/gl_image_io_surface.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698