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

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

Issue 659883003: gpu: Move image creation part of GpuMemoryBufferFactory interface to gpu namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move-gpu-memory-buffer-manager-to-gpu
Patch Set: rebase 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
« no previous file with comments | « no previous file | content/common/gpu/gpu_command_buffer_stub.cc » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/client/command_buffer_proxy_impl.h" 5 #include "content/common/gpu/client/command_buffer_proxy_impl.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/shared_memory.h" 10 #include "base/memory/shared_memory.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "content/common/child_process_messages.h" 12 #include "content/common/child_process_messages.h"
13 #include "content/common/gpu/client/gpu_channel_host.h" 13 #include "content/common/gpu/client/gpu_channel_host.h"
14 #include "content/common/gpu/client/gpu_video_decode_accelerator_host.h" 14 #include "content/common/gpu/client/gpu_video_decode_accelerator_host.h"
15 #include "content/common/gpu/client/gpu_video_encode_accelerator_host.h" 15 #include "content/common/gpu/client/gpu_video_encode_accelerator_host.h"
16 #include "content/common/gpu/gpu_messages.h" 16 #include "content/common/gpu/gpu_messages.h"
17 #include "content/common/view_messages.h" 17 #include "content/common/view_messages.h"
18 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" 18 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
19 #include "gpu/command_buffer/common/cmd_buffer_common.h" 19 #include "gpu/command_buffer/common/cmd_buffer_common.h"
20 #include "gpu/command_buffer/common/command_buffer_shared.h" 20 #include "gpu/command_buffer/common/command_buffer_shared.h"
21 #include "gpu/command_buffer/common/gpu_memory_allocation.h" 21 #include "gpu/command_buffer/common/gpu_memory_allocation.h"
22 #include "gpu/command_buffer/service/image_factory.h"
22 #include "ui/gfx/size.h" 23 #include "ui/gfx/size.h"
23 #include "ui/gl/gl_bindings.h" 24 #include "ui/gl/gl_bindings.h"
24 25
25 namespace content { 26 namespace content {
26 namespace {
27
28 gfx::GpuMemoryBuffer::Format ImageFormatToGpuMemoryBufferFormat(
29 unsigned internalformat) {
30 switch (internalformat) {
31 case GL_RGB:
32 return gfx::GpuMemoryBuffer::RGBX_8888;
33 case GL_RGBA:
34 return gfx::GpuMemoryBuffer::RGBA_8888;
35 default:
36 NOTREACHED();
37 return gfx::GpuMemoryBuffer::RGBA_8888;
38 }
39 }
40
41 gfx::GpuMemoryBuffer::Usage ImageUsageToGpuMemoryBufferUsage(unsigned usage) {
42 switch (usage) {
43 case GL_MAP_CHROMIUM:
44 return gfx::GpuMemoryBuffer::MAP;
45 case GL_SCANOUT_CHROMIUM:
46 return gfx::GpuMemoryBuffer::SCANOUT;
47 default:
48 NOTREACHED();
49 return gfx::GpuMemoryBuffer::MAP;
50 }
51 }
52
53 bool IsImageFormatCompatibleWithGpuMemoryBufferFormat(
54 gfx::GpuMemoryBuffer::Format format,
55 unsigned internalformat) {
56 switch (internalformat) {
57 case GL_RGB:
58 switch (format) {
59 case gfx::GpuMemoryBuffer::RGBX_8888:
60 return true;
61 case gfx::GpuMemoryBuffer::RGBA_8888:
62 case gfx::GpuMemoryBuffer::BGRA_8888:
63 return false;
64 }
65 NOTREACHED();
66 return false;
67 case GL_RGBA:
68 switch (format) {
69 case gfx::GpuMemoryBuffer::RGBX_8888:
70 return false;
71 case gfx::GpuMemoryBuffer::RGBA_8888:
72 case gfx::GpuMemoryBuffer::BGRA_8888:
73 return true;
74 }
75 NOTREACHED();
76 return false;
77 default:
78 NOTREACHED();
79 return false;
80 }
81 }
82
83 } // namespace
84 27
85 CommandBufferProxyImpl::CommandBufferProxyImpl( 28 CommandBufferProxyImpl::CommandBufferProxyImpl(
86 GpuChannelHost* channel, 29 GpuChannelHost* channel,
87 int route_id) 30 int route_id)
88 : channel_(channel), 31 : channel_(channel),
89 route_id_(route_id), 32 route_id_(route_id),
90 flush_count_(0), 33 flush_count_(0),
91 last_put_offset_(-1), 34 last_put_offset_(-1),
92 next_signal_id_(0) { 35 next_signal_id_(0) {
93 } 36 }
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 buffer); 313 buffer);
371 DCHECK(gpu_memory_buffer); 314 DCHECK(gpu_memory_buffer);
372 315
373 // This handle is owned by the GPU process and must be passed to it or it 316 // This handle is owned by the GPU process and must be passed to it or it
374 // will leak. In otherwords, do not early out on error between here and the 317 // will leak. In otherwords, do not early out on error between here and the
375 // sending of the CreateImage IPC below. 318 // sending of the CreateImage IPC below.
376 gfx::GpuMemoryBufferHandle handle = 319 gfx::GpuMemoryBufferHandle handle =
377 channel_->ShareGpuMemoryBufferToGpuProcess( 320 channel_->ShareGpuMemoryBufferToGpuProcess(
378 gpu_memory_buffer->GetHandle()); 321 gpu_memory_buffer->GetHandle());
379 322
380 DCHECK(IsImageFormatCompatibleWithGpuMemoryBufferFormat( 323 DCHECK(gpu::ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat(
381 gpu_memory_buffer->GetFormat(), internalformat)); 324 internalformat, gpu_memory_buffer->GetFormat()));
382 if (!Send(new GpuCommandBufferMsg_CreateImage(route_id_, 325 if (!Send(new GpuCommandBufferMsg_CreateImage(route_id_,
383 new_id, 326 new_id,
384 handle, 327 handle,
385 gfx::Size(width, height), 328 gfx::Size(width, height),
386 gpu_memory_buffer->GetFormat(), 329 gpu_memory_buffer->GetFormat(),
387 internalformat))) { 330 internalformat))) {
388 return -1; 331 return -1;
389 } 332 }
390 333
391 return new_id; 334 return new_id;
392 } 335 }
393 336
394 void CommandBufferProxyImpl::DestroyImage(int32 id) { 337 void CommandBufferProxyImpl::DestroyImage(int32 id) {
395 if (last_state_.error != gpu::error::kNoError) 338 if (last_state_.error != gpu::error::kNoError)
396 return; 339 return;
397 340
398 Send(new GpuCommandBufferMsg_DestroyImage(route_id_, id)); 341 Send(new GpuCommandBufferMsg_DestroyImage(route_id_, id));
399 } 342 }
400 343
401 int32_t CommandBufferProxyImpl::CreateGpuMemoryBufferImage( 344 int32_t CommandBufferProxyImpl::CreateGpuMemoryBufferImage(
402 size_t width, 345 size_t width,
403 size_t height, 346 size_t height,
404 unsigned internalformat, 347 unsigned internalformat,
405 unsigned usage) { 348 unsigned usage) {
406 scoped_ptr<gfx::GpuMemoryBuffer> buffer( 349 scoped_ptr<gfx::GpuMemoryBuffer> buffer(
407 channel_->gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer( 350 channel_->gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer(
408 gfx::Size(width, height), 351 gfx::Size(width, height),
409 ImageFormatToGpuMemoryBufferFormat(internalformat), 352 gpu::ImageFactory::ImageFormatToGpuMemoryBufferFormat(internalformat),
410 ImageUsageToGpuMemoryBufferUsage(usage))); 353 gpu::ImageFactory::ImageUsageToGpuMemoryBufferUsage(usage)));
411 if (!buffer) 354 if (!buffer)
412 return -1; 355 return -1;
413 356
414 return CreateImage(buffer->AsClientBuffer(), width, height, internalformat); 357 return CreateImage(buffer->AsClientBuffer(), width, height, internalformat);
415 } 358 }
416 359
417 int CommandBufferProxyImpl::GetRouteID() const { 360 int CommandBufferProxyImpl::GetRouteID() const {
418 return route_id_; 361 return route_id_;
419 } 362 }
420 363
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 if (!ui::LatencyInfo::Verify( 525 if (!ui::LatencyInfo::Verify(
583 latency_info, "CommandBufferProxyImpl::OnSwapBuffersCompleted")) { 526 latency_info, "CommandBufferProxyImpl::OnSwapBuffersCompleted")) {
584 swap_buffers_completion_callback_.Run(std::vector<ui::LatencyInfo>()); 527 swap_buffers_completion_callback_.Run(std::vector<ui::LatencyInfo>());
585 return; 528 return;
586 } 529 }
587 swap_buffers_completion_callback_.Run(latency_info); 530 swap_buffers_completion_callback_.Run(latency_info);
588 } 531 }
589 } 532 }
590 533
591 } // namespace content 534 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/common/gpu/gpu_command_buffer_stub.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698