mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-05 08:35:26 +00:00
84a1b0dd5a
There is some ambiguity about whether ScheduleComposite will necessarily trigger a composite all the way to nsWindow::DrawWindowUnderlay. Android robocop tests assume it will, because they rely on DrawWindowOverlay being called so they can take a screenshot and make progress, but this is a very fragile assumption. They also rely on the entire window being painted, which is also a fragile assumption. This patch improves the situation by explicitly invalidating the current window area when Android Java code needs to trigger a composite. This avoids regressions from future patches in this series which make composition bail out when there is nothing invalid. The resulting setup is still a bit fragile for my taste but I'm not sure what the ideal solution would be. --HG-- extra : commitid : 3t3xqRdZs24 extra : rebase_source : b23749613663ca805484776ccf5e36b4ff00e3fe
118 lines
3.9 KiB
Java
118 lines
3.9 KiB
Java
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
package org.mozilla.gecko;
|
|
|
|
import android.annotation.TargetApi;
|
|
import android.app.Presentation;
|
|
import android.content.Context;
|
|
import android.os.Bundle;
|
|
import android.support.v7.media.MediaRouter;
|
|
import android.util.Log;
|
|
import android.view.Display;
|
|
import android.view.SurfaceHolder;
|
|
import android.view.SurfaceView;
|
|
import android.view.ViewGroup;
|
|
import android.view.WindowManager;
|
|
|
|
import org.mozilla.gecko.AppConstants.Versions;
|
|
|
|
/**
|
|
* A MediaPlayerManager with API 17+ Presentation support.
|
|
*/
|
|
@TargetApi(17)
|
|
public class PresentationMediaPlayerManager extends MediaPlayerManager {
|
|
|
|
private static final String LOGTAG = "Gecko" + PresentationMediaPlayerManager.class.getSimpleName();
|
|
|
|
private GeckoPresentation presentation;
|
|
|
|
public PresentationMediaPlayerManager() {
|
|
if (!Versions.feature17Plus) {
|
|
throw new IllegalStateException(PresentationMediaPlayerManager.class.getSimpleName() +
|
|
" does not support < API 17");
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onStop() {
|
|
super.onStop();
|
|
if (presentation != null) {
|
|
presentation.dismiss();
|
|
presentation = null;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void updatePresentation() {
|
|
if (mediaRouter == null) {
|
|
return;
|
|
}
|
|
|
|
MediaRouter.RouteInfo route = mediaRouter.getSelectedRoute();
|
|
Display display = route != null ? route.getPresentationDisplay() : null;
|
|
|
|
if (display != null) {
|
|
if ((presentation != null) && (presentation.getDisplay() != display)) {
|
|
presentation.dismiss();
|
|
presentation = null;
|
|
}
|
|
|
|
if (presentation == null) {
|
|
presentation = new GeckoPresentation(getActivity(), display);
|
|
|
|
try {
|
|
presentation.show();
|
|
} catch (WindowManager.InvalidDisplayException ex) {
|
|
Log.w(LOGTAG, "Couldn't show presentation! Display was removed in "
|
|
+ "the meantime.", ex);
|
|
presentation = null;
|
|
}
|
|
}
|
|
} else if (presentation != null) {
|
|
presentation.dismiss();
|
|
presentation = null;
|
|
}
|
|
}
|
|
|
|
private final static class GeckoPresentation extends Presentation {
|
|
private SurfaceView mView;
|
|
public GeckoPresentation(Context context, Display display) {
|
|
super(context, display);
|
|
}
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
|
|
mView = new SurfaceView(getContext());
|
|
setContentView(mView, new ViewGroup.LayoutParams(
|
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
|
ViewGroup.LayoutParams.MATCH_PARENT));
|
|
mView.getHolder().addCallback(new SurfaceListener());
|
|
}
|
|
}
|
|
|
|
private static class SurfaceListener implements SurfaceHolder.Callback {
|
|
@Override
|
|
public void surfaceChanged(SurfaceHolder holder, int format, int width,
|
|
int height) {
|
|
// Surface changed so force a composite
|
|
GeckoAppShell.invalidateAndScheduleComposite();
|
|
}
|
|
|
|
@Override
|
|
public void surfaceCreated(SurfaceHolder holder) {
|
|
GeckoAppShell.addPresentationSurface(holder.getSurface());
|
|
GeckoAppShell.invalidateAndScheduleComposite();
|
|
}
|
|
|
|
@Override
|
|
public void surfaceDestroyed(SurfaceHolder holder) {
|
|
GeckoAppShell.removePresentationSurface(holder.getSurface());
|
|
}
|
|
}
|
|
}
|