| OLD | NEW |
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 public SurfaceViewRenderer(Context context, AttributeSet attrs) { | 146 public SurfaceViewRenderer(Context context, AttributeSet attrs) { |
| 147 super(context, attrs); | 147 super(context, attrs); |
| 148 getHolder().addCallback(this); | 148 getHolder().addCallback(this); |
| 149 } | 149 } |
| 150 | 150 |
| 151 /** | 151 /** |
| 152 * Initialize this class, sharing resources with |sharedContext|. It is allowe
d to call init() to | 152 * Initialize this class, sharing resources with |sharedContext|. It is allowe
d to call init() to |
| 153 * reinitialize the renderer after a previous init()/release() cycle. | 153 * reinitialize the renderer after a previous init()/release() cycle. |
| 154 */ | 154 */ |
| 155 public void init( | 155 public void init( |
| 156 EGLContext sharedContext, RendererCommon.RendererEvents rendererEvents) { | 156 EglBase.Context sharedContext, RendererCommon.RendererEvents rendererEvent
s) { |
| 157 synchronized (handlerLock) { | 157 synchronized (handlerLock) { |
| 158 if (renderThreadHandler != null) { | 158 if (renderThreadHandler != null) { |
| 159 throw new IllegalStateException(getResourceName() + "Already initialized
"); | 159 throw new IllegalStateException(getResourceName() + "Already initialized
"); |
| 160 } | 160 } |
| 161 Logging.d(TAG, getResourceName() + "Initializing."); | 161 Logging.d(TAG, getResourceName() + "Initializing."); |
| 162 this.rendererEvents = rendererEvents; | 162 this.rendererEvents = rendererEvents; |
| 163 renderThread = new HandlerThread(TAG); | 163 renderThread = new HandlerThread(TAG); |
| 164 renderThread.start(); | 164 renderThread.start(); |
| 165 drawer = new GlRectDrawer(); | 165 drawer = new GlRectDrawer(); |
| 166 eglBase = new EglBase(sharedContext, EglBase.ConfigType.PLAIN); | 166 eglBase = EglBase.create(sharedContext, EglBase.ConfigType.PLAIN); |
| 167 renderThreadHandler = new Handler(renderThread.getLooper()); | 167 renderThreadHandler = new Handler(renderThread.getLooper()); |
| 168 } | 168 } |
| 169 tryCreateEglSurface(); | 169 tryCreateEglSurface(); |
| 170 } | 170 } |
| 171 | 171 |
| 172 @Deprecated |
| 173 // TODO(perkj): Remove when applications has been updated. |
| 174 public void init( |
| 175 EGLContext sharedContext, RendererCommon.RendererEvents rendererEvents) { |
| 176 init(sharedContext != null ? new EglBase.Context(sharedContext) : null, rend
ererEvents); |
| 177 } |
| 178 |
| 172 /** | 179 /** |
| 173 * Create and make an EGLSurface current if both init() and surfaceCreated() h
ave been called. | 180 * Create and make an EGLSurface current if both init() and surfaceCreated() h
ave been called. |
| 174 */ | 181 */ |
| 175 public void tryCreateEglSurface() { | 182 public void tryCreateEglSurface() { |
| 176 // |renderThreadHandler| is only created after |eglBase| is created in init(
), so the | 183 // |renderThreadHandler| is only created after |eglBase| is created in init(
), so the |
| 177 // following code will only execute if eglBase != null. | 184 // following code will only execute if eglBase != null. |
| 178 runOnRenderThread(new Runnable() { | 185 runOnRenderThread(new Runnable() { |
| 179 @Override public void run() { | 186 @Override public void run() { |
| 180 synchronized (layoutLock) { | 187 synchronized (layoutLock) { |
| 181 if (isSurfaceCreated && !eglBase.hasSurface()) { | 188 if (isSurfaceCreated && !eglBase.hasSurface()) { |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 } | 560 } |
| 554 } | 561 } |
| 555 | 562 |
| 556 private void logStatistics() { | 563 private void logStatistics() { |
| 557 synchronized (statisticsLock) { | 564 synchronized (statisticsLock) { |
| 558 Logging.d(TAG, getResourceName() + "Frames received: " | 565 Logging.d(TAG, getResourceName() + "Frames received: " |
| 559 + framesReceived + ". Dropped: " + framesDropped + ". Rendered: " + fr
amesRendered); | 566 + framesReceived + ". Dropped: " + framesDropped + ". Rendered: " + fr
amesRendered); |
| 560 if (framesReceived > 0 && framesRendered > 0) { | 567 if (framesReceived > 0 && framesRendered > 0) { |
| 561 final long timeSinceFirstFrameNs = System.nanoTime() - firstFrameTimeNs; | 568 final long timeSinceFirstFrameNs = System.nanoTime() - firstFrameTimeNs; |
| 562 Logging.d(TAG, getResourceName() + "Duration: " + (int) (timeSinceFirstF
rameNs / 1e6) + | 569 Logging.d(TAG, getResourceName() + "Duration: " + (int) (timeSinceFirstF
rameNs / 1e6) + |
| 563 " ms. FPS: " + (float) framesRendered * 1e9 / timeSinceFirstFrameNs)
; | 570 " ms. FPS: " + framesRendered * 1e9 / timeSinceFirstFrameNs); |
| 564 Logging.d(TAG, getResourceName() + "Average render time: " | 571 Logging.d(TAG, getResourceName() + "Average render time: " |
| 565 + (int) (renderTimeNs / (1000 * framesRendered)) + " us."); | 572 + (int) (renderTimeNs / (1000 * framesRendered)) + " us."); |
| 566 } | 573 } |
| 567 } | 574 } |
| 568 } | 575 } |
| 569 } | 576 } |
| OLD | NEW |