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

Side by Side Diff: content/common/gpu/client/gpu_memory_buffer_impl_io_surface.cc

Issue 77023002: gpu: Add IOSurface backed GpuMemoryBuffer implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix overflow check Created 7 years 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h"
6
7 #include "base/logging.h"
8 #include "ui/gl/gl_bindings.h"
9 #include "ui/gl/io_surface_support_mac.h"
10
11 namespace content {
12
13 GpuMemoryBufferImplIOSurface::GpuMemoryBufferImplIOSurface(
14 gfx::Size size, unsigned internalformat)
15 : GpuMemoryBufferImpl(size, internalformat),
16 io_surface_support_(IOSurfaceSupport::Initialize()) {
17 CHECK(io_surface_support_);
18 }
19
20 GpuMemoryBufferImplIOSurface::~GpuMemoryBufferImplIOSurface() {
21 }
22
23 // static
24 bool GpuMemoryBufferImplIOSurface::IsFormatSupported(unsigned internalformat) {
25 switch (internalformat) {
26 case GL_BGRA8_EXT:
27 return true;
28 default:
29 return false;
30 }
31 }
32
33 // static
34 uint32 GpuMemoryBufferImplIOSurface::PixelFormat(unsigned internalformat) {
35 switch (internalformat) {
36 case GL_BGRA8_EXT:
37 return 'BGRA';
38 default:
39 NOTREACHED();
40 return 0;
41 }
42 }
43
44 bool GpuMemoryBufferImplIOSurface::Initialize(
45 gfx::GpuMemoryBufferHandle handle) {
46 io_surface_.reset(io_surface_support_->IOSurfaceLookup(handle.io_surface_id));
47 if (!io_surface_) {
48 VLOG(1) << "IOSurface lookup failed";
49 return false;
50 }
51
52 return true;
53 }
54
55 void GpuMemoryBufferImplIOSurface::Map(AccessMode mode, void** vaddr) {
56 DCHECK(!mapped_);
57 io_surface_support_->IOSurfaceLock(io_surface_, 0, NULL);
58 *vaddr = io_surface_support_->IOSurfaceGetBaseAddress(io_surface_);
59 mapped_ = true;
60 }
61
62 void GpuMemoryBufferImplIOSurface::Unmap() {
63 DCHECK(mapped_);
64 io_surface_support_->IOSurfaceUnlock(io_surface_, 0, NULL);
65 mapped_ = false;
66 }
67
68 uint32 GpuMemoryBufferImplIOSurface::GetStride() const {
69 return io_surface_support_->IOSurfaceGetBytesPerRow(io_surface_);
70 }
71
72 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplIOSurface::GetHandle() const {
73 gfx::GpuMemoryBufferHandle handle;
74 handle.type = gfx::IO_SURFACE_BUFFER;
75 handle.io_surface_id = io_surface_support_->IOSurfaceGetID(io_surface_);
76 return handle;
77 }
78
79 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698