Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: blimp/client/app/android/java/src/org/chromium/blimp/BlimpView.java

Issue 2266863003: blimp: Move BlimpCompositor to use delegated rendering. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tests work. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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.blimp; 5 package org.chromium.blimp;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.graphics.Color; 8 import android.graphics.Color;
9 import android.graphics.Point; 9 import android.graphics.Point;
10 import android.os.Build; 10 import android.os.Build;
11 import android.util.AttributeSet; 11 import android.util.AttributeSet;
12 import android.view.MotionEvent; 12 import android.view.MotionEvent;
13 import android.view.Surface; 13 import android.view.Surface;
14 import android.view.SurfaceHolder; 14 import android.view.SurfaceHolder;
15 import android.view.SurfaceView; 15 import android.view.SurfaceView;
16 import android.view.View;
16 import android.view.WindowManager; 17 import android.view.WindowManager;
17 18
18 import org.chromium.base.annotations.CalledByNative; 19 import org.chromium.base.annotations.CalledByNative;
19 import org.chromium.base.annotations.JNINamespace; 20 import org.chromium.base.annotations.JNINamespace;
20 import org.chromium.blimp.session.BlimpClientSession; 21 import org.chromium.blimp.session.BlimpClientSession;
21 import org.chromium.ui.UiUtils; 22 import org.chromium.ui.UiUtils;
22 23
23 /** 24 /**
24 * A {@link View} that will visually represent the Blimp rendered content. This {@link View} starts 25 * A {@link View} that will visually represent the Blimp rendered content. This {@link View} starts
25 * a native compositor. 26 * a native compositor.
26 */ 27 */
27 @JNINamespace("blimp::client") 28 @JNINamespace("blimp::client")
28 public class BlimpView extends SurfaceView implements SurfaceHolder.Callback { 29 public class BlimpView
30 extends SurfaceView implements SurfaceHolder.Callback, View.OnLayoutChan geListener {
29 private long mNativeBlimpViewPtr; 31 private long mNativeBlimpViewPtr;
30 32
31 /** 33 /**
32 * Builds a new {@link BlimpView}. 34 * Builds a new {@link BlimpView}.
33 * @param context A {@link Context} instance. 35 * @param context A {@link Context} instance.
34 * @param attrs An {@link AttributeSet} instance. 36 * @param attrs An {@link AttributeSet} instance.
35 */ 37 */
36 public BlimpView(Context context, AttributeSet attrs) { 38 public BlimpView(Context context, AttributeSet attrs) {
37 super(context, attrs); 39 super(context, attrs);
38 setFocusable(true); 40 setFocusable(true);
39 setFocusableInTouchMode(true); 41 setFocusableInTouchMode(true);
42 addOnLayoutChangeListener(this);
40 } 43 }
41 44
42 /** 45 /**
43 * Starts up rendering for this {@link View}. This will start up the native compositor and will 46 * Starts up rendering for this {@link View}. This will start up the native compositor and will
44 * display it's contents. 47 * display it's contents.
45 * @param blimpClientSession The {@link BlimpClientSession} that contains th e content-lite 48 * @param blimpClientSession The {@link BlimpClientSession} that contains th e content-lite
46 * features required by the native components of t he compositor. 49 * features required by the native components of t he compositor.
47 */ 50 */
48 public void initializeRenderer(BlimpClientSession blimpClientSession) { 51 public void initializeRenderer(BlimpClientSession blimpClientSession) {
49 assert mNativeBlimpViewPtr == 0; 52 assert mNativeBlimpViewPtr == 0;
(...skipping 19 matching lines...) Expand all
69 * should not be used after this. 72 * should not be used after this.
70 */ 73 */
71 public void destroyRenderer() { 74 public void destroyRenderer() {
72 getHolder().removeCallback(this); 75 getHolder().removeCallback(this);
73 if (mNativeBlimpViewPtr != 0) { 76 if (mNativeBlimpViewPtr != 0) {
74 nativeDestroy(mNativeBlimpViewPtr); 77 nativeDestroy(mNativeBlimpViewPtr);
75 mNativeBlimpViewPtr = 0; 78 mNativeBlimpViewPtr = 0;
76 } 79 }
77 } 80 }
78 81
79 /** 82 // View.OnLayoutChangeListener implementation.
80 * Triggers a redraw of the native compositor, pushing a new frame. 83 @Override
81 */ 84 public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
82 public void setNeedsComposite() { 85 int oldTop, int oldRight, int oldBottom) {
83 if (mNativeBlimpViewPtr == 0) return; 86 if (mNativeBlimpViewPtr == 0) return;
84 nativeSetNeedsComposite(mNativeBlimpViewPtr); 87 nativeOnContentAreaSizeChanged(mNativeBlimpViewPtr, right - left, bottom - top,
85 } 88 getContext().getResources().getDisplayMetrics().density);
86
87 /**
88 * Toggles whether or not the native compositor draws to this {@link View} o r not.
89 * @param visible Whether or not the compositor should draw or not.
90 */
91 public void setCompositorVisibility(boolean visible) {
92 if (mNativeBlimpViewPtr == 0) return;
93 nativeSetVisibility(mNativeBlimpViewPtr, visible);
94 } 89 }
95 90
96 // View overrides. 91 // View overrides.
97 @Override 92 @Override
98 public boolean onTouchEvent(MotionEvent event) { 93 public boolean onTouchEvent(MotionEvent event) {
99 if (mNativeBlimpViewPtr == 0) return false; 94 if (mNativeBlimpViewPtr == 0) return false;
100 95
101 int eventAction = event.getActionMasked(); 96 int eventAction = event.getActionMasked();
102 97
103 // Close the IME. It might be open for typing URL into toolbar. 98 // Close the IME. It might be open for typing URL into toolbar.
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 public void onSwapBuffersCompleted() { 179 public void onSwapBuffersCompleted() {
185 if (getBackground() == null) return; 180 if (getBackground() == null) return;
186 181
187 setBackgroundResource(0); 182 setBackgroundResource(0);
188 } 183 }
189 184
190 // Native Methods 185 // Native Methods
191 private native long nativeInit(BlimpClientSession blimpClientSession, int ph ysicalWidth, 186 private native long nativeInit(BlimpClientSession blimpClientSession, int ph ysicalWidth,
192 int physicalHeight, int displayWidth, int displayHeight, float dpToP ixel); 187 int physicalHeight, int displayWidth, int displayHeight, float dpToP ixel);
193 private native void nativeDestroy(long nativeBlimpView); 188 private native void nativeDestroy(long nativeBlimpView);
194 private native void nativeSetNeedsComposite(long nativeBlimpView); 189 private native void nativeOnContentAreaSizeChanged(
190 long nativeBlimpView, int width, int height, float dpToPx);
195 private native void nativeOnSurfaceChanged( 191 private native void nativeOnSurfaceChanged(
196 long nativeBlimpView, int format, int width, int height, Surface sur face); 192 long nativeBlimpView, int format, int width, int height, Surface sur face);
197 private native void nativeOnSurfaceCreated(long nativeBlimpView); 193 private native void nativeOnSurfaceCreated(long nativeBlimpView);
198 private native void nativeOnSurfaceDestroyed(long nativeBlimpView); 194 private native void nativeOnSurfaceDestroyed(long nativeBlimpView);
199 private native void nativeSetVisibility(long nativeBlimpView, boolean visibl e);
200 private native boolean nativeOnTouchEvent( 195 private native boolean nativeOnTouchEvent(
201 long nativeBlimpView, MotionEvent event, 196 long nativeBlimpView, MotionEvent event,
202 long timeMs, int action, int pointerCount, int historySize, int acti onIndex, 197 long timeMs, int action, int pointerCount, int historySize, int acti onIndex,
203 float x0, float y0, float x1, float y1, 198 float x0, float y0, float x1, float y1,
204 int pointerId0, int pointerId1, 199 int pointerId0, int pointerId1,
205 float touchMajor0, float touchMajor1, 200 float touchMajor0, float touchMajor1,
206 float touchMinor0, float touchMinor1, 201 float touchMinor0, float touchMinor1,
207 float orientation0, float orientation1, 202 float orientation0, float orientation1,
208 float tilt0, float tilt1, 203 float tilt0, float tilt1,
209 float rawX, float rawY, 204 float rawX, float rawY,
210 int androidToolType0, int androidToolType1, 205 int androidToolType0, int androidToolType1,
211 int androidButtonState, int androidMetaState); 206 int androidButtonState, int androidMetaState);
212 } 207 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698