osr_view_proxy.cc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright (c) 2017 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "shell/browser/osr/osr_view_proxy.h"
  5. #include <memory>
  6. namespace electron {
  7. OffscreenViewProxy::OffscreenViewProxy(views::View* view) : view_(view) {
  8. view_bitmap_ = std::make_unique<SkBitmap>();
  9. }
  10. OffscreenViewProxy::~OffscreenViewProxy() {
  11. if (observer_) {
  12. observer_->ProxyViewDestroyed(this);
  13. }
  14. }
  15. void OffscreenViewProxy::SetObserver(OffscreenViewProxyObserver* observer) {
  16. if (observer_) {
  17. observer_->ProxyViewDestroyed(this);
  18. }
  19. observer_ = observer;
  20. }
  21. void OffscreenViewProxy::RemoveObserver() {
  22. observer_ = nullptr;
  23. }
  24. void OffscreenViewProxy::SetBitmap(const SkBitmap& bitmap) {
  25. if (view_bounds_.width() == bitmap.width() &&
  26. view_bounds_.height() == bitmap.height() && observer_) {
  27. view_bitmap_ = std::make_unique<SkBitmap>(bitmap);
  28. observer_->OnProxyViewPaint(view_bounds_);
  29. }
  30. }
  31. void OffscreenViewProxy::SetBounds(const gfx::Rect& bounds) {
  32. view_bounds_ = bounds;
  33. }
  34. void OffscreenViewProxy::OnEvent(ui::Event* event) {
  35. if (view_) {
  36. view_->OnEvent(event);
  37. }
  38. }
  39. } // namespace electron