提交 287d187e 编写于 作者: A Adam Barth

Add GLFW platform to //sky/shell

上级 76dfd240
......@@ -338,7 +338,7 @@ component("skia") {
"//third_party/skia/src/fonts/SkGScalerContext.h",
]
if (is_ios || is_mac || is_android) {
if (is_ios || is_mac || is_android || use_glfw) {
sources -= [
"//third_party/skia/src/gpu/gl/GrGLCreateNativeInterface_none.cpp"
]
......@@ -357,6 +357,10 @@ component("skia") {
sources += [
"//third_party/skia/src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp"
]
} else if (use_glfw) {
sources += [
"//skia/ext/GrGLCreateNativeInterface_glfw.cpp"
]
}
set_sources_assignment_filter(sources_assignment_filter)
......@@ -522,6 +526,10 @@ component("skia") {
configs -= [ "//build/config/compiler:optimize" ]
configs += [ "//build/config/compiler:optimize_max" ]
}
if (use_glfw) {
deps += [ "//third_party/glfw" ]
}
}
# Separated out so it can be compiled with different flags for SSE.
......
/*
* Copyright 2014 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "gl/GrGLInterface.h"
#include "gl/GrGLAssembleInterface.h"
#include "gl/GrGLUtil.h"
#include "GLFW/glfw3.h"
static GrGLFuncPtr glfw_get(void* ctx, const char name[]) {
SkASSERT(nullptr == ctx);
SkASSERT(glfwGetCurrentContext());
return glfwGetProcAddress(name);
}
const GrGLInterface* GrGLCreateNativeInterface() {
if (nullptr == glfwGetCurrentContext()) {
return nullptr;
}
return GrGLAssembleInterface(nullptr, glfw_get);
}
......@@ -2,6 +2,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/ui.gni")
source_set("common") {
sources = [
"gpu/picture_serializer.cc",
......@@ -400,7 +402,6 @@ if (is_android) {
sources = [
"platform/linux/main_linux.cc",
"platform/linux/platform_view_linux.cc",
]
deps = [
......@@ -411,6 +412,21 @@ if (is_android) {
":gpu_direct",
":testing",
]
if (use_glfw) {
sources += [
"//sky/shell/platform/glfw/init_glfw.cc",
"//sky/shell/platform/glfw/init_glfw.h",
"//sky/shell/platform/glfw/platform_view_glfw.cc",
"//sky/shell/platform/glfw/platform_view_glfw.h",
"//sky/shell/platform/glfw/window_impl.cc",
"//sky/shell/platform/glfw/window_impl.h",
]
deps += [ "//third_party/glfw" ]
} else {
sources += [ "platform/linux/platform_view_linux.cc" ]
}
}
} else if (is_mac) {
import("//build/config/mac/rules.gni")
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/shell/platform/glfw/init_glfw.h"
#include <GLFW/glfw3.h>
#include <memory>
#include <string>
#include "base/command_line.h"
#include "sky/shell/platform/glfw/platform_view_glfw.h"
#include "sky/shell/platform/glfw/window_impl.h"
#include "sky/shell/switches.h"
#include "ui/gl/gl_surface.h"
namespace sky {
namespace shell {
bool InitInteractive() {
base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
std::string bundle_path =
command_line.GetSwitchValueASCII(sky::shell::switches::kFLX);
if (bundle_path.empty())
return false;
if (!glfwInit())
return false;
GLFWwindow* window = glfwCreateWindow(640, 480, "Flutter", NULL, NULL);
if (!window) {
glfwTerminate();
return false;
}
glfwMakeContextCurrent(window);
CHECK(gfx::GLSurface::InitializeOneOff());
glfwMakeContextCurrent(NULL);
std::string script_uri = std::string("file://") + bundle_path;
// TODO(abarth): Listen for a GLFW callback to delete this window.
(new WindowImpl(window))->RunFromBundle(script_uri, bundle_path);
return true;
}
} // namespace shell
} // namespace sky
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_SHELL_PLATFORM_GLFW_INIT_GLFW_H_
#define SKY_SHELL_PLATFORM_GLFW_INIT_GLFW_H_
namespace sky {
namespace shell {
bool InitInteractive();
} // namespace shell
} // namespace sky
#endif // SKY_SHELL_PLATFORM_GLFW_INIT_GLFW_H_
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/shell/platform/glfw/platform_view_glfw.h"
#include "sky/shell/gpu/direct/surface_notifications_direct.h"
namespace sky {
namespace shell {
PlatformView* PlatformView::Create(const Config& config) {
return new PlatformViewGLFW(config);
}
PlatformViewGLFW::PlatformViewGLFW(const Config& config)
: PlatformView(config), window_(gfx::kNullAcceleratedWidget) {}
PlatformViewGLFW::~PlatformViewGLFW() {}
void PlatformViewGLFW::SurfaceCreated(gfx::AcceleratedWidget widget) {
DCHECK(window_ == gfx::kNullAcceleratedWidget);
window_ = widget;
SurfaceNotificationsDirect::NotifyCreated(config_, window_);
}
void PlatformViewGLFW::SurfaceDestroyed() {
DCHECK(window_ != gfx::kNullAcceleratedWidget);
window_ = gfx::kNullAcceleratedWidget;
SurfaceNotificationsDirect::NotifyDestroyed(config_);
}
} // namespace shell
} // namespace sky
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_SHELL_PLATFORM_GLFW_PLATFORM_VIEW_GLFW_H_
#define SKY_SHELL_PLATFORM_GLFW_PLATFORM_VIEW_GLFW_H_
#include "sky/shell/platform_view.h"
namespace sky {
namespace shell {
class PlatformViewGLFW : public PlatformView {
public:
explicit PlatformViewGLFW(const Config& config);
~PlatformViewGLFW() override;
void SurfaceCreated(gfx::AcceleratedWidget widget);
void SurfaceDestroyed(void);
private:
gfx::AcceleratedWidget window_;
DISALLOW_COPY_AND_ASSIGN(PlatformViewGLFW);
};
} // namespace shell
} // namespace sky
#endif // SKY_SHELL_PLATFORM_GLFW_PLATFORM_VIEW_GLFW_H_
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/shell/platform/glfw/window_impl.h"
#include <GLFW/glfw3.h>
#include "sky/shell/platform/glfw/platform_view_glfw.h"
#include "sky/shell/shell.h"
namespace sky {
namespace shell {
namespace {
WindowImpl* ToImpl(GLFWwindow* window) {
return static_cast<WindowImpl*>(glfwGetWindowUserPointer(window));
}
void OnWindowSizeChanged(GLFWwindow* window, int width, int height) {
ToImpl(window)->UpdateViewportMetrics(width, height);
}
} // namespace
WindowImpl::WindowImpl(GLFWwindow* window)
: window_(window),
shell_view_(new ShellView(Shell::Shared())) {
glfwSetWindowUserPointer(window_, this);
auto platform_view =
static_cast<sky::shell::PlatformViewGLFW*>(shell_view_->view());
platform_view->SurfaceCreated(window);
platform_view->ConnectToEngine(mojo::GetProxy(&engine_));
int width = 0;
int height = 0;
glfwGetWindowSize(window_, &width, &height);
UpdateViewportMetrics(width, height);
glfwSetWindowSizeCallback(window_, OnWindowSizeChanged);
}
WindowImpl::~WindowImpl() {
shell_view_.reset();
glfwDestroyWindow(window_);
window_ = nullptr;
}
void WindowImpl::RunFromBundle(const std::string& script_uri,
const std::string& bundle_path) {
engine_->RunFromBundle(script_uri, bundle_path);
}
void WindowImpl::UpdateViewportMetrics(int width, int height) {
auto metrics = sky::ViewportMetrics::New();
metrics->physical_width = width;
metrics->physical_height = height;
// TODO(abarth): There doesn't appear to be a way to get the device pixel
// ratio from GLFW.
metrics->device_pixel_ratio = 1.0;
engine_->OnViewportMetricsChanged(metrics.Pass());
}
} // namespace shell
} // namespace sky
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_SHELL_PLATFORM_GLFW_WINDOW_IMPL_H_
#define SKY_SHELL_PLATFORM_GLFW_WINDOW_IMPL_H_
#include <memory>
#include <string>
#include "sky/services/engine/sky_engine.mojom.h"
#include "sky/shell/platform_view.h"
#include "sky/shell/shell_view.h"
namespace sky {
namespace shell {
class WindowImpl {
public:
explicit WindowImpl(GLFWwindow* window);
~WindowImpl();
void RunFromBundle(const std::string& script_uri,
const std::string& bundle_path);
void UpdateViewportMetrics(int width, int height);
private:
GLFWwindow* window_;
std::unique_ptr<ShellView> shell_view_;
sky::SkyEnginePtr engine_;
DISALLOW_COPY_AND_ASSIGN(WindowImpl);
};
} // namespace shell
} // namespace sky
#endif // SKY_SHELL_PLATFORM_GLFW_WINDOW_IMPL_H_
......@@ -14,6 +14,10 @@
#include "sky/shell/switches.h"
#include "sky/shell/testing/testing.h"
#if defined(USE_GLFW)
#include "sky/shell/platform/glfw/init_glfw.h"
#endif
int main(int argc, const char* argv[]) {
base::AtExitManager exit_manager;
base::CommandLine::Init(argc, argv);
......@@ -26,12 +30,16 @@ int main(int argc, const char* argv[]) {
}
base::MessageLoop message_loop;
mojo::embedder::Init(mojo::embedder::CreateSimplePlatformSupport());
sky::shell::Shell::InitStandalone();
if (!sky::shell::InitForTesting()) {
bool running = false;
#if defined(USE_GLFW)
if (!command_line.HasSwitch(sky::shell::switches::kNonInteractive))
running = sky::shell::InitInteractive();
#endif
if (!running && !sky::shell::InitForTesting()) {
sky::shell::switches::PrintUsage("sky_shell");
return 1;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册