#include "base/logging.h"
#include "ui/ozone/platform/dri/dri_buffer.h"
+#include "ui/ozone/platform/dri/dri_window_delegate.h"
#include "ui/ozone/platform/dri/dri_wrapper.h"
#include "ui/ozone/platform/dri/gbm_buffer_base.h"
+#include "ui/ozone/platform/dri/hardware_display_controller.h"
#include "ui/ozone/platform/dri/scanout_buffer.h"
namespace ui {
} // namespace
-GbmSurface::GbmSurface(
- const base::WeakPtr<HardwareDisplayController>& controller,
- gbm_device* device,
- DriWrapper* dri)
- : GbmSurfaceless(controller),
+GbmSurface::GbmSurface(DriWindowDelegate* window_delegate,
+ gbm_device* device,
+ DriWrapper* dri)
+ : GbmSurfaceless(window_delegate),
gbm_device_(device),
dri_(dri),
native_surface_(NULL),
- current_buffer_(NULL) {}
+ current_buffer_(NULL) {
+}
GbmSurface::~GbmSurface() {
if (current_buffer_)
}
bool GbmSurface::Initialize() {
+ // If we're initializing the surface without a controller (possible on startup
+ // where the surface creation can happen before the native window delegate
+ // IPCs arrive), initialize the size to a valid value such that surface
+ // creation doesn't fail.
+ gfx::Size size(1, 1);
+ if (window_delegate_->GetController()) {
+ size = window_delegate_->GetController()->GetModeSize();
+ }
// TODO(dnicoara) Check underlying system support for pixel format.
- native_surface_ = gbm_surface_create(
- gbm_device_,
- controller_->get_mode().hdisplay,
- controller_->get_mode().vdisplay,
- GBM_BO_FORMAT_XRGB8888,
- GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
+ native_surface_ =
+ gbm_surface_create(gbm_device_,
+ size.width(),
+ size.height(),
+ GBM_BO_FORMAT_XRGB8888,
+ GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
if (!native_surface_)
return false;
- size_.SetSize(controller_->get_mode().hdisplay,
- controller_->get_mode().vdisplay);
+ size_ = size;
return true;
}
gbm_bo* pending_buffer = gbm_surface_lock_front_buffer(native_surface_);
scoped_refptr<GbmSurfaceBuffer> primary =
GbmSurfaceBuffer::GetBuffer(pending_buffer);
- if (!primary) {
+ if (!primary.get()) {
primary = GbmSurfaceBuffer::CreateBuffer(dri_, pending_buffer);
- if (!primary) {
+ if (!primary.get()) {
LOG(ERROR) << "Failed to associate the buffer with the controller";
return false;
}
}
// The primary buffer is a special case.
- controller_->QueueOverlayPlane(OverlayPlane(primary));
+ if (window_delegate_->GetController())
+ window_delegate_->GetController()->QueueOverlayPlane(OverlayPlane(primary));
if (!GbmSurfaceless::OnSwapBuffers())
return false;