Browse Source

build: turn on OSR for GN builds (#14352)

* build: turn on OSR for GN builds

* remove mac-only speech functions in osr

They were removed as a part of https://chromium-review.googlesource.com/c/chromium/src/+/923548

* implement WasResized in MacHelper

* add missing screen include

* fix: use proper bitmap operations to construct frame to avoid failing checks

* switch to SkCanvas for drawing
Alexey Kuzmin 6 years ago
parent
commit
638311b6b3

+ 1 - 1
BUILD.gn

@@ -34,7 +34,7 @@ declare_args() {
 
   enable_desktop_capturer = true
   enable_run_as_node = true
-  enable_osr = false
+  enable_osr = true
   enable_view_api = false
 
   # Provide a fake location provider for mocking

+ 12 - 46
atom/browser/osr/osr_render_widget_host_view.cc

@@ -27,13 +27,16 @@
 #include "content/public/browser/context_factory.h"
 #include "content/public/browser/render_process_host.h"
 #include "media/base/video_frame.h"
+#include "third_party/skia/include/core/SkCanvas.h"
 #include "third_party/blink/public/platform/web_input_event.h"
 #include "ui/compositor/compositor.h"
 #include "ui/compositor/layer.h"
 #include "ui/compositor/layer_type.h"
 #include "ui/events/base_event_utils.h"
 #include "ui/events/event_constants.h"
+#include "ui/gfx/canvas.h"
 #include "ui/gfx/geometry/dip_util.h"
+#include "ui/gfx/image/image_skia.h"
 #include "ui/gfx/native_widget_types.h"
 #include "ui/gfx/skbitmap_operations.h"
 #include "ui/latency/latency_info.h"
@@ -951,32 +954,6 @@ void OffScreenRenderWidgetHostView::SetWantsAnimateOnlyBeginFrames() {
   }
 }
 
-void CopyBitmapTo(const SkBitmap& destination,
-                  const SkBitmap& source,
-                  const gfx::Rect& pos) {
-  char* src = static_cast<char*>(source.getPixels());
-  char* dest = static_cast<char*>(destination.getPixels());
-  int pixelsize = source.bytesPerPixel();
-
-  int width =
-      pos.x() + pos.width() <= destination.width()
-          ? pos.width()
-          : pos.width() - ((pos.x() + pos.width()) - destination.width());
-  int height =
-      pos.y() + pos.height() <= destination.height()
-          ? pos.height()
-          : pos.height() - ((pos.y() + pos.height()) - destination.height());
-
-  if (width > 0 && height > 0) {
-    for (int i = 0; i < height; i++) {
-      memcpy(dest + ((pos.y() + i) * destination.width() + pos.x()) * pixelsize,
-             src + (i * source.width()) * pixelsize, width * pixelsize);
-    }
-  }
-
-  destination.notifyPixelsChanged();
-}
-
 void OffScreenRenderWidgetHostView::OnPaint(const gfx::Rect& damage_rect,
                                             const SkBitmap& bitmap) {
   TRACE_EVENT0("electron", "OffScreenRenderWidgetHostView::OnPaint");
@@ -988,40 +965,29 @@ void OffScreenRenderWidgetHostView::OnPaint(const gfx::Rect& damage_rect,
   } else {
     gfx::Rect damage(damage_rect);
 
-    std::vector<gfx::Rect> damages;
-    std::vector<const SkBitmap*> bitmaps;
-    std::vector<SkBitmap> originals;
+    gfx::Size size = GetViewBounds().size();
+    SkBitmap backing;
+    backing.allocN32Pixels(size.width(), size.height(), false);
+    SkCanvas canvas(backing);
+
+    canvas.writePixels(bitmap, 0, 0);
 
     if (popup_host_view_ && popup_bitmap_.get()) {
       gfx::Rect pos = popup_host_view_->popup_position_;
       damage.Union(pos);
-      damages.push_back(pos);
-      bitmaps.push_back(popup_bitmap_.get());
-      originals.push_back(SkBitmapOperations::CreateTiledBitmap(
-          bitmap, pos.x(), pos.y(), pos.width(), pos.height()));
+      canvas.writePixels(*popup_bitmap_.get(), pos.x(), pos.y());
     }
 
     for (auto* proxy_view : proxy_views_) {
       gfx::Rect pos = proxy_view->GetBounds();
       damage.Union(pos);
-      damages.push_back(pos);
-      bitmaps.push_back(proxy_view->GetBitmap());
-      originals.push_back(SkBitmapOperations::CreateTiledBitmap(
-          bitmap, pos.x(), pos.y(), pos.width(), pos.height()));
-    }
-
-    for (size_t i = 0; i < damages.size(); i++) {
-      CopyBitmapTo(bitmap, *(bitmaps[i]), damages[i]);
+      canvas.writePixels(*proxy_view->GetBitmap(), pos.x(), pos.y());
     }
 
     damage.Intersect(GetViewBounds());
     paint_callback_running_ = true;
-    callback_.Run(damage, bitmap);
+    callback_.Run(damage, backing);
     paint_callback_running_ = false;
-
-    for (size_t i = 0; i < damages.size(); i++) {
-      CopyBitmapTo(bitmap, originals[i], damages[i]);
-    }
   }
 
   ReleaseResize();

+ 0 - 3
atom/browser/osr/osr_render_widget_host_view.h

@@ -112,11 +112,8 @@ class OffScreenRenderWidgetHostView
 #if defined(OS_MACOSX)
   void SetActive(bool active) override;
   void ShowDefinitionForSelection() override;
-  bool SupportsSpeech() const override;
   void SpeakSelection() override;
-  bool IsSpeaking() const override;
   bool ShouldContinueToPauseForFrame() override;
-  void StopSpeaking() override;
   bool UpdateNSViewAndDisplay();
 #endif  // defined(OS_MACOSX)
 

+ 3 - 10
atom/browser/osr/osr_render_widget_host_view_mac.mm

@@ -9,6 +9,7 @@
 #include "base/strings/utf_string_conversions.h"
 #include "content/common/view_messages.h"
 #include "ui/accelerated_widget_mac/accelerated_widget_mac.h"
+#include "ui/display/screen.h"
 
 namespace {
 
@@ -67,6 +68,8 @@ class MacHelper : public content::BrowserCompositorMacClient,
 
   void DestroyCompositorForShutdown() override {}
 
+  void WasResized() override { view_->render_widget_host()->WasResized(); }
+
  private:
   OffScreenRenderWidgetHostView* view_;
 
@@ -77,18 +80,8 @@ void OffScreenRenderWidgetHostView::SetActive(bool active) {}
 
 void OffScreenRenderWidgetHostView::ShowDefinitionForSelection() {}
 
-bool OffScreenRenderWidgetHostView::SupportsSpeech() const {
-  return false;
-}
-
 void OffScreenRenderWidgetHostView::SpeakSelection() {}
 
-bool OffScreenRenderWidgetHostView::IsSpeaking() const {
-  return false;
-}
-
-void OffScreenRenderWidgetHostView::StopSpeaking() {}
-
 bool OffScreenRenderWidgetHostView::UpdateNSViewAndDisplay() {
   return browser_compositor_->UpdateNSViewAndDisplay(
       GetRootLayer()->bounds().size(), GetDisplay());