Skip to content

Commit bee2ef8

Browse files
committed
Fix empty contents when moving an OSR window between displays.
The GLContext will be re-initialized when moving the window between displays. The GLContext.makeCurrent() return value must be checked for CONTEXT_NOT_CURRENT during this time. Additionally, CefRenderer.cleanup() should reset the view width/height so that the texture is correctly updated on the next call to onPaint().
1 parent 542cab7 commit bee2ef8

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

java/org/cef/browser/CefBrowserOsr.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ public void paint(Graphics g) {
109109
}
110110
};
111111

112+
// The GLContext will be re-initialized when changing displays, resulting in calls to
113+
// dispose/init/reshape.
112114
canvas_.addGLEventListener(new GLEventListener() {
113115
@Override
114116
public void reshape(
@@ -251,7 +253,11 @@ public void onPaint(CefBrowser browser, boolean popup, Rectangle[] dirtyRects,
251253
return;
252254
}
253255

254-
context.makeCurrent();
256+
// This result can occur due to GLContext re-initialization when changing displays.
257+
if (context.makeCurrent() == GLContext.CONTEXT_NOT_CURRENT) {
258+
return;
259+
}
260+
255261
renderer_.onPaint(canvas_.getGL().getGL2(), popup, dirtyRects, buffer, width, height);
256262
context.release();
257263
SwingUtilities.invokeLater(new Runnable() {

java/org/cef/browser/CefRenderer.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
package org.cef.browser;
66

7+
import com.jogamp.opengl.GL2;
8+
79
import java.awt.Rectangle;
810
import java.nio.ByteBuffer;
911
import java.nio.FloatBuffer;
1012

11-
import com.jogamp.opengl.GL2;
12-
1313
class CefRenderer {
1414
private boolean transparent_;
1515
private GL2 initialized_context_ = null;
@@ -53,7 +53,7 @@ protected void initialize(GL2 gl2) {
5353

5454
// Create the texture.
5555
gl2.glGenTextures(1, texture_id_, 0);
56-
assert(texture_id_[0] != 0);
56+
assert (texture_id_[0] != 0);
5757

5858
gl2.glBindTexture(gl2.GL_TEXTURE_2D, texture_id_[0]);
5959
gl2.glTexParameteri(gl2.GL_TEXTURE_2D, gl2.GL_TEXTURE_MIN_FILTER, gl2.GL_NEAREST);
@@ -63,13 +63,14 @@ protected void initialize(GL2 gl2) {
6363

6464
protected void cleanup(GL2 gl2) {
6565
if (texture_id_[0] != 0) gl2.glDeleteTextures(1, texture_id_, 0);
66+
view_width_ = view_height_ = 0;
6667
}
6768

6869
@SuppressWarnings("static-access")
6970
protected void render(GL2 gl2) {
7071
if (use_draw_pixels_ || view_width_ == 0 || view_height_ == 0) return;
7172

72-
assert(initialized_context_ != null);
73+
assert (initialized_context_ != null);
7374

7475
final float[] vertex_data = {// tu, tv, x, y, z
7576
0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
@@ -114,7 +115,7 @@ protected void render(GL2 gl2) {
114115
gl2.glEnable(gl2.GL_TEXTURE_2D);
115116

116117
// Draw the facets with the texture.
117-
assert(texture_id_[0] != 0);
118+
assert (texture_id_[0] != 0);
118119
gl2.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
119120
gl2.glBindTexture(gl2.GL_TEXTURE_2D, texture_id_[0]);
120121
gl2.glInterleavedArrays(gl2.GL_T2F_V3F, 0, vertices);
@@ -178,7 +179,7 @@ protected void onPaint(GL2 gl2, boolean popup, Rectangle[] dirtyRects, ByteBuffe
178179
// Enable 2D textures.
179180
gl2.glEnable(gl2.GL_TEXTURE_2D);
180181

181-
assert(texture_id_[0] != 0);
182+
assert (texture_id_[0] != 0);
182183
gl2.glBindTexture(gl2.GL_TEXTURE_2D, texture_id_[0]);
183184

184185
if (!popup) {

0 commit comments

Comments
 (0)