mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Stand up async panning and zooming
This commit is contained in:
parent
c9d1e74c7a
commit
8f577231bf
@ -82,10 +82,10 @@ CompositorParent::RecvStop()
|
||||
|
||||
|
||||
void
|
||||
CompositorParent::ScheduleCompositionOnCompositorThread(::base::Thread &aCompositorThread)
|
||||
CompositorParent::ScheduleRenderOnCompositorThread(::base::Thread &aCompositorThread)
|
||||
{
|
||||
CancelableTask *composeTask = NewRunnableMethod(this, &CompositorParent::Composite);
|
||||
aCompositorThread.message_loop()->PostTask(FROM_HERE, composeTask);
|
||||
CancelableTask *renderTask = NewRunnableMethod(this, &CompositorParent::AsyncRender);
|
||||
aCompositorThread.message_loop()->PostTask(FROM_HERE, renderTask);
|
||||
}
|
||||
|
||||
void
|
||||
@ -223,12 +223,13 @@ CompositorParent::AsyncRender()
|
||||
}
|
||||
|
||||
Layer* root = mLayerManager->GetRoot();
|
||||
|
||||
/*
|
||||
ContainerLayer* container = root->AsContainerLayer();
|
||||
if (!container)
|
||||
return;
|
||||
|
||||
FrameMetrics metrics = container->GetFrameMetrics();
|
||||
/*
|
||||
printf("FrameMetrics: mViewPort: X: %d, Y: %d, Width: %d, Height: %d ",
|
||||
metrics.mViewport.X(), metrics.mViewport.Y(), metrics.mViewport.Width(),
|
||||
metrics.mViewport.Height());
|
||||
@ -240,17 +241,25 @@ CompositorParent::AsyncRender()
|
||||
printf("mViewPortScrollOffset: x: %d, y: %d\n",
|
||||
metrics.mViewportScrollOffset.x,
|
||||
metrics.mViewportScrollOffset.y);
|
||||
*/
|
||||
// Modify framemetrics here, just as a test.
|
||||
metrics.mScrollId = FrameMetrics::ROOT_SCROLL_ID;
|
||||
container->SetFrameMetrics(metrics);
|
||||
*/
|
||||
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
RequestViewTransform();
|
||||
#endif
|
||||
|
||||
gfx3DMatrix worldTransform;
|
||||
gfxPoint3D offset(-mScrollOffset.x, -mScrollOffset.y, 0.0f);
|
||||
worldTransform.Translate(offset);
|
||||
worldTransform.Scale(mXScale, mYScale, 1.0f);
|
||||
root->AsShadowLayer()->SetShadowTransform(worldTransform);
|
||||
|
||||
#if 0
|
||||
ViewTransform transform;
|
||||
TransformShadowTree(root, transform);
|
||||
#endif
|
||||
|
||||
Composite();
|
||||
}
|
||||
@ -259,8 +268,11 @@ CompositorParent::AsyncRender()
|
||||
void
|
||||
CompositorParent::RequestViewTransform()
|
||||
{
|
||||
mozilla::AndroidBridge::Bridge()->GetViewTransform(mScrollOffset, mXScale,
|
||||
mYScale);
|
||||
mozilla::AndroidBridge::Bridge()->GetViewTransform(mScrollOffset, mXScale, mYScale);
|
||||
|
||||
__android_log_print(ANDROID_LOG_ERROR, "Gecko", "### mScrollOffset=%g %g "
|
||||
"mXScale=%g mYScale=%g", (float)mScrollOffset.x, (float)mScrollOffset.y,
|
||||
(float)mXScale, (float)mYScale);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -90,7 +90,7 @@ public:
|
||||
|
||||
void SetTransformation(float aScale, nsIntPoint aScrollOffset);
|
||||
void AsyncRender();
|
||||
void ScheduleCompositionOnCompositorThread(::base::Thread &aCompositorThread);
|
||||
void ScheduleRenderOnCompositorThread(::base::Thread &aCompositorThread);
|
||||
|
||||
protected:
|
||||
virtual PLayersParent* AllocPLayers(const LayersBackend &backendType);
|
||||
|
197
mobile/android/base/gfx/GeckoGLLayerClient.java
Normal file
197
mobile/android/base/gfx/GeckoGLLayerClient.java
Normal file
@ -0,0 +1,197 @@
|
||||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Android code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009-2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Patrick Walton <pcwalton@mozilla.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
package org.mozilla.gecko.gfx;
|
||||
|
||||
import org.mozilla.gecko.GeckoAppShell;
|
||||
import org.mozilla.gecko.GeckoEvent;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.Rect;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
public class GeckoGLLayerClient extends GeckoLayerClient
|
||||
implements FlexibleGLSurfaceView.Listener, VirtualLayer.Listener {
|
||||
private static final String LOGTAG = "GeckoGLLayerClient";
|
||||
|
||||
public GeckoGLLayerClient(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean beginDrawing(int width, int height, int tileWidth, int tileHeight,
|
||||
String metadata, boolean hasDirectTexture) {
|
||||
if (!super.beginDrawing(width, height, tileWidth, tileHeight, metadata,
|
||||
hasDirectTexture)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Be sure to adjust the buffer size; if it's not at least as large as the viewport size,
|
||||
// ViewportMetrics.getOptimumViewportOffset() gets awfully confused and severe display
|
||||
// corruption results!
|
||||
if (mBufferSize.width != width || mBufferSize.height != height) {
|
||||
mBufferSize = new IntSize(width, height);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean handleDirectTextureChange(boolean hasDirectTexture) {
|
||||
Log.e(LOGTAG, "### handleDirectTextureChange");
|
||||
if (mTileLayer != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Log.e(LOGTAG, "### Creating virtual layer");
|
||||
VirtualLayer virtualLayer = new VirtualLayer();
|
||||
virtualLayer.setListener(this);
|
||||
virtualLayer.setSize(getBufferSize());
|
||||
getLayerController().setRoot(virtualLayer);
|
||||
mTileLayer = virtualLayer;
|
||||
|
||||
sendResizeEventIfNecessary(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLayerController(LayerController layerController) {
|
||||
super.setLayerController(layerController);
|
||||
|
||||
((FlexibleGLSurfaceView)layerController.getView()).setListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldDrawProceed(int tileWidth, int tileHeight) {
|
||||
Log.e(LOGTAG, "### shouldDrawProceed");
|
||||
// Always draw.
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateLayerAfterDraw(Rect updatedRect) {
|
||||
Log.e(LOGTAG, "### updateLayerAfterDraw");
|
||||
// Nothing to do.
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IntSize getBufferSize() {
|
||||
View view = (View)getLayerController().getView();
|
||||
IntSize size = new IntSize(view.getWidth(), view.getHeight());
|
||||
Log.e(LOGTAG, "### getBufferSize " + size);
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IntSize getTileSize() {
|
||||
Log.e(LOGTAG, "### getTileSize " + getBufferSize());
|
||||
return getBufferSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tileLayerUpdated() {
|
||||
// Set the new origin and resolution instantly.
|
||||
mTileLayer.performUpdates(null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bitmap getBitmap() {
|
||||
Log.e(LOGTAG, "### getBitmap");
|
||||
IntSize size = getBufferSize();
|
||||
return Bitmap.createBitmap(size.width, size.height, Bitmap.Config.RGB_565);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
Log.e(LOGTAG, "### getType");
|
||||
return LAYER_CLIENT_TYPE_GL;
|
||||
}
|
||||
|
||||
public void dimensionsChanged(Point newOrigin, float newResolution) {
|
||||
Log.e(LOGTAG, "### dimensionsChanged " + newOrigin + " " + newResolution);
|
||||
}
|
||||
|
||||
/* Informs Gecko that the screen size has changed. */
|
||||
@Override
|
||||
protected void sendResizeEventIfNecessary(boolean force) {
|
||||
Log.e(LOGTAG, "### sendResizeEventIfNecessary " + force);
|
||||
|
||||
IntSize newSize = getBufferSize();
|
||||
if (!force && mScreenSize != null && mScreenSize.equals(newSize)) {
|
||||
return;
|
||||
}
|
||||
|
||||
mScreenSize = newSize;
|
||||
|
||||
Log.e(LOGTAG, "### Screen-size changed to " + mScreenSize);
|
||||
GeckoEvent event = new GeckoEvent(GeckoEvent.SIZE_CHANGED,
|
||||
mScreenSize.width, mScreenSize.height,
|
||||
mScreenSize.width, mScreenSize.height,
|
||||
mScreenSize.width, mScreenSize.height);
|
||||
GeckoAppShell.sendEventToGecko(event);
|
||||
}
|
||||
|
||||
/** For Gecko to use. */
|
||||
public ViewTransform getViewTransform() {
|
||||
Log.e(LOGTAG, "### getViewTransform()");
|
||||
|
||||
// NB: We don't begin a transaction here because this can be called in a synchronous
|
||||
// manner between beginDrawing() and endDrawing(), and that will cause a deadlock.
|
||||
|
||||
LayerController layerController = getLayerController();
|
||||
synchronized (layerController) {
|
||||
ViewportMetrics viewportMetrics = layerController.getViewportMetrics();
|
||||
PointF viewportOrigin = viewportMetrics.getOrigin();
|
||||
Point tileOrigin = mTileLayer.getOrigin();
|
||||
float scrollX = viewportOrigin.x - tileOrigin.x;
|
||||
float scrollY = viewportOrigin.y - tileOrigin.y;
|
||||
float zoomFactor = viewportMetrics.getZoomFactor() / mTileLayer.getResolution();
|
||||
Log.e(LOGTAG, "### Viewport metrics = " + viewportMetrics + " tile reso = " +
|
||||
mTileLayer.getResolution());
|
||||
return new ViewTransform(scrollX, scrollY, zoomFactor);
|
||||
}
|
||||
}
|
||||
|
||||
public void renderRequested() {
|
||||
Log.e(LOGTAG, "### Render requested, scheduling composite");
|
||||
GeckoAppShell.scheduleComposite();
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ public abstract class GeckoLayerClient extends LayerClient implements GeckoEvent
|
||||
/* The viewport that Gecko will display when drawing is finished */
|
||||
protected ViewportMetrics mNewGeckoViewport;
|
||||
|
||||
private static final long MIN_VIEWPORT_CHANGE_DELAY = 15L;
|
||||
private static final long MIN_VIEWPORT_CHANGE_DELAY = 200L;
|
||||
private long mLastViewportChangeTime;
|
||||
private boolean mPendingViewportAdjust;
|
||||
private boolean mViewportSizeChanged;
|
||||
@ -96,6 +96,7 @@ public abstract class GeckoLayerClient extends LayerClient implements GeckoEvent
|
||||
protected abstract void updateLayerAfterDraw(Rect updatedRect);
|
||||
protected abstract IntSize getBufferSize();
|
||||
protected abstract IntSize getTileSize();
|
||||
protected abstract void tileLayerUpdated();
|
||||
public abstract Bitmap getBitmap();
|
||||
public abstract int getType();
|
||||
|
||||
@ -140,6 +141,8 @@ public abstract class GeckoLayerClient extends LayerClient implements GeckoEvent
|
||||
JSONObject viewportObject = new JSONObject(metadata);
|
||||
mNewGeckoViewport = new ViewportMetrics(viewportObject);
|
||||
|
||||
Log.e(LOGTAG, "### beginDrawing new Gecko viewport " + mNewGeckoViewport);
|
||||
|
||||
// Update the background color, if it's present.
|
||||
String backgroundColorString = viewportObject.optString("backgroundColor");
|
||||
if (backgroundColorString != null) {
|
||||
@ -193,6 +196,10 @@ public abstract class GeckoLayerClient extends LayerClient implements GeckoEvent
|
||||
mTileLayer.setOrigin(PointUtils.round(displayportOrigin));
|
||||
mTileLayer.setResolution(mGeckoViewport.getZoomFactor());
|
||||
|
||||
this.tileLayerUpdated();
|
||||
Log.e(LOGTAG, "### updateViewport onlyUpdatePageSize=" + onlyUpdatePageSize +
|
||||
" getTileViewport " + mGeckoViewport);
|
||||
|
||||
if (onlyUpdatePageSize) {
|
||||
// Don't adjust page size when zooming unless zoom levels are
|
||||
// approximately equal.
|
||||
@ -304,12 +311,14 @@ public abstract class GeckoLayerClient extends LayerClient implements GeckoEvent
|
||||
|
||||
public void handleMessage(String event, JSONObject message) {
|
||||
if ("Viewport:UpdateAndDraw".equals(event)) {
|
||||
Log.e(LOGTAG, "### Java side Viewport:UpdateAndDraw()!");
|
||||
mUpdateViewportOnEndDraw = true;
|
||||
|
||||
// Redraw everything.
|
||||
Rect rect = new Rect(0, 0, mBufferSize.width, mBufferSize.height);
|
||||
GeckoAppShell.sendEventToGecko(new GeckoEvent(GeckoEvent.DRAW, rect));
|
||||
} else if ("Viewport:UpdateLater".equals(event)) {
|
||||
Log.e(LOGTAG, "### Java side Viewport:UpdateLater()!");
|
||||
mUpdateViewportOnEndDraw = true;
|
||||
}
|
||||
}
|
||||
|
@ -244,6 +244,11 @@ public class GeckoSoftwareLayerClient extends GeckoLayerClient {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tileLayerUpdated() {
|
||||
/* No-op. */
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bitmap getBitmap() {
|
||||
if (mTileLayer == null)
|
||||
|
81
mobile/android/base/gfx/VirtualLayer.java
Normal file
81
mobile/android/base/gfx/VirtualLayer.java
Normal file
@ -0,0 +1,81 @@
|
||||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Android code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009-2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Patrick Walton <pcwalton@mozilla.com>
|
||||
* Chris Lord <chrislord.net@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
package org.mozilla.gecko.gfx;
|
||||
|
||||
import android.graphics.Point;
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
|
||||
public class VirtualLayer extends Layer {
|
||||
private Listener mListener;
|
||||
private IntSize mSize;
|
||||
|
||||
public void setListener(Listener listener) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(RenderContext context) {
|
||||
// No-op.
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntSize getSize() {
|
||||
return mSize;
|
||||
}
|
||||
|
||||
public void setSize(IntSize size) {
|
||||
mSize = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean performUpdates(GL10 gl, RenderContext context) {
|
||||
boolean dimensionsChanged = dimensionChangesPending();
|
||||
boolean result = super.performUpdates(gl, context);
|
||||
if (dimensionsChanged && mListener != null) {
|
||||
mListener.dimensionsChanged(getOrigin(), getResolution());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public interface Listener {
|
||||
void dimensionsChanged(Point newOrigin, float newResolution);
|
||||
}
|
||||
}
|
||||
|
@ -1550,6 +1550,7 @@ Tab.prototype = {
|
||||
|
||||
this._viewport.width = gScreenWidth = aViewport.width;
|
||||
this._viewport.height = gScreenHeight = aViewport.height;
|
||||
dump("### gScreenWidth = " + gScreenWidth + "\n");
|
||||
|
||||
let transformChanged = false;
|
||||
|
||||
@ -1664,6 +1665,8 @@ Tab.prototype = {
|
||||
},
|
||||
|
||||
updateViewport: function(aReset, aZoomLevel) {
|
||||
dump("### JS side updateViewport " + aReset + " zoom " + aZoomLevel + "\n");
|
||||
|
||||
if (!aZoomLevel)
|
||||
aZoomLevel = this.getDefaultZoomLevel();
|
||||
|
||||
@ -2071,6 +2074,7 @@ Tab.prototype = {
|
||||
return md.defaultZoom;
|
||||
|
||||
let browserWidth = parseInt(this.browser.style.width);
|
||||
dump("### getDefaultZoomLevel gScreenWidth=" + gScreenWidth);
|
||||
return gScreenWidth / browserWidth;
|
||||
},
|
||||
|
||||
|
@ -1865,19 +1865,30 @@ void
|
||||
AndroidBridge::ScheduleComposite()
|
||||
{
|
||||
if (mCompositorParent) {
|
||||
mCompositorParent->ScheduleCompositionOnCompositorThread(*mCompositorThread);
|
||||
mCompositorParent->ScheduleRenderOnCompositorThread(*mCompositorThread);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
AndroidBridge::SetViewTransformGetter(AndroidViewTransformGetter& aViewTransformGetter)
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_ERROR, "Gecko", "### SetViewTransformGetter()");
|
||||
mViewTransformGetter = &aViewTransformGetter;
|
||||
}
|
||||
|
||||
void
|
||||
AndroidBridge::GetViewTransform(nsIntPoint& aScrollOffset, float& aScaleX, float& aScaleY)
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_ERROR, "Gecko", "### GetViewTransform() TODO");
|
||||
__android_log_print(ANDROID_LOG_ERROR, "Gecko", "### GetViewTransform()");
|
||||
if (mViewTransformGetter) {
|
||||
(*mViewTransformGetter)(aScrollOffset, aScaleX, aScaleY);
|
||||
}
|
||||
}
|
||||
|
||||
AndroidBridge::AndroidBridge()
|
||||
: mLayerClient(NULL)
|
||||
, mLayerClientType(0)
|
||||
, mViewTransformGetter(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -403,6 +403,7 @@ public:
|
||||
void SetCompositorParent(mozilla::layers::CompositorParent* aCompositorParent,
|
||||
base::Thread* aCompositorThread);
|
||||
void ScheduleComposite();
|
||||
void SetViewTransformGetter(AndroidViewTransformGetter& aViewTransformGetter);
|
||||
void GetViewTransform(nsIntPoint& aScrollOffset, float& aScaleX, float& aScaleY);
|
||||
|
||||
protected:
|
||||
@ -423,6 +424,7 @@ protected:
|
||||
|
||||
nsRefPtr<mozilla::layers::CompositorParent> mCompositorParent;
|
||||
base::Thread *mCompositorThread;
|
||||
AndroidViewTransformGetter *mViewTransformGetter;
|
||||
|
||||
// the GeckoAppShell java class
|
||||
jclass mGeckoAppShellClass;
|
||||
|
@ -118,6 +118,12 @@ jmethodID AndroidGeckoSoftwareLayerClient::jUnlockBufferMethod = 0;
|
||||
jmethodID AndroidGeckoSoftwareLayerClient::jGetRenderOffsetMethod = 0;
|
||||
|
||||
jclass AndroidGeckoGLLayerClient::jGeckoGLLayerClientClass = 0;
|
||||
jmethodID AndroidGeckoGLLayerClient::jGetViewTransformMethod = 0;
|
||||
|
||||
jclass AndroidViewTransform::jViewTransformClass = 0;
|
||||
jfieldID AndroidViewTransform::jXField = 0;
|
||||
jfieldID AndroidViewTransform::jYField = 0;
|
||||
jfieldID AndroidViewTransform::jScaleField = 0;
|
||||
|
||||
jclass AndroidGeckoSurfaceView::jGeckoSurfaceViewClass = 0;
|
||||
jmethodID AndroidGeckoSurfaceView::jBeginDrawingMethod = 0;
|
||||
@ -151,6 +157,8 @@ mozilla::InitAndroidJavaWrappers(JNIEnv *jEnv)
|
||||
AndroidRect::InitRectClass(jEnv);
|
||||
AndroidGeckoLayerClient::InitGeckoLayerClientClass(jEnv);
|
||||
AndroidGeckoSoftwareLayerClient::InitGeckoSoftwareLayerClientClass(jEnv);
|
||||
AndroidGeckoGLLayerClient::InitGeckoGLLayerClientClass(jEnv);
|
||||
AndroidViewTransform::InitViewTransformClass(jEnv);
|
||||
AndroidGeckoSurfaceView::InitGeckoSurfaceViewClass(jEnv);
|
||||
}
|
||||
|
||||
@ -360,6 +368,23 @@ AndroidGeckoGLLayerClient::InitGeckoGLLayerClientClass(JNIEnv *jEnv)
|
||||
initInit();
|
||||
|
||||
jGeckoGLLayerClientClass = getClassGlobalRef("org/mozilla/gecko/gfx/GeckoGLLayerClient");
|
||||
|
||||
jGetViewTransformMethod = getMethod("getViewTransform",
|
||||
"()Lorg/mozilla/gecko/gfx/ViewTransform;");
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
AndroidViewTransform::InitViewTransformClass(JNIEnv *jEnv)
|
||||
{
|
||||
#ifdef MOZ_JAVA_COMPOSITOR
|
||||
initInit();
|
||||
|
||||
jViewTransformClass = getClassGlobalRef("org/mozilla/gecko/gfx/ViewTransform");
|
||||
|
||||
jXField = getField("x", "F");
|
||||
jYField = getField("y", "F");
|
||||
jScaleField = getField("scale", "F");
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -625,6 +650,16 @@ AndroidGeckoGLLayerClient::Init(jobject jobj)
|
||||
{
|
||||
NS_ASSERTION(wrapped_obj == nsnull, "Init called on non-null wrapped_obj!");
|
||||
wrapped_obj = jobj;
|
||||
|
||||
// Register the view transform getter.
|
||||
AndroidBridge::Bridge()->SetViewTransformGetter(mViewTransformGetter);
|
||||
}
|
||||
|
||||
void
|
||||
AndroidViewTransform::Init(jobject jobj)
|
||||
{
|
||||
NS_ABORT_IF_FALSE(wrapped_obj == nsnull, "Init called on non-null wrapped_obj!");
|
||||
wrapped_obj = jobj;
|
||||
}
|
||||
|
||||
void
|
||||
@ -794,6 +829,60 @@ AndroidGeckoSurfaceView::GetSurfaceHolder()
|
||||
return GetJNIForThread()->CallObjectMethod(wrapped_obj, jGetHolderMethod);
|
||||
}
|
||||
|
||||
void
|
||||
AndroidGeckoGLLayerClient::GetViewTransform(AndroidViewTransform& aViewTransform)
|
||||
{
|
||||
JNIEnv *env = GetJNIForThread();
|
||||
NS_ABORT_IF_FALSE(env, "No JNI environment at GetViewTransform()!");
|
||||
if (!env) {
|
||||
return;
|
||||
}
|
||||
|
||||
jobject viewTransformJObj = env->CallObjectMethod(wrapped_obj, jGetViewTransformMethod);
|
||||
NS_ABORT_IF_FALSE(viewTransformJObj, "No view transform object!");
|
||||
aViewTransform.Init(viewTransformJObj);
|
||||
}
|
||||
|
||||
float
|
||||
AndroidViewTransform::GetX()
|
||||
{
|
||||
JNIEnv *env = GetJNIForThread();
|
||||
if (!env)
|
||||
return 0.0f;
|
||||
return env->GetFloatField(wrapped_obj, jXField);
|
||||
}
|
||||
|
||||
float
|
||||
AndroidViewTransform::GetY()
|
||||
{
|
||||
JNIEnv *env = GetJNIForThread();
|
||||
if (!env)
|
||||
return 0.0f;
|
||||
return env->GetFloatField(wrapped_obj, jYField);
|
||||
}
|
||||
|
||||
float
|
||||
AndroidViewTransform::GetScale()
|
||||
{
|
||||
JNIEnv *env = GetJNIForThread();
|
||||
if (!env)
|
||||
return 0.0f;
|
||||
return env->GetFloatField(wrapped_obj, jScaleField);
|
||||
}
|
||||
|
||||
void
|
||||
AndroidGeckoGLLayerClientViewTransformGetter::operator()(nsIntPoint& aScrollOffset, float& aScaleX,
|
||||
float& aScaleY)
|
||||
{
|
||||
AndroidViewTransform viewTransform;
|
||||
|
||||
AndroidBridge::AutoLocalJNIFrame jniFrame(GetJNIForThread());
|
||||
mLayerClient.GetViewTransform(viewTransform);
|
||||
|
||||
aScrollOffset = nsIntPoint(viewTransform.GetX(), viewTransform.GetY());
|
||||
aScaleX = aScaleY = viewTransform.GetScale();
|
||||
}
|
||||
|
||||
void
|
||||
AndroidRect::Init(JNIEnv *jenv, jobject jobj)
|
||||
{
|
||||
|
@ -58,6 +58,8 @@
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class AndroidGeckoGLLayerClient;
|
||||
|
||||
void InitAndroidJavaWrappers(JNIEnv *jEnv);
|
||||
|
||||
/*
|
||||
@ -193,17 +195,63 @@ protected:
|
||||
static jmethodID jGetRenderOffsetMethod;
|
||||
};
|
||||
|
||||
/** A callback that retrieves the view transform. */
|
||||
class AndroidViewTransformGetter
|
||||
{
|
||||
public:
|
||||
virtual void operator()(nsIntPoint& aScrollOffset, float& aScaleX, float& aScaleY) = 0;
|
||||
};
|
||||
|
||||
class AndroidGeckoGLLayerClientViewTransformGetter : public AndroidViewTransformGetter {
|
||||
public:
|
||||
AndroidGeckoGLLayerClientViewTransformGetter(AndroidGeckoGLLayerClient& aLayerClient)
|
||||
: mLayerClient(aLayerClient) {}
|
||||
|
||||
virtual void operator()(nsIntPoint& aScrollOffset, float& aScaleX, float& aScaleY);
|
||||
|
||||
private:
|
||||
AndroidGeckoGLLayerClient& mLayerClient;
|
||||
};
|
||||
|
||||
class AndroidViewTransform : public WrappedJavaObject {
|
||||
public:
|
||||
static void InitViewTransformClass(JNIEnv *jEnv);
|
||||
|
||||
void Init(jobject jobj);
|
||||
|
||||
AndroidViewTransform() {}
|
||||
AndroidViewTransform(jobject jobj) { Init(jobj); }
|
||||
|
||||
float GetX();
|
||||
float GetY();
|
||||
float GetScale();
|
||||
|
||||
private:
|
||||
static jclass jViewTransformClass;
|
||||
static jfieldID jXField;
|
||||
static jfieldID jYField;
|
||||
static jfieldID jScaleField;
|
||||
};
|
||||
|
||||
class AndroidGeckoGLLayerClient : public AndroidGeckoLayerClient {
|
||||
public:
|
||||
static void InitGeckoGLLayerClientClass(JNIEnv *jEnv);
|
||||
|
||||
void Init(jobject jobj);
|
||||
|
||||
AndroidGeckoGLLayerClient() {}
|
||||
AndroidGeckoGLLayerClient(jobject jobj) { Init(jobj); }
|
||||
AndroidGeckoGLLayerClient()
|
||||
: mViewTransformGetter(*this) {}
|
||||
|
||||
AndroidGeckoGLLayerClient(jobject jobj)
|
||||
: mViewTransformGetter(*this) { Init(jobj); }
|
||||
|
||||
void GetViewTransform(AndroidViewTransform& aViewTransform);
|
||||
|
||||
private:
|
||||
static jclass jGeckoGLLayerClientClass;
|
||||
static jmethodID jGetViewTransformMethod;
|
||||
|
||||
AndroidGeckoGLLayerClientViewTransformGetter mViewTransformGetter;
|
||||
};
|
||||
|
||||
class AndroidGeckoSurfaceView : public WrappedJavaObject
|
||||
|
Loading…
Reference in New Issue
Block a user