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

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

Issue 1418483003: Revert of ui: Move GLImage::BindTexImage fallback from GLImage implementations to GLES2CmdDecoder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « ui/gl/gl_image_io_surface.h ('k') | ui/gl/gl_image_memory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/mac/foundation_util.h" 10 #include "base/mac/foundation_util.h"
11 #include "base/trace_event/memory_allocator_dump.h"
12 #include "base/trace_event/memory_dump_manager.h"
13 #include "base/trace_event/process_memory_dump.h"
14 #include "ui/gl/gl_bindings.h" 11 #include "ui/gl/gl_bindings.h"
15 #include "ui/gl/gl_context.h" 12 #include "ui/gl/gl_context.h"
16 13
17 // Note that this must be included after gl_bindings.h to avoid conflicts. 14 // Note that this must be included after gl_bindings.h to avoid conflicts.
18 #include <OpenGL/CGLIOSurface.h> 15 #include <OpenGL/CGLIOSurface.h>
19 #include <Quartz/Quartz.h> 16 #include <Quartz/Quartz.h>
20 17
21 namespace gfx { 18 namespace gfx {
22 namespace { 19 namespace {
23 20
24 using WidgetToLayerMap = std::map<AcceleratedWidget, CALayer*>; 21 typedef std::map<gfx::AcceleratedWidget,CALayer*> WidgetToLayerMap;
25 base::LazyInstance<WidgetToLayerMap> g_widget_to_layer_map; 22 base::LazyInstance<WidgetToLayerMap> g_widget_to_layer_map;
26 23
27 bool ValidInternalFormat(unsigned internalformat) { 24 bool ValidInternalFormat(unsigned internalformat) {
28 switch (internalformat) { 25 switch (internalformat) {
29 case GL_R8: 26 case GL_R8:
30 case GL_BGRA_EXT: 27 case GL_BGRA_EXT:
31 case GL_RGB: 28 case GL_RGB:
32 case GL_RGB_YCBCR_422_CHROMIUM: 29 case GL_RGB_YCBCR_422_CHROMIUM:
33 return true; 30 return true;
34 default: 31 default:
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 NOTREACHED(); 131 NOTREACHED();
135 return 0; 132 return 0;
136 } 133 }
137 134
138 NOTREACHED(); 135 NOTREACHED();
139 return 0; 136 return 0;
140 } 137 }
141 138
142 } // namespace 139 } // namespace
143 140
144 GLImageIOSurface::GLImageIOSurface(const Size& size, unsigned internalformat) 141 GLImageIOSurface::GLImageIOSurface(const gfx::Size& size,
142 unsigned internalformat)
145 : size_(size), 143 : size_(size),
146 internalformat_(internalformat), 144 internalformat_(internalformat),
147 format_(BufferFormat::RGBA_8888) {} 145 format_(BufferFormat::RGBA_8888) {}
148 146
149 GLImageIOSurface::~GLImageIOSurface() { 147 GLImageIOSurface::~GLImageIOSurface() {
150 DCHECK(thread_checker_.CalledOnValidThread()); 148 DCHECK(thread_checker_.CalledOnValidThread());
151 DCHECK(!io_surface_); 149 DCHECK(!io_surface_);
152 } 150 }
153 151
154 bool GLImageIOSurface::Initialize(IOSurfaceRef io_surface, 152 bool GLImageIOSurface::Initialize(IOSurfaceRef io_surface,
155 GenericSharedMemoryId io_surface_id, 153 gfx::GenericSharedMemoryId io_surface_id,
156 BufferFormat format) { 154 BufferFormat format) {
157 DCHECK(thread_checker_.CalledOnValidThread()); 155 DCHECK(thread_checker_.CalledOnValidThread());
158 DCHECK(!io_surface_); 156 DCHECK(!io_surface_);
159 157
160 if (!ValidInternalFormat(internalformat_)) { 158 if (!ValidInternalFormat(internalformat_)) {
161 LOG(ERROR) << "Invalid internalformat: " << internalformat_; 159 LOG(ERROR) << "Invalid internalformat: " << internalformat_;
162 return false; 160 return false;
163 } 161 }
164 162
165 if (!ValidFormat(format)) { 163 if (!ValidFormat(format)) {
166 LOG(ERROR) << "Invalid format: " << static_cast<int>(format); 164 LOG(ERROR) << "Invalid format: " << static_cast<int>(format);
167 return false; 165 return false;
168 } 166 }
169 167
170 format_ = format; 168 format_ = format;
171 io_surface_.reset(io_surface, base::scoped_policy::RETAIN); 169 io_surface_.reset(io_surface, base::scoped_policy::RETAIN);
172 io_surface_id_ = io_surface_id; 170 io_surface_id_ = io_surface_id;
173 return true; 171 return true;
174 } 172 }
175 173
176 void GLImageIOSurface::Destroy(bool have_context) { 174 void GLImageIOSurface::Destroy(bool have_context) {
177 DCHECK(thread_checker_.CalledOnValidThread()); 175 DCHECK(thread_checker_.CalledOnValidThread());
178 io_surface_.reset(); 176 io_surface_.reset();
179 } 177 }
180 178
181 Size GLImageIOSurface::GetSize() { 179 gfx::Size GLImageIOSurface::GetSize() { return size_; }
182 return size_;
183 }
184 180
185 unsigned GLImageIOSurface::GetInternalFormat() { return internalformat_; } 181 unsigned GLImageIOSurface::GetInternalFormat() { return internalformat_; }
186 182
187 bool GLImageIOSurface::BindTexImage(unsigned target) { 183 bool GLImageIOSurface::BindTexImage(unsigned target) {
188 DCHECK(thread_checker_.CalledOnValidThread()); 184 DCHECK(thread_checker_.CalledOnValidThread());
189 if (target != GL_TEXTURE_RECTANGLE_ARB) { 185 if (target != GL_TEXTURE_RECTANGLE_ARB) {
190 // This might be supported in the future. For now, perform strict 186 // This might be supported in the future. For now, perform strict
191 // validation so we know what's going on. 187 // validation so we know what's going on.
192 LOG(ERROR) << "IOSurface requires TEXTURE_RECTANGLE_ARB target"; 188 LOG(ERROR) << "IOSurface requires TEXTURE_RECTANGLE_ARB target";
193 return false; 189 return false;
194 } 190 }
195 191
196 CGLContextObj cgl_context = 192 CGLContextObj cgl_context =
197 static_cast<CGLContextObj>(GLContext::GetCurrent()->GetHandle()); 193 static_cast<CGLContextObj>(GLContext::GetCurrent()->GetHandle());
198 194
199 DCHECK(io_surface_); 195 DCHECK(io_surface_);
200 CGLError cgl_error = 196 CGLError cgl_error =
201 CGLTexImageIOSurface2D(cgl_context, target, TextureFormat(format_), 197 CGLTexImageIOSurface2D(cgl_context, target, TextureFormat(format_),
202 size_.width(), size_.height(), DataFormat(format_), 198 size_.width(), size_.height(), DataFormat(format_),
203 DataType(format_), io_surface_.get(), 0); 199 DataType(format_), io_surface_.get(), 0);
204 if (cgl_error != kCGLNoError) { 200 if (cgl_error != kCGLNoError) {
205 LOG(ERROR) << "Error in CGLTexImageIOSurface2D"; 201 LOG(ERROR) << "Error in CGLTexImageIOSurface2D";
206 return false; 202 return false;
207 } 203 }
208 204
209 return true; 205 return true;
210 } 206 }
211 207
212 bool GLImageIOSurface::CopyTexImage(unsigned target) {
213 return false;
214 }
215
216 bool GLImageIOSurface::CopyTexSubImage(unsigned target, 208 bool GLImageIOSurface::CopyTexSubImage(unsigned target,
217 const Point& offset, 209 const Point& offset,
218 const Rect& rect) { 210 const Rect& rect) {
219 return false; 211 return false;
220 } 212 }
221 213
222 bool GLImageIOSurface::ScheduleOverlayPlane(AcceleratedWidget widget, 214 bool GLImageIOSurface::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
223 int z_order, 215 int z_order,
224 OverlayTransform transform, 216 OverlayTransform transform,
225 const Rect& bounds_rect, 217 const Rect& bounds_rect,
226 const RectF& crop_rect) { 218 const RectF& crop_rect) {
227 NOTREACHED(); 219 NOTREACHED();
228 return false; 220 return false;
229 } 221 }
230 222
231 void GLImageIOSurface::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, 223 void GLImageIOSurface::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd,
232 uint64_t process_tracing_id, 224 uint64_t process_tracing_id,
233 const std::string& dump_name) { 225 const std::string& dump_name) {
234 // IOSurfaceGetAllocSize will return 0 if io_surface_ is invalid. In this case 226 // IOSurfaceGetAllocSize will return 0 if io_surface_ is invalid. In this case
235 // we log 0 for consistency with other GLImage memory dump functions. 227 // we log 0 for consistency with other GLImage memory dump functions.
236 size_t size_bytes = IOSurfaceGetAllocSize(io_surface_); 228 size_t size_bytes = IOSurfaceGetAllocSize(io_surface_);
237 229
238 base::trace_event::MemoryAllocatorDump* dump = 230 base::trace_event::MemoryAllocatorDump* dump =
239 pmd->CreateAllocatorDump(dump_name); 231 pmd->CreateAllocatorDump(dump_name);
240 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, 232 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
241 base::trace_event::MemoryAllocatorDump::kUnitsBytes, 233 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
242 static_cast<uint64_t>(size_bytes)); 234 static_cast<uint64_t>(size_bytes));
243 235
244 auto guid = 236 auto guid = gfx::GetGenericSharedMemoryGUIDForTracing(process_tracing_id,
245 GetGenericSharedMemoryGUIDForTracing(process_tracing_id, io_surface_id_); 237 io_surface_id_);
246 pmd->CreateSharedGlobalAllocatorDump(guid); 238 pmd->CreateSharedGlobalAllocatorDump(guid);
247 pmd->AddOwnershipEdge(dump->guid(), guid); 239 pmd->AddOwnershipEdge(dump->guid(), guid);
248 } 240 }
249 241
250 base::ScopedCFTypeRef<IOSurfaceRef> GLImageIOSurface::io_surface() { 242 base::ScopedCFTypeRef<IOSurfaceRef> GLImageIOSurface::io_surface() {
251 return io_surface_; 243 return io_surface_;
252 } 244 }
253 245
254 // static 246 // static
255 void GLImageIOSurface::SetLayerForWidget(AcceleratedWidget widget, 247 void GLImageIOSurface::SetLayerForWidget(
256 CALayer* layer) { 248 gfx::AcceleratedWidget widget, CALayer* layer) {
257 if (layer) 249 if (layer)
258 g_widget_to_layer_map.Pointer()->insert(std::make_pair(widget, layer)); 250 g_widget_to_layer_map.Pointer()->insert(std::make_pair(widget, layer));
259 else 251 else
260 g_widget_to_layer_map.Pointer()->erase(widget); 252 g_widget_to_layer_map.Pointer()->erase(widget);
261 } 253 }
262 254
263 } // namespace gfx 255 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gl/gl_image_io_surface.h ('k') | ui/gl/gl_image_memory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698