blob: 6e959a74d129e0550cb213c72111a6c7a47674a7 [file] [log] [blame]
Jason Sams326e0dd2009-05-22 14:03:28 -07001/*
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 Sams326e0dd2009-05-22 14:03:28 -070019#include "rsThreadIO.h"
20
21using namespace android;
22using namespace android::renderscript;
23
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080024ThreadIO::ThreadIO() {
Jason Sams326e0dd2009-05-22 14:03:28 -070025 mToCore.init(16 * 1024);
Jason Sams8c401ef2009-10-06 13:58:47 -070026 mToClient.init(1024);
Jason Sams326e0dd2009-05-22 14:03:28 -070027}
28
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080029ThreadIO::~ThreadIO() {
Jason Sams326e0dd2009-05-22 14:03:28 -070030}
31
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080032void ThreadIO::shutdown() {
Jason Sams8c0ee652009-08-25 14:49:07 -070033 mToCore.shutdown();
34}
35
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080036bool ThreadIO::playCoreCommands(Context *con, bool waitForCommand) {
Jason Samsa44cb292009-06-04 17:58:03 -070037 bool ret = false;
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080038 while (!mToCore.isEmpty() || waitForCommand) {
Jason Sams24371d92009-08-19 12:17:14 -070039 uint32_t cmdID = 0;
40 uint32_t cmdSize = 0;
Jason Samsa44cb292009-06-04 17:58:03 -070041 ret = true;
Jason Sams1fddd902009-09-25 15:25:00 -070042 if (con->props.mLogTimes) {
Joe Onorato76371ff2009-09-23 16:37:36 -070043 con->timerSet(Context::RS_TIMER_IDLE);
44 }
Jason Sams326e0dd2009-05-22 14:03:28 -070045 const void * data = mToCore.get(&cmdID, &cmdSize);
Jason Samse514b452009-09-25 14:51:22 -070046 if (!cmdSize) {
47 // exception occured, probably shutdown.
48 return false;
49 }
Jason Sams1fddd902009-09-25 15:25:00 -070050 if (con->props.mLogTimes) {
Joe Onorato76371ff2009-09-23 16:37:36 -070051 con->timerSet(Context::RS_TIMER_INTERNAL);
52 }
Jason Sams732f1c02009-06-18 16:58:42 -070053 waitForCommand = false;
Jason Sams992a0b72009-06-23 12:22:47 -070054 //LOGV("playCoreCommands 3 %i %i", cmdID, cmdSize);
Jason Sams326e0dd2009-05-22 14:03:28 -070055
Jason Sams185b8b02011-01-16 14:54:28 -080056 if (cmdID >= (sizeof(gPlaybackFuncs) / sizeof(void *))) {
57 rsAssert(cmdID < (sizeof(gPlaybackFuncs) / sizeof(void *)));
58 LOGE("playCoreCommands error con %p, cmd %i", con, cmdID);
Jason Sams1dda6752011-01-18 18:12:26 -080059 mToCore.printDebugData();
Jason Sams185b8b02011-01-16 14:54:28 -080060 }
Jason Sams5fb1aeb2011-04-27 15:12:49 -070061 gPlaybackFuncs[cmdID](con, data, cmdSize << 2);
Jason Sams326e0dd2009-05-22 14:03:28 -070062 mToCore.next();
Jason Sams326e0dd2009-05-22 14:03:28 -070063 }
Jason Samsa44cb292009-06-04 17:58:03 -070064 return ret;
Jason Sams326e0dd2009-05-22 14:03:28 -070065}
66
67