osr_view_proxy.cc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. const SkBitmap* OffscreenViewProxy::GetBitmap() const {
  25. return view_bitmap_.get();
  26. }
  27. void OffscreenViewProxy::SetBitmap(const SkBitmap& bitmap) {
  28. if (view_bounds_.width() == bitmap.width() &&
  29. view_bounds_.height() == bitmap.height() && observer_) {
  30. view_bitmap_ = std::make_unique<SkBitmap>(bitmap);
  31. observer_->OnProxyViewPaint(view_bounds_);
  32. }
  33. }
  34. const gfx::Rect& OffscreenViewProxy::GetBounds() {
  35. return view_bounds_;
  36. }
  37. void OffscreenViewProxy::SetBounds(const gfx::Rect& bounds) {
  38. view_bounds_ = bounds;
  39. }
  40. void OffscreenViewProxy::OnEvent(ui::Event* event) {
  41. if (view_) {
  42. view_->OnEvent(event);
  43. }
  44. }
  45. } // namespace electron