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.
5 #include "ui/gl/gl_surface_egl.h"
7 #if defined(OS_ANDROID)
8 #include <android/native_window_jni.h>
11 #include "base/command_line.h"
12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/message_loop/message_loop.h"
15 #include "base/trace_event/trace_event.h"
16 #include "build/build_config.h"
17 #include "ui/gfx/geometry/rect.h"
18 #include "ui/gl/egl_util.h"
19 #include "ui/gl/gl_context.h"
20 #include "ui/gl/gl_implementation.h"
21 #include "ui/gl/gl_surface_stub.h"
22 #include "ui/gl/gl_switches.h"
23 #include "ui/gl/scoped_make_current.h"
24 #include "ui/gl/sync_control_vsync_provider.h"
32 #if defined (USE_OZONE)
33 #include "ui/ozone/public/ozone_platform.h"
34 #include "ui/ozone/public/surface_factory_ozone.h"
37 #if !defined(EGL_FIXED_SIZE_ANGLE)
38 #define EGL_FIXED_SIZE_ANGLE 0x3201
41 #if !defined(EGL_OPENGL_ES3_BIT)
42 #define EGL_OPENGL_ES3_BIT 0x00000040
45 // From ANGLE's egl/eglext.h.
47 #ifndef EGL_ANGLE_platform_angle
48 #define EGL_ANGLE_platform_angle 1
49 #define EGL_PLATFORM_ANGLE_ANGLE 0x3202
50 #define EGL_PLATFORM_ANGLE_TYPE_ANGLE 0x3203
51 #define EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE 0x3204
52 #define EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE 0x3205
53 #define EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE 0x3206
54 #endif /* EGL_ANGLE_platform_angle */
56 #ifndef EGL_ANGLE_platform_angle_d3d
57 #define EGL_ANGLE_platform_angle_d3d 1
58 #define EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE 0x3207
59 #define EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE 0x3208
60 #define EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE 0x3209
61 #define EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE 0x320A
62 #define EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE 0x320B
63 #define EGL_PLATFORM_ANGLE_DEVICE_TYPE_REFERENCE_ANGLE 0x320C
64 #endif /* EGL_ANGLE_platform_angle_d3d */
66 #ifndef EGL_ANGLE_platform_angle_opengl
67 #define EGL_ANGLE_platform_angle_opengl 1
68 #define EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE 0x320D
69 #define EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE 0x320E
70 #endif /* EGL_ANGLE_platform_angle_opengl */
72 using ui::GetLastEGLErrorString
;
77 unsigned int NativeViewGLSurfaceEGL::current_swap_generation_
= 0;
78 unsigned int NativeViewGLSurfaceEGL::swaps_this_generation_
= 0;
79 unsigned int NativeViewGLSurfaceEGL::last_multiswap_generation_
= 0;
81 const unsigned int MULTISWAP_FRAME_VSYNC_THRESHOLD
= 60;
88 EGLNativeDisplayType g_native_display
;
90 const char* g_egl_extensions
= NULL
;
91 bool g_egl_create_context_robustness_supported
= false;
92 bool g_egl_sync_control_supported
= false;
93 bool g_egl_window_fixed_size_supported
= false;
94 bool g_egl_surfaceless_context_supported
= false;
96 class EGLSyncControlVSyncProvider
97 : public gfx::SyncControlVSyncProvider
{
99 explicit EGLSyncControlVSyncProvider(EGLSurface surface
)
100 : SyncControlVSyncProvider(),
104 ~EGLSyncControlVSyncProvider() override
{}
107 bool GetSyncValues(int64
* system_time
,
108 int64
* media_stream_counter
,
109 int64
* swap_buffer_counter
) override
{
110 uint64 u_system_time
, u_media_stream_counter
, u_swap_buffer_counter
;
111 bool result
= eglGetSyncValuesCHROMIUM(
112 g_display
, surface_
, &u_system_time
,
113 &u_media_stream_counter
, &u_swap_buffer_counter
) == EGL_TRUE
;
115 *system_time
= static_cast<int64
>(u_system_time
);
116 *media_stream_counter
= static_cast<int64
>(u_media_stream_counter
);
117 *swap_buffer_counter
= static_cast<int64
>(u_swap_buffer_counter
);
122 bool GetMscRate(int32
* numerator
, int32
* denominator
) override
{
129 DISALLOW_COPY_AND_ASSIGN(EGLSyncControlVSyncProvider
);
132 EGLDisplay
GetPlatformANGLEDisplay(EGLNativeDisplayType native_display
,
133 EGLenum platform_type
,
135 std::vector
<EGLint
> display_attribs
;
137 display_attribs
.push_back(EGL_PLATFORM_ANGLE_TYPE_ANGLE
);
138 display_attribs
.push_back(platform_type
);
141 display_attribs
.push_back(EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE
);
142 display_attribs
.push_back(EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE
);
145 display_attribs
.push_back(EGL_NONE
);
147 return eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE
,
148 reinterpret_cast<void*>(native_display
),
149 &display_attribs
[0]);
152 EGLDisplay
GetDisplayFromType(DisplayType display_type
,
153 EGLNativeDisplayType native_display
) {
154 switch (display_type
) {
157 return eglGetDisplay(native_display
);
159 return GetPlatformANGLEDisplay(native_display
,
160 EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE
, true);
162 return GetPlatformANGLEDisplay(native_display
,
163 EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE
, false);
165 return GetPlatformANGLEDisplay(
166 native_display
, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE
, false);
168 return GetPlatformANGLEDisplay(
169 native_display
, EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE
, false);
171 return GetPlatformANGLEDisplay(
172 native_display
, EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE
, false);
175 return EGL_NO_DISPLAY
;
179 const char* DisplayTypeString(DisplayType display_type
) {
180 switch (display_type
) {
184 return "SwiftShader";
203 void GetEGLInitDisplays(bool supports_angle_d3d
,
204 bool supports_angle_opengl
,
205 const base::CommandLine
* command_line
,
206 std::vector
<DisplayType
>* init_displays
) {
207 // SwiftShader does not use the platform extensions
208 if (command_line
->GetSwitchValueASCII(switches::kUseGL
) ==
209 kGLImplementationSwiftShaderName
) {
210 init_displays
->push_back(SWIFT_SHADER
);
214 std::string requested_renderer
=
215 command_line
->GetSwitchValueASCII(switches::kUseANGLE
);
217 if (supports_angle_d3d
) {
218 bool use_angle_default
=
219 !command_line
->HasSwitch(switches::kUseANGLE
) ||
220 requested_renderer
== kANGLEImplementationDefaultName
;
222 if (use_angle_default
) {
223 // Default mode for ANGLE - try D3D11, else try D3D9
224 if (!command_line
->HasSwitch(switches::kDisableD3D11
)) {
225 init_displays
->push_back(ANGLE_D3D11
);
227 init_displays
->push_back(ANGLE_D3D9
);
229 if (requested_renderer
== kANGLEImplementationD3D11Name
) {
230 init_displays
->push_back(ANGLE_D3D11
);
232 if (requested_renderer
== kANGLEImplementationD3D9Name
) {
233 init_displays
->push_back(ANGLE_D3D9
);
235 if (requested_renderer
== kANGLEImplementationWARPName
) {
236 init_displays
->push_back(ANGLE_WARP
);
241 if (supports_angle_opengl
) {
242 if (requested_renderer
== kANGLEImplementationOpenGLName
) {
243 init_displays
->push_back(ANGLE_OPENGL
);
245 if (requested_renderer
== kANGLEImplementationOpenGLESName
) {
246 init_displays
->push_back(ANGLE_OPENGLES
);
250 // If no displays are available due to missing angle extensions or invalid
251 // flags, request the default display.
252 if (init_displays
->empty()) {
253 init_displays
->push_back(DEFAULT
);
257 GLSurfaceEGL::GLSurfaceEGL() {}
259 bool GLSurfaceEGL::InitializeOneOff() {
260 static bool initialized
= false;
265 if (g_display
== EGL_NO_DISPLAY
)
268 // Choose an EGL configuration.
269 // On X this is only used for PBuffer surfaces.
270 EGLint renderable_type
= EGL_OPENGL_ES2_BIT
;
271 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
272 switches::kEnableUnsafeES3APIs
)) {
273 renderable_type
= EGL_OPENGL_ES3_BIT
;
275 const EGLint kConfigAttribs
[] = {
281 EGL_RENDERABLE_TYPE
, renderable_type
,
282 EGL_SURFACE_TYPE
, EGL_WINDOW_BIT
| EGL_PBUFFER_BIT
,
286 #if defined(USE_OZONE)
287 const EGLint
* config_attribs
= ui::OzonePlatform::GetInstance()
288 ->GetSurfaceFactoryOzone()
289 ->GetEGLSurfaceProperties(kConfigAttribs
);
291 const EGLint
* config_attribs
= kConfigAttribs
;
295 if (!eglChooseConfig(g_display
,
300 LOG(ERROR
) << "eglChooseConfig failed with error "
301 << GetLastEGLErrorString();
305 if (num_configs
== 0) {
306 LOG(ERROR
) << "No suitable EGL configs found.";
310 if (!eglChooseConfig(g_display
,
315 LOG(ERROR
) << "eglChooseConfig failed with error "
316 << GetLastEGLErrorString();
320 g_egl_extensions
= eglQueryString(g_display
, EGL_EXTENSIONS
);
321 g_egl_create_context_robustness_supported
=
322 HasEGLExtension("EGL_EXT_create_context_robustness");
323 g_egl_sync_control_supported
=
324 HasEGLExtension("EGL_CHROMIUM_sync_control");
325 g_egl_window_fixed_size_supported
=
326 HasEGLExtension("EGL_ANGLE_window_fixed_size");
328 // TODO(oetuaho@nvidia.com): Surfaceless is disabled on Android as a temporary
329 // workaround, since code written for Android WebView takes different paths
330 // based on whether GL surface objects have underlying EGL surface handles,
331 // conflicting with the use of surfaceless. See https://crbug.com/382349
332 #if defined(OS_ANDROID)
333 DCHECK(!g_egl_surfaceless_context_supported
);
335 // Check if SurfacelessEGL is supported.
336 g_egl_surfaceless_context_supported
=
337 HasEGLExtension("EGL_KHR_surfaceless_context");
338 if (g_egl_surfaceless_context_supported
) {
339 // EGL_KHR_surfaceless_context is supported but ensure
340 // GL_OES_surfaceless_context is also supported. We need a current context
341 // to query for supported GL extensions.
342 scoped_refptr
<GLSurface
> surface
= new SurfacelessEGL(Size(1, 1));
343 scoped_refptr
<GLContext
> context
= GLContext::CreateGLContext(
344 NULL
, surface
.get(), PreferIntegratedGpu
);
345 if (!context
->MakeCurrent(surface
.get()))
346 g_egl_surfaceless_context_supported
= false;
348 // Ensure context supports GL_OES_surfaceless_context.
349 if (g_egl_surfaceless_context_supported
) {
350 g_egl_surfaceless_context_supported
= context
->HasExtension(
351 "GL_OES_surfaceless_context");
352 context
->ReleaseCurrent(surface
.get());
362 EGLDisplay
GLSurfaceEGL::GetDisplay() {
366 EGLDisplay
GLSurfaceEGL::GetHardwareDisplay() {
370 EGLNativeDisplayType
GLSurfaceEGL::GetNativeDisplay() {
371 return g_native_display
;
374 const char* GLSurfaceEGL::GetEGLExtensions() {
375 return g_egl_extensions
;
378 bool GLSurfaceEGL::HasEGLExtension(const char* name
) {
379 return ExtensionsContain(GetEGLExtensions(), name
);
382 bool GLSurfaceEGL::IsCreateContextRobustnessSupported() {
383 return g_egl_create_context_robustness_supported
;
386 bool GLSurfaceEGL::IsEGLSurfacelessContextSupported() {
387 return g_egl_surfaceless_context_supported
;
390 GLSurfaceEGL::~GLSurfaceEGL() {}
392 // InitializeDisplay is necessary because the static binding code
393 // needs a full Display init before it can query the Display extensions.
395 EGLDisplay
GLSurfaceEGL::InitializeDisplay() {
396 if (g_display
!= EGL_NO_DISPLAY
) {
400 g_native_display
= GetPlatformDefaultEGLNativeDisplay();
402 // If EGL_EXT_client_extensions not supported this call to eglQueryString
404 const char* client_extensions
=
405 eglQueryString(EGL_NO_DISPLAY
, EGL_EXTENSIONS
);
407 bool supports_angle_d3d
= false;
408 bool supports_angle_opengl
= false;
409 // Check for availability of ANGLE extensions.
410 if (client_extensions
&&
411 ExtensionsContain(client_extensions
, "EGL_ANGLE_platform_angle")) {
413 ExtensionsContain(client_extensions
, "EGL_ANGLE_platform_angle_d3d");
414 supports_angle_opengl
=
415 ExtensionsContain(client_extensions
, "EGL_ANGLE_platform_angle_opengl");
418 std::vector
<DisplayType
> init_displays
;
419 GetEGLInitDisplays(supports_angle_d3d
, supports_angle_opengl
,
420 base::CommandLine::ForCurrentProcess(), &init_displays
);
422 for (size_t disp_index
= 0; disp_index
< init_displays
.size(); ++disp_index
) {
423 DisplayType display_type
= init_displays
[disp_index
];
425 GetDisplayFromType(display_type
, g_native_display
);
426 if (display
== EGL_NO_DISPLAY
) {
427 LOG(ERROR
) << "EGL display query failed with error "
428 << GetLastEGLErrorString();
431 if (!eglInitialize(display
, nullptr, nullptr)) {
432 bool is_last
= disp_index
== init_displays
.size() - 1;
434 LOG(ERROR
) << "eglInitialize " << DisplayTypeString(display_type
)
435 << " failed with error " << GetLastEGLErrorString()
436 << (is_last
? "" : ", trying next display type");
446 NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL(EGLNativeWindowType window
)
449 supports_post_sub_buffer_(false),
453 #if defined(OS_ANDROID)
455 ANativeWindow_acquire(window
);
459 vsync_override_
= false;
460 swap_generation_
= 0;
462 if (GetClientRect(window_
, &windowRect
))
463 size_
= gfx::Rect(windowRect
).size();
467 bool NativeViewGLSurfaceEGL::Initialize() {
468 return Initialize(nullptr);
471 bool NativeViewGLSurfaceEGL::Initialize(
472 scoped_ptr
<VSyncProvider
> sync_provider
) {
476 LOG(ERROR
) << "Trying to create surface with invalid display.";
480 std::vector
<EGLint
> egl_window_attributes
;
482 if (g_egl_window_fixed_size_supported
) {
483 egl_window_attributes
.push_back(EGL_FIXED_SIZE_ANGLE
);
484 egl_window_attributes
.push_back(EGL_TRUE
);
485 egl_window_attributes
.push_back(EGL_WIDTH
);
486 egl_window_attributes
.push_back(size_
.width());
487 egl_window_attributes
.push_back(EGL_HEIGHT
);
488 egl_window_attributes
.push_back(size_
.height());
491 if (gfx::g_driver_egl
.ext
.b_EGL_NV_post_sub_buffer
) {
492 egl_window_attributes
.push_back(EGL_POST_SUB_BUFFER_SUPPORTED_NV
);
493 egl_window_attributes
.push_back(EGL_TRUE
);
496 egl_window_attributes
.push_back(EGL_NONE
);
497 // Create a surface for the native window.
498 surface_
= eglCreateWindowSurface(
499 GetDisplay(), GetConfig(), window_
, &egl_window_attributes
[0]);
502 LOG(ERROR
) << "eglCreateWindowSurface failed with error "
503 << GetLastEGLErrorString();
508 if (gfx::g_driver_egl
.ext
.b_EGL_NV_post_sub_buffer
) {
510 EGLBoolean retVal
= eglQuerySurface(
511 GetDisplay(), surface_
, EGL_POST_SUB_BUFFER_SUPPORTED_NV
, &surfaceVal
);
512 supports_post_sub_buffer_
= (surfaceVal
&& retVal
) == EGL_TRUE
;
516 vsync_provider_
.reset(sync_provider
.release());
517 else if (g_egl_sync_control_supported
)
518 vsync_provider_
.reset(new EGLSyncControlVSyncProvider(surface_
));
522 void NativeViewGLSurfaceEGL::Destroy() {
524 if (!eglDestroySurface(GetDisplay(), surface_
)) {
525 LOG(ERROR
) << "eglDestroySurface failed with error "
526 << GetLastEGLErrorString();
532 EGLConfig
NativeViewGLSurfaceEGL::GetConfig() {
533 #if !defined(USE_X11)
537 // Get a config compatible with the window
539 XWindowAttributes win_attribs
;
540 if (!XGetWindowAttributes(GetNativeDisplay(), window_
, &win_attribs
)) {
544 // Try matching the window depth with an alpha channel,
545 // because we're worried the destination alpha width could
546 // constrain blending precision.
547 const int kBufferSizeOffset
= 1;
548 const int kAlphaSizeOffset
= 3;
549 EGLint config_attribs
[] = {
555 EGL_RENDERABLE_TYPE
, EGL_OPENGL_ES2_BIT
,
556 EGL_SURFACE_TYPE
, EGL_WINDOW_BIT
| EGL_PBUFFER_BIT
,
559 config_attribs
[kBufferSizeOffset
] = win_attribs
.depth
;
562 if (!eglChooseConfig(g_display
,
567 LOG(ERROR
) << "eglChooseConfig failed with error "
568 << GetLastEGLErrorString();
574 if (!eglGetConfigAttrib(g_display
,
578 LOG(ERROR
) << "eglGetConfigAttrib failed with error "
579 << GetLastEGLErrorString();
583 if (config_depth
== win_attribs
.depth
) {
588 // Try without an alpha channel.
589 config_attribs
[kAlphaSizeOffset
] = 0;
590 if (!eglChooseConfig(g_display
,
595 LOG(ERROR
) << "eglChooseConfig failed with error "
596 << GetLastEGLErrorString();
600 if (num_configs
== 0) {
601 LOG(ERROR
) << "No suitable EGL configs found.";
609 bool NativeViewGLSurfaceEGL::IsOffscreen() {
613 gfx::SwapResult
NativeViewGLSurfaceEGL::SwapBuffers() {
614 TRACE_EVENT2("gpu", "NativeViewGLSurfaceEGL:RealSwapBuffers",
615 "width", GetSize().width(),
616 "height", GetSize().height());
619 if (swap_interval_
!= 0) {
620 // This code is a simple way of enforcing that we only vsync if one surface
621 // is swapping per frame. This provides single window cases a stable refresh
622 // while allowing multi-window cases to not slow down due to multiple syncs
623 // on a single thread. A better way to fix this problem would be to have
624 // each surface present on its own thread.
626 if (current_swap_generation_
== swap_generation_
) {
627 if (swaps_this_generation_
> 1)
628 last_multiswap_generation_
= current_swap_generation_
;
629 swaps_this_generation_
= 0;
630 current_swap_generation_
++;
633 swap_generation_
= current_swap_generation_
;
635 if (swaps_this_generation_
!= 0 ||
636 (current_swap_generation_
- last_multiswap_generation_
<
637 MULTISWAP_FRAME_VSYNC_THRESHOLD
)) {
638 // Override vsync settings and switch it off
639 if (!vsync_override_
) {
640 eglSwapInterval(GetDisplay(), 0);
641 vsync_override_
= true;
643 } else if (vsync_override_
) {
644 // Only one window swapping, so let the normal vsync setting take over
645 eglSwapInterval(GetDisplay(), swap_interval_
);
646 vsync_override_
= false;
649 swaps_this_generation_
++;
653 if (!eglSwapBuffers(GetDisplay(), surface_
)) {
654 DVLOG(1) << "eglSwapBuffers failed with error "
655 << GetLastEGLErrorString();
656 return gfx::SwapResult::SWAP_FAILED
;
659 return gfx::SwapResult::SWAP_ACK
;
662 gfx::Size
NativeViewGLSurfaceEGL::GetSize() {
665 if (!eglQuerySurface(GetDisplay(), surface_
, EGL_WIDTH
, &width
) ||
666 !eglQuerySurface(GetDisplay(), surface_
, EGL_HEIGHT
, &height
)) {
667 NOTREACHED() << "eglQuerySurface failed with error "
668 << GetLastEGLErrorString();
672 return gfx::Size(width
, height
);
675 bool NativeViewGLSurfaceEGL::Resize(const gfx::Size
& size
) {
676 if (size
== GetSize())
681 scoped_ptr
<ui::ScopedMakeCurrent
> scoped_make_current
;
682 GLContext
* current_context
= GLContext::GetCurrent();
684 current_context
&& current_context
->IsCurrent(this);
686 scoped_make_current
.reset(
687 new ui::ScopedMakeCurrent(current_context
, this));
688 current_context
->ReleaseCurrent(this);
694 LOG(ERROR
) << "Failed to resize window.";
701 bool NativeViewGLSurfaceEGL::Recreate() {
704 LOG(ERROR
) << "Failed to create surface.";
710 EGLSurface
NativeViewGLSurfaceEGL::GetHandle() {
714 bool NativeViewGLSurfaceEGL::SupportsPostSubBuffer() {
715 return supports_post_sub_buffer_
;
718 gfx::SwapResult
NativeViewGLSurfaceEGL::PostSubBuffer(int x
,
722 DCHECK(supports_post_sub_buffer_
);
723 if (!eglPostSubBufferNV(GetDisplay(), surface_
, x
, y
, width
, height
)) {
724 DVLOG(1) << "eglPostSubBufferNV failed with error "
725 << GetLastEGLErrorString();
726 return gfx::SwapResult::SWAP_FAILED
;
728 return gfx::SwapResult::SWAP_ACK
;
731 VSyncProvider
* NativeViewGLSurfaceEGL::GetVSyncProvider() {
732 return vsync_provider_
.get();
735 void NativeViewGLSurfaceEGL::OnSetSwapInterval(int interval
) {
736 swap_interval_
= interval
;
739 NativeViewGLSurfaceEGL::~NativeViewGLSurfaceEGL() {
741 #if defined(OS_ANDROID)
743 ANativeWindow_release(window_
);
747 PbufferGLSurfaceEGL::PbufferGLSurfaceEGL(const gfx::Size
& size
)
750 // Some implementations of Pbuffer do not support having a 0 size. For such
751 // cases use a (1, 1) surface.
752 if (size_
.GetArea() == 0)
756 bool PbufferGLSurfaceEGL::Initialize() {
757 EGLSurface old_surface
= surface_
;
759 EGLDisplay display
= GetDisplay();
761 LOG(ERROR
) << "Trying to create surface with invalid display.";
765 // Allocate the new pbuffer surface before freeing the old one to ensure
766 // they have different addresses. If they have the same address then a
767 // future call to MakeCurrent might early out because it appears the current
768 // context and surface have not changed.
769 const EGLint pbuffer_attribs
[] = {
770 EGL_WIDTH
, size_
.width(),
771 EGL_HEIGHT
, size_
.height(),
775 EGLSurface new_surface
= eglCreatePbufferSurface(display
,
779 LOG(ERROR
) << "eglCreatePbufferSurface failed with error "
780 << GetLastEGLErrorString();
785 eglDestroySurface(display
, old_surface
);
787 surface_
= new_surface
;
791 void PbufferGLSurfaceEGL::Destroy() {
793 if (!eglDestroySurface(GetDisplay(), surface_
)) {
794 LOG(ERROR
) << "eglDestroySurface failed with error "
795 << GetLastEGLErrorString();
801 EGLConfig
PbufferGLSurfaceEGL::GetConfig() {
805 bool PbufferGLSurfaceEGL::IsOffscreen() {
809 gfx::SwapResult
PbufferGLSurfaceEGL::SwapBuffers() {
810 NOTREACHED() << "Attempted to call SwapBuffers on a PbufferGLSurfaceEGL.";
811 return gfx::SwapResult::SWAP_FAILED
;
814 gfx::Size
PbufferGLSurfaceEGL::GetSize() {
818 bool PbufferGLSurfaceEGL::Resize(const gfx::Size
& size
) {
822 scoped_ptr
<ui::ScopedMakeCurrent
> scoped_make_current
;
823 GLContext
* current_context
= GLContext::GetCurrent();
825 current_context
&& current_context
->IsCurrent(this);
827 scoped_make_current
.reset(
828 new ui::ScopedMakeCurrent(current_context
, this));
834 LOG(ERROR
) << "Failed to resize pbuffer.";
841 EGLSurface
PbufferGLSurfaceEGL::GetHandle() {
845 void* PbufferGLSurfaceEGL::GetShareHandle() {
846 #if defined(OS_ANDROID)
850 if (!gfx::g_driver_egl
.ext
.b_EGL_ANGLE_query_surface_pointer
)
853 if (!gfx::g_driver_egl
.ext
.b_EGL_ANGLE_surface_d3d_texture_2d_share_handle
)
857 if (!eglQuerySurfacePointerANGLE(g_display
,
859 EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE
,
868 PbufferGLSurfaceEGL::~PbufferGLSurfaceEGL() {
872 SurfacelessEGL::SurfacelessEGL(const gfx::Size
& size
)
876 bool SurfacelessEGL::Initialize() {
880 void SurfacelessEGL::Destroy() {
883 EGLConfig
SurfacelessEGL::GetConfig() {
887 bool SurfacelessEGL::IsOffscreen() {
891 bool SurfacelessEGL::IsSurfaceless() const {
895 gfx::SwapResult
SurfacelessEGL::SwapBuffers() {
896 LOG(ERROR
) << "Attempted to call SwapBuffers with SurfacelessEGL.";
897 return gfx::SwapResult::SWAP_FAILED
;
900 gfx::Size
SurfacelessEGL::GetSize() {
904 bool SurfacelessEGL::Resize(const gfx::Size
& size
) {
909 EGLSurface
SurfacelessEGL::GetHandle() {
910 return EGL_NO_SURFACE
;
913 void* SurfacelessEGL::GetShareHandle() {
917 SurfacelessEGL::~SurfacelessEGL() {