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

Unified Diff: ui/ozone/platform/cast/surface_factory_cast.cc

Issue 2723583003: Convert Ozone cast to use GLOzone API. (Closed)
Patch Set: . Created 3 years, 10 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/ozone/platform/cast/surface_factory_cast.h ('k') | ui/ozone/public/native_pixmap.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/ozone/platform/cast/surface_factory_cast.cc
diff --git a/ui/ozone/platform/cast/surface_factory_cast.cc b/ui/ozone/platform/cast/surface_factory_cast.cc
index 04e3cfa125def513d357adb1a9c9daaa6d841b4e..5d12590852b9194f1d6da8df5ba37ef1311798ef 100644
--- a/ui/ozone/platform/cast/surface_factory_cast.cc
+++ b/ui/ozone/platform/cast/surface_factory_cast.cc
@@ -4,56 +4,21 @@
#include "ui/ozone/platform/cast/surface_factory_cast.h"
-#include <EGL/egl.h>
-#include <dlfcn.h>
-
#include <utility>
-#include "base/callback_helpers.h"
-#include "base/command_line.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
-#include "base/strings/string_number_conversions.h"
-#include "chromecast/base/chromecast_switches.h"
#include "chromecast/public/cast_egl_platform.h"
-#include "chromecast/public/graphics_types.h"
#include "third_party/skia/include/core/SkSurface.h"
-#include "ui/gfx/geometry/quad_f.h"
+#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/vsync_provider.h"
-#include "ui/ozone/platform/cast/gl_surface_cast.h"
#include "ui/ozone/public/native_pixmap.h"
#include "ui/ozone/public/surface_ozone_canvas.h"
-using chromecast::CastEglPlatform;
-
namespace ui {
namespace {
-typedef EGLDisplay (*EGLGetDisplayFn)(NativeDisplayType);
-typedef EGLBoolean (*EGLTerminateFn)(EGLDisplay);
-
-chromecast::Size FromGfxSize(const gfx::Size& size) {
- return chromecast::Size(size.width(), size.height());
-}
-
-// Display resolution, set in browser process and passed by switches.
-gfx::Size GetDisplaySize() {
- base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
- int width, height;
- if (base::StringToInt(
- cmd_line->GetSwitchValueASCII(switches::kCastInitialScreenWidth),
- &width) &&
- base::StringToInt(
- cmd_line->GetSwitchValueASCII(switches::kCastInitialScreenHeight),
- &height)) {
- return gfx::Size(width, height);
- }
- LOG(WARNING) << "Unable to get initial screen resolution from command line,"
- << "using default 720p";
- return gfx::Size(1280, 720);
-}
-
class DummySurface : public SurfaceOzoneCanvas {
public:
DummySurface() {}
@@ -79,258 +44,90 @@ class DummySurface : public SurfaceOzoneCanvas {
DISALLOW_COPY_AND_ASSIGN(DummySurface);
};
-} // namespace
-
-SurfaceFactoryCast::SurfaceFactoryCast() : SurfaceFactoryCast(nullptr) {}
-
-SurfaceFactoryCast::SurfaceFactoryCast(
- std::unique_ptr<CastEglPlatform> egl_platform)
- : state_(kUninitialized),
- display_type_(0),
- have_display_type_(false),
- window_(0),
- display_size_(GetDisplaySize()),
- egl_platform_(std::move(egl_platform)),
- overlay_count_(0),
- previous_frame_overlay_count_(0) {}
-
-SurfaceFactoryCast::~SurfaceFactoryCast() {
- // eglTerminate must be called first on display before releasing resources
- // and shutting down hardware
- TerminateDisplay();
- ShutdownHardware();
-}
+class CastPixmap : public NativePixmap {
+ public:
+ explicit CastPixmap(GLOzoneEglCast* parent) : parent_(parent) {}
-void SurfaceFactoryCast::InitializeHardware() {
- if (state_ == kInitialized) {
- return;
+ void* GetEGLClientBuffer() const override {
+ // TODO(halliwell): try to implement this through CastEglPlatform.
+ return nullptr;
}
- CHECK_EQ(state_, kUninitialized);
-
- if (egl_platform_->InitializeHardware()) {
- state_ = kInitialized;
- } else {
- ShutdownHardware();
- state_ = kFailed;
+ bool AreDmaBufFdsValid() const override { return false; }
+ size_t GetDmaBufFdCount() const override { return 0; }
+ int GetDmaBufFd(size_t plane) const override { return -1; }
+ int GetDmaBufPitch(size_t plane) const override { return 0; }
+ int GetDmaBufOffset(size_t plane) const override { return 0; }
+ uint64_t GetDmaBufModifier(size_t plane) const override { return 0; }
+ gfx::BufferFormat GetBufferFormat() const override {
+ return gfx::BufferFormat::BGRA_8888;
}
-}
-
-void SurfaceFactoryCast::TerminateDisplay() {
- void* egl_lib_handle = egl_platform_->GetEglLibrary();
- if (!egl_lib_handle)
- return;
-
- EGLGetDisplayFn get_display =
- reinterpret_cast<EGLGetDisplayFn>(dlsym(egl_lib_handle, "eglGetDisplay"));
- EGLTerminateFn terminate =
- reinterpret_cast<EGLTerminateFn>(dlsym(egl_lib_handle, "eglTerminate"));
- DCHECK(get_display);
- DCHECK(terminate);
-
- EGLDisplay display = get_display(GetNativeDisplay());
- DCHECK_NE(display, EGL_NO_DISPLAY);
-
- EGLBoolean terminate_result = terminate(display);
- DCHECK_EQ(terminate_result, static_cast<EGLBoolean>(EGL_TRUE));
-}
-
-void SurfaceFactoryCast::ShutdownHardware() {
- if (state_ != kInitialized)
- return;
-
- DestroyDisplayTypeAndWindow();
-
- egl_platform_->ShutdownHardware();
-
- state_ = kUninitialized;
-}
-
-void SurfaceFactoryCast::OnSwapBuffers() {
- DCHECK(overlay_count_ == 0 || overlay_count_ == 1);
-
- // Logging for overlays to help diagnose bugs when nothing is visible on
- // screen. Logging this every frame would be overwhelming, so we just
- // log on the transitions from 0 overlays -> 1 overlay and vice versa.
- if (overlay_count_ == 0 && previous_frame_overlay_count_ != 0) {
- LOG(INFO) << "Overlays deactivated";
- } else if (overlay_count_ != 0 && previous_frame_overlay_count_ == 0) {
- LOG(INFO) << "Overlays activated: " << overlay_bounds_.ToString();
- } else if (overlay_count_ == previous_frame_overlay_count_ &&
- overlay_bounds_ != previous_frame_overlay_bounds_) {
- LOG(INFO) << "Overlay geometry changed to " << overlay_bounds_.ToString();
+ gfx::Size GetBufferSize() const override { return gfx::Size(); }
+
+ bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
+ int plane_z_order,
+ gfx::OverlayTransform plane_transform,
+ const gfx::Rect& display_bounds,
+ const gfx::RectF& crop_rect) override {
+ parent_->OnOverlayScheduled(display_bounds);
+ return true;
+ }
+ void SetProcessingCallback(
+ const ProcessingCallback& processing_callback) override {}
+ gfx::NativePixmapHandle ExportHandle() override {
+ return gfx::NativePixmapHandle();
}
- previous_frame_overlay_count_ = overlay_count_;
- previous_frame_overlay_bounds_ = overlay_bounds_;
- overlay_count_ = 0;
-}
+ private:
+ ~CastPixmap() override {}
-void SurfaceFactoryCast::OnOverlayScheduled(const gfx::Rect& display_bounds) {
- ++overlay_count_;
- overlay_bounds_ = display_bounds;
-}
+ GLOzoneEglCast* parent_;
-scoped_refptr<gl::GLSurface> SurfaceFactoryCast::CreateViewGLSurface(
- gl::GLImplementation implementation,
- gfx::AcceleratedWidget widget) {
- if (implementation != gl::kGLImplementationEGLGLES2) {
- NOTREACHED();
- return nullptr;
- }
+ DISALLOW_COPY_AND_ASSIGN(CastPixmap);
+};
- // Verify requested widget dimensions match our current display size.
- DCHECK_EQ(widget >> 16, display_size_.width());
- DCHECK_EQ(widget & 0xffff, display_size_.height());
+} // namespace
- return gl::InitializeGLSurface(new GLSurfaceCast(widget, this));
-}
+SurfaceFactoryCast::SurfaceFactoryCast() {}
-scoped_refptr<gl::GLSurface> SurfaceFactoryCast::CreateOffscreenGLSurface(
- gl::GLImplementation implementation,
- const gfx::Size& size) {
- if (implementation != gl::kGLImplementationEGLGLES2) {
- NOTREACHED();
- return nullptr;
+SurfaceFactoryCast::SurfaceFactoryCast(
+ std::unique_ptr<chromecast::CastEglPlatform> egl_platform)
+ : egl_implementation_(
+ base::MakeUnique<GLOzoneEglCast>(std::move(egl_platform))) {}
+
+SurfaceFactoryCast::~SurfaceFactoryCast() {}
+
+std::vector<gl::GLImplementation>
+SurfaceFactoryCast::GetAllowedGLImplementations() {
+ std::vector<gl::GLImplementation> impls;
+ if (egl_implementation_)
+ impls.push_back(gl::kGLImplementationEGLGLES2);
+ impls.push_back(gl::kGLImplementationOSMesaGL);
+ return impls;
+}
+
+GLOzone* SurfaceFactoryCast::GetGLOzone(gl::GLImplementation implementation) {
+ switch (implementation) {
+ case gl::kGLImplementationEGLGLES2:
+ return egl_implementation_.get();
+ default:
+ return nullptr;
}
-
- return gl::InitializeGLSurface(new gl::PbufferGLSurfaceEGL(size));
}
std::unique_ptr<SurfaceOzoneCanvas> SurfaceFactoryCast::CreateCanvasForWidget(
gfx::AcceleratedWidget widget) {
// Software canvas support only in headless mode
- if (egl_platform_)
+ if (egl_implementation_)
return nullptr;
return base::WrapUnique<SurfaceOzoneCanvas>(new DummySurface());
}
-intptr_t SurfaceFactoryCast::GetNativeDisplay() {
- CreateDisplayTypeAndWindowIfNeeded();
- return reinterpret_cast<intptr_t>(display_type_);
-}
-
-void SurfaceFactoryCast::CreateDisplayTypeAndWindowIfNeeded() {
- if (state_ == kUninitialized) {
- InitializeHardware();
- }
- DCHECK_EQ(state_, kInitialized);
- if (!have_display_type_) {
- chromecast::Size create_size = FromGfxSize(display_size_);
- display_type_ = egl_platform_->CreateDisplayType(create_size);
- have_display_type_ = true;
- }
- if (!window_) {
- chromecast::Size create_size = FromGfxSize(display_size_);
- window_ = egl_platform_->CreateWindow(display_type_, create_size);
- if (!window_) {
- DestroyDisplayTypeAndWindow();
- state_ = kFailed;
- LOG(FATAL) << "Create EGLNativeWindowType(" << display_size_.ToString()
- << ") failed.";
- }
- }
-}
-
-intptr_t SurfaceFactoryCast::GetNativeWindow() {
- CreateDisplayTypeAndWindowIfNeeded();
- return reinterpret_cast<intptr_t>(window_);
-}
-
-bool SurfaceFactoryCast::ResizeDisplay(gfx::Size size) {
- DCHECK_EQ(size.width(), display_size_.width());
- DCHECK_EQ(size.height(), display_size_.height());
- return true;
-}
-
-void SurfaceFactoryCast::DestroyWindow() {
- if (window_) {
- egl_platform_->DestroyWindow(window_);
- window_ = 0;
- }
-}
-
-void SurfaceFactoryCast::DestroyDisplayTypeAndWindow() {
- DestroyWindow();
- if (have_display_type_) {
- egl_platform_->DestroyDisplayType(display_type_);
- display_type_ = 0;
- have_display_type_ = false;
- }
-}
-
-void SurfaceFactoryCast::ChildDestroyed() {
- if (egl_platform_->MultipleSurfaceUnsupported())
- DestroyWindow();
-}
-
scoped_refptr<NativePixmap> SurfaceFactoryCast::CreateNativePixmap(
gfx::AcceleratedWidget widget,
gfx::Size size,
gfx::BufferFormat format,
gfx::BufferUsage usage) {
- class CastPixmap : public NativePixmap {
- public:
- explicit CastPixmap(SurfaceFactoryCast* parent) : parent_(parent) {}
-
- void* GetEGLClientBuffer() const override {
- // TODO(halliwell): try to implement this through CastEglPlatform.
- return nullptr;
- }
- bool AreDmaBufFdsValid() const override { return false; }
- size_t GetDmaBufFdCount() const override { return 0; }
- int GetDmaBufFd(size_t plane) const override { return -1; }
- int GetDmaBufPitch(size_t plane) const override { return 0; }
- int GetDmaBufOffset(size_t plane) const override { return 0; }
- uint64_t GetDmaBufModifier(size_t plane) const override { return 0; }
- gfx::BufferFormat GetBufferFormat() const override {
- return gfx::BufferFormat::BGRA_8888;
- }
- gfx::Size GetBufferSize() const override { return gfx::Size(); }
-
- bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
- int plane_z_order,
- gfx::OverlayTransform plane_transform,
- const gfx::Rect& display_bounds,
- const gfx::RectF& crop_rect) override {
- parent_->OnOverlayScheduled(display_bounds);
- return true;
- }
- void SetProcessingCallback(
- const ProcessingCallback& processing_callback) override {}
- gfx::NativePixmapHandle ExportHandle() override {
- return gfx::NativePixmapHandle();
- }
-
- private:
- ~CastPixmap() override {}
-
- SurfaceFactoryCast* parent_;
-
- DISALLOW_COPY_AND_ASSIGN(CastPixmap);
- };
- return make_scoped_refptr(new CastPixmap(this));
-}
-
-bool SurfaceFactoryCast::LoadEGLGLES2Bindings() {
- if (state_ != kInitialized) {
- InitializeHardware();
- if (state_ != kInitialized) {
- return false;
- }
- }
-
- void* lib_egl = egl_platform_->GetEglLibrary();
- void* lib_gles2 = egl_platform_->GetGles2Library();
- gl::GLGetProcAddressProc gl_proc = reinterpret_cast<gl::GLGetProcAddressProc>(
- egl_platform_->GetGLProcAddressProc());
- if (!lib_egl || !lib_gles2 || !gl_proc) {
- return false;
- }
-
- gl::SetGLGetProcAddressProc(gl_proc);
- gl::AddGLNativeLibrary(lib_egl);
- gl::AddGLNativeLibrary(lib_gles2);
- return true;
+ return make_scoped_refptr(new CastPixmap(egl_implementation_.get()));
}
} // namespace ui
« no previous file with comments | « ui/ozone/platform/cast/surface_factory_cast.h ('k') | ui/ozone/public/native_pixmap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698