Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "rsContext.h" |
| 18 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 19 | #include "rsThreadIO.h" |
| 20 | |
| 21 | using namespace android; |
| 22 | using namespace android::renderscript; |
| 23 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 24 | ThreadIO::ThreadIO() { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 25 | mToCore.init(16 * 1024); |
Jason Sams | 8c401ef | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 26 | mToClient.init(1024); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 27 | } |
| 28 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 29 | ThreadIO::~ThreadIO() { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 30 | } |
| 31 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 32 | void ThreadIO::shutdown() { |
Jason Sams | 8c0ee65 | 2009-08-25 14:49:07 -0700 | [diff] [blame] | 33 | mToCore.shutdown(); |
| 34 | } |
| 35 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 36 | bool ThreadIO::playCoreCommands(Context *con, bool waitForCommand) { |
Jason Sams | a44cb29 | 2009-06-04 17:58:03 -0700 | [diff] [blame] | 37 | bool ret = false; |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 38 | while (!mToCore.isEmpty() || waitForCommand) { |
Jason Sams | 24371d9 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 39 | uint32_t cmdID = 0; |
| 40 | uint32_t cmdSize = 0; |
Jason Sams | a44cb29 | 2009-06-04 17:58:03 -0700 | [diff] [blame] | 41 | ret = true; |
Jason Sams | 1fddd90 | 2009-09-25 15:25:00 -0700 | [diff] [blame] | 42 | if (con->props.mLogTimes) { |
Joe Onorato | 76371ff | 2009-09-23 16:37:36 -0700 | [diff] [blame] | 43 | con->timerSet(Context::RS_TIMER_IDLE); |
| 44 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 45 | const void * data = mToCore.get(&cmdID, &cmdSize); |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 46 | if (!cmdSize) { |
| 47 | // exception occured, probably shutdown. |
| 48 | return false; |
| 49 | } |
Jason Sams | 1fddd90 | 2009-09-25 15:25:00 -0700 | [diff] [blame] | 50 | if (con->props.mLogTimes) { |
Joe Onorato | 76371ff | 2009-09-23 16:37:36 -0700 | [diff] [blame] | 51 | con->timerSet(Context::RS_TIMER_INTERNAL); |
| 52 | } |
Jason Sams | 732f1c0 | 2009-06-18 16:58:42 -0700 | [diff] [blame] | 53 | waitForCommand = false; |
Jason Sams | 992a0b7 | 2009-06-23 12:22:47 -0700 | [diff] [blame] | 54 | //LOGV("playCoreCommands 3 %i %i", cmdID, cmdSize); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 55 | |
Jason Sams | 185b8b0 | 2011-01-16 14:54:28 -0800 | [diff] [blame^] | 56 | if (cmdID >= (sizeof(gPlaybackFuncs) / sizeof(void *))) { |
| 57 | rsAssert(cmdID < (sizeof(gPlaybackFuncs) / sizeof(void *))); |
| 58 | LOGE("playCoreCommands error con %p, cmd %i", con, cmdID); |
| 59 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 60 | gPlaybackFuncs[cmdID](con, data); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 61 | mToCore.next(); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 62 | } |
Jason Sams | a44cb29 | 2009-06-04 17:58:03 -0700 | [diff] [blame] | 63 | return ret; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | |