rsThreadIO.cpp revision 185b8b01f417488e2fbf6e6c00dfbd3d1d43d98a
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
19#include "rsThreadIO.h"
20
21using namespace android;
22using namespace android::renderscript;
23
24ThreadIO::ThreadIO() {
25    mToCore.init(16 * 1024);
26    mToClient.init(1024);
27}
28
29ThreadIO::~ThreadIO() {
30}
31
32void ThreadIO::shutdown() {
33    mToCore.shutdown();
34}
35
36bool ThreadIO::playCoreCommands(Context *con, bool waitForCommand) {
37    bool ret = false;
38    while (!mToCore.isEmpty() || waitForCommand) {
39        uint32_t cmdID = 0;
40        uint32_t cmdSize = 0;
41        ret = true;
42        if (con->props.mLogTimes) {
43            con->timerSet(Context::RS_TIMER_IDLE);
44        }
45        const void * data = mToCore.get(&cmdID, &cmdSize);
46        if (!cmdSize) {
47            // exception occured, probably shutdown.
48            return false;
49        }
50        if (con->props.mLogTimes) {
51            con->timerSet(Context::RS_TIMER_INTERNAL);
52        }
53        waitForCommand = false;
54        //LOGV("playCoreCommands 3 %i %i", cmdID, cmdSize);
55
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        }
60        gPlaybackFuncs[cmdID](con, data);
61        mToCore.next();
62    }
63    return ret;
64}
65
66
67