OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gl/gl_surface_egl.h" | 5 #include "ui/gl/gl_surface_egl.h" |
6 | 6 |
7 #if defined(OS_ANDROID) | 7 #if defined(OS_ANDROID) |
8 #include <android/native_window_jni.h> | 8 #include <android/native_window_jni.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "ui/gl/scoped_make_current.h" | 23 #include "ui/gl/scoped_make_current.h" |
24 #include "ui/gl/sync_control_vsync_provider.h" | 24 #include "ui/gl/sync_control_vsync_provider.h" |
25 | 25 |
26 #if defined(USE_X11) | 26 #if defined(USE_X11) |
27 extern "C" { | 27 extern "C" { |
28 #include <X11/Xlib.h> | 28 #include <X11/Xlib.h> |
29 } | 29 } |
30 #endif | 30 #endif |
31 | 31 |
32 #if defined (USE_OZONE) | 32 #if defined (USE_OZONE) |
33 #include "ui/ozone/public/surface_factory_ozone.h" | 33 #include "ui/ozone/public/ozone_platform.h" // nogncheck |
| 34 #include "ui/ozone/public/surface_factory_ozone.h" // nogncheck |
34 #endif | 35 #endif |
35 | 36 |
36 #if !defined(EGL_FIXED_SIZE_ANGLE) | 37 #if !defined(EGL_FIXED_SIZE_ANGLE) |
37 #define EGL_FIXED_SIZE_ANGLE 0x3201 | 38 #define EGL_FIXED_SIZE_ANGLE 0x3201 |
38 #endif | 39 #endif |
39 | 40 |
40 #if !defined(EGL_OPENGL_ES3_BIT) | 41 #if !defined(EGL_OPENGL_ES3_BIT) |
41 #define EGL_OPENGL_ES3_BIT 0x00000040 | 42 #define EGL_OPENGL_ES3_BIT 0x00000040 |
42 #endif | 43 #endif |
43 | 44 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 &win_attribs)) { | 136 &win_attribs)) { |
136 return nullptr; | 137 return nullptr; |
137 } | 138 } |
138 #endif | 139 #endif |
139 | 140 |
140 EGLint renderable_type = EGL_OPENGL_ES2_BIT; | 141 EGLint renderable_type = EGL_OPENGL_ES2_BIT; |
141 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 142 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
142 switches::kEnableUnsafeES3APIs)) { | 143 switches::kEnableUnsafeES3APIs)) { |
143 renderable_type = EGL_OPENGL_ES3_BIT; | 144 renderable_type = EGL_OPENGL_ES3_BIT; |
144 } | 145 } |
145 EGLint config_attribs[] = { | 146 EGLint kConfigAttribs[] = { |
146 EGL_BUFFER_SIZE, configuration.alpha_bits + | 147 EGL_BUFFER_SIZE, configuration.alpha_bits + |
147 configuration.red_bits + | 148 configuration.red_bits + |
148 configuration.green_bits + | 149 configuration.green_bits + |
149 configuration.blue_bits, | 150 configuration.blue_bits, |
150 EGL_ALPHA_SIZE, configuration.alpha_bits, | 151 EGL_ALPHA_SIZE, configuration.alpha_bits, |
151 EGL_BLUE_SIZE, configuration.blue_bits, | 152 EGL_BLUE_SIZE, configuration.blue_bits, |
152 EGL_GREEN_SIZE, configuration.green_bits, | 153 EGL_GREEN_SIZE, configuration.green_bits, |
153 EGL_RED_SIZE, configuration.red_bits, | 154 EGL_RED_SIZE, configuration.red_bits, |
154 EGL_DEPTH_SIZE, configuration.depth_bits, | 155 EGL_DEPTH_SIZE, configuration.depth_bits, |
155 EGL_STENCIL_SIZE, configuration.stencil_bits, | 156 EGL_STENCIL_SIZE, configuration.stencil_bits, |
156 EGL_RENDERABLE_TYPE, renderable_type, | 157 EGL_RENDERABLE_TYPE, renderable_type, |
157 EGL_SURFACE_TYPE, (allow_window_bit ? | 158 EGL_SURFACE_TYPE, (allow_window_bit ? |
158 (EGL_WINDOW_BIT | EGL_PBUFFER_BIT) : | 159 (EGL_WINDOW_BIT | EGL_PBUFFER_BIT) : |
159 EGL_PBUFFER_BIT), | 160 EGL_PBUFFER_BIT), |
160 EGL_NONE | 161 EGL_NONE |
161 }; | 162 }; |
162 | 163 |
163 #if defined(USE_OZONE) | 164 #if defined(USE_OZONE) |
164 config_attribs = | 165 const EGLint* config_attribs = ui::OzonePlatform::GetInstance() |
165 ui::SurfaceFactoryOzone::GetInstance()->GetEGLSurfaceProperties( | 166 ->GetSurfaceFactoryOzone() |
166 config_attribs); | 167 ->GetEGLSurfaceProperties(kConfigAttribs); |
167 #elif defined(USE_X11) | 168 #elif defined(USE_X11) |
| 169 EGLint* config_attribs = kConfigAttribs; |
168 // Try matching the window depth with an alpha channel, | 170 // Try matching the window depth with an alpha channel, |
169 // because we're worried the destination alpha width could | 171 // because we're worried the destination alpha width could |
170 // constrain blending precision. | 172 // constrain blending precision. |
171 const int kBufferSizeOffset = 1; | 173 const int kBufferSizeOffset = 1; |
172 const int kAlphaSizeOffset = 3; | 174 const int kAlphaSizeOffset = 3; |
173 config_attribs[kBufferSizeOffset] = win_attribs.depth; | 175 config_attribs[kBufferSizeOffset] = win_attribs.depth; |
| 176 #else |
| 177 const EGLint* config_attribs = kConfigAttribs; |
174 #endif | 178 #endif |
175 | 179 |
176 EGLint num_configs; | 180 EGLint num_configs; |
177 if (!eglChooseConfig(g_display, | 181 if (!eglChooseConfig(g_display, |
178 config_attribs, | 182 config_attribs, |
179 NULL, | 183 NULL, |
180 0, | 184 0, |
181 &num_configs)) { | 185 &num_configs)) { |
182 LOG(ERROR) << "eglChooseConfig failed with error " | 186 LOG(ERROR) << "eglChooseConfig failed with error " |
183 << GetLastEGLErrorString(); | 187 << GetLastEGLErrorString(); |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 DCHECK(window_); | 443 DCHECK(window_); |
440 config_ = GetEGLConfig(window_, this->get_surface_configuration(), true); | 444 config_ = GetEGLConfig(window_, this->get_surface_configuration(), true); |
441 } | 445 } |
442 return config_; | 446 return config_; |
443 } | 447 } |
444 | 448 |
445 bool NativeViewGLSurfaceEGL::IsOffscreen() { | 449 bool NativeViewGLSurfaceEGL::IsOffscreen() { |
446 return false; | 450 return false; |
447 } | 451 } |
448 | 452 |
449 bool NativeViewGLSurfaceEGL::SwapBuffers() { | 453 gfx::SwapResult NativeViewGLSurfaceEGL::SwapBuffers() { |
450 TRACE_EVENT2("gpu", "NativeViewGLSurfaceEGL:RealSwapBuffers", | 454 TRACE_EVENT2("gpu", "NativeViewGLSurfaceEGL:RealSwapBuffers", |
451 "width", GetSize().width(), | 455 "width", GetSize().width(), |
452 "height", GetSize().height()); | 456 "height", GetSize().height()); |
453 | 457 |
454 if (!eglSwapBuffers(GetDisplay(), surface_)) { | 458 if (!eglSwapBuffers(GetDisplay(), surface_)) { |
455 DVLOG(1) << "eglSwapBuffers failed with error " | 459 DVLOG(1) << "eglSwapBuffers failed with error " |
456 << GetLastEGLErrorString(); | 460 << GetLastEGLErrorString(); |
457 return false; | 461 return gfx::SwapResult::SWAP_FAILED; |
458 } | 462 } |
459 | 463 |
460 return true; | 464 return gfx::SwapResult::SWAP_ACK; |
461 } | 465 } |
462 | 466 |
463 gfx::Size NativeViewGLSurfaceEGL::GetSize() { | 467 gfx::Size NativeViewGLSurfaceEGL::GetSize() { |
464 EGLint width; | 468 EGLint width; |
465 EGLint height; | 469 EGLint height; |
466 if (!eglQuerySurface(GetDisplay(), surface_, EGL_WIDTH, &width) || | 470 if (!eglQuerySurface(GetDisplay(), surface_, EGL_WIDTH, &width) || |
467 !eglQuerySurface(GetDisplay(), surface_, EGL_HEIGHT, &height)) { | 471 !eglQuerySurface(GetDisplay(), surface_, EGL_HEIGHT, &height)) { |
468 NOTREACHED() << "eglQuerySurface failed with error " | 472 NOTREACHED() << "eglQuerySurface failed with error " |
469 << GetLastEGLErrorString(); | 473 << GetLastEGLErrorString(); |
470 return gfx::Size(); | 474 return gfx::Size(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 } | 513 } |
510 | 514 |
511 EGLSurface NativeViewGLSurfaceEGL::GetHandle() { | 515 EGLSurface NativeViewGLSurfaceEGL::GetHandle() { |
512 return surface_; | 516 return surface_; |
513 } | 517 } |
514 | 518 |
515 bool NativeViewGLSurfaceEGL::SupportsPostSubBuffer() { | 519 bool NativeViewGLSurfaceEGL::SupportsPostSubBuffer() { |
516 return supports_post_sub_buffer_; | 520 return supports_post_sub_buffer_; |
517 } | 521 } |
518 | 522 |
519 bool NativeViewGLSurfaceEGL::PostSubBuffer( | 523 gfx::SwapResult NativeViewGLSurfaceEGL::PostSubBuffer( |
520 int x, int y, int width, int height) { | 524 int x, int y, int width, int height) { |
521 DCHECK(supports_post_sub_buffer_); | 525 DCHECK(supports_post_sub_buffer_); |
522 if (!eglPostSubBufferNV(GetDisplay(), surface_, x, y, width, height)) { | 526 if (!eglPostSubBufferNV(GetDisplay(), surface_, x, y, width, height)) { |
523 DVLOG(1) << "eglPostSubBufferNV failed with error " | 527 DVLOG(1) << "eglPostSubBufferNV failed with error " |
524 << GetLastEGLErrorString(); | 528 << GetLastEGLErrorString(); |
525 return false; | 529 return gfx::SwapResult::SWAP_FAILED; |
526 } | 530 } |
527 return true; | 531 return gfx::SwapResult::SWAP_ACK; |
528 } | 532 } |
529 | 533 |
530 VSyncProvider* NativeViewGLSurfaceEGL::GetVSyncProvider() { | 534 VSyncProvider* NativeViewGLSurfaceEGL::GetVSyncProvider() { |
531 return vsync_provider_.get(); | 535 return vsync_provider_.get(); |
532 } | 536 } |
533 | 537 |
534 void NativeViewGLSurfaceEGL::OnSetSwapInterval(int interval) { | 538 void NativeViewGLSurfaceEGL::OnSetSwapInterval(int interval) { |
535 swap_interval_ = interval; | 539 swap_interval_ = interval; |
536 } | 540 } |
537 | 541 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 this->get_surface_configuration(), | 611 this->get_surface_configuration(), |
608 false); | 612 false); |
609 } | 613 } |
610 return config_; | 614 return config_; |
611 } | 615 } |
612 | 616 |
613 bool PbufferGLSurfaceEGL::IsOffscreen() { | 617 bool PbufferGLSurfaceEGL::IsOffscreen() { |
614 return true; | 618 return true; |
615 } | 619 } |
616 | 620 |
617 bool PbufferGLSurfaceEGL::SwapBuffers() { | 621 gfx::SwapResult PbufferGLSurfaceEGL::SwapBuffers() { |
618 NOTREACHED() << "Attempted to call SwapBuffers on a PbufferGLSurfaceEGL."; | 622 NOTREACHED() << "Attempted to call SwapBuffers on a PbufferGLSurfaceEGL."; |
619 return false; | 623 return gfx::SwapResult::SWAP_FAILED; |
620 } | 624 } |
621 | 625 |
622 gfx::Size PbufferGLSurfaceEGL::GetSize() { | 626 gfx::Size PbufferGLSurfaceEGL::GetSize() { |
623 return size_; | 627 return size_; |
624 } | 628 } |
625 | 629 |
626 bool PbufferGLSurfaceEGL::Resize(const gfx::Size& size) { | 630 bool PbufferGLSurfaceEGL::Resize(const gfx::Size& size) { |
627 if (size == size_) | 631 if (size == size_) |
628 return true; | 632 return true; |
629 | 633 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 } | 699 } |
696 | 700 |
697 bool SurfacelessEGL::IsOffscreen() { | 701 bool SurfacelessEGL::IsOffscreen() { |
698 return true; | 702 return true; |
699 } | 703 } |
700 | 704 |
701 bool SurfacelessEGL::IsSurfaceless() const { | 705 bool SurfacelessEGL::IsSurfaceless() const { |
702 return true; | 706 return true; |
703 } | 707 } |
704 | 708 |
705 bool SurfacelessEGL::SwapBuffers() { | 709 gfx::SwapResult SurfacelessEGL::SwapBuffers() { |
706 LOG(ERROR) << "Attempted to call SwapBuffers with SurfacelessEGL."; | 710 LOG(ERROR) << "Attempted to call SwapBuffers with SurfacelessEGL."; |
707 return false; | 711 return gfx::SwapResult::SWAP_FAILED; |
708 } | 712 } |
709 | 713 |
710 gfx::Size SurfacelessEGL::GetSize() { | 714 gfx::Size SurfacelessEGL::GetSize() { |
711 return size_; | 715 return size_; |
712 } | 716 } |
713 | 717 |
714 bool SurfacelessEGL::Resize(const gfx::Size& size) { | 718 bool SurfacelessEGL::Resize(const gfx::Size& size) { |
715 size_ = size; | 719 size_ = size; |
716 return true; | 720 return true; |
717 } | 721 } |
718 | 722 |
719 EGLSurface SurfacelessEGL::GetHandle() { | 723 EGLSurface SurfacelessEGL::GetHandle() { |
720 return EGL_NO_SURFACE; | 724 return EGL_NO_SURFACE; |
721 } | 725 } |
722 | 726 |
723 void* SurfacelessEGL::GetShareHandle() { | 727 void* SurfacelessEGL::GetShareHandle() { |
724 return NULL; | 728 return NULL; |
725 } | 729 } |
726 | 730 |
727 SurfacelessEGL::~SurfacelessEGL() { | 731 SurfacelessEGL::~SurfacelessEGL() { |
728 } | 732 } |
729 | 733 |
730 } // namespace gfx | 734 } // namespace gfx |
OLD | NEW |