Skip to content
Snippets Groups Projects
Commit da429e8b authored by Nick's avatar Nick :v:
Browse files

VncFlinger: fix us being too fast for framework

fixes input going to internal display sometimes

Change-Id: I4a7c18cd74445cf08512948f79c5f2f7c37a382c
parent 98b3af87
No related branches found
No related tags found
No related merge requests found
......@@ -26,7 +26,7 @@ import android.view.Surface;
import com.libremobileos.vncflinger.IVncFlinger;
public class VncFlinger extends Service {
public class VncFlinger extends Service implements DisplayManager.DisplayListener {
static {
System.loadLibrary("jni_vncflinger");
......@@ -48,6 +48,7 @@ public class VncFlinger extends Service {
public String mIntentPkg = null;
public String mIntentComponent = null;
public DisplayManager mDisplayManager;
public VirtualDisplay mDisplay;
public ClipboardManager mClipboard;
public String[] mVNCFlingerArgs;
......@@ -154,12 +155,13 @@ public class VncFlinger extends Service {
mAudioStreamerArgs = new String[] { "audiostreamer", "-u", "@audiostreamer" };
if (!mMirrorInternal) {
mDisplay = ((DisplayManager) getSystemService(DISPLAY_SERVICE))
.createVirtualDisplay("VNC",
mDisplayManager = (DisplayManager) getSystemService(DISPLAY_SERVICE);
mDisplay = mDisplayManager.createVirtualDisplay("VNC",
mWidth, mHeight, mDPI, null,
VIRTUAL_DISPLAY_FLAG_SECURE | VIRTUAL_DISPLAY_FLAG_PUBLIC | VIRTUAL_DISPLAY_FLAG_TRUSTED
| VIRTUAL_DISPLAY_FLAG_SUPPORTS_TOUCH
| VIRTUAL_DISPLAY_FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS);
mDisplayManager.registerDisplayListener(this, null);
}
if (mSupportClipboard) {
mClipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
......@@ -213,6 +215,34 @@ public class VncFlinger extends Service {
System.exit(0);
}
@Override
public void onDisplayAdded(int displayId) {
if (mDisplay == null) {
throw new IllegalStateException();
}
if (mDisplay.getDisplay().getDisplayId() != displayId)
return;
mDisplayManager.unregisterDisplayListener(this);
// dear google, i literally wait till framework tells me
// this display is ready so WHY is the delay needed
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
notifyDisplayReady();
}
@Override
public void onDisplayChanged(int displayId) {
onDisplayAdded(displayId);
}
@Override
public void onDisplayRemoved(int displayId) {
mDisplayManager.unregisterDisplayListener(this);
}
@Override
public IBinder onBind(Intent intent) {
return mBinder;
......@@ -264,6 +294,9 @@ public class VncFlinger extends Service {
int exitCode;
if ((exitCode = initializeVncFlinger(mVNCFlingerArgs)) == 0) {
doSetDisplayProps();
if (mMirrorInternal) {
notifyDisplayReady();
}
if ((exitCode = startService()) == 0) {
stopSelf();
return;
......@@ -351,6 +384,8 @@ public class VncFlinger extends Service {
private native void notifyServerClipboardChanged();
private native void notifyDisplayReady();
private native int startAudioStreamer(String[] commandLineArgs);
private native void endAudioStreamer();
......
......@@ -279,6 +279,22 @@ rfb::ScreenSet AndroidDesktop::computeScreenLayout() {
mServer->setScreenLayout(screens);
}
void AndroidDesktop::notifyInputChanged() {
mInputChanged = true;
notify();
}
void AndroidDesktop::processInputChanged() {
if (mInputChanged && mInputDevice != nullptr) {
mInputChanged = false;
reloadInput();
}
}
void AndroidDesktop::reloadInput() {
mInputDevice->reconfigure(mDisplayModeRotated.width, mDisplayModeRotated.height, touch, relative);
}
void AndroidDesktop::onBufferDimensionsChanged(uint32_t width, uint32_t height) {
ALOGI("Dimensions changed: old=(%ux%u) new=(%ux%u)", mDisplayRect.getWidth(),
mDisplayRect.getHeight(), width, height);
......@@ -290,7 +306,9 @@ void AndroidDesktop::onBufferDimensionsChanged(uint32_t width, uint32_t height)
mDisplayRect = mVirtualDisplay->getDisplayRect();
mInputDevice->reconfigure(mDisplayModeRotated.width, mDisplayModeRotated.height, touch, relative);
if (mInputDevice->isOpened()) { // if we are resizing, first start gets called by java later
reloadInput();
}
mServer->setPixelBuffer(mPixels.get(), computeScreenLayout());
mServer->setScreenLayout(computeScreenLayout());
......
......@@ -42,6 +42,8 @@ class AndroidDesktop : public rfb::SDesktop,
virtual void handleClipboardData(const char* data);
virtual void notifyClipboardChanged();
virtual void processClipboard();
virtual void processInputChanged();
virtual void notifyInputChanged();
virtual void setCursor(uint32_t width, uint32_t height, int hotX, int hotY, const uint8_t* buffer);
virtual void processCursor();
......@@ -70,6 +72,7 @@ class AndroidDesktop : public rfb::SDesktop,
std::mutex jniConfigMutex;
private:
virtual void notify();
virtual void reloadInput();
virtual status_t updateDisplayInfo(bool force = false);
......@@ -91,6 +94,7 @@ class AndroidDesktop : public rfb::SDesktop,
bool frameChanged = false;
bool clipboardChanged = false;
bool mInputChanged = false;
// Primary display
ui::Size mDisplayMode = {};
......
......@@ -39,6 +39,7 @@ class InputDevice : public RefBase {
virtual void keyEvent(bool down, uint32_t key);
virtual void pointerEvent(int buttonMask, int x, int y);
inline bool isOpened() { return mOpened; }
InputDevice() : mFD(-1) {
}
virtual ~InputDevice() {
......
......@@ -196,6 +196,15 @@ extern "C" void Java_com_libremobileos_vncflinger_VncFlinger_notifyServerClipboa
desktop->notifyClipboardChanged();
}
extern "C" void Java_com_libremobileos_vncflinger_VncFlinger_notifyDisplayReady(
JNIEnv* env, jobject thiz) {
if (desktop == NULL) {
ALOGW("notifyDisplayReady: desktop == NULL");
return;
}
desktop->notifyInputChanged();
}
int desktopSetup(int argc, char** argv) {
rfb::initAndroidLogger();
rfb::LogWriter::setLogParams("*:android:30");
......@@ -372,6 +381,7 @@ int startService() {
if (status > 0 && eventVal > 0) {
//ALOGV("status=%d eventval=%" PRIu64, status, eventVal);
desktop->processCursor();
desktop->processInputChanged();
desktop->processFrames();
desktop->processClipboard();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment