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

Side by Side Diff: talk/app/webrtc/java/android/org/webrtc/EglBase.java

Issue 1461083002: Use EGL14 if supported on Android (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Changed VideoRendererGui to return an EglBase.Context. Created 5 years 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 /* 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 16 matching lines...) Expand all
27 27
28 package org.webrtc; 28 package org.webrtc;
29 29
30 import android.graphics.Canvas; 30 import android.graphics.Canvas;
31 import android.graphics.SurfaceTexture; 31 import android.graphics.SurfaceTexture;
32 import android.graphics.Rect; 32 import android.graphics.Rect;
33 import android.view.Surface; 33 import android.view.Surface;
34 import android.view.SurfaceHolder; 34 import android.view.SurfaceHolder;
35 35
36 import org.webrtc.Logging; 36 import org.webrtc.Logging;
37 import org.webrtc.EglBase.ConfigType;
38 import org.webrtc.EglBase.Context;
37 39
38 import javax.microedition.khronos.egl.EGL10; 40 import javax.microedition.khronos.egl.EGL10;
39 import javax.microedition.khronos.egl.EGLConfig; 41 import javax.microedition.khronos.egl.EGLConfig;
40 import javax.microedition.khronos.egl.EGLContext; 42 import javax.microedition.khronos.egl.EGLContext;
41 import javax.microedition.khronos.egl.EGLDisplay; 43 import javax.microedition.khronos.egl.EGLDisplay;
42 import javax.microedition.khronos.egl.EGLSurface; 44 import javax.microedition.khronos.egl.EGLSurface;
43 45
44 /** 46 /**
45 * Holds EGL state and utility methods for handling an EGLContext, an EGLDisplay , and an EGLSurface. 47 * Holds EGL state and utility methods for handling an egl 1.0 EGLContext, an EG LDisplay,
48 * and an EGLSurface.
46 */ 49 */
47 public class EglBase { 50 public class EglBase {
48 private static final String TAG = "EglBase"; 51 private static final String TAG = "EglBase";
49 // These constants are taken from EGL14.EGL_OPENGL_ES2_BIT and EGL14.EGL_CONTE XT_CLIENT_VERSION. 52 // These constants are taken from EGL14.EGL_OPENGL_ES2_BIT and EGL14.EGL_CONTE XT_CLIENT_VERSION.
50 // https://android.googlesource.com/platform/frameworks/base/+/master/opengl/j ava/android/opengl/EGL14.java 53 // https://android.googlesource.com/platform/frameworks/base/+/master/opengl/j ava/android/opengl/EGL14.java
51 // This is similar to how GlSurfaceView does: 54 // This is similar to how GlSurfaceView does:
52 // http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.androi d/android/5.1.1_r1/android/opengl/GLSurfaceView.java#760 55 // http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.androi d/android/5.1.1_r1/android/opengl/GLSurfaceView.java#760
53 private static final int EGL_OPENGL_ES2_BIT = 4; 56 private static final int EGL_OPENGL_ES2_BIT = 4;
54 private static final int EGL_CONTEXT_CLIENT_VERSION = 0x3098; 57 private static final int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
55 // Android-specific extension. 58 // Android-specific extension.
56 private static final int EGL_RECORDABLE_ANDROID = 0x3142; 59 private static final int EGL_RECORDABLE_ANDROID = 0x3142;
57 60
58 private final EGL10 egl; 61 private final EGL10 egl;
59 private EGLContext eglContext; 62 private EGLContext eglContext;
60 private ConfigType configType; 63 private ConfigType configType;
61 private EGLConfig eglConfig; 64 private EGLConfig eglConfig;
62 private EGLDisplay eglDisplay; 65 private EGLDisplay eglDisplay;
63 private EGLSurface eglSurface = EGL10.EGL_NO_SURFACE; 66 private EGLSurface eglSurface = EGL10.EGL_NO_SURFACE;
64 67
68 // EGL wrapper for an actual EGLContext.
69 public static class Context {
70 private final EGLContext eglContext;
71
72 public Context(EGLContext eglContext) {
73 this.eglContext = eglContext;
74 }
75 }
76
65 // EGLConfig constructor type. Influences eglChooseConfig arguments. 77 // EGLConfig constructor type. Influences eglChooseConfig arguments.
66 public static enum ConfigType { 78 public static enum ConfigType {
67 // No special parameters. 79 // No special parameters.
68 PLAIN, 80 PLAIN,
69 // Configures with EGL_SURFACE_TYPE = EGL_PBUFFER_BIT. 81 // Configures with EGL_SURFACE_TYPE = EGL_PBUFFER_BIT.
70 PIXEL_BUFFER, 82 PIXEL_BUFFER,
71 // Configures with EGL_RECORDABLE_ANDROID = 1. 83 // Configures with EGL_RECORDABLE_ANDROID = 1.
72 // Discourages EGL from using pixel formats that cannot efficiently be 84 // Discourages EGL from using pixel formats that cannot efficiently be
73 // converted to something usable by the video encoder. 85 // converted to something usable by the video encoder.
74 RECORDABLE 86 RECORDABLE
75 } 87 }
76 88
77 // Create root context without any EGLSurface or parent EGLContext. This can b e used for branching 89 // Create a new context with the specified config type, sharing data with shar edContext.
90 // |sharedContext| can be null.
91 public static EglBase create(Context sharedContext, ConfigType configType) {
92 return (EglBase14.isEGL14Supported()
93 && (sharedContext == null || sharedContext instanceof EglBase14.Context) )
94 ? new EglBase14((EglBase14.Context) sharedContext, configType)
95 : new EglBase(sharedContext, configType);
96 }
97
98 public static EglBase create() {
99 return create(null, ConfigType.PLAIN);
100 }
101
102 //Create root context without any EGLSurface or parent EGLContext. This can be used for branching
78 // new contexts that share data. 103 // new contexts that share data.
104 @Deprecated
79 public EglBase() { 105 public EglBase() {
80 this(EGL10.EGL_NO_CONTEXT, ConfigType.PLAIN); 106 this((Context) null, ConfigType.PLAIN);
107 }
108
109 @Deprecated
110 public EglBase(EGLContext sharedContext, ConfigType configType) {
111 this(new Context(sharedContext), configType);
112 Logging.d(TAG, "EglBase created");
113 }
114
115 @Deprecated
116 public EGLContext getContext() {
117 return eglContext;
81 } 118 }
82 119
83 // Create a new context with the specified config type, sharing data with shar edContext. 120 // Create a new context with the specified config type, sharing data with shar edContext.
84 public EglBase(EGLContext sharedContext, ConfigType configType) { 121 EglBase(Context sharedContext, ConfigType configType) {
85 this.egl = (EGL10) EGLContext.getEGL(); 122 this.egl = (EGL10) EGLContext.getEGL();
86 this.configType = configType; 123 this.configType = configType;
87 eglDisplay = getEglDisplay(); 124 eglDisplay = getEglDisplay();
88 eglConfig = getEglConfig(eglDisplay, configType); 125 eglConfig = getEglConfig(eglDisplay, configType);
89 eglContext = createEglContext(sharedContext, eglDisplay, eglConfig); 126 eglContext = createEglContext(sharedContext, eglDisplay, eglConfig);
90 } 127 }
91 128
92 // Create EGLSurface from the Android Surface. 129 // TODO(perkj): This is a hacky ctor used to allow us to create an EGLBase14. Remove this and
130 // make EglBase an abstract class once all applications have started using the create factory
131 // method.
132 protected EglBase(boolean dummy) {
133 this.egl = null;
134 }
135
93 public void createSurface(Surface surface) { 136 public void createSurface(Surface surface) {
94 /** 137 /**
95 * We have to wrap Surface in a SurfaceHolder because for some reason eglCre ateWindowSurface 138 * We have to wrap Surface in a SurfaceHolder because for some reason eglCre ateWindowSurface
96 * couldn't actually take a Surface object until API 17. Older versions fort unately just call 139 * couldn't actually take a Surface object until API 17. Older versions fort unately just call
97 * SurfaceHolder.getSurface(), so we'll do that. No other methods are releva nt. 140 * SurfaceHolder.getSurface(), so we'll do that. No other methods are releva nt.
98 */ 141 */
99 class FakeSurfaceHolder implements SurfaceHolder { 142 class FakeSurfaceHolder implements SurfaceHolder {
100 private final Surface surface; 143 private final Surface surface;
101 144
102 FakeSurfaceHolder(Surface surface) { 145 FakeSurfaceHolder(Surface surface) {
103 this.surface = surface; 146 this.surface = surface;
104 } 147 }
105 148
106 @Override 149 @Override
107 public void addCallback(Callback callback) {} 150 public void addCallback(Callback callback) {}
108 151
109 @Override 152 @Override
110 public void removeCallback(Callback callback) {} 153 public void removeCallback(Callback callback) {}
111 154
112 @Override 155 @Override
113 public boolean isCreating() { 156 public boolean isCreating() {
114 return false; 157 return false;
115 } 158 }
116 159
160 @Deprecated
117 @Override 161 @Override
118 public void setType(int i) {} 162 public void setType(int i) {}
119 163
120 @Override 164 @Override
121 public void setFixedSize(int i, int i2) {} 165 public void setFixedSize(int i, int i2) {}
122 166
123 @Override 167 @Override
124 public void setSizeFromLayout() {} 168 public void setSizeFromLayout() {}
125 169
126 @Override 170 @Override
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 if (eglSurface != EGL10.EGL_NO_SURFACE) { 238 if (eglSurface != EGL10.EGL_NO_SURFACE) {
195 throw new RuntimeException("Already has an EGLSurface"); 239 throw new RuntimeException("Already has an EGLSurface");
196 } 240 }
197 int[] surfaceAttribs = {EGL10.EGL_WIDTH, width, EGL10.EGL_HEIGHT, height, EG L10.EGL_NONE}; 241 int[] surfaceAttribs = {EGL10.EGL_WIDTH, width, EGL10.EGL_HEIGHT, height, EG L10.EGL_NONE};
198 eglSurface = egl.eglCreatePbufferSurface(eglDisplay, eglConfig, surfaceAttri bs); 242 eglSurface = egl.eglCreatePbufferSurface(eglDisplay, eglConfig, surfaceAttri bs);
199 if (eglSurface == EGL10.EGL_NO_SURFACE) { 243 if (eglSurface == EGL10.EGL_NO_SURFACE) {
200 throw new RuntimeException("Failed to create pixel buffer surface"); 244 throw new RuntimeException("Failed to create pixel buffer surface");
201 } 245 }
202 } 246 }
203 247
204 public EGLContext getContext() { 248 public Context getEglBaseContext() {
205 return eglContext; 249 return new Context(eglContext);
206 } 250 }
207 251
208 public boolean hasSurface() { 252 public boolean hasSurface() {
209 return eglSurface != EGL10.EGL_NO_SURFACE; 253 return eglSurface != EGL10.EGL_NO_SURFACE;
210 } 254 }
211 255
212 public int surfaceWidth() { 256 public int surfaceWidth() {
213 final int widthArray[] = new int[1]; 257 final int widthArray[] = new int[1];
214 egl.eglQuerySurface(eglDisplay, eglSurface, EGL10.EGL_WIDTH, widthArray); 258 egl.eglQuerySurface(eglDisplay, eglSurface, EGL10.EGL_WIDTH, widthArray);
215 return widthArray[0]; 259 return widthArray[0];
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 int[] numConfigs = new int[1]; 361 int[] numConfigs = new int[1];
318 if (!egl.eglChooseConfig( 362 if (!egl.eglChooseConfig(
319 eglDisplay, configAttributes, configs, configs.length, numConfigs)) { 363 eglDisplay, configAttributes, configs, configs.length, numConfigs)) {
320 throw new RuntimeException("Unable to find RGB888 " + configType + " EGL c onfig"); 364 throw new RuntimeException("Unable to find RGB888 " + configType + " EGL c onfig");
321 } 365 }
322 return configs[0]; 366 return configs[0];
323 } 367 }
324 368
325 // Return an EGLConfig, or die trying. 369 // Return an EGLConfig, or die trying.
326 private EGLContext createEglContext( 370 private EGLContext createEglContext(
327 EGLContext sharedContext, EGLDisplay eglDisplay, EGLConfig eglConfig) { 371 Context sharedContext, EGLDisplay eglDisplay, EGLConfig eglConfig) {
328 int[] contextAttributes = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE}; 372 int[] contextAttributes = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE};
373 EGLContext rootContext =
374 sharedContext == null ? EGL10.EGL_NO_CONTEXT : sharedContext.eglContext;
329 EGLContext eglContext = 375 EGLContext eglContext =
330 egl.eglCreateContext(eglDisplay, eglConfig, sharedContext, contextAttrib utes); 376 egl.eglCreateContext(eglDisplay, eglConfig, rootContext, contextAttribut es);
331 if (eglContext == EGL10.EGL_NO_CONTEXT) { 377 if (eglContext == EGL10.EGL_NO_CONTEXT) {
332 throw new RuntimeException("Failed to create EGL context"); 378 throw new RuntimeException("Failed to create EGL context");
333 } 379 }
334 return eglContext; 380 return eglContext;
335 } 381 }
336 } 382 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698