void Transport::Send(const Packet& packet) { if (!g_SentArchtecturePacket) { g_SentArchtecturePacket = true; SetArchitecture architecturePacket; GetGlobalBuffer().Add(architecturePacket.Serialize()); NumItems++; } GetGlobalBuffer().Add(packet.Serialize()); NumItems++; //PacketQueue.Enqueue(buffer); }
void CPUMappedBuffer::TryMapping() { // Do we have an IonBuffer for this shared memory object? if (buffer_ == nullptr) { // Has it been too long since we last connected to the display service? const auto current_time_ns = GetSystemClockNs(); if ((current_time_ns - last_display_service_connection_ns_) < (1e9 / kDisplayServiceTriesPerSecond)) { // Early exit. return; } last_display_service_connection_ns_ = current_time_ns; // Create a display client and get the buffer. auto display_client = display::DisplayClient::Create(); if (display_client) { auto get_result = display_client->GetGlobalBuffer(buffer_key_); if (get_result.ok()) { owned_buffer_ = get_result.take(); buffer_ = owned_buffer_.get(); } else { // The buffer has not been created yet. This is OK, we will keep // retrying. } } else { ALOGE("Unable to create display client for shared buffer access"); } } if (buffer_) { auto usage = buffer_->usage() & ~GRALLOC_USAGE_SW_READ_MASK & ~GRALLOC_USAGE_SW_WRITE_MASK; // Figure out the usage bits. switch (usage_mode_) { case CPUUsageMode::READ_OFTEN: usage |= GRALLOC_USAGE_SW_READ_OFTEN; break; case CPUUsageMode::READ_RARELY: usage |= GRALLOC_USAGE_SW_READ_RARELY; break; case CPUUsageMode::WRITE_OFTEN: usage |= GRALLOC_USAGE_SW_WRITE_OFTEN; break; case CPUUsageMode::WRITE_RARELY: usage |= GRALLOC_USAGE_SW_WRITE_RARELY; break; } int width = static_cast<int>(buffer_->width()); int height = 1; const auto ret = buffer_->Lock(usage, 0, 0, width, height, &address_); if (ret < 0 || !address_) { ALOGE("Pose failed to map ring buffer: ret:%d, addr:%p", ret, address_); buffer_->Unlock(); } else { size_ = width; } } }
Buffer& Transport::BuildFinalBuffer(Thread& callingThread) { // This builds up the final packet bundle static Buffer buffer; buffer.Clear(); buffer.Add((void*)&Version, sizeof(Version)); callingThread.StartCriticalSection(); buffer.Add((void*)&NumItems, sizeof(NumItems)); buffer.Add((void*)GetGlobalBuffer().GetData(), GetGlobalBuffer().GetSize()); NumItems = 0; GetGlobalBuffer().Clear(); callingThread.EndCriticalSection(); return buffer; }
// **************************************************************************** // // Function Name: RAlert::FormatAlertString( ) // // Description: Format an a string with variable text for alert output. // Retrieve the message from a resource file and format the // subString into the resource string (likely to be a file // name for an error message). // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // RMBCString RAlert::FormatAlertString( YResourceId alertId, const RMBCString& subString ) { LPSZ lpszString = (LPSZ)GetGlobalBuffer(); *lpszString = 0; // Make sure the string is null terminated... RMBCString string = GetResourceManager().GetResourceString( alertId ); wsprintf( lpszString, (LPCSZ)string, (LPCSZ)subString ); RMBCString returnString(lpszString); ReleaseGlobalBuffer( (unsigned char*)lpszString ); #ifdef TPSDEBUG char buffer[10]; buffer[0] = '\0'; WinCode( wsprintf( buffer, " - %d", alertId ) ); returnString += buffer; #endif return returnString; }