PhoneMachine::PhoneMachine(PhoneService *service) : mRILfd(-1) , mAudioMode(AUDIO_MODE_NORMAL) // Strictly speaking we should initialize this , mService(service) { char *flags = ::getenv("DEBUG_PHONE"); if (flags != NULL) { mDebug = DEBUG_BASIC; char *token = strtok(flags, ":"); while (token != NULL) { if (!strncasecmp(token, "in", 2)) mDebug |= DEBUG_INCOMING; else if (!strncasecmp(token, "out", 3)) mDebug |= DEBUG_OUTGOING; token = strtok(NULL, ":"); } } mRILfd = socket_local_client("rild", ANDROID_SOCKET_NAMESPACE_RESERVED, SOCK_STREAM); if (mRILfd < 0) { perror("opening rild socket"); exit(-1); } if (AudioSystem::setMasterMute(false) != NO_ERROR) LOG_ALWAYS_FATAL("Unable to write master mute to false\n"); SLOGV("Audio configured\n"); if (createThread(beginOutgoingThread, this) == false) LOG_ALWAYS_FATAL("ERROR! Unable to create outgoing thread for RILD socket\n"); if (createThread(beginIncomingThread, this) == false) LOG_ALWAYS_FATAL("ERROR! Unable to create incoming thread for RILD socket\n"); }
void selectorLoop(Selector* selector) { // Make sure we're not already looping. if (selector->looping) { LOG_ALWAYS_FATAL("Already looping."); } selector->looping = true; while (true) { setInSelect(selector, true); prepareForSelect(selector); LOGD("Entering select()."); // Select file descriptors. int result = select(selector->maxFd + 1, &selector->readFds, &selector->writeFds, &selector->exceptFds, NULL); LOGD("Exiting select()."); setInSelect(selector, false); if (result == -1) { // Abort on everything except EINTR. if (errno == EINTR) { LOGI("select() interrupted."); } else { LOG_ALWAYS_FATAL("select() error: %s", strerror(errno)); } } else if (result > 0) { fireEvents(selector); } } }
/** Sets the non-blocking flag on a descriptor. */ static void setNonBlocking(int fd) { int flags; if ((flags = fcntl(fd, F_GETFL, 0)) < 0) { LOG_ALWAYS_FATAL("fcntl() error: %s", strerror(errno)); } if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) { LOG_ALWAYS_FATAL("fcntl() error: %s", strerror(errno)); } }
/** * Reads input from a peer process. */ static void peerProxyRead(SelectableFd* fd) { ALOGD("Reading..."); PeerProxy* peerProxy = (PeerProxy*) fd->data; int state = peerProxy->inputState; Buffer* in = peerProxy->inputBuffer; switch (state) { case READING_HEADER: if (peerProxyBufferInput(peerProxy)) { ALOGD("Header read."); // We've read the complete header. Header* header = (Header*) in->data; peerProxyHandleHeader(peerProxy, header); } break; case READING_BYTES: ALOGD("Reading bytes..."); if (peerProxyBufferInput(peerProxy)) { ALOGD("Bytes read."); // We have the complete packet. Notify bytes listener. peerProxy->peer->onBytes(peerProxy->credentials, in->data, in->size); // Get ready for the next packet. peerProxyExpectHeader(peerProxy); } break; case ACCEPTING_CONNECTION: masterProxyAcceptConnection(peerProxy); break; default: LOG_ALWAYS_FATAL("Unknown state: %d", state); } }
Mapper::Mapper() { mMapper = IMapper::getService(); if (mMapper == nullptr || mMapper->isRemote()) { LOG_ALWAYS_FATAL("gralloc-mapper must be in passthrough mode"); } }
JNIEnv* jnienv() { JNIEnv* env; if (mVm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) { LOG_ALWAYS_FATAL("Failed to get JNIEnv for JavaVM: %p", mVm); } return env; }
void Snapshot::buildScreenSpaceTransform(Matrix4* outTransform) const { #if HWUI_NEW_OPS LOG_ALWAYS_FATAL("not supported - not needed by new ops"); #else // build (reverse ordered) list of the stack of snapshots, terminated with a NULL Vector<const Snapshot*> snapshotList; snapshotList.push(nullptr); const Snapshot* current = this; do { snapshotList.push(current); current = current->previous; } while (current); // traverse the list, adding in each transform that contributes to the total transform outTransform->loadIdentity(); for (size_t i = snapshotList.size() - 1; i > 0; i--) { // iterate down the stack const Snapshot* current = snapshotList[i]; const Snapshot* next = snapshotList[i - 1]; if (current->flags & kFlagIsFboLayer) { // if we've hit a layer, translate by the layer's draw offset outTransform->translate(current->layer->layer.left, current->layer->layer.top); } if (!next || (next->flags & kFlagIsFboLayer)) { // if this snapshot is last, or if this snapshot is last before an // FBO layer (which reset the transform), apply it outTransform->multiply(*(current->transform)); } } #endif }
bool EglManager::swapBuffers(const Frame& frame, const SkRect& screenDirty) { if (CC_UNLIKELY(Properties::waitForGpuCompletion)) { ATRACE_NAME("Finishing GPU work"); fence(); } EGLint rects[4]; frame.map(screenDirty, rects); eglSwapBuffersWithDamageKHR(mEglDisplay, frame.mSurface, rects, screenDirty.isEmpty() ? 0 : 1); EGLint err = eglGetError(); if (CC_LIKELY(err == EGL_SUCCESS)) { return true; } if (err == EGL_BAD_SURFACE || err == EGL_BAD_NATIVE_WINDOW) { // For some reason our surface was destroyed out from under us // This really shouldn't happen, but if it does we can recover easily // by just not trying to use the surface anymore ALOGW("swapBuffers encountered EGL error %d on %p, halting rendering...", err, frame.mSurface); return false; } LOG_ALWAYS_FATAL("Encountered EGL error %d %s during rendering", err, egl_error_str(err)); // Impossible to hit this, but the compiler doesn't know that return false; }
Allocator::Allocator(const Mapper& mapper) : mMapper(mapper) { mAllocator = IAllocator::getService(); if (mAllocator == nullptr) { LOG_ALWAYS_FATAL("gralloc-alloc is missing"); } }
int gralloc_unlock(gralloc_module_t const* module, buffer_handle_t buffer) { GraphicsBuffer* gb = GetGraphicsBuffer(buffer); if (!module || !gb || !gb->IsValid()) { LOG_ALWAYS_FATAL("%s: Invalid graphics buffer handle.", __FUNCTION__); return -EINVAL; } return gb->Unlock(); }
~weakref_impl() { bool dumpStack = false; if (!mRetain && mStrongRefs != NULL) { dumpStack = true; #if DEBUG_REFS_FATAL_SANITY_CHECKS LOG_ALWAYS_FATAL("Strong references remain!"); #else ALOGE("Strong references remain:"); #endif ref_entry* refs = mStrongRefs; while (refs) { char inc = refs->ref >= 0 ? '+' : '-'; ALOGD("\t%c ID %p (ref %d):", inc, refs->id, refs->ref); #if DEBUG_REFS_CALLSTACK_ENABLED refs->stack.dump(); #endif refs = refs->next; } } if (!mRetain && mWeakRefs != NULL) { dumpStack = true; #if DEBUG_REFS_FATAL_SANITY_CHECKS LOG_ALWAYS_FATAL("Weak references remain:"); #else ALOGE("Weak references remain!"); #endif ref_entry* refs = mWeakRefs; while (refs) { char inc = refs->ref >= 0 ? '+' : '-'; ALOGD("\t%c ID %p (ref %d):", inc, refs->id, refs->ref); #if DEBUG_REFS_CALLSTACK_ENABLED refs->stack.dump(); #endif refs = refs->next; } } if (dumpStack) { ALOGE("above errors at:"); CallStack stack; stack.update(); stack.dump(); } }
/** * Called when the peer dies. */ static void peerProxyKill(PeerProxy* peerProxy, bool errnoIsSet) { if (errnoIsSet) { ALOGI("Peer %d died. errno: %s", peerProxy->credentials.pid, strerror(errno)); } else { ALOGI("Peer %d died.", peerProxy->credentials.pid); } // If we lost the master, we're up a creek. We can't let this happen. if (peerProxy->master) { LOG_ALWAYS_FATAL("Lost connection to master."); } Peer* localPeer = peerProxy->peer; pid_t pid = peerProxy->credentials.pid; peerLock(localPeer); // Remember for awhile that the peer died. localPeer->deadPeers[localPeer->deadPeerCursor] = peerProxy->credentials.pid; localPeer->deadPeerCursor++; if (localPeer->deadPeerCursor == PEER_HISTORY) { localPeer->deadPeerCursor = 0; } // Remove from peer map. hashmapRemove(localPeer->peerProxies, &pid); // External threads can no longer get to this peer proxy, so we don't // need the lock anymore. peerUnlock(localPeer); // Remove the fd from the selector. if (peerProxy->fd != NULL) { peerProxy->fd->remove = true; } // Clear outgoing packet queue. while (peerProxyNextPacket(peerProxy)) {} bufferFree(peerProxy->inputBuffer); // This only applies to the master. if (peerProxy->connections != NULL) { // We can't leave these other maps pointing to freed memory. hashmapForEach(peerProxy->connections, &peerProxyRemoveConnection, peerProxy); hashmapFree(peerProxy->connections); } // Invoke death listener. localPeer->onDeath(pid); // Free the peer proxy itself. free(peerProxy); }
void GpuMemoryTracker::onGLContextDestroyed() { gGpuThread = 0; if (CC_UNLIKELY(gObjectSet.size() > 0)) { std::stringstream os; dump(os); ALOGE("%s", os.str().c_str()); LOG_ALWAYS_FATAL("Leaked %zd GPU objects!", gObjectSet.size()); } }
static DvmDex* getDvmDexFromClassPathEntry(ClassPathEntry* cpe) { if (cpe->kind == kCpeDex) { return ((RawDexFile*) cpe->ptr)->pDvmDex; } if (cpe->kind == kCpeJar) { return ((JarFile*) cpe->ptr)->pDvmDex; } LOG_ALWAYS_FATAL("Unknown cpe->kind=%d", cpe->kind); }
int gralloc_lock(gralloc_module_t const* module, buffer_handle_t buffer, int usage, int l, int t, int w, int h, void** vaddr) { GraphicsBuffer* gb = GetGraphicsBuffer(buffer); if (!module || !gb || !gb->IsValid()) { LOG_ALWAYS_FATAL("%s: Invalid graphics buffer handle.", __FUNCTION__); return -EINVAL; } return gb->Lock(usage, l, t, w, h, vaddr); }
// LDRH/LDRSB/LDRSH/STRH (immediate and Rm can be negative, which indicate U=0) uint32_t ArmToMips64Assembler::immed8_pre(int32_t immed8, int W) { LOG_ALWAYS_FATAL("adr mode immed8_pre not yet implemented\n"); LOG_ALWAYS_FATAL_IF(abs(immed8) >= 0x100, "LDRH/LDRSB/LDRSH/STRH immediate too big (%08x)", immed8); return AMODE_IMM_8_PRE; }
/** Reads and ignores wake up data. */ static void eatWakeupData(SelectableFd* wakeupFd) { static char garbage[64]; if (read(wakeupFd->fd, garbage, sizeof(garbage)) < 0) { if (errno == EINTR) { LOGI("read() interrupted."); } else { LOG_ALWAYS_FATAL("This should never happen: %s", strerror(errno)); } } }
float CanvasPropertyPaintAnimator::getValue(RenderNode* target) const { switch (mField) { case STROKE_WIDTH: return mProperty->value.getStrokeWidth(); case ALPHA: return mProperty->value.getAlpha(); } LOG_ALWAYS_FATAL("Unknown field %d", (int) mField); return -1; }
void CanvasPropertyPaintAnimator::setValue(RenderNode* target, float value) { switch (mField) { case STROKE_WIDTH: mProperty->value.setStrokeWidth(value); return; case ALPHA: mProperty->value.setAlpha(to_uint8(value)); return; } LOG_ALWAYS_FATAL("Unknown field %d", (int) mField); }
static int gralloc_free(alloc_device_t* dev, buffer_handle_t buffer) { GraphicsBuffer* gb = GetGraphicsBuffer(buffer); if (!dev || !gb || !gb->IsValid()) { LOG_ALWAYS_FATAL("%s: Invalid graphics buffer handle.", __FUNCTION__); return -EINVAL; } gralloc_device_t* grdev = reinterpret_cast<gralloc_device_t*>(dev); grdev->unregister_graphics_buffer(gb); delete gb; return 0; }
void EglManager::damageFrame(const Frame& frame, const SkRect& dirty) { #ifdef EGL_KHR_partial_update if (EglExtensions.setDamage && mSwapBehavior == SwapBehavior::BufferAge) { EGLint rects[4]; frame.map(dirty, rects); if (!eglSetDamageRegionKHR(mEglDisplay, frame.mSurface, rects, 1)) { LOG_ALWAYS_FATAL("Failed to set damage region on surface %p, error=%s", (void*)frame.mSurface, eglErrorString()); } } #endif }
static DvmDex* getDvmDexFromClassPathEntry(ClassPathEntry* cpe) { #ifdef FASTIVA assert("getDvmDexFromClassPathEntry not supported" == NULL); #endif if (cpe->kind == kCpeDex) { return ((RawDexFile*) cpe->ptr)->pDvmDex; } if (cpe->kind == kCpeJar) { return ((JarFile*) cpe->ptr)->pDvmDex; } LOG_ALWAYS_FATAL("Unknown cpe->kind=%d", cpe->kind); }
Program::Program(const ProgramDescription& description, const char* vertex, const char* fragment) { mInitialized = false; mHasColorUniform = false; mHasSampler = false; mUse = false; // No need to cache compiled shaders, rely instead on Android's // persistent shaders cache mVertexShader = buildShader(vertex, GL_VERTEX_SHADER); if (mVertexShader) { mFragmentShader = buildShader(fragment, GL_FRAGMENT_SHADER); if (mFragmentShader) { mProgramId = glCreateProgram(); glAttachShader(mProgramId, mVertexShader); glAttachShader(mProgramId, mFragmentShader); bindAttrib("position", kBindingPosition); if (description.hasTexture || description.hasExternalTexture) { texCoords = bindAttrib("texCoords", kBindingTexCoords); } else { texCoords = -1; } ATRACE_BEGIN("linkProgram"); glLinkProgram(mProgramId); ATRACE_END(); GLint status; glGetProgramiv(mProgramId, GL_LINK_STATUS, &status); if (status != GL_TRUE) { GLint infoLen = 0; glGetProgramiv(mProgramId, GL_INFO_LOG_LENGTH, &infoLen); if (infoLen > 1) { GLchar log[infoLen]; glGetProgramInfoLog(mProgramId, infoLen, nullptr, &log[0]); ALOGE("%s", log); } LOG_ALWAYS_FATAL("Error while linking shaders"); } else { mInitialized = true; } } else { glDeleteShader(mVertexShader); } } if (mInitialized) { transform = addUniform("transform"); projection = addUniform("projection"); } }
// static const char *FastMixerState::commandToString(Command command) { const char *str = FastThreadState::commandToString(command); if (str != NULL) { return str; } switch (command) { case FastMixerState::MIX: return "MIX"; case FastMixerState::WRITE: return "WRITE"; case FastMixerState::MIX_WRITE: return "MIX_WRITE"; } LOG_ALWAYS_FATAL("%s", __func__); }
// Set the attribute value for the specified surface. EGLBoolean eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value) { EGL_API_ENTRY("%p, %p, 0x%x, %d", dpy, surface, attribute, value); EglDisplayImpl* display = EglDisplayImpl::GetDisplay(dpy); if (display == NULL || display->IsInitialized() == false) { SetError(EGL_BAD_DISPLAY); return EGL_FALSE; } SurfacePtr s = display->GetSurfaces().Get(surface); if (s == NULL) { SetError(EGL_BAD_SURFACE); return EGL_FALSE; } switch (attribute) { case EGL_MIPMAP_LEVEL: if (value == 0) { return EGL_TRUE; } LOG_ALWAYS_FATAL("Unsupported attribute/value: %x %x", attribute, value); return EGL_FALSE; case EGL_MULTISAMPLE_RESOLVE: if (value == EGL_MULTISAMPLE_RESOLVE) { return EGL_TRUE; } LOG_ALWAYS_FATAL("Unsupported attribute/value: %x %x", attribute, value); return EGL_FALSE; case EGL_SWAP_BEHAVIOR: if (value == EGL_BUFFER_DESTROYED) { return EGL_TRUE; } LOG_ALWAYS_FATAL("Unsupported attribute/value: %x %x", attribute, value); return EGL_FALSE; default: ALOGE("Unsupported attribute: %x", attribute); SetError(EGL_BAD_ATTRIBUTE); return EGL_FALSE; } }
/** * Creates the local peer. */ static Peer* peerCreate() { Peer* peer = calloc(1, sizeof(Peer)); if (peer == NULL) { LOG_ALWAYS_FATAL("malloc() error."); } peer->peerProxies = hashmapCreate(10, &pidHash, &pidEquals); peer->selector = selectorCreate(); pthread_mutexattr_t attributes; if (pthread_mutexattr_init(&attributes) != 0) { LOG_ALWAYS_FATAL("pthread_mutexattr_init() error."); } if (pthread_mutexattr_settype(&attributes, PTHREAD_MUTEX_RECURSIVE) != 0) { LOG_ALWAYS_FATAL("pthread_mutexattr_settype() error."); } if (pthread_mutex_init(&peer->mutex, &attributes) != 0) { LOG_ALWAYS_FATAL("pthread_mutex_init() error."); } peer->pid = getpid(); return peer; }
void Snapshot::resetTransform(float x, float y, float z) { #if HWUI_NEW_OPS LOG_ALWAYS_FATAL("not supported - light center managed differently"); #else // before resetting, map current light pos with inverse of current transform Vector3 center = mRelativeLightCenter; mat4 inverse; inverse.loadInverse(*transform); inverse.mapPoint3d(center); mRelativeLightCenter = center; transform = &mTransformRoot; transform->loadTranslate(x, y, z); #endif }
void selectorWakeUp(Selector* selector) { if (!isInSelect(selector)) { // We only need to write wake-up data if we're blocked in select(). return; } static char garbage[1]; if (write(selector->wakeupPipe[1], garbage, sizeof(garbage)) < 0) { if (errno == EINTR) { LOGI("read() interrupted."); } else { LOG_ALWAYS_FATAL("This should never happen: %s", strerror(errno)); } } }
Selector* selectorCreate(void) { Selector* selector = calloc(1, sizeof(Selector)); if (selector == NULL) { LOG_ALWAYS_FATAL("malloc() error."); } selector->selectableFds = arrayCreate(); // Set up wake-up pipe. if (pipe(selector->wakeupPipe) < 0) { LOG_ALWAYS_FATAL("pipe() error: %s", strerror(errno)); } LOGD("Wakeup fd: %d", selector->wakeupPipe[0]); SelectableFd* wakeupFd = selectorAdd(selector, selector->wakeupPipe[0]); if (wakeupFd == NULL) { LOG_ALWAYS_FATAL("malloc() error."); } wakeupFd->onReadable = &eatWakeupData; pthread_mutex_init(&selector->inSelectLock, NULL); return selector; }
void NativeMessageQueue::raiseException(JNIEnv* env, const char* msg, jthrowable exceptionObj) { if (exceptionObj) { if (mInCallback) { if (mExceptionObj) { env->DeleteLocalRef(mExceptionObj); } mExceptionObj = jthrowable(env->NewLocalRef(exceptionObj)); ALOGE("Exception in MessageQueue callback: %s", msg); jniLogException(env, ANDROID_LOG_ERROR, LOG_TAG, exceptionObj); } else { ALOGE("Exception: %s", msg); jniLogException(env, ANDROID_LOG_ERROR, LOG_TAG, exceptionObj); LOG_ALWAYS_FATAL("raiseException() was called when not in a callback, exiting."); } } }