EMMA Coverage Report (generated Fri Aug 23 16:39:17 PDT 2013)
[all classes][org.chromium.content.browser]

COVERAGE SUMMARY FOR SOURCE FILE [ContentViewRenderView.java]

nameclass, %method, %block, %line, %
ContentViewRenderView.java100% (3/3)91%  (20/22)85%  (248/293)85%  (48.4/57)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ContentViewRenderView100% (1/1)83%  (10/12)82%  (120/146)77%  (20/26)
destroy (): void 0%   (0/1)0%   (0/14)0%   (0/4)
onReadyToRender (): void 0%   (0/1)0%   (0/1)0%   (0/1)
<static initializer> 100% (1/1)75%  (6/8)75%  (0.8/1)
setCurrentContentView (ContentView): void 100% (1/1)89%  (31/35)94%  (6.6/7)
isInitialized (): boolean 100% (1/1)89%  (8/9)88%  (0.9/1)
ContentViewRenderView (Context): void 100% (1/1)92%  (49/53)98%  (9.8/10)
access$000 (ContentViewRenderView): int 100% (1/1)100% (3/3)100% (1/1)
access$100 (ContentViewRenderView, int, int, int): void 100% (1/1)100% (6/6)100% (1/1)
access$200 (ContentViewRenderView): ContentView 100% (1/1)100% (3/3)100% (1/1)
access$300 (ContentViewRenderView, int, Surface): void 100% (1/1)100% (5/5)100% (1/1)
access$400 (ContentViewRenderView, int): void 100% (1/1)100% (4/4)100% (1/1)
createSurfaceView (Context): SurfaceView 100% (1/1)100% (5/5)100% (1/1)
     
class ContentViewRenderView$1100% (1/1)100% (5/5)83%  (69/83)90%  (11.6/13)
<static initializer> 100% (1/1)75%  (6/8)75%  (0.8/1)
surfaceDestroyed (SurfaceHolder): void 100% (1/1)76%  (13/17)87%  (2.6/3)
surfaceCreated (SurfaceHolder): void 100% (1/1)82%  (18/22)90%  (3.6/4)
surfaceChanged (SurfaceHolder, int, int, int): void 100% (1/1)87%  (26/30)92%  (4.6/5)
ContentViewRenderView$1 (ContentViewRenderView): void 100% (1/1)100% (6/6)100% (1/1)
     
class ContentViewRenderView$VSyncAdapter100% (1/1)100% (5/5)92%  (59/64)93%  (17.8/19)
onVSync (VSyncMonitor, long): void 100% (1/1)83%  (25/30)84%  (6.8/8)
ContentViewRenderView$VSyncAdapter (Context): void 100% (1/1)100% (10/10)100% (3/3)
registerVSyncListener (VSyncManager$Listener): void 100% (1/1)100% (10/10)100% (3/3)
setVSyncListener (VSyncManager$Listener): void 100% (1/1)100% (10/10)100% (3/3)
unregisterVSyncListener (VSyncManager$Listener): void 100% (1/1)100% (4/4)100% (2/2)

1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4 
5package org.chromium.content.browser;
6 
7import android.content.Context;
8import android.os.Build;
9import android.view.Surface;
10import android.view.SurfaceView;
11import android.view.SurfaceHolder;
12import android.widget.FrameLayout;
13 
14import org.chromium.base.JNINamespace;
15 
16/***
17 * This view is used by a ContentView to render its content.
18 * Call {@link #setCurrentContentView(ContentView)} with the contentView that should be displayed.
19 * Note that only one ContentView can be shown at a time.
20 */
21@JNINamespace("content")
22public class ContentViewRenderView extends FrameLayout {
23 
24    // The native side of this object.
25    private int mNativeContentViewRenderView = 0;
26    private final SurfaceHolder.Callback mSurfaceCallback;
27 
28    private SurfaceView mSurfaceView;
29    private VSyncAdapter mVSyncAdapter;
30 
31    private ContentView mCurrentContentView;
32 
33    /**
34     * Constructs a new ContentViewRenderView that should be can to a view hierarchy.
35     * Native code should add/remove the layers to be rendered through the ContentViewLayerRenderer.
36     * @param context The context used to create this.
37     */
38    public ContentViewRenderView(Context context) {
39        super(context);
40 
41        mNativeContentViewRenderView = nativeInit();
42        assert mNativeContentViewRenderView != 0;
43 
44        mSurfaceView = createSurfaceView(getContext());
45        mSurfaceCallback = new SurfaceHolder.Callback() {
46            @Override
47            public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
48                assert mNativeContentViewRenderView != 0;
49                nativeSurfaceSetSize(mNativeContentViewRenderView, width, height);
50                if (mCurrentContentView != null) {
51                    mCurrentContentView.getContentViewCore().onPhysicalBackingSizeChanged(
52                            width, height);
53                }
54            }
55 
56            @Override
57            public void surfaceCreated(SurfaceHolder holder) {
58                assert mNativeContentViewRenderView != 0;
59                nativeSurfaceCreated(mNativeContentViewRenderView, holder.getSurface());
60                onReadyToRender();
61            }
62 
63            @Override
64            public void surfaceDestroyed(SurfaceHolder holder) {
65                assert mNativeContentViewRenderView != 0;
66                nativeSurfaceDestroyed(mNativeContentViewRenderView);
67            }
68        };
69        mSurfaceView.getHolder().addCallback(mSurfaceCallback);
70 
71        mVSyncAdapter = new VSyncAdapter(getContext());
72        addView(mSurfaceView,
73                new FrameLayout.LayoutParams(
74                        FrameLayout.LayoutParams.MATCH_PARENT,
75                        FrameLayout.LayoutParams.MATCH_PARENT));
76    }
77 
78    private static class VSyncAdapter implements VSyncManager.Provider, VSyncMonitor.Listener {
79        private final VSyncMonitor mVSyncMonitor;
80        private boolean mVSyncNotificationEnabled;
81        private VSyncManager.Listener mVSyncListener;
82 
83        // The VSyncMonitor gives the timebase for the actual vsync, but we don't want render until
84        // we have had a chance for input events to propagate to the compositor thread. This takes
85        // 3 ms typically, so we adjust the vsync timestamps forward by a bit to give input events a
86        // chance to arrive.
87        private static final long INPUT_EVENT_LAG_FROM_VSYNC_MICROSECONDS = 3200;
88 
89        VSyncAdapter(Context context) {
90            mVSyncMonitor = new VSyncMonitor(context, this);
91        }
92 
93        @Override
94        public void onVSync(VSyncMonitor monitor, long vsyncTimeMicros) {
95            if (mVSyncListener == null) return;
96            if (mVSyncNotificationEnabled) {
97                mVSyncListener.onVSync(vsyncTimeMicros);
98                mVSyncMonitor.requestUpdate();
99            } else {
100                // Compensate for input event lag. Input events are delivered immediately on
101                // pre-JB releases, so this adjustment is only done for later versions.
102                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
103                    vsyncTimeMicros += INPUT_EVENT_LAG_FROM_VSYNC_MICROSECONDS;
104                }
105                mVSyncListener.updateVSync(vsyncTimeMicros,
106                        mVSyncMonitor.getVSyncPeriodInMicroseconds());
107            }
108        }
109 
110        @Override
111        public void registerVSyncListener(VSyncManager.Listener listener) {
112            if (!mVSyncNotificationEnabled) mVSyncMonitor.requestUpdate();
113            mVSyncNotificationEnabled = true;
114        }
115 
116        @Override
117        public void unregisterVSyncListener(VSyncManager.Listener listener) {
118            mVSyncNotificationEnabled = false;
119        }
120 
121        void setVSyncListener(VSyncManager.Listener listener) {
122            mVSyncListener = listener;
123            if (mVSyncListener != null) mVSyncMonitor.requestUpdate();
124        }
125    }
126 
127    /**
128     * Should be called when the ContentViewRenderView is not needed anymore so its associated
129     * native resource can be freed.
130     */
131    public void destroy() {
132        mSurfaceView.getHolder().removeCallback(mSurfaceCallback);
133        nativeDestroy(mNativeContentViewRenderView);
134        mNativeContentViewRenderView = 0;
135    }
136 
137    /**
138     * Makes the passed ContentView the one displayed by this ContentViewRenderView.
139     */
140    public void setCurrentContentView(ContentView contentView) {
141        assert mNativeContentViewRenderView != 0;
142        ContentViewCore contentViewCore = contentView.getContentViewCore();
143        nativeSetCurrentContentView(mNativeContentViewRenderView,
144                contentViewCore.getNativeContentViewCore());
145 
146        mCurrentContentView = contentView;
147        contentViewCore.onPhysicalBackingSizeChanged(getWidth(), getHeight());
148        mVSyncAdapter.setVSyncListener(contentViewCore.getVSyncListener(mVSyncAdapter));
149    }
150 
151    /**
152     * This method should be subclassed to provide actions to be performed once the view is ready to
153     * render.
154     */
155    protected void onReadyToRender() {
156    }
157 
158    /**
159     * This method could be subclassed optionally to provide a custom SurfaceView object to
160     * this ContentViewRenderView.
161     * @param context The context used to create the SurfaceView object.
162     * @return The created SurfaceView object.
163     */
164    protected SurfaceView createSurfaceView(Context context) {
165        return new SurfaceView(context);
166    }
167 
168    /**
169     * @return whether the surface view is initialized and ready to render.
170     */
171    public boolean isInitialized() {
172        return mSurfaceView.getHolder().getSurface() != null;
173    }
174 
175    private static native int nativeInit();
176    private native void nativeDestroy(int nativeContentViewRenderView);
177    private native void nativeSetCurrentContentView(int nativeContentViewRenderView,
178            int nativeContentView);
179    private native void nativeSurfaceCreated(int nativeContentViewRenderView, Surface surface);
180    private native void nativeSurfaceDestroyed(int nativeContentViewRenderView);
181    private native void nativeSurfaceSetSize(int nativeContentViewRenderView,
182            int width, int height);
183}

[all classes][org.chromium.content.browser]
EMMA 2.0.5312 (C) Vladimir Roubtsov