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

Side by Side Diff: content/common/gpu/gpu_memory_buffer_factory_ozone.cc

Issue 685983005: gpu: Associate all GpuMemoryBuffers with unique IDs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 2014 The Chromium Authors. All rights reserved. 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 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 "content/common/gpu/gpu_memory_buffer_factory.h" 5 #include "content/common/gpu/gpu_memory_buffer_factory.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "gpu/command_buffer/service/image_factory.h" 8 #include "gpu/command_buffer/service/image_factory.h"
9 #include "ui/gl/gl_image.h" 9 #include "ui/gl/gl_image.h"
10 #include "ui/gl/gl_image_shared_memory.h" 10 #include "ui/gl/gl_image_shared_memory.h"
11 #include "ui/ozone/gpu/gpu_memory_buffer_factory_ozone_native_buffer.h" 11 #include "ui/ozone/gpu/gpu_memory_buffer_factory_ozone_native_buffer.h"
12 12
13 namespace content { 13 namespace content {
14 namespace { 14 namespace {
15 15
16 class GpuMemoryBufferFactoryImpl : public GpuMemoryBufferFactory, 16 class GpuMemoryBufferFactoryImpl : public GpuMemoryBufferFactory,
17 public gpu::ImageFactory { 17 public gpu::ImageFactory {
18 public: 18 public:
19 // Overridden from GpuMemoryBufferFactory: 19 // Overridden from GpuMemoryBufferFactory:
20 virtual gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer( 20 virtual gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer(
21 const gfx::GpuMemoryBufferHandle& handle, 21 gfx::GpuMemoryBufferType type,
22 gfx::GpuMemoryBufferId id,
22 const gfx::Size& size, 23 const gfx::Size& size,
23 gfx::GpuMemoryBuffer::Format format, 24 gfx::GpuMemoryBuffer::Format format,
24 gfx::GpuMemoryBuffer::Usage usage) override { 25 gfx::GpuMemoryBuffer::Usage usage,
25 switch (handle.type) { 26 int client_id) override {
27 switch (type) {
26 case gfx::OZONE_NATIVE_BUFFER: 28 case gfx::OZONE_NATIVE_BUFFER:
27 return ozone_buffer_factory_.CreateGpuMemoryBuffer( 29 return ozone_buffer_factory_.CreateGpuMemoryBuffer(
28 handle.global_id, size, format, usage) 30 id, size, format, usage, client_id)
29 ? handle 31 ? handle
30 : gfx::GpuMemoryBufferHandle(); 32 : gfx::GpuMemoryBufferHandle();
31 default: 33 default:
32 NOTREACHED(); 34 NOTREACHED();
33 return gfx::GpuMemoryBufferHandle(); 35 return gfx::GpuMemoryBufferHandle();
34 } 36 }
35 } 37 }
36 virtual void DestroyGpuMemoryBuffer( 38 virtual void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferType type,
37 const gfx::GpuMemoryBufferHandle& handle) override { 39 gfx::GpuMemoryBufferId id,
38 switch (handle.type) { 40 int client_id) override {
41 switch (type) {
39 case gfx::OZONE_NATIVE_BUFFER: 42 case gfx::OZONE_NATIVE_BUFFER:
40 ozone_buffer_factory_.DestroyGpuMemoryBuffer(handle.global_id); 43 ozone_buffer_factory_.DestroyGpuMemoryBuffer(id, client_id);
41 break; 44 break;
42 default: 45 default:
43 NOTREACHED(); 46 NOTREACHED();
44 break; 47 break;
45 } 48 }
46 } 49 }
47 virtual gpu::ImageFactory* AsImageFactory() override { return this; } 50 virtual gpu::ImageFactory* AsImageFactory() override { return this; }
48 51
49 // Overridden from gpu::ImageFactory: 52 // Overridden from gpu::ImageFactory:
50 virtual scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer( 53 virtual scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer(
51 const gfx::GpuMemoryBufferHandle& handle, 54 const gfx::GpuMemoryBufferHandle& handle,
52 const gfx::Size& size, 55 const gfx::Size& size,
53 gfx::GpuMemoryBuffer::Format format, 56 gfx::GpuMemoryBuffer::Format format,
54 unsigned internalformat, 57 unsigned internalformat,
55 int client_id) override { 58 int client_id) override {
56 switch (handle.type) { 59 switch (handle.type) {
57 case gfx::SHARED_MEMORY_BUFFER: { 60 case gfx::SHARED_MEMORY_BUFFER: {
58 scoped_refptr<gfx::GLImageSharedMemory> image( 61 scoped_refptr<gfx::GLImageSharedMemory> image(
59 new gfx::GLImageSharedMemory(size, internalformat)); 62 new gfx::GLImageSharedMemory(size, internalformat));
60 if (!image->Initialize(handle, format)) 63 if (!image->Initialize(handle, format))
61 return NULL; 64 return NULL;
62 65
63 return image; 66 return image;
64 } 67 }
65 case gfx::OZONE_NATIVE_BUFFER: 68 case gfx::OZONE_NATIVE_BUFFER:
66 // Verify that client is the owner of the buffer we're about to use.
67 if (handle.global_id.secondary_id != client_id)
68 return scoped_refptr<gfx::GLImage>();
69
70 return ozone_buffer_factory_.CreateImageForGpuMemoryBuffer( 69 return ozone_buffer_factory_.CreateImageForGpuMemoryBuffer(
71 handle.global_id, size, format, internalformat); 70 handle.id, size, format, internalformat, client_id);
72 default: 71 default:
73 NOTREACHED(); 72 NOTREACHED();
74 return scoped_refptr<gfx::GLImage>(); 73 return scoped_refptr<gfx::GLImage>();
75 } 74 }
76 } 75 }
77 76
78 private: 77 private:
79 ui::GpuMemoryBufferFactoryOzoneNativeBuffer ozone_buffer_factory_; 78 ui::GpuMemoryBufferFactoryOzoneNativeBuffer ozone_buffer_factory_;
80 }; 79 };
81 80
82 } // namespace 81 } // namespace
83 82
84 // static 83 // static
85 scoped_ptr<GpuMemoryBufferFactory> GpuMemoryBufferFactory::Create() { 84 scoped_ptr<GpuMemoryBufferFactory> GpuMemoryBufferFactory::Create() {
86 return make_scoped_ptr<GpuMemoryBufferFactory>( 85 return make_scoped_ptr<GpuMemoryBufferFactory>(
87 new GpuMemoryBufferFactoryImpl); 86 new GpuMemoryBufferFactoryImpl);
88 } 87 }
89 88
90 } // namespace content 89 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698