Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <windows.ui.composition.h>
#include <winrt/Windows.Foundation.h>

#include <mutex>

#include "util/rohelper.h"

namespace flutter_inappwebview_plugin
Expand All @@ -24,6 +26,10 @@ namespace flutter_inappwebview_plugin
{
return device_context_.get();
}
// The immediate context is shared by every WebView of the plugin and is
// not thread-safe. Hold this while issuing a sequence of calls on it from
// a thread other than the one that created it (capture threads).
std::mutex& device_context_mutex() const { return device_context_mutex_; }

winrt::com_ptr<ABI::Windows::UI::Composition::ICompositor> CreateCompositor();

Expand All @@ -50,5 +56,6 @@ namespace flutter_inappwebview_plugin
device_winrt_;
winrt::com_ptr<ID3D11Device> device_{ nullptr };
winrt::com_ptr<ID3D11DeviceContext> device_context_{ nullptr };
mutable std::mutex device_context_mutex_;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ namespace flutter_inappwebview_plugin
if (SUCCEEDED(frame->get_Surface(frame_surface.put()))) {
last_frame_ =
TryGetDXGIInterfaceFromObject<ID3D11Texture2D>(frame_surface);
has_frame = !ShouldDropFrame();
has_frame = last_frame_ && !ShouldDropFrame() && AcceptFrame(last_frame_);
}
}

Expand All @@ -148,6 +148,11 @@ namespace flutter_inappwebview_plugin
}
}

bool TextureBridge::AcceptFrame(const winrt::com_ptr<ID3D11Texture2D>&)
{
return true;
}

bool TextureBridge::ShouldDropFrame()
{
if (!frame_duration_.has_value()) {
Expand Down Expand Up @@ -186,4 +191,4 @@ namespace flutter_inappwebview_plugin
last_frame_timestamp_.reset();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ namespace flutter_inappwebview_plugin
EventRegistrationToken on_frame_arrived_token_ = {};

virtual void StopInternal();
// Called under |mutex_| for every captured frame that survived the fps
// limit. Returning false skips the frame: Flutter is not notified and the
// frame is not drawn. The base bridge accepts everything; the GPU bridge
// rejects frames whose pixels equal the frame Flutter already shows, since
// Windows.Graphics.Capture delivers a frame on every compositor tick even
// when the captured visual has not changed.
virtual bool AcceptFrame(const winrt::com_ptr<ID3D11Texture2D>& frame);
void OnFrameArrived();
bool ShouldDropFrame();

Expand Down
Loading
Loading