| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.android_webview; | 5 package org.chromium.android_webview; |
| 6 | 6 |
| 7 import android.graphics.Canvas; | 7 import android.graphics.Canvas; |
| 8 import android.view.ViewGroup; | 8 import android.view.ViewGroup; |
| 9 | 9 |
| 10 import org.chromium.base.annotations.CalledByNative; | 10 import org.chromium.base.annotations.CalledByNative; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 @Override | 29 @Override |
| 30 public void run() { | 30 public void run() { |
| 31 nativeDestroy(mNativeAwGLFunctor); | 31 nativeDestroy(mNativeAwGLFunctor); |
| 32 } | 32 } |
| 33 } | 33 } |
| 34 | 34 |
| 35 private final long mNativeAwGLFunctor; | 35 private final long mNativeAwGLFunctor; |
| 36 // Same gc-life time as this, but does not reference any members like |mCont
ainerView|. | 36 // Same gc-life time as this, but does not reference any members like |mCont
ainerView|. |
| 37 private final Object mLifetimeObject; | 37 private final Object mLifetimeObject; |
| 38 private final CleanupReference mCleanupReference; | 38 private final CleanupReference mCleanupReference; |
| 39 private final AwContents.NativeGLDelegate mNativeGLDelegate; | 39 private final AwContents.NativeDrawGLFunctor mNativeDrawGLFunctor; |
| 40 private final ViewGroup mContainerView; | 40 private final ViewGroup mContainerView; |
| 41 private final Runnable mFunctorReleasedCallback; | 41 private final Runnable mFunctorReleasedCallback; |
| 42 | 42 |
| 43 public AwGLFunctor(AwContents.NativeGLDelegate nativeGLDelegate, ViewGroup c
ontainerView) { | 43 public AwGLFunctor(AwContents.NativeDrawGLFunctorFactory nativeDrawGLFunctor
Factory, |
| 44 ViewGroup containerView) { |
| 44 mNativeAwGLFunctor = nativeCreate(this); | 45 mNativeAwGLFunctor = nativeCreate(this); |
| 45 mLifetimeObject = new Object(); | 46 mLifetimeObject = new Object(); |
| 46 mCleanupReference = | 47 mCleanupReference = |
| 47 new CleanupReference(mLifetimeObject, new DestroyRunnable(mNativ
eAwGLFunctor)); | 48 new CleanupReference(mLifetimeObject, new DestroyRunnable(mNativ
eAwGLFunctor)); |
| 48 mNativeGLDelegate = nativeGLDelegate; | 49 mNativeDrawGLFunctor = nativeDrawGLFunctorFactory.createFunctor(getAwDra
wGLViewContext()); |
| 49 mContainerView = containerView; | 50 mContainerView = containerView; |
| 50 if (mNativeGLDelegate.supportsDrawGLFunctorReleasedCallback()) { | 51 if (mNativeDrawGLFunctor.supportsDrawGLFunctorReleasedCallback()) { |
| 51 mFunctorReleasedCallback = new Runnable() { | 52 mFunctorReleasedCallback = new Runnable() { |
| 52 @Override | 53 @Override |
| 53 public void run() { | 54 public void run() { |
| 54 // Deliberate no-op. This Runnable is holding a strong refer
ence back to the | 55 // Deliberate no-op. This Runnable is holding a strong refer
ence back to the |
| 55 // AwGLFunctor, which serves its purpose for now. | 56 // AwGLFunctor, which serves its purpose for now. |
| 56 } | 57 } |
| 57 }; | 58 }; |
| 58 } else { | 59 } else { |
| 59 mFunctorReleasedCallback = null; | 60 mFunctorReleasedCallback = null; |
| 60 } | 61 } |
| 61 } | 62 } |
| 62 | 63 |
| 63 public static long getAwDrawGLFunction() { | 64 public static long getAwDrawGLFunction() { |
| 64 return nativeGetAwDrawGLFunction(); | 65 return nativeGetAwDrawGLFunction(); |
| 65 } | 66 } |
| 66 | 67 |
| 67 public long getNativeAwGLFunctor() { | 68 public long getNativeAwGLFunctor() { |
| 68 return mNativeAwGLFunctor; | 69 return mNativeAwGLFunctor; |
| 69 } | 70 } |
| 70 | 71 |
| 71 public Object getNativeLifetimeObject() { | 72 public Object getNativeLifetimeObject() { |
| 72 return mLifetimeObject; | 73 return mLifetimeObject; |
| 73 } | 74 } |
| 74 | 75 |
| 75 public boolean requestDrawGLForCanvas(Canvas canvas) { | 76 public boolean requestDrawGLForCanvas(Canvas canvas) { |
| 76 return mNativeGLDelegate.requestDrawGL( | 77 return mNativeDrawGLFunctor.requestDrawGL(canvas, mFunctorReleasedCallba
ck); |
| 77 canvas, false, mContainerView, mFunctorReleasedCallback); | |
| 78 } | 78 } |
| 79 | 79 |
| 80 @CalledByNative | 80 @CalledByNative |
| 81 private boolean requestDrawGL(boolean waitForCompletion) { | 81 private boolean requestInvokeGL(boolean waitForCompletion) { |
| 82 return mNativeGLDelegate.requestDrawGL(null, waitForCompletion, mContain
erView, null); | 82 return mNativeDrawGLFunctor.requestInvokeGL(mContainerView, waitForCompl
etion); |
| 83 } | 83 } |
| 84 | 84 |
| 85 @CalledByNative | 85 @CalledByNative |
| 86 private void detachFunctorFromView() { | 86 private void detachFunctorFromView() { |
| 87 mNativeGLDelegate.detachGLFunctor(); | 87 mNativeDrawGLFunctor.detach(mContainerView); |
| 88 mContainerView.invalidate(); | 88 mContainerView.invalidate(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 public void deleteHardwareRenderer() { | 91 public void deleteHardwareRenderer() { |
| 92 nativeDeleteHardwareRenderer(mNativeAwGLFunctor); | 92 nativeDeleteHardwareRenderer(mNativeAwGLFunctor); |
| 93 } | 93 } |
| 94 | 94 |
| 95 public long getAwDrawGLViewContext() { | 95 public long getAwDrawGLViewContext() { |
| 96 return nativeGetAwDrawGLViewContext(mNativeAwGLFunctor); | 96 return nativeGetAwDrawGLViewContext(mNativeAwGLFunctor); |
| 97 } | 97 } |
| 98 | 98 |
| 99 private native void nativeDeleteHardwareRenderer(long nativeAwGLFunctor); | 99 private native void nativeDeleteHardwareRenderer(long nativeAwGLFunctor); |
| 100 private native long nativeGetAwDrawGLViewContext(long nativeAwGLFunctor); | 100 private native long nativeGetAwDrawGLViewContext(long nativeAwGLFunctor); |
| 101 | 101 |
| 102 private static native long nativeGetAwDrawGLFunction(); | 102 private static native long nativeGetAwDrawGLFunction(); |
| 103 private static native void nativeDestroy(long nativeAwGLFunctor); | 103 private static native void nativeDestroy(long nativeAwGLFunctor); |
| 104 private static native long nativeCreate(AwGLFunctor javaProxy); | 104 private static native long nativeCreate(AwGLFunctor javaProxy); |
| 105 } | 105 } |
| OLD | NEW |