提交 9546168c 编写于 作者: J Jason Simmons 提交者: GitHub

Recreate the EGL surface after a resize in order to correctly handle screen...

Recreate the EGL surface after a resize in order to correctly handle screen rotation on Android (#2813)
上级 d75656b0
......@@ -83,14 +83,17 @@ void RasterizerDirect::Draw(uint64_t layer_tree_ptr,
std::unique_ptr<flow::LayerTree> layer_tree(
reinterpret_cast<flow::LayerTree*>(layer_tree_ptr));
SkISize size = layer_tree->frame_size();
if (platform_view_->GetSize() != size) {
platform_view_->Resize(size);
}
if (platform_view_ == nullptr || !platform_view_->ContextMakeCurrent() ||
!layer_tree->root_layer()) {
callback.Run();
return;
}
SkISize size = layer_tree->frame_size();
// There is no way for the compositor to know how long the layer tree
// construction took. Fortunately, the layer tree does. Grab that time
// for instrumentation.
......
......@@ -129,6 +129,30 @@ class AndroidGLContext {
bool SwapBuffers() { return eglSwapBuffers(display_, surface_); }
SkISize GetSize() {
EGLint width = 0;
EGLint height = 0;
if (!eglQuerySurface(display_, surface_, EGL_WIDTH, &width) ||
!eglQuerySurface(display_, surface_, EGL_HEIGHT, &height)) {
LOG(ERROR) << "Unable to query EGL surface size";
return SkISize::Make(0, 0);
}
return SkISize::Make(width, height);
}
void Resize(const SkISize& size) {
eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
TeardownSurface(display_, surface_);
bool success;
std::tie(success, surface_) =
CreateWindowSurface(display_, config_, window_.handle());
if (!success) {
LOG(ERROR) << "Unable to create EGL window surface";
}
}
private:
AndroidNativeWindow window_;
EGLDisplay display_;
......@@ -318,5 +342,13 @@ bool PlatformViewAndroid::SwapBuffers() {
return context_ != nullptr ? context_->SwapBuffers() : false;
}
SkISize PlatformViewAndroid::GetSize() {
return context_->GetSize();
}
void PlatformViewAndroid::Resize(const SkISize& size) {
context_->Resize(size);
}
} // namespace shell
} // namespace sky
......@@ -48,6 +48,12 @@ class PlatformViewAndroid : public PlatformView {
// sky::shell::PlatformView override
bool SwapBuffers() override;
// sky::shell::PlatformView override
virtual SkISize GetSize();
// sky::shell::PlatformView override
virtual void Resize(const SkISize& size);
private:
// In principle, the ShellView should own the PlatformView, but because our
// lifetime is controlled by the Android view hierarchy, we flip around the
......
......@@ -19,7 +19,8 @@ PlatformView::Config::~Config() {}
PlatformView::PlatformView(const PlatformView::Config& config,
SurfaceConfig surface_config)
: config_(config), surface_config_(surface_config) {}
: config_(config), surface_config_(surface_config),
size_(SkISize::Make(0, 0)) {}
PlatformView::~PlatformView() {}
......@@ -72,5 +73,13 @@ void PlatformView::NotifyDestroyed() {
latch.Wait();
}
SkISize PlatformView::GetSize() {
return size_;
}
void PlatformView::Resize(const SkISize& size) {
size_ = size;
}
} // namespace shell
} // namespace sky
......@@ -9,6 +9,7 @@
#include "base/memory/weak_ptr.h"
#include "base/synchronization/waitable_event.h"
#include "sky/shell/ui_delegate.h"
#include "third_party/skia/include/core/SkSize.h"
namespace sky {
namespace shell {
......@@ -57,11 +58,16 @@ class PlatformView {
virtual bool SwapBuffers() = 0;
virtual SkISize GetSize();
virtual void Resize(const SkISize& size);
protected:
explicit PlatformView(const Config& config, SurfaceConfig surface_config);
Config config_;
SurfaceConfig surface_config_;
SkISize size_;
private:
DISALLOW_COPY_AND_ASSIGN(PlatformView);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册