Repository: electron/electron
File: shell/browser/osr/osr_render_widget_host_view.cc (C++)

Code before:
      render_widget_host_(content::RenderWidgetHostImpl::From(host)),
      parent_host_view_(parent_host_view),
      transparent_(transparent),
      offscreen_use_shared_texture_(offscreen_use_shared_texture),
      offscreen_shared_texture_pixel_format_(
          offscreen_shared_texture_pixel_format),
      offscreen_device_scale_factor_(offscreen_device_scale_factor),
      callback_(callback),
      frame_rate_(frame_rate),
      size_(initial_size),
      painting_(painting),
      delegated_frame_host_client_{
          std::make_unique<ElectronDelegatedFrameHostClient>(this)},
      delegated_frame_host_{std::make_unique<content::DelegatedFrameHost>(
          AllocateFrameSinkId(),
          delegated_frame_host_client_.get(),
          true /* should_register_frame_sink_id */)},
      cursor_manager_(std::make_unique<input::CursorManager>(this)),
      mouse_wheel_phase_handler_(this),
      backing_(std::make_unique<SkBitmap>()) {
  DCHECK(render_widget_host_);
  DCHECK(!render_widget_host_->GetView());

  // TODO(reito): Remove this when breaking change is announced for a sufficient
  // period.
  if (offscreen_device_scale_factor_ == 0.0f) {
    offscreen_device_scale_factor_ =
        GetDefaultDeviceScaleFactorFromDisplayInfo();
  }

  delegated_frame_host_allocator_.GenerateId();
  delegated_frame_host_surface_id_ =
      delegated_frame_host_allocator_.GetCurrentLocalSurfaceId();
  compositor_allocator_.GenerateId();
  compositor_surface_id_ = compositor_allocator_.GetCurrentLocalSurfaceId();

  root_layer_ = std::make_unique<ui::Layer>(ui::LAYER_SOLID_COLOR);

  root_layer()->SetColor(background_color_);

  ui::ContextFactory* context_factory = content::GetContextFactory();
  compositor_ = std::make_unique<ui::Compositor>(
      context_factory->AllocateFrameSinkId(), context_factory,
      base::SingleThreadTaskRunner::GetCurrentDefault(),
      false /* enable_pixel_canvas */,
      false /* use_external_begin_frame_control */);
  compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget);
  compositor_->SetDelegate(this);
  compositor_->SetRootLayer(root_layer_.get());

  ResizeRootLayer(false);

Review comment (suggestion):
Slightly risky to do a raw equality check for floating points. This is what `components/` uses:

```suggestion
  if (cc::MathUtil::IsWithinEpsilon(offscreen_device_scale_factor_, 0.0f)) {
```

Code after:
      parent_host_view_(parent_host_view),
      transparent_(transparent),
      offscreen_use_shared_texture_(offscreen_use_shared_texture),
      offscreen_shared_texture_pixel_format_(
          offscreen_shared_texture_pixel_format),
      offscreen_device_scale_factor_(offscreen_device_scale_factor),
      callback_(callback),
      frame_rate_(frame_rate),
      size_(initial_size),
      painting_(painting),
      delegated_frame_host_client_{
          std::make_unique<ElectronDelegatedFrameHostClient>(this)},
      delegated_frame_host_{std::make_unique<content::DelegatedFrameHost>(
          AllocateFrameSinkId(),
          delegated_frame_host_client_.get(),
          true /* should_register_frame_sink_id */)},
      cursor_manager_(std::make_unique<input::CursorManager>(this)),
      mouse_wheel_phase_handler_(this),
      backing_(std::make_unique<SkBitmap>()) {
  DCHECK(render_widget_host_);
  DCHECK(!render_widget_host_->GetView());

  // TODO(reito): Remove this when Electron 42.
  if (cc::MathUtil::IsWithinEpsilon(offscreen_device_scale_factor_, 0.0f)) {
    offscreen_device_scale_factor_ =
        GetDefaultDeviceScaleFactorFromDisplayInfo();
  }

  delegated_frame_host_allocator_.GenerateId();
  delegated_frame_host_surface_id_ =
      delegated_frame_host_allocator_.GetCurrentLocalSurfaceId();
  compositor_allocator_.GenerateId();
  compositor_surface_id_ = compositor_allocator_.GetCurrentLocalSurfaceId();

  root_layer_ = std::make_unique<ui::Layer>(ui::LAYER_SOLID_COLOR);

  root_layer()->SetColor(background_color_);

  ui::ContextFactory* context_factory = content::GetContextFactory();
  compositor_ = std::make_unique<ui::Compositor>(
      context_factory->AllocateFrameSinkId(), context_factory,
      base::SingleThreadTaskRunner::GetCurrentDefault(),
      false /* enable_pixel_canvas */,
      false /* use_external_begin_frame_control */);
  compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget);
  compositor_->SetDelegate(this);
  compositor_->SetRootLayer(root_layer_.get());

  ResizeRootLayer(false);

  render_widget_host_->SetView(this);