rsThreadIO.cpp revision 1dda675ff34a2708b519bea44b33a390712f6a6f
1326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams/* 2326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * Copyright (C) 2009 The Android Open Source Project 3326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * 4326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * Licensed under the Apache License, Version 2.0 (the "License"); 5326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * you may not use this file except in compliance with the License. 6326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * You may obtain a copy of the License at 7326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * 8326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * http://www.apache.org/licenses/LICENSE-2.0 9326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * 10326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * Unless required by applicable law or agreed to in writing, software 11326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * distributed under the License is distributed on an "AS IS" BASIS, 12326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * See the License for the specific language governing permissions and 14326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * limitations under the License. 15326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams */ 16326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams 17326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams#include "rsContext.h" 18326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams 19326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams#include "rsThreadIO.h" 20326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams 21326e0ddf89e8df2837752fbfd7a014814b32082cJason Samsusing namespace android; 22326e0ddf89e8df2837752fbfd7a014814b32082cJason Samsusing namespace android::renderscript; 23326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams 24afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex SakhartchoukThreadIO::ThreadIO() { 25326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams mToCore.init(16 * 1024); 268c401effb0837155fc39ca0364f57a882d127d38Jason Sams mToClient.init(1024); 27326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams} 28326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams 29afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex SakhartchoukThreadIO::~ThreadIO() { 30326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams} 31326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams 32afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex Sakhartchoukvoid ThreadIO::shutdown() { 338c0ee6567b3c874dd472843eb7918ae68d1b9739Jason Sams mToCore.shutdown(); 348c0ee6567b3c874dd472843eb7918ae68d1b9739Jason Sams} 358c0ee6567b3c874dd472843eb7918ae68d1b9739Jason Sams 36afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex Sakhartchoukbool ThreadIO::playCoreCommands(Context *con, bool waitForCommand) { 37a44cb29164726cd9d812117819abdd7b60dfdd93Jason Sams bool ret = false; 38afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex Sakhartchouk while (!mToCore.isEmpty() || waitForCommand) { 3924371d93cdb6999971c4058f78974da3c3d5fc64Jason Sams uint32_t cmdID = 0; 4024371d93cdb6999971c4058f78974da3c3d5fc64Jason Sams uint32_t cmdSize = 0; 41a44cb29164726cd9d812117819abdd7b60dfdd93Jason Sams ret = true; 421fddd90849deaae89b546ff492c345d485bbce42Jason Sams if (con->props.mLogTimes) { 4376371fff76412fd020e24ddb8bf1ddb5c75f0ed1Joe Onorato con->timerSet(Context::RS_TIMER_IDLE); 4476371fff76412fd020e24ddb8bf1ddb5c75f0ed1Joe Onorato } 45326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams const void * data = mToCore.get(&cmdID, &cmdSize); 46e514b45de8561fbc6ef6770845102ca10b0a69d7Jason Sams if (!cmdSize) { 47e514b45de8561fbc6ef6770845102ca10b0a69d7Jason Sams // exception occured, probably shutdown. 48e514b45de8561fbc6ef6770845102ca10b0a69d7Jason Sams return false; 49e514b45de8561fbc6ef6770845102ca10b0a69d7Jason Sams } 501fddd90849deaae89b546ff492c345d485bbce42Jason Sams if (con->props.mLogTimes) { 5176371fff76412fd020e24ddb8bf1ddb5c75f0ed1Joe Onorato con->timerSet(Context::RS_TIMER_INTERNAL); 5276371fff76412fd020e24ddb8bf1ddb5c75f0ed1Joe Onorato } 53732f1c0a29cc468ea271ca3bd654239a0a973fd5Jason Sams waitForCommand = false; 54992a0b70d8fd7a14f0c57bc3c7e16c1f269a6609Jason Sams //LOGV("playCoreCommands 3 %i %i", cmdID, cmdSize); 55326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams 56185b8b01f417488e2fbf6e6c00dfbd3d1d43d98aJason Sams if (cmdID >= (sizeof(gPlaybackFuncs) / sizeof(void *))) { 57185b8b01f417488e2fbf6e6c00dfbd3d1d43d98aJason Sams rsAssert(cmdID < (sizeof(gPlaybackFuncs) / sizeof(void *))); 58185b8b01f417488e2fbf6e6c00dfbd3d1d43d98aJason Sams LOGE("playCoreCommands error con %p, cmd %i", con, cmdID); 591dda675ff34a2708b519bea44b33a390712f6a6fJason Sams mToCore.printDebugData(); 60185b8b01f417488e2fbf6e6c00dfbd3d1d43d98aJason Sams } 61326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams gPlaybackFuncs[cmdID](con, data); 62326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams mToCore.next(); 63326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams } 64a44cb29164726cd9d812117819abdd7b60dfdd93Jason Sams return ret; 65326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams} 66326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams 67326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams 68