Skip to content

Commit

Permalink
Merge pull request flutter#2310 from abarth/mozart
Browse files Browse the repository at this point in the history
Port flutter.mojo to Mozart
  • Loading branch information
abarth committed Jan 29, 2016
2 parents 8d7a4bb + 215b19e commit 7e7df7f
Show file tree
Hide file tree
Showing 55 changed files with 1,522 additions and 1,164 deletions.
3 changes: 3 additions & 0 deletions flow/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ source_set("flow") {
"color_filter_layer.h",
"container_layer.cc",
"container_layer.h",
"child_scene_layer.cc",
"child_scene_layer.h",
"instrumentation.cc",
"instrumentation.h",
"layer.cc",
Expand All @@ -41,5 +43,6 @@ source_set("flow") {
deps = [
"//base",
"//skia",
"//mojo/services/gfx/composition/interfaces",
]
}
18 changes: 18 additions & 0 deletions flow/child_scene_layer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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 "flow/child_scene_layer.h"

namespace flow {

ChildSceneLayer::ChildSceneLayer() {
}

ChildSceneLayer::~ChildSceneLayer() {
}

void ChildSceneLayer::Paint(PaintContext::ScopedFrame& frame) {
}

} // namespace flow
40 changes: 40 additions & 0 deletions flow/child_scene_layer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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 FLOW_CHILD_SCENE_LAYER_H_
#define FLOW_CHILD_SCENE_LAYER_H_

#include "flow/layer.h"
#include "mojo/services/gfx/composition/interfaces/scenes.mojom.h"

namespace flow {

class ChildSceneLayer : public Layer {
public:
ChildSceneLayer();
~ChildSceneLayer() override;

void set_offset(const SkPoint& offset) { offset_ = offset; }

void set_physical_size(const SkISize& physical_size) {
physical_size_ = physical_size;
}

void set_scene_token(mojo::gfx::composition::SceneTokenPtr scene_token) {
scene_token_ = scene_token.Pass();
}

void Paint(PaintContext::ScopedFrame& frame) override;

private:
SkPoint offset_;
SkISize physical_size_;
mojo::gfx::composition::SceneTokenPtr scene_token_;

DISALLOW_COPY_AND_ASSIGN(ChildSceneLayer);
};

} // namespace flow

#endif // FLOW_CHILD_SCENE_LAYER_H_
33 changes: 4 additions & 29 deletions mojo/gpu/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ source_set("gpu") {
"gl_context_owner.h",
"gl_texture.cc",
"gl_texture.h",
"texture_cache.cc",
"texture_cache.h",
"texture_uploader.cc",
"texture_uploader.h",
]

public_deps = [
"//mojo/public/c/gpu",
]

deps = [
Expand All @@ -33,30 +33,5 @@ source_set("gpu") {
"//mojo/services/geometry/cpp",
"//mojo/services/geometry/interfaces",
"//mojo/services/gpu/interfaces",
"//mojo/services/surfaces/cpp",
"//mojo/services/surfaces/interfaces",
"//mojo/services/surfaces/interfaces:surface_id",
]
}

mojo_native_application("apptests") {
output_name = "texture_apptests"

testonly = true

sources = [
"texture_cache_unittest.cc",
"texture_uploader_unittest.cc",
]

deps = [
":gpu",
"//base",
"//mojo/application",
"//mojo/application:test_support",
"//mojo/public/cpp/bindings:callback",
"//mojo/services/geometry/interfaces",
"//mojo/services/surfaces/interfaces:surface_id",
"//testing/gtest",
]
}
38 changes: 22 additions & 16 deletions mojo/gpu/gl_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,41 @@
#include "mojo/gpu/gl_context.h"

#include "mojo/public/cpp/application/connect.h"
#include "mojo/public/interfaces/application/shell.mojom.h"
#include "mojo/public/interfaces/application/application_connector.mojom.h"
#include "mojo/services/gpu/interfaces/gpu.mojom.h"

namespace mojo {

GLContext::Observer::~Observer() {
}
GLContext::Observer::~Observer() {}

GLContext::GLContext(Shell* shell) : weak_factory_(this) {
ServiceProviderPtr native_viewport;
shell->ConnectToApplication("mojo:native_viewport_service",
GetProxy(&native_viewport), nullptr);
GpuPtr gpu_service;
ConnectToService(native_viewport.get(), &gpu_service);
CommandBufferPtr command_buffer;
gpu_service->CreateOffscreenGLES2Context(GetProxy(&command_buffer));
context_ = MGLCreateContext(MGL_API_VERSION_GLES2,
GLContext::GLContext(CommandBufferPtr command_buffer) : weak_factory_(this) {
context_ = MGLCreateContext(
MGL_API_VERSION_GLES2,
command_buffer.PassInterface().PassHandle().release().value(),
MGL_NO_CONTEXT,
&ContextLostThunk, this, Environment::GetDefaultAsyncWaiter());
MGL_NO_CONTEXT, &ContextLostThunk, this,
Environment::GetDefaultAsyncWaiter());
DCHECK(context_ != MGL_NO_CONTEXT);
}

GLContext::~GLContext() {
MGLDestroyContext(context_);
}

base::WeakPtr<GLContext> GLContext::Create(Shell* shell) {
return (new GLContext(shell))->weak_factory_.GetWeakPtr();
base::WeakPtr<GLContext> GLContext::CreateOffscreen(
ApplicationConnector* connector) {
ServiceProviderPtr native_viewport;
connector->ConnectToApplication("mojo:native_viewport_service",
GetProxy(&native_viewport), nullptr);
GpuPtr gpu_service;
ConnectToService(native_viewport.get(), &gpu_service);
CommandBufferPtr command_buffer;
gpu_service->CreateOffscreenGLES2Context(GetProxy(&command_buffer));
return CreateFromCommandBuffer(command_buffer.Pass());
}

base::WeakPtr<GLContext> GLContext::CreateFromCommandBuffer(
CommandBufferPtr command_buffer) {
return (new GLContext(command_buffer.Pass()))->weak_factory_.GetWeakPtr();
}

void GLContext::MakeCurrent() {
Expand Down
14 changes: 12 additions & 2 deletions mojo/gpu/gl_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "mojo/public/c/gpu/MGL/mgl.h"
#include "mojo/public/cpp/bindings/interface_ptr.h"

namespace mojo {
class ApplicationConnector;
class CommandBuffer;
using CommandBufferPtr = InterfacePtr<CommandBuffer>;
class Shell;

class GLContext {
Expand All @@ -23,7 +27,13 @@ class GLContext {
virtual ~Observer();
};

static base::WeakPtr<GLContext> Create(Shell* shell);
// Creates an offscreen GL context.
static base::WeakPtr<GLContext> CreateOffscreen(
ApplicationConnector* connector);

// Creates a GL context from a command buffer.
static base::WeakPtr<GLContext> CreateFromCommandBuffer(
CommandBufferPtr command_buffer);

void MakeCurrent();
bool IsCurrent();
Expand All @@ -33,7 +43,7 @@ class GLContext {
void RemoveObserver(Observer* observer);

private:
explicit GLContext(Shell* shell);
explicit GLContext(CommandBufferPtr command_buffer);
~GLContext();

static void ContextLostThunk(void* self);
Expand Down
5 changes: 2 additions & 3 deletions mojo/gpu/gl_context_owner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

namespace mojo {

GLContextOwner::GLContextOwner(mojo::Shell* shell)
: context_(mojo::GLContext::Create(shell)) {
}
GLContextOwner::GLContextOwner(ApplicationConnector* connector)
: context_(GLContext::CreateOffscreen(connector)) {}

GLContextOwner::~GLContextOwner() {
context_->Destroy();
Expand Down
4 changes: 3 additions & 1 deletion mojo/gpu/gl_context_owner.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@

namespace mojo {
class GLContext;
class ApplicationConnector;
class Shell;

class GLContextOwner {
public:
explicit GLContextOwner(mojo::Shell* shell);
explicit GLContextOwner(ApplicationConnector* connector);

~GLContextOwner();

const base::WeakPtr<mojo::GLContext>& context() const { return context_; }
Expand Down
3 changes: 2 additions & 1 deletion mojo/gpu/gl_texture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "mojo/gpu/gl_texture.h"

#include "mojo/public/c/gpu/GLES2/gl2.h"
#include <GLES2/gl2.h>

namespace mojo {

Expand All @@ -17,6 +17,7 @@ GLTexture::GLTexture(base::WeakPtr<GLContext> context, mojo::Size size)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size_.width, size_.height, 0, GL_RGBA,
GL_UNSIGNED_BYTE, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);
}

GLTexture::~GLTexture() {
Expand Down
108 changes: 0 additions & 108 deletions mojo/gpu/texture_cache.cc

This file was deleted.

Loading

0 comments on commit 7e7df7f

Please sign in to comment.