Commit 19a1b4cb authored by ckitagawa's avatar ckitagawa Committed by Commit Bot

[Paint Preview] Reduce Memory Overcommit

Use slightly wider tiles, but request fewer at a time. This should
reduce memory overcommit. On low mem devices don't request more than 1
tile at a time.

Bug: 1144768
Change-Id: I115524c5a226487675d040d37865e0a858abf28c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2546964Reviewed-by: default avatarMehran Mahmoudi <mahmoudi@chromium.org>
Commit-Queue: Calder Kitagawa <ckitagawa@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828823}
parent cc2d2c93
......@@ -11,6 +11,7 @@ import android.text.TextUtils;
import androidx.annotation.NonNull;
import org.chromium.base.Callback;
import org.chromium.base.SysUtils;
import org.chromium.base.UnguessableToken;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
......@@ -27,6 +28,8 @@ import java.util.List;
*/
@JNINamespace("paint_preview")
class PlayerCompositorDelegateImpl implements PlayerCompositorDelegate {
private static final int LOW_MEMORY_THRESHOLD_KB = 2048;
private CompositorListener mCompositorListener;
private long mNativePlayerCompositorDelegate;
private List<Runnable> mMemoryPressureListeners = new ArrayList<>();
......@@ -38,7 +41,8 @@ class PlayerCompositorDelegateImpl implements PlayerCompositorDelegate {
if (service != null && service.getNativeService() != 0) {
mNativePlayerCompositorDelegate = PlayerCompositorDelegateImplJni.get().initialize(this,
service.getNativeService(), url.getSpec(), directoryKey,
compositorErrorCallback);
compositorErrorCallback,
SysUtils.amountOfPhysicalMemoryKB() < LOW_MEMORY_THRESHOLD_KB);
}
// TODO(crbug.com/1021590): Handle initialization errors when
// mNativePlayerCompositorDelegate == 0.
......@@ -132,7 +136,8 @@ class PlayerCompositorDelegateImpl implements PlayerCompositorDelegate {
@NativeMethods
interface Natives {
long initialize(PlayerCompositorDelegateImpl caller, long nativePaintPreviewBaseService,
String urlSpec, String directoryKey, Callback<Integer> compositorErrorCallback);
String urlSpec, String directoryKey, Callback<Integer> compositorErrorCallback,
boolean isLowMemory);
void destroy(long nativePlayerCompositorDelegateAndroid);
int requestBitmap(long nativePlayerCompositorDelegateAndroid, UnguessableToken frameGuid,
Callback<Bitmap> bitmapCallback, Runnable errorCallback, float scaleFactor,
......
......@@ -74,10 +74,9 @@ public class PlayerFrameBitmapStateController {
(mLoadingBitmapState == null) ? mVisibleBitmapState : mLoadingBitmapState;
if (scaleUpdated || activeLoadingState == null) {
invalidateLoadingBitmaps();
mLoadingBitmapState =
new PlayerFrameBitmapState(mGuid, Math.round(mViewport.getWidth() / 2.0f),
Math.round(mViewport.getHeight() / 2.0f), mViewport.getScale(),
mContentSize, mCompositorDelegate, this, mTaskRunner);
mLoadingBitmapState = new PlayerFrameBitmapState(mGuid, mViewport.getWidth(),
Math.round(mViewport.getHeight() / 2.0f), mViewport.getScale(), mContentSize,
mCompositorDelegate, this, mTaskRunner);
if (mVisibleBitmapState == null) {
mLoadingBitmapState.skipWaitingForVisibleBitmaps();
swap(mLoadingBitmapState);
......
......@@ -32,7 +32,8 @@ namespace paint_preview {
namespace {
// To minimize peak memory usage limit the number of concurrent bitmap requests.
constexpr size_t kMaxParallelBitmapRequests = 6;
constexpr size_t kMaxParallelBitmapRequests = 3;
constexpr size_t kMaxParallelBitmapRequestsLowMemory = 1;
ScopedJavaLocalRef<jobjectArray> ToJavaUnguessableTokenArray(
JNIEnv* env,
......@@ -65,12 +66,14 @@ jlong JNI_PlayerCompositorDelegateImpl_Initialize(
jlong paint_preview_service,
const JavaParamRef<jstring>& j_url_spec,
const JavaParamRef<jstring>& j_directory_key,
const JavaParamRef<jobject>& j_compositor_error_callback) {
const JavaParamRef<jobject>& j_compositor_error_callback,
jboolean j_is_low_mem) {
PlayerCompositorDelegateAndroid* delegate =
new PlayerCompositorDelegateAndroid(
env, j_object,
reinterpret_cast<PaintPreviewBaseService*>(paint_preview_service),
j_url_spec, j_directory_key, j_compositor_error_callback);
j_url_spec, j_directory_key, j_compositor_error_callback,
j_is_low_mem);
return reinterpret_cast<intptr_t>(delegate);
}
......@@ -80,7 +83,8 @@ PlayerCompositorDelegateAndroid::PlayerCompositorDelegateAndroid(
PaintPreviewBaseService* paint_preview_service,
const JavaParamRef<jstring>& j_url_spec,
const JavaParamRef<jstring>& j_directory_key,
const JavaParamRef<jobject>& j_compositor_error_callback)
const JavaParamRef<jobject>& j_compositor_error_callback,
jboolean j_is_low_mem)
: PlayerCompositorDelegate(),
request_id_(0),
startup_timestamp_(base::TimeTicks::Now()) {
......@@ -91,7 +95,9 @@ PlayerCompositorDelegateAndroid::PlayerCompositorDelegateAndroid(
base::android::ConvertJavaStringToUTF8(env, j_directory_key)},
base::BindOnce(&base::android::RunIntCallbackAndroid,
ScopedJavaGlobalRef<jobject>(j_compositor_error_callback)),
base::TimeDelta::FromSeconds(15), kMaxParallelBitmapRequests);
base::TimeDelta::FromSeconds(15),
(static_cast<bool>(j_is_low_mem) ? kMaxParallelBitmapRequestsLowMemory
: kMaxParallelBitmapRequests));
java_ref_.Reset(env, j_object);
}
......
......@@ -23,7 +23,8 @@ class PlayerCompositorDelegateAndroid : public PlayerCompositorDelegate {
PaintPreviewBaseService* paint_preview_service,
const base::android::JavaParamRef<jstring>& j_url_spec,
const base::android::JavaParamRef<jstring>& j_directory_key,
const base::android::JavaParamRef<jobject>& j_compositor_error_callback);
const base::android::JavaParamRef<jobject>& j_compositor_error_callback,
jboolean j_is_low_mem);
void OnCompositorReady(
CompositorStatus compositor_status,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment