提交 c44eaa41 编写于 作者: C Chinmay Garde

Extract and reuse common sky/shell components on Mac and iOS

上级 764ce409
......@@ -158,9 +158,6 @@ if (is_android) {
source_set(scaffolding_target) {
sources = [
"ios/main_ios.mm",
"ios/platform_service_provider_ios.cc",
"ios/platform_view_ios.h",
"ios/platform_view_ios.mm",
"ios/sky_app_delegate.h",
"ios/sky_app_delegate.mm",
"ios/sky_surface.h",
......@@ -169,10 +166,20 @@ if (is_android) {
"ios/sky_view_controller.mm",
]
set_sources_assignment_filter([])
sources += [
"mac/platform_mac.h",
"mac/platform_mac.mm",
"mac/platform_service_provider_mac.cc",
"mac/platform_view_mac.h",
"mac/platform_view_mac.mm",
]
set_sources_assignment_filter(sources_assignment_filter)
deps = common_deps + [
":common",
"//sky/services/ns_net",
]
":common",
"//sky/services/ns_net",
]
}
deps = [
......@@ -193,9 +200,57 @@ if (is_android) {
]
deps = common_deps + [
":common",
"//sky/services/testing:interfaces",
]
":common",
"//sky/services/testing:interfaces",
]
}
} else if (is_mac) {
import("//build/config/mac/rules.gni")
mac_app("shell") {
app_name = "Sky"
info_plist = "mac/Info.plist"
scaffolding_target = "mac_scaffolding"
# entitlements_path = ""
# code_signing_identity = ""
xibs = [
"mac/sky_mac.xib"
]
resource_copy_mac("sky_resources") {
resources = [ "//third_party/icu/android/icudtl.dat" ]
bundle_directory = "."
}
source_set(scaffolding_target) {
sources = [
"mac/main_mac.mm",
"mac/platform_mac.h",
"mac/platform_mac.mm",
"mac/platform_service_provider_mac.cc",
"mac/platform_view_mac.h",
"mac/platform_view_mac.mm",
"mac/sky_app_delegate.h",
"mac/sky_app_delegate.m",
"mac/sky_window.h",
"mac/sky_window.mm",
"testing/test_runner.cc",
"testing/test_runner.h",
]
deps = common_deps + [
":common",
"//sky/services/ns_net",
"//sky/services/testing:interfaces",
]
}
deps = [
":$scaffolding_target",
":sky_resources",
]
}
} else {
assert(false, "Unsupported platform")
......
......@@ -3,14 +3,9 @@
// found in the LICENSE file.
#import <UIKit/UIKit.h>
#include <asl.h>
#import "sky_app_delegate.h"
#include "base/at_exit.h"
#include "base/logging.h"
#include "base/i18n/icu_util.h"
#include "base/command_line.h"
#include "base/mac/scoped_nsautorelease_pool.h"
#include "ui/gl/gl_surface.h"
#import "sky/shell/ios/sky_app_delegate.h"
#include "sky/shell/mac/platform_mac.h"
extern "C" {
// TODO(csg): HACK! boringssl accesses this on Android using a weak symbol
......@@ -22,49 +17,9 @@ unsigned long getauxval(unsigned long type) {
}
}
static void InitializeLogging() {
logging::LoggingSettings settings;
settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
logging::InitLogging(settings);
logging::SetLogItems(false, // Process ID
false, // Thread ID
false, // Timestamp
false); // Tick count
}
static void RedirectIOConnectionsToSyslog() {
asl_log_descriptor(NULL, NULL, ASL_LEVEL_INFO, STDOUT_FILENO,
ASL_LOG_DESCRIPTOR_WRITE);
asl_log_descriptor(NULL, NULL, ASL_LEVEL_NOTICE, STDERR_FILENO,
ASL_LOG_DESCRIPTOR_WRITE);
}
#ifndef NDEBUG
static void SkyDebuggerHookMain(void) {
// By default, LLDB breaks way too early. This is before libraries have been
// loaded and __attribute__((constructor)) methods have been called. In most
// situations, this is unnecessary. Also, breakpoint resolution is not
// immediate. So we provide this hook to break on.
}
#endif
int main(int argc, char* argv[]) {
#ifndef NDEBUG
SkyDebuggerHookMain();
#endif
base::mac::ScopedNSAutoreleasePool pool;
base::AtExitManager exit_manager;
RedirectIOConnectionsToSyslog();
auto result = false;
result = base::CommandLine::Init(0, nullptr);
DLOG_ASSERT(result);
InitializeLogging();
result = base::i18n::InitializeICU();
DLOG_ASSERT(result);
result = gfx::GLSurface::InitializeOneOff();
DLOG_ASSERT(result);
return UIApplicationMain(argc, argv, nil,
NSStringFromClass([SkyAppDelegate class]));
int main(int argc, const char * argv[]) {
return PlatformMacMain(argc, argv, ^(){
return UIApplicationMain(argc, (char **)argv, nil,
NSStringFromClass([SkyAppDelegate class]));
});
}
......@@ -5,41 +5,11 @@
#import "sky_app_delegate.h"
#import "sky_view_controller.h"
#include "sky/shell/shell.h"
#include "sky/shell/service_provider.h"
#include "sky/shell/ui_delegate.h"
#include "base/lazy_instance.h"
#include "base/message_loop/message_loop.h"
@implementation SkyAppDelegate {
base::LazyInstance<scoped_ptr<base::MessageLoop>> _main_message_loop;
}
@implementation SkyAppDelegate
- (BOOL)application:(UIApplication*)application
didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
[self setupSkyShell];
[self setupViewport];
return YES;
}
- (void)setupSkyShell {
[self adoptPlatformRunLoop];
auto service_provider_context =
make_scoped_ptr(new sky::shell::ServiceProviderContext(
_main_message_loop.Get()->task_runner()));
sky::shell::Shell::Init(service_provider_context.Pass());
}
- (void)adoptPlatformRunLoop {
_main_message_loop.Get().reset(new base::MessageLoopForUI);
// One cannot start the message loop on the platform main thread. Instead,
// we attach to the CFRunLoop
base::MessageLoopForUI::current()->Attach();
}
- (void)setupViewport {
CGRect frame = [UIScreen mainScreen].bounds;
UIWindow* window = [[UIWindow alloc] initWithFrame:frame];
SkyViewController* viewController = [[SkyViewController alloc] init];
......@@ -48,6 +18,8 @@
self.window = window;
[window release];
[self.window makeKeyAndVisible];
return YES;
}
@end
......@@ -11,7 +11,7 @@
#include "base/time/time.h"
#include "mojo/public/cpp/bindings/interface_request.h"
#include "sky/services/engine/input_event.mojom.h"
#include "sky/shell/ios/platform_view_ios.h"
#include "sky/shell/mac/platform_view_mac.h"
#include "sky/shell/shell_view.h"
#include "sky/shell/shell.h"
#include "sky/shell/ui_delegate.h"
......@@ -114,8 +114,8 @@ static sky::InputEventPtr BasicInputEventFromRecognizer(
[self connectToEngineAndLoad];
}
- (sky::shell::PlatformViewIOS*)platformView {
auto view = static_cast<sky::shell::PlatformViewIOS*>(_shell_view->view());
- (sky::shell::PlatformViewMac*)platformView {
auto view = static_cast<sky::shell::PlatformViewMac*>(_shell_view->view());
DCHECK(view);
return view;
}
......
.idea/
.sconsign.dblite
.svn/
.DS_Store
*.swp
*.lock
profile
DerivedData/
build/
*.pbxuser
*.mode1v3
*.mode2v3
*.perspectivev3
!default.pbxuser
!default.mode1v3
!default.mode2v3
!default.perspectivev3
xcuserdata
*.moved-aside
Sky.xcodeproj/
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>Sky</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>org.domokit.sky</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Sky</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>10.6</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2015 The Chromium Authors. All rights reserved.</string>
<key>NSMainNibFile</key>
<string>sky_mac</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
// Copyright 2015 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.
#import <Cocoa/Cocoa.h>
#include <iostream>
#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "sky/engine/public/web/WebRuntimeFeatures.h"
#include "sky/shell/mac/platform_mac.h"
#include "base/command_line.h"
#include "sky/shell/switches.h"
#include "sky/shell/testing/test_runner.h"
namespace sky {
namespace shell {
namespace {
bool FlagsValid() {
base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(sky::shell::switches::kHelp) ||
(!command_line.HasSwitch(sky::shell::switches::kPackageRoot) &&
!command_line.HasSwitch(sky::shell::switches::kSnapshot))) {
return false;
}
return true;
}
void Usage() {
std::cerr << "(For Test Shell) Usage: sky_shell"
<< " --" << switches::kNonInteractive
<< " --" << switches::kPackageRoot << "=PACKAGE_ROOT"
<< " --" << switches::kSnapshot << "=SNAPSHOT"
<< " [ MAIN_DART ]" << std::endl;
}
void Init() {
base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
blink::WebRuntimeFeatures::enableObservatory(
!command_line.HasSwitch(switches::kNonInteractive));
// Explicitly boot the shared test runner.
TestRunner& runner = TestRunner::Shared();
std::string package_root =
command_line.GetSwitchValueASCII(switches::kPackageRoot);
runner.set_package_root(package_root);
scoped_ptr<TestRunner::SingleTest> single_test;
if (command_line.HasSwitch(switches::kSnapshot)) {
single_test.reset(new TestRunner::SingleTest);
single_test->path = command_line.GetSwitchValueASCII(switches::kSnapshot);
single_test->is_snapshot = true;
} else {
auto args = command_line.GetArgs();
if (!args.empty()) {
single_test.reset(new TestRunner::SingleTest);
single_test->path = args[0];
}
}
runner.Start(single_test.Pass());
}
} // namespace
} // namespace shell
} // namespace sky
int main(int argc, const char * argv[]) {
return PlatformMacMain(argc, argv, ^(){
if (!sky::shell::FlagsValid()) {
sky::shell::Usage();
return NSApplicationMain(argc, argv);
} else {
auto loop = base::MessageLoop::current();
loop->PostTask(FROM_HERE, base::Bind(&sky::shell::Init));
loop->Run();
return EXIT_SUCCESS;
}
});
}
// Copyright 2015 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_MAC_PLATFORM_MAC_H_
#define SKY_SHELL_MAC_PLATFORM_MAC_H_
#ifdef __cplusplus
extern "C" {
#endif
typedef int(^PlatformMacMainCallback)(void);
int PlatformMacMain(int argc, const char *argv[],
PlatformMacMainCallback callback);
#ifdef __cplusplus
}
#endif
#endif // SKY_SHELL_MAC_PLATFORM_MAC_H_
// Copyright 2015 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/mac/platform_mac.h"
#include <asl.h>
#include "base/at_exit.h"
#include "base/logging.h"
#include "base/i18n/icu_util.h"
#include "base/command_line.h"
#include "base/mac/scoped_nsautorelease_pool.h"
#include "ui/gl/gl_surface.h"
#include "sky/shell/shell.h"
#include "sky/shell/service_provider.h"
#include "sky/shell/ui_delegate.h"
#include "base/lazy_instance.h"
#include "base/message_loop/message_loop.h"
static void InitializeLogging() {
logging::LoggingSettings settings;
settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
logging::InitLogging(settings);
logging::SetLogItems(false, // Process ID
false, // Thread ID
false, // Timestamp
false); // Tick count
}
static void RedirectIOConnectionsToSyslog() {
#if TARGET_OS_IPHONE
asl_log_descriptor(NULL, NULL, ASL_LEVEL_INFO, STDOUT_FILENO,
ASL_LOG_DESCRIPTOR_WRITE);
asl_log_descriptor(NULL, NULL, ASL_LEVEL_NOTICE, STDERR_FILENO,
ASL_LOG_DESCRIPTOR_WRITE);
#endif
}
int PlatformMacMain(int argc, const char *argv[],
PlatformMacMainCallback callback) {
base::mac::ScopedNSAutoreleasePool pool;
base::AtExitManager exit_manager;
RedirectIOConnectionsToSyslog();
auto result = false;
result = base::CommandLine::Init(argc, argv);
DLOG_ASSERT(result);
InitializeLogging();
result = base::i18n::InitializeICU();
DLOG_ASSERT(result);
result = gfx::GLSurface::InitializeOneOff();
DLOG_ASSERT(result);
scoped_ptr<base::MessageLoopForUI> main_message_loop(
new base::MessageLoopForUI());
#if TARGET_OS_IPHONE
// One cannot start the message loop on the platform main thread. Instead,
// we attach to the CFRunLoop
main_message_loop->Attach();
#endif
auto service_provider_context =
make_scoped_ptr(new sky::shell::ServiceProviderContext(
main_message_loop->task_runner()));
sky::shell::Shell::Init(service_provider_context.Pass());
result = callback();
#if !TARGET_OS_IPHONE
if (result == EXIT_SUCCESS) {
main_message_loop->QuitNow();
}
#endif
return result;
}
......@@ -2,26 +2,26 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_SHELL_PLATFORM_VIEW_IOS_H_
#define SKY_SHELL_PLATFORM_VIEW_IOS_H_
#ifndef SKY_SHELL_PLATFORM_VIEW_MAC_H_
#define SKY_SHELL_PLATFORM_VIEW_MAC_H_
#include "sky/shell/platform_view.h"
namespace sky {
namespace shell {
class PlatformViewIOS : public PlatformView {
class PlatformViewMac : public PlatformView {
public:
explicit PlatformViewIOS(const Config& config);
~PlatformViewIOS() override;
explicit PlatformViewMac(const Config& config);
~PlatformViewMac() override;
void SurfaceCreated(gfx::AcceleratedWidget widget);
void SurfaceDestroyed(void);
private:
DISALLOW_COPY_AND_ASSIGN(PlatformViewIOS);
DISALLOW_COPY_AND_ASSIGN(PlatformViewMac);
};
} // namespace shell
} // namespace sky
#endif // SKY_SHELL_PLATFORM_VIEW_IOS_H_
#endif // SKY_SHELL_PLATFORM_VIEW_MAC_H_
......@@ -2,29 +2,29 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "platform_view_ios.h"
#include "sky/shell/mac/platform_view_mac.h"
namespace sky {
namespace shell {
PlatformView* PlatformView::Create(const Config& config) {
return new PlatformViewIOS(config);
return new PlatformViewMac(config);
}
PlatformViewIOS::PlatformViewIOS(const Config& config)
PlatformViewMac::PlatformViewMac(const Config& config)
: PlatformView(config) {
}
PlatformViewIOS::~PlatformViewIOS() {
PlatformViewMac::~PlatformViewMac() {
}
void PlatformViewIOS::SurfaceCreated(gfx::AcceleratedWidget widget) {
void PlatformViewMac::SurfaceCreated(gfx::AcceleratedWidget widget) {
DCHECK(window_ == 0);
window_ = widget;
SurfaceWasCreated();
}
void PlatformViewIOS::SurfaceDestroyed() {
void PlatformViewMac::SurfaceDestroyed() {
DCHECK(window_);
window_ = 0;
SurfaceWasDestroyed();
......
// Copyright 2015 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.
#import <Cocoa/Cocoa.h>
@interface SkyAppDelegate : NSObject <NSApplicationDelegate>
@end
// Copyright 2015 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.
#import "sky_app_delegate.h"
@interface SkyAppDelegate ()
@property (assign) IBOutlet NSWindow *window;
@end
@implementation SkyAppDelegate
@end
此差异已折叠。
// Copyright 2015 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.
#import <Cocoa/Cocoa.h>
@interface SkyWindow : NSWindow
@end
// Copyright 2015 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.
#import "sky_window.h"
#include "base/time/time.h"
#include "mojo/public/cpp/bindings/interface_request.h"
#include "sky/services/engine/input_event.mojom.h"
#include "sky/shell/mac/platform_view_mac.h"
#include "sky/shell/shell_view.h"
#include "sky/shell/shell.h"
#include "sky/shell/ui_delegate.h"
@interface SkyWindow () <NSWindowDelegate>
@property (assign) IBOutlet NSOpenGLView *renderSurface;
@property (getter=isSurfaceSetup) BOOL surfaceSetup;
@end
@implementation SkyWindow {
sky::SkyEnginePtr _sky_engine;
scoped_ptr<sky::shell::ShellView> _shell_view;
}
@synthesize renderSurface=_renderSurface;
@synthesize surfaceSetup=_surfaceSetup;
-(void) awakeFromNib {
[super awakeFromNib];
self.delegate = self;
[self windowDidResize:nil];
}
-(void) setupShell {
NSAssert(_shell_view == nullptr, @"The shell view must not already be set");
auto shell_view = new sky::shell::ShellView(sky::shell::Shell::Shared());
_shell_view.reset(shell_view);
auto widget = reinterpret_cast<gfx::AcceleratedWidget>(self.renderSurface);
self.platformView->SurfaceCreated(widget);
}
-(NSString *) skyInitialLoadURL {
return @"http://localhost:8080/sky/sdk/example/rendering/simple_autolayout.dart";
}
-(void) setupAndLoadDart {
auto interface_request = mojo::GetProxy(&_sky_engine);
self.platformView->ConnectToEngine(interface_request.Pass());
mojo::String string(self.skyInitialLoadURL.UTF8String);
_sky_engine->RunFromNetwork(string);
}
-(void) windowDidResize:(NSNotification *)notification {
[self setupSurfaceIfNecessary];
// Resize
// sky::ViewportMetricsPtr metrics = sky::ViewportMetrics::New();
// metrics->physical_width = size.width * scale;
// metrics->physical_height = size.height * scale;
// metrics->device_pixel_ratio = scale;
// _sky_engine->OnViewportMetricsChanged(metrics.Pass());
}
-(void) setupSurfaceIfNecessary {
if (self.isSurfaceSetup) {
return;
}
self.surfaceSetup = YES;
[self setupShell];
[self setupAndLoadDart];
}
- (sky::shell::PlatformViewMac*)platformView {
auto view = static_cast<sky::shell::PlatformViewMac*>(_shell_view->view());
DCHECK(view);
return view;
}
#pragma mark - Responder overrides
- (void)dispatchEvent:(NSEvent *)event phase:(NSEventPhase) phase {
NSPoint location = [_renderSurface convertPoint:event.locationInWindow
fromView:nil];
location.y = _renderSurface.frame.size.height - location.y;
}
- (void)mouseDown:(NSEvent *)event {
[self dispatchEvent:event phase:NSEventPhaseBegan];
}
- (void)mouseDragged:(NSEvent *)event {
[self dispatchEvent:event phase:NSEventPhaseChanged];
}
- (void)mouseUp:(NSEvent *)event {
[self dispatchEvent:event phase:NSEventPhaseEnded];
}
- (void) dealloc {
self.platformView->SurfaceDestroyed();
[super dealloc];
}
@end
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Copyright 2014 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 "ui/gl/gl_surface.h"
#include "ui/gl/gl_surface_mac.h"
#include "base/basictypes.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/trace_event/trace_event.h"
#include "ui/gl/gl_bindings.h"
#include "base/mac/scoped_nsautorelease_pool.h"
#include "ui/gl/gl_context.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_surface_stub.h"
#include "ui/gl/gpu_switching_manager.h"
#include <OpenGL/CGLRenderers.h>
#include <OpenGL/CGLTypes.h>
extern "C" {
// The header <OpenGL/OpenGL.h> may not be directly imported since it includes
// gltypes.h which conflict with the types already included
extern CGLError CGLChoosePixelFormat(const CGLPixelFormatAttribute *attribs,
CGLPixelFormatObj *pix, GLint *npix);
extern void CGLReleasePixelFormat(CGLPixelFormatObj pix);
}
#include "ui/gl/gl_enums.h"
#include "base/logging.h"
namespace gfx {
namespace {
// A "no-op" surface. It is not required that a CGLContextObj have an
// associated drawable (pbuffer or fullscreen context) in order to be
// made current. Everywhere this surface type is used, we allocate an
// FBO at the user level as the drawable of the associated context.
class GL_EXPORT NoOpGLSurface : public GLSurface {
public:
explicit NoOpGLSurface(const gfx::Size& size,
const gfx::SurfaceConfiguration conf)
: GLSurface(conf),
size_(size) {}
// Implement GLSurface.
bool Initialize() override { return true; }
void Destroy() override {}
bool IsOffscreen() override { return true; }
bool SwapBuffers() override {
NOTREACHED() << "Cannot call SwapBuffers on a NoOpGLSurface.";
return false;
}
gfx::Size GetSize() override { return size_; }
void* GetHandle() override { return NULL; }
void* GetDisplay() override { return NULL; }
bool IsSurfaceless() const override { return true; }
protected:
~NoOpGLSurface() override {}
private:
gfx::Size size_;
DISALLOW_COPY_AND_ASSIGN(NoOpGLSurface);
};
// static
bool InitializeOneOffForSandbox() {
static bool initialized = false;
if (initialized)
return true;
// This is called from the sandbox warmup code on Mac OS X.
// GPU-related stuff is very slow without this, probably because
// the sandbox prevents loading graphics drivers or some such.
std::vector<CGLPixelFormatAttribute> attribs;
if (ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus()) {
// Avoid switching to the discrete GPU just for this pixel
// format selection.
attribs.push_back(kCGLPFAAllowOfflineRenderers);
}
if (GetGLImplementation() == kGLImplementationAppleGL) {
attribs.push_back(kCGLPFARendererID);
attribs.push_back(static_cast<CGLPixelFormatAttribute>(
kCGLRendererGenericFloatID));
}
attribs.push_back(static_cast<CGLPixelFormatAttribute>(0));
CGLPixelFormatObj format;
GLint num_pixel_formats;
if (CGLChoosePixelFormat(&attribs.front(),
&format,
&num_pixel_formats) != kCGLNoError) {
LOG(ERROR) << "Error choosing pixel format.";
return false;
}
if (!format) {
LOG(ERROR) << "format == 0.";
return false;
}
CGLReleasePixelFormat(format);
DCHECK_NE(num_pixel_formats, 0);
initialized = true;
return true;
GLSurfaceMac::GLSurfaceMac(gfx::AcceleratedWidget widget,
const gfx::SurfaceConfiguration requested_configuration)
: GLSurface(requested_configuration),
widget_(widget) {
}
} // namespace
GLSurfaceMac::~GLSurfaceMac() {
Destroy();
}
bool GLSurfaceMac::OnMakeCurrent(GLContext* context) {
DCHECK(false);
return false;
}
bool GLSurfaceMac::SwapBuffers() {
DCHECK(false);
return false;
}
void GLSurfaceMac::Destroy() {
DCHECK(false);
}
bool GLSurfaceMac::IsOffscreen() {
DCHECK(false);
return false;
}
gfx::Size GLSurfaceMac::GetSize() {
DCHECK(false);
return Size(0.0, 0.0);
}
void* GLSurfaceMac::GetHandle() {
return (void*)widget_;
}
bool GLSurface::InitializeOneOffInternal() {
switch (GetGLImplementation()) {
case kGLImplementationDesktopGL:
case kGLImplementationAppleGL:
if (!InitializeOneOffForSandbox()) {
LOG(ERROR) << "GLSurfaceCGL::InitializeOneOff failed.";
return false;
}
break;
default:
break;
}
// On EGL, this method is used to perfom one-time initialization tasks like
// initializing the display, setting up config lists, etc. There is no such
// setup on Mac.
return true;
}
// static
scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
gfx::AcceleratedWidget window,
const gfx::SurfaceConfiguration& conf) {
TRACE_EVENT0("gpu", "GLSurface::CreateViewGLSurface");
switch (GetGLImplementation()) {
case kGLImplementationDesktopGL:
case kGLImplementationAppleGL: {
NOTIMPLEMENTED() << "No onscreen support on Mac.";
return NULL;
}
case kGLImplementationMockGL:
return new GLSurfaceStub(conf);
default:
NOTREACHED();
return NULL;
}
}
gfx::AcceleratedWidget window,
const gfx::SurfaceConfiguration& requested_configuration) {
DCHECK(window != kNullAcceleratedWidget);
scoped_refptr<GLSurfaceMac> surface =
new GLSurfaceMac(window, requested_configuration);
if (!surface->Initialize())
return NULL;
scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface(
const gfx::Size& size,
const gfx::SurfaceConfiguration& conf) {
TRACE_EVENT0("gpu", "GLSurface::CreateOffscreenGLSurface");
switch (GetGLImplementation()) {
case kGLImplementationDesktopGL:
case kGLImplementationAppleGL: {
scoped_refptr<GLSurface> surface(new NoOpGLSurface(size, conf));
if (!surface->Initialize())
return NULL;
return surface;
}
case kGLImplementationMockGL:
return new GLSurfaceStub(conf);
default:
NOTREACHED();
return NULL;
}
return surface;
}
} // namespace gfx
// Copyright 2014 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 "ui/gl/gl_surface.h"
namespace gfx {
class GL_EXPORT GLSurfaceMac : public GLSurface {
public:
GLSurfaceMac(gfx::AcceleratedWidget widget,
const gfx::SurfaceConfiguration requested_configuration);
bool SwapBuffers() override;
void Destroy() override;
bool IsOffscreen() override;
gfx::Size GetSize() override;
void* GetHandle() override;
bool OnMakeCurrent(GLContext* context) override;
private:
~GLSurfaceMac() override;
gfx::AcceleratedWidget widget_;
DISALLOW_COPY_AND_ASSIGN(GLSurfaceMac);
};
} // namespace gfx
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册