OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "o3d/gpu_plugin/gpu_processor.h" | 5 #include "o3d/gpu_plugin/gpu_processor.h" |
| 6 #include "o3d/gpu_plugin/system_services/shared_memory_public.h" |
6 | 7 |
7 namespace o3d { | 8 namespace o3d { |
8 namespace gpu_plugin { | 9 namespace gpu_plugin { |
9 | 10 |
10 // Placeholder command processing. | |
11 void GPUProcessor::ProcessCommands() { | 11 void GPUProcessor::ProcessCommands() { |
12 int32 get_offset = command_buffer_->GetGetOffset(); | 12 if (command_buffer_->GetErrorStatus()) |
13 int32 put_offset = command_buffer_->GetPutOffset(); | |
14 int32 size = command_buffer_->GetSize(); | |
15 if (size == 0) | |
16 return; | 13 return; |
17 | 14 |
18 NPObjectPointer<CHRSharedMemory> shared_memory = | 15 parser_->set_put(command_buffer_->GetPutOffset()); |
19 command_buffer_->GetRingBuffer(); | |
20 if (!shared_memory.Get()) | |
21 return; | |
22 if (!shared_memory->ptr) | |
23 return; | |
24 | 16 |
25 int8* ptr = static_cast<int8*>(shared_memory->ptr); | 17 int commands_processed = 0; |
26 | 18 while (commands_processed < commands_per_update_ && !parser_->IsEmpty()) { |
27 int32 end_offset = (get_offset + sizeof(int32)) % size; | 19 command_buffer::BufferSyncInterface::ParseError parse_error = |
28 if (get_offset > put_offset || end_offset <= put_offset) { | 20 parser_->ProcessCommand(); |
29 int32 command = *reinterpret_cast<int32*>(ptr + get_offset); | 21 switch (parse_error) { |
30 | 22 case command_buffer::BufferSyncInterface::PARSE_UNKNOWN_COMMAND: |
31 switch (command) { | 23 case command_buffer::BufferSyncInterface::PARSE_INVALID_ARGUMENTS: |
32 case 0: | 24 command_buffer_->SetParseError(parse_error); |
33 get_offset = end_offset; | |
34 command_buffer_->SetGetOffset(get_offset); | |
35 break; | 25 break; |
36 | 26 |
37 // Rectangle case is temporary and not tested. | 27 case command_buffer::BufferSyncInterface::PARSE_INVALID_SIZE: |
38 case 1: { | 28 case command_buffer::BufferSyncInterface::PARSE_OUT_OF_BOUNDS: |
39 end_offset += 20; | 29 command_buffer_->SetParseError(parse_error); |
40 if (end_offset >= size) { | 30 command_buffer_->RaiseErrorStatus(); |
41 DCHECK(false); | 31 return; |
42 break; | |
43 } | |
44 | |
45 if (get_offset <= put_offset && end_offset > put_offset) { | |
46 DCHECK(false); | |
47 break; | |
48 } | |
49 | |
50 uint32 color = *reinterpret_cast<uint32*>(ptr + get_offset + 4); | |
51 int32 left = *reinterpret_cast<int32*>(ptr + get_offset + 8); | |
52 int32 top = *reinterpret_cast<int32*>(ptr + get_offset + 12); | |
53 int32 right = *reinterpret_cast<int32*>(ptr + get_offset + 16); | |
54 int32 bottom = *reinterpret_cast<int32*>(ptr + get_offset + 20); | |
55 DrawRectangle(color, left, top, right, bottom); | |
56 | |
57 get_offset = end_offset; | |
58 command_buffer_->SetGetOffset(get_offset); | |
59 break; | |
60 } | |
61 default: | |
62 DCHECK(false); | |
63 break; | |
64 } | 32 } |
65 | 33 |
| 34 ++commands_processed; |
66 } | 35 } |
67 | 36 |
68 // In practice, this will handle many more than one command before posting | 37 command_buffer_->SetGetOffset(static_cast<int32>(parser_->get())); |
69 // the processing of the remainder to the message loop. | 38 |
70 if (get_offset != put_offset) { | 39 if (!parser_->IsEmpty()) { |
71 MessageLoop::current()->PostTask( | 40 MessageLoop::current()->PostTask( |
72 FROM_HERE, | 41 FROM_HERE, |
73 NewRunnableMethod(this, &GPUProcessor::ProcessCommands)); | 42 NewRunnableMethod(this, &GPUProcessor::ProcessCommands)); |
74 } | 43 } |
75 } | 44 } |
76 | 45 |
| 46 void *GPUProcessor::GetSharedMemoryAddress(unsigned int shm_id) { |
| 47 // TODO(apatrick): Verify that the NPClass is in fact shared memory before |
| 48 // accessing the members. |
| 49 NPObjectPointer<CHRSharedMemory> shared_memory(static_cast<CHRSharedMemory*>( |
| 50 command_buffer_->GetRegisteredObject(static_cast<int32>(shm_id)).Get())); |
| 51 |
| 52 // Return address if shared memory is already mapped to this process. |
| 53 if (shared_memory->ptr) |
| 54 return shared_memory->ptr; |
| 55 |
| 56 // If the call fails or returns false then ptr will still be NULL. |
| 57 bool result; |
| 58 NPInvoke(npp_, shared_memory, "map", &result); |
| 59 |
| 60 return shared_memory->ptr; |
| 61 } |
| 62 |
| 63 size_t GPUProcessor::GetSharedMemorySize(unsigned int shm_id) { |
| 64 // TODO(apatrick): Verify that the NPClass is in fact shared memory before |
| 65 // accessing the members. |
| 66 NPObjectPointer<CHRSharedMemory> shared_memory(static_cast<CHRSharedMemory*>( |
| 67 command_buffer_->GetRegisteredObject(static_cast<int32>(shm_id)).Get())); |
| 68 |
| 69 return shared_memory->size; |
| 70 } |
| 71 |
| 72 void GPUProcessor::set_token(unsigned int token) { |
| 73 command_buffer_->SetToken(static_cast<int32>(token)); |
| 74 } |
| 75 |
77 } // namespace gpu_plugin | 76 } // namespace gpu_plugin |
78 } // namespace o3d | 77 } // namespace o3d |
OLD | NEW |