Skip to content

Commit

Permalink
compositor_unittests target is unimplmented on Mac
Browse files Browse the repository at this point in the history
Adds necessary pieces to get the WebKit compositor working with
compositor_unittests target on Mac.  Required gyp build flags are:

    'use_aura': 1,
    'use_webkit_compositor': 1,
    'use_skia': 1,

BUG=104390, 104555
TEST=compositor_unittests --gtest_filter=LayerWithRealCompositorTest.* passes and shows correct visual results.

Review URL: http://codereview.chromium.org/8486020

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110875 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
dhollowa@chromium.org committed Nov 21, 2011
1 parent 21ee224 commit 2f47fc4
Show file tree
Hide file tree
Showing 21 changed files with 467 additions and 34 deletions.
2 changes: 1 addition & 1 deletion base/base.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@
[ 'toolkit_uses_gtk==0', {
'sources!': [ 'message_pump_gtk.cc', ],
}],
[ '(touchui==0 and use_aura==0) or OS == "win"', {
[ '(touchui==0 and use_aura==0) or OS == "win" or OS == "mac"', {
'sources!' : [ 'message_pump_x.cc', ],
}, {
'sources!' : [ 'message_pump_gtk.cc', ],
Expand Down
2 changes: 1 addition & 1 deletion printing/printed_document.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class PRINTING_EXPORT PrintedDocument

// Draws the page in the context.
// Note: locks for a short amount of time in debug only.
#if defined(OS_WIN) || defined(OS_MACOSX)
#if defined(OS_WIN) || defined(OS_MACOSX) && !defined(USE_AURA)
void RenderPrintedPage(const PrintedPage& page,
gfx::NativeDrawingContext context) const;
#elif defined(OS_POSIX)
Expand Down
8 changes: 8 additions & 0 deletions printing/printing.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@
['exclude', 'metafile_skia_wrapper\\.(cc|h)$'],
],
}],
# Mac-Aura does not support printing.
['OS=="mac" and use_aura==1',{
'sources!': [
'printed_document_mac.cc',
'printing_context_mac.mm',
'printing_context_mac.h',
],
}],
['OS=="mac" and use_aura==0',{
'sources': [
'printing_context_mac.mm',
Expand Down
5 changes: 0 additions & 5 deletions ui/base/animation/tween.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
#endif

#include "base/logging.h"

#if !defined(OS_MACOSX)
#include "ui/gfx/interpolated_transform.h"
#endif

namespace ui {

Expand Down Expand Up @@ -86,7 +83,6 @@ gfx::Rect Tween::ValueBetween(double value,
target_bounds.height()));
}

#if !defined(OS_MACOSX)
// static
Transform Tween::ValueBetween(double value,
const Transform& start_transform,
Expand Down Expand Up @@ -127,6 +123,5 @@ Transform Tween::ValueBetween(double value,

return to_return;
}
#endif

} // namespace ui
5 changes: 0 additions & 5 deletions ui/base/animation/tween.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
#include "base/basictypes.h"
#include "ui/base/ui_export.h"
#include "ui/gfx/rect.h"

#if !defined(OS_MACOSX)
#include "ui/gfx/transform.h"
#endif

namespace ui {

Expand All @@ -37,11 +34,9 @@ class UI_EXPORT Tween {
static gfx::Rect ValueBetween(double value,
const gfx::Rect& start_bounds,
const gfx::Rect& target_bounds);
#if !defined(OS_MACOSX)
static Transform ValueBetween(double value,
const Transform& start_transform,
const Transform& target_transform);
#endif

private:
Tween();
Expand Down
9 changes: 5 additions & 4 deletions ui/gfx/compositor/compositor.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
'compositor_switches.cc',
'compositor_switches.h',
'compositor_win.cc',
'debug_utils.cc',
'debug_utils.h',
'debug_utils.cc',
'debug_utils.h',
'layer.cc',
'layer.h',
'layer_animation_delegate.h',
Expand All @@ -62,7 +62,7 @@
'screen_rotation.h',
],
'conditions': [
['os_posix == 1 and OS != "mac"', {
['os_posix == 1', {
'sources!': [
'compositor_stub.cc',
],
Expand Down Expand Up @@ -92,7 +92,7 @@
}],
['use_webkit_compositor == 1', {
'sources/': [
['exclude', '^compositor_(gl|win|stub).(h|cc)$'],
['exclude', '^compositor_(gl|mac|win|stub).(h|cc|mm)$'],
],
'dependencies': [
'<(DEPTH)/third_party/WebKit/Source/WebKit/chromium/WebKit.gyp:webkit',
Expand Down Expand Up @@ -162,6 +162,7 @@
'run_all_unittests.cc',
'test/test_compositor_host.h',
'test/test_compositor_host_linux.cc',
'test/test_compositor_host_mac.mm',
'test/test_compositor_host_win.cc',
'test/test_layer_animation_delegate.cc',
'test/test_layer_animation_delegate.h',
Expand Down
4 changes: 4 additions & 0 deletions ui/gfx/compositor/test/test_compositor_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ namespace ui {

class Compositor;

#if defined (OS_MACOSX)
class TestCompositorHost {
#else
class TestCompositorHost : public MessageLoop::Dispatcher {
#endif
public:
virtual ~TestCompositorHost() {}

Expand Down
146 changes: 146 additions & 0 deletions ui/gfx/compositor/test/test_compositor_host_mac.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
// Copyright (c) 2011 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/gfx/compositor/test/test_compositor_host.h"

#import <AppKit/NSApplication.h>
#import <AppKit/NSOpenGL.h>
#import <AppKit/NSView.h>
#import <AppKit/NSWindow.h>
#import <Foundation/NSAutoreleasePool.h>

#include "base/compiler_specific.h"
#include "ui/gfx/compositor/compositor.h"
#include "ui/gfx/rect.h"

// AcceleratedTestView provides an NSView class that delegates drawing to a
// ui::Compositor delegate, setting up the NSOpenGLContext as required.
@interface AcceleratedTestView : NSView {
scoped_refptr<ui::Compositor> compositor_;
}
// Designated initializer.
-(id)init;
-(void)setCompositor:(scoped_refptr<ui::Compositor>)compositor;
@end

@implementation AcceleratedTestView
-(id)init {
// The frame will be resized when reparented into the window's view hierarchy.
self = [super initWithFrame:NSZeroRect];
return self;
}

-(void)setCompositor:(scoped_refptr<ui::Compositor>)compositor {
compositor_ = compositor;
}

- (void)drawRect:(NSRect)rect {
DCHECK(compositor_) << "Drawing with no compositor set.";
compositor_->Draw(false);
}
@end

namespace ui {

// Tests that use Objective-C memory semantics need to have a top-level
// NSAutoreleasePool set up and initialized prior to execution and drained upon
// exit. The tests will leak otherwise.
class FoundationHost {
protected:
FoundationHost() {
pool_ = [[NSAutoreleasePool alloc] init];
}
virtual ~FoundationHost() {
[pool_ drain];
}

private:
NSAutoreleasePool* pool_;
DISALLOW_COPY_AND_ASSIGN(FoundationHost);
};

// Tests that use the AppKit framework need to have the NSApplication
// initialized prior to doing anything with display objects such as windows,
// views, or controls.
class AppKitHost : public FoundationHost {
protected:
AppKitHost() {
[NSApplication sharedApplication];
}
virtual ~AppKitHost() {
}
private:
DISALLOW_COPY_AND_ASSIGN(AppKitHost);
};

// TestCompositorHostMac provides a window surface and a coordinated compositor
// for use in the compositor unit tests.
class TestCompositorHostMac : public TestCompositorHost,
public CompositorDelegate,
public AppKitHost {
public:
TestCompositorHostMac(const gfx::Rect& bounds);
virtual ~TestCompositorHostMac();

private:
// TestCompositorHost:
virtual void Show() OVERRIDE;
virtual ui::Compositor* GetCompositor() OVERRIDE;

// CompositorDelegate:
virtual void ScheduleDraw() OVERRIDE;

gfx::Rect bounds_;
scoped_refptr<ui::Compositor> compositor_;

// Owned. Released when window is closed.
NSWindow* window_;

DISALLOW_COPY_AND_ASSIGN(TestCompositorHostMac);
};

TestCompositorHostMac::TestCompositorHostMac(const gfx::Rect& bounds)
: bounds_(bounds), window_(nil) {
}

TestCompositorHostMac::~TestCompositorHostMac() {
[window_ orderOut:nil];
[window_ close];
}

void TestCompositorHostMac::Show() {
DCHECK(!window_);
window_ = [[NSWindow alloc]
initWithContentRect:NSMakeRect(bounds_.x(),
bounds_.y(),
bounds_.width(),
bounds_.height())
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO];
AcceleratedTestView* view = [[[AcceleratedTestView alloc] init] autorelease];
compositor_ = ui::Compositor::Create(this, view, bounds_.size());
[view setCompositor:compositor_];
[window_ setContentView:view];
[window_ orderFront:nil];
}

ui::Compositor* TestCompositorHostMac::GetCompositor() {
return compositor_;
}

void TestCompositorHostMac::ScheduleDraw() {
if (!compositor_)
return;

// Force display now.
[window_ display];
}

// static
TestCompositorHost* TestCompositorHost::Create(const gfx::Rect& bounds) {
return new TestCompositorHostMac(bounds);
}

} // namespace ui
4 changes: 0 additions & 4 deletions ui/gfx/compositor/test/test_suite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ void CompositorTestSuite::Initialize() {
gfx::RegisterPathProvider();
ui::RegisterPathProvider();

// Force unittests to run using en-US so if we test against string
// output, it'll pass regardless of the system language.
ui::ResourceBundle::InitSharedInstance("en-US");

message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI));
ui::CompositorTestSupport::Initialize();
}
Expand Down
2 changes: 1 addition & 1 deletion ui/gfx/compositor/test/test_suite.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MessageLoop;
class CompositorTestSuite : public base::TestSuite {
public:
CompositorTestSuite(int argc, char** argv);
~CompositorTestSuite();
virtual ~CompositorTestSuite();

protected:
// base::TestSuite:
Expand Down
10 changes: 9 additions & 1 deletion ui/gfx/gl/gl.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
'gl_context.cc',
'gl_context.h',
'gl_context_linux.cc',
'gl_context_mac.cc',
'gl_context_mac.mm',
'gl_context_osmesa.cc',
'gl_context_osmesa.h',
'gl_context_stub.cc',
Expand Down Expand Up @@ -172,6 +172,14 @@
],
},
}],
['OS=="mac" and use_aura == 1', {
'sources': [
'gl_context_nsview.mm',
'gl_context_nsview.h',
'gl_surface_nsview.mm',
'gl_surface_nsview.h',
],
}],
],
},
],
Expand Down
22 changes: 17 additions & 5 deletions ui/gfx/gl/gl_context_mac.cc → ui/gfx/gl/gl_context_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
#include "ui/gfx/gl/gl_context_osmesa.h"
#include "ui/gfx/gl/gl_context_stub.h"
#include "ui/gfx/gl/gl_implementation.h"
#include "ui/gfx/gl/gl_surface_cgl.h"
#include "ui/gfx/gl/gl_surface_osmesa.h"
#include "ui/gfx/gl/gl_surface.h"

#if defined(USE_AURA)
#include "ui/gfx/gl/gl_context_nsview.h"
#endif

namespace {

Expand All @@ -38,9 +41,18 @@ scoped_refptr<GLContext> GLContext::CreateGLContext(
GpuPreference gpu_preference) {
switch (GetGLImplementation()) {
case kGLImplementationDesktopGL: {
scoped_refptr<GLContext> context(new GLContextCGL(share_group));
if (!context->Initialize(compatible_surface, gpu_preference))
return NULL;
scoped_refptr<GLContext> context;
if (compatible_surface->IsOffscreen()) {
context = new GLContextCGL(share_group);
if (!context->Initialize(compatible_surface, gpu_preference))
return NULL;
} else {
#if defined(USE_AURA)
context = new GLContextNSView(share_group);
if (!context->Initialize(compatible_surface, gpu_preference))
return NULL;
#endif
}

return context;
}
Expand Down
Loading

0 comments on commit 2f47fc4

Please sign in to comment.