Apply _RELATIVE relocations ahead of others.
[chromium-blink-merge.git] / content / common / gpu / gpu_memory_buffer_factory_ozone.cc
blobf2a296e72b6d56c6ac5d23452c5fb0a84e61823b
1 // Copyright 2014 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.
5 #include "content/common/gpu/gpu_memory_buffer_factory.h"
7 #include "base/logging.h"
8 #include "gpu/command_buffer/service/image_factory.h"
9 #include "ui/gl/gl_image.h"
10 #include "ui/gl/gl_image_shared_memory.h"
11 #include "ui/ozone/gpu/gpu_memory_buffer_factory_ozone_native_buffer.h"
13 namespace content {
14 namespace {
16 class GpuMemoryBufferFactoryImpl : public GpuMemoryBufferFactory,
17 public gpu::ImageFactory {
18 public:
19 // Overridden from GpuMemoryBufferFactory:
20 virtual gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer(
21 gfx::GpuMemoryBufferType type,
22 gfx::GpuMemoryBufferId id,
23 const gfx::Size& size,
24 gfx::GpuMemoryBuffer::Format format,
25 gfx::GpuMemoryBuffer::Usage usage,
26 int client_id) override {
27 switch (type) {
28 case gfx::OZONE_NATIVE_BUFFER: {
29 if (!ozone_buffer_factory_.CreateGpuMemoryBuffer(
30 id, size, format, usage, client_id)) {
31 return gfx::GpuMemoryBufferHandle();
33 gfx::GpuMemoryBufferHandle handle;
34 handle.type = gfx::OZONE_NATIVE_BUFFER;
35 handle.id = id;
36 return handle;
38 default:
39 NOTREACHED();
40 return gfx::GpuMemoryBufferHandle();
43 virtual void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferType type,
44 gfx::GpuMemoryBufferId id,
45 int client_id) override {
46 switch (type) {
47 case gfx::OZONE_NATIVE_BUFFER:
48 ozone_buffer_factory_.DestroyGpuMemoryBuffer(id, client_id);
49 break;
50 default:
51 NOTREACHED();
52 break;
55 virtual gpu::ImageFactory* AsImageFactory() override { return this; }
57 // Overridden from gpu::ImageFactory:
58 virtual scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer(
59 const gfx::GpuMemoryBufferHandle& handle,
60 const gfx::Size& size,
61 gfx::GpuMemoryBuffer::Format format,
62 unsigned internalformat,
63 int client_id) override {
64 switch (handle.type) {
65 case gfx::SHARED_MEMORY_BUFFER: {
66 scoped_refptr<gfx::GLImageSharedMemory> image(
67 new gfx::GLImageSharedMemory(size, internalformat));
68 if (!image->Initialize(handle, format))
69 return NULL;
71 return image;
73 case gfx::OZONE_NATIVE_BUFFER:
74 return ozone_buffer_factory_.CreateImageForGpuMemoryBuffer(
75 handle.id, size, format, internalformat, client_id);
76 default:
77 NOTREACHED();
78 return scoped_refptr<gfx::GLImage>();
82 private:
83 ui::GpuMemoryBufferFactoryOzoneNativeBuffer ozone_buffer_factory_;
86 } // namespace
88 // static
89 scoped_ptr<GpuMemoryBufferFactory> GpuMemoryBufferFactory::Create() {
90 return make_scoped_ptr<GpuMemoryBufferFactory>(
91 new GpuMemoryBufferFactoryImpl);
94 } // namespace content