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 // This include must be here so that the includes provided transitively |
| 6 // by gl_surface_egl.h don't make it impossible to compile this code. |
| 7 #include "third_party/mesa/src/include/GL/osmesa.h" |
| 8 |
5 #include "ui/gl/gl_surface_egl.h" | 9 #include "ui/gl/gl_surface_egl.h" |
6 | 10 |
7 #if defined(OS_ANDROID) | 11 #if defined(OS_ANDROID) |
8 #include <android/native_window_jni.h> | 12 #include <android/native_window_jni.h> |
9 #endif | 13 #endif |
10 | 14 |
11 #include "base/logging.h" | 15 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
13 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
14 #include "build/build_config.h" | 18 #include "build/build_config.h" |
15 #include "ui/gl/egl_util.h" | 19 #include "ui/gl/egl_util.h" |
16 #include "ui/gl/gl_context.h" | 20 #include "ui/gl/gl_context.h" |
17 #include "ui/gl/gl_implementation.h" | 21 #include "ui/gl/gl_implementation.h" |
| 22 #include "ui/gl/gl_surface_osmesa.h" |
18 #include "ui/gl/gl_surface_stub.h" | 23 #include "ui/gl/gl_surface_stub.h" |
19 #include "ui/gl/scoped_make_current.h" | 24 #include "ui/gl/scoped_make_current.h" |
20 | 25 |
21 #if defined(USE_X11) | 26 #if defined(USE_X11) |
22 extern "C" { | 27 extern "C" { |
23 #include <X11/Xlib.h> | 28 #include <X11/Xlib.h> |
24 } | 29 } |
25 #endif | 30 #endif |
26 | 31 |
27 #if defined (USE_OZONE) | 32 #if defined (USE_OZONE) |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 return handle; | 560 return handle; |
556 #endif | 561 #endif |
557 } | 562 } |
558 | 563 |
559 PbufferGLSurfaceEGL::~PbufferGLSurfaceEGL() { | 564 PbufferGLSurfaceEGL::~PbufferGLSurfaceEGL() { |
560 Destroy(); | 565 Destroy(); |
561 } | 566 } |
562 | 567 |
563 #if defined(ANDROID) || defined(USE_OZONE) | 568 #if defined(ANDROID) || defined(USE_OZONE) |
564 | 569 |
| 570 // A thin subclass of |GLSurfaceOSMesa| that can be used in place |
| 571 // of a native hardware-provided surface when a native surface |
| 572 // provider is not available. |
| 573 class GLSurfaceOSMesaHeadless : public GLSurfaceOSMesa { |
| 574 public: |
| 575 explicit GLSurfaceOSMesaHeadless(gfx::AcceleratedWidget window); |
| 576 |
| 577 virtual bool IsOffscreen() OVERRIDE; |
| 578 virtual bool SwapBuffers() OVERRIDE; |
| 579 |
| 580 protected: |
| 581 virtual ~GLSurfaceOSMesaHeadless(); |
| 582 |
| 583 private: |
| 584 |
| 585 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOSMesaHeadless); |
| 586 }; |
| 587 |
| 588 bool GLSurfaceOSMesaHeadless::IsOffscreen() { return false; } |
| 589 |
| 590 bool GLSurfaceOSMesaHeadless::SwapBuffers() { return true; } |
| 591 |
| 592 GLSurfaceOSMesaHeadless::GLSurfaceOSMesaHeadless(gfx::AcceleratedWidget window) |
| 593 : GLSurfaceOSMesa(OSMESA_BGRA, gfx::Size(1, 1)) { |
| 594 DCHECK(window); |
| 595 } |
| 596 |
| 597 GLSurfaceOSMesaHeadless::~GLSurfaceOSMesaHeadless() { Destroy(); } |
| 598 |
565 // static | 599 // static |
566 bool GLSurface::InitializeOneOffInternal() { | 600 bool GLSurface::InitializeOneOffInternal() { |
| 601 if (GetGLImplementation() == kGLImplementationOSMesaGL) { |
| 602 return true; |
| 603 } |
567 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); | 604 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); |
568 | 605 |
569 if (!GLSurfaceEGL::InitializeOneOff()) { | 606 if (!GLSurfaceEGL::InitializeOneOff()) { |
570 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; | 607 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; |
571 return false; | 608 return false; |
572 } | 609 } |
573 return true; | 610 return true; |
574 } | 611 } |
575 | 612 |
576 // static | 613 // static |
577 scoped_refptr<GLSurface> | 614 scoped_refptr<GLSurface> |
578 GLSurface::CreateViewGLSurface(gfx::AcceleratedWidget window) { | 615 GLSurface::CreateViewGLSurface(gfx::AcceleratedWidget window) { |
| 616 |
| 617 if (GetGLImplementation() == kGLImplementationOSMesaGL) { |
| 618 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless(window)); |
| 619 if (!surface->Initialize()) |
| 620 return NULL; |
| 621 return surface; |
| 622 } |
579 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); | 623 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); |
580 if (window) { | 624 if (window) { |
581 scoped_refptr<NativeViewGLSurfaceEGL> surface; | 625 scoped_refptr<NativeViewGLSurfaceEGL> surface; |
582 VSyncProvider* sync_provider = NULL; | 626 VSyncProvider* sync_provider = NULL; |
583 #if defined(USE_OZONE) | 627 #if defined(USE_OZONE) |
584 window = ui::SurfaceFactoryOzone::GetInstance()->RealizeAcceleratedWidget( | 628 window = ui::SurfaceFactoryOzone::GetInstance()->RealizeAcceleratedWidget( |
585 window); | 629 window); |
586 sync_provider = | 630 sync_provider = |
587 ui::SurfaceFactoryOzone::GetInstance()->GetVSyncProvider(window); | 631 ui::SurfaceFactoryOzone::GetInstance()->GetVSyncProvider(window); |
588 #endif | 632 #endif |
589 surface = new NativeViewGLSurfaceEGL(window); | 633 surface = new NativeViewGLSurfaceEGL(window); |
590 if(surface->Initialize(sync_provider)) | 634 if(surface->Initialize(sync_provider)) |
591 return surface; | 635 return surface; |
592 } else { | 636 } else { |
593 scoped_refptr<GLSurface> surface = new GLSurfaceStub(); | 637 scoped_refptr<GLSurface> surface = new GLSurfaceStub(); |
594 if (surface->Initialize()) | 638 if (surface->Initialize()) |
595 return surface; | 639 return surface; |
596 } | 640 } |
597 return NULL; | 641 return NULL; |
598 } | 642 } |
599 | 643 |
600 // static | 644 // static |
601 scoped_refptr<GLSurface> | 645 scoped_refptr<GLSurface> |
602 GLSurface::CreateOffscreenGLSurface(const gfx::Size& size) { | 646 GLSurface::CreateOffscreenGLSurface(const gfx::Size& size) { |
603 switch (GetGLImplementation()) { | 647 switch (GetGLImplementation()) { |
| 648 case kGLImplementationOSMesaGL: { |
| 649 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesa(1, size)); |
| 650 if (!surface->Initialize()) |
| 651 return NULL; |
| 652 |
| 653 return surface; |
| 654 } |
604 case kGLImplementationEGLGLES2: { | 655 case kGLImplementationEGLGLES2: { |
605 scoped_refptr<PbufferGLSurfaceEGL> surface( | 656 scoped_refptr<PbufferGLSurfaceEGL> surface( |
606 new PbufferGLSurfaceEGL(size)); | 657 new PbufferGLSurfaceEGL(size)); |
607 if (!surface->Initialize()) | 658 if (!surface->Initialize()) |
608 return NULL; | 659 return NULL; |
609 return surface; | 660 return surface; |
610 } | 661 } |
611 default: | 662 default: |
612 NOTREACHED(); | 663 NOTREACHED(); |
613 return NULL; | 664 return NULL; |
614 } | 665 } |
615 } | 666 } |
616 | 667 |
617 #endif | 668 #endif |
618 | 669 |
619 } // namespace gfx | 670 } // namespace gfx |
OLD | NEW |