blob: e9e4215943c210ff84f9677978aacde11a8c1559 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/common/gpu/gpu_memory_buffer_factory.h"
#include "base/logging.h"
#include "content/common/gpu/gpu_memory_buffer_factory_io_surface.h"
#include "ui/gl/gl_image.h"
#include "ui/gl/gl_image_shared_memory.h"
namespace content {
namespace {
class GpuMemoryBufferFactoryImpl : public GpuMemoryBufferFactory {
public:
// Overridden from GpuMemoryBufferFactory:
virtual gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer(
const gfx::GpuMemoryBufferHandle& handle,
const gfx::Size& size,
unsigned internalformat,
unsigned usage) OVERRIDE {
switch (handle.type) {
case gfx::IO_SURFACE_BUFFER:
return io_surface_factory_.CreateGpuMemoryBuffer(
handle.global_id, size, internalformat);
default:
NOTREACHED();
return gfx::GpuMemoryBufferHandle();
}
}
virtual void DestroyGpuMemoryBuffer(
const gfx::GpuMemoryBufferHandle& handle) OVERRIDE {
switch (handle.type) {
case gfx::IO_SURFACE_BUFFER:
io_surface_factory_.DestroyGpuMemoryBuffer(handle.global_id);
break;
default:
NOTREACHED();
break;
}
}
virtual scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer(
const gfx::GpuMemoryBufferHandle& handle,
const gfx::Size& size,
unsigned internalformat,
int client_id) OVERRIDE {
switch (handle.type) {
case gfx::SHARED_MEMORY_BUFFER: {
scoped_refptr<gfx::GLImageSharedMemory> image(
new gfx::GLImageSharedMemory(size, internalformat));
if (!image->Initialize(handle))
return NULL;
return image;
}
case gfx::IO_SURFACE_BUFFER: {
// Verify that client is the owner of the buffer we're about to use.
if (handle.global_id.secondary_id != client_id)
return scoped_refptr<gfx::GLImage>();
return io_surface_factory_.CreateImageForGpuMemoryBuffer(
handle.global_id, size, internalformat);
}
default:
NOTREACHED();
return scoped_refptr<gfx::GLImage>();
}
}
private:
GpuMemoryBufferFactoryIOSurface io_surface_factory_;
};
} // namespace
// static
scoped_ptr<GpuMemoryBufferFactory> GpuMemoryBufferFactory::Create() {
return make_scoped_ptr<GpuMemoryBufferFactory>(
new GpuMemoryBufferFactoryImpl);
}
} // namespace content
|