Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(506)

Unified Diff: mojo/examples/surfaces_app/surfaces_app.cc

Issue 451753003: Mojo multiple command buffer support and sample (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: better casts Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/examples/surfaces_app/embedder.cc ('k') | mojo/gles2/command_buffer_client_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/examples/surfaces_app/surfaces_app.cc
diff --git a/mojo/examples/surfaces_app/surfaces_app.cc b/mojo/examples/surfaces_app/surfaces_app.cc
index 6b7a9e94194a6675d672f2343c67698a8e6c3a92..d5f46848e464c02733e5a1bf83549fc2659d11d7 100644
--- a/mojo/examples/surfaces_app/surfaces_app.cc
+++ b/mojo/examples/surfaces_app/surfaces_app.cc
@@ -14,6 +14,7 @@
#include "mojo/services/gles2/command_buffer.mojom.h"
#include "mojo/services/public/cpp/geometry/geometry_type_converters.h"
#include "mojo/services/public/cpp/surfaces/surfaces_type_converters.h"
+#include "mojo/services/public/interfaces/gpu/gpu.mojom.h"
#include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.h"
#include "ui/gfx/rect.h"
@@ -24,7 +25,7 @@ class SurfacesApp : public ApplicationDelegate,
public SurfaceClient,
public NativeViewportClient {
public:
- SurfacesApp() {}
+ SurfacesApp() : native_viewport_id_(0) {}
virtual ~SurfacesApp() {}
// ApplicationDelegate implementation
@@ -34,6 +35,10 @@ class SurfacesApp : public ApplicationDelegate,
&viewport_);
viewport_.set_client(this);
+ // TODO(jamesr): Should be mojo:mojo_gpu_service
+ connection->ConnectToService("mojo:mojo_native_viewport_service",
+ &gpu_service_);
+
connection->ConnectToService("mojo:mojo_surfaces_service", &surfaces_);
surfaces_.set_client(this);
@@ -44,7 +49,8 @@ class SurfacesApp : public ApplicationDelegate,
child_size_ = gfx::Size(size_.width() / 3, size_.height() / 2);
connection->ConnectToService("mojo:mojo_surfaces_child_app", &child_one_);
- connection->ConnectToService("mojo:mojo_surfaces_child_app", &child_two_);
+ connection->ConnectToService("mojo:mojo_surfaces_child_gl_app",
+ &child_two_);
child_one_->ProduceFrame(Color::From(SK_ColorBLUE),
Size::From(child_size_),
base::Bind(&SurfacesApp::ChildOneProducedFrame,
@@ -59,40 +65,34 @@ class SurfacesApp : public ApplicationDelegate,
void ChildOneProducedFrame(SurfaceIdPtr id) {
child_one_id_ = id.To<cc::SurfaceId>();
- Draw(45.0);
+ Draw(10);
}
void ChildTwoProducedFrame(SurfaceIdPtr id) {
child_two_id_ = id.To<cc::SurfaceId>();
- Draw(45.0);
+ Draw(10);
}
- void Draw(double rotation_degrees) {
- if (onscreen_id_.is_null()) {
- onscreen_id_ = allocator_->GenerateId();
- CommandBufferPtr cb;
- viewport_->CreateGLES2Context(Get(&cb));
- surfaces_->CreateGLES2BoundSurface(
- cb.Pass(),
- SurfaceId::From(onscreen_id_),
- Size::From(size_));
- embedder_->SetSurfaceId(onscreen_id_);
- }
- if (child_one_id_.is_null() || child_two_id_.is_null())
+ void Draw(int offset) {
+ if (onscreen_id_.is_null() || child_one_id_.is_null() ||
+ child_two_id_.is_null())
return;
+ int bounced_offset = offset;
+ if (offset > 200)
+ bounced_offset = 400 - offset;
embedder_->ProduceFrame(
- child_one_id_, child_two_id_, child_size_, size_, rotation_degrees);
+ child_one_id_, child_two_id_, child_size_, size_, bounced_offset);
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::Bind(
- &SurfacesApp::Draw, base::Unretained(this), rotation_degrees + 2.0),
- base::TimeDelta::FromMilliseconds(17));
+ &SurfacesApp::Draw, base::Unretained(this), (offset + 2) % 400),
+ base::TimeDelta::FromMilliseconds(50));
}
// SurfaceClient implementation.
virtual void SetIdNamespace(uint32_t id_namespace) OVERRIDE {
allocator_.reset(new cc::SurfaceIdAllocator(id_namespace));
- Draw(45.0);
+ CreateSurfaceIfReady();
}
virtual void ReturnResources(
Array<ReturnedResourcePtr> resources) OVERRIDE {
@@ -100,11 +100,34 @@ class SurfacesApp : public ApplicationDelegate,
}
// NativeViewportClient implementation
- virtual void OnCreated() OVERRIDE {}
- virtual void OnBoundsChanged(mojo::RectPtr bounds) OVERRIDE {}
- virtual void OnDestroyed(const mojo::Callback<void()>& callback) OVERRIDE {
- callback.Run();
+ virtual void OnCreated(uint64_t native_viewport_id) OVERRIDE {
+ native_viewport_id_ = native_viewport_id;
+ CreateSurfaceIfReady();
}
+
+ // We can't create our GLES2-bound surface until we have our id namespace from
+ // the surfaces service and our native viewport id from the native viewport
+ // service. There's no way of knowing which we'll get first, so we just start
+ // whenever both arrive.
+ void CreateSurfaceIfReady() {
+ if (!onscreen_id_.is_null())
+ return;
+ if (native_viewport_id_ == 0)
+ return;
+ if (!allocator_)
+ return;
+
+ onscreen_id_ = allocator_->GenerateId();
+ embedder_->SetSurfaceId(onscreen_id_);
+ CommandBufferPtr cb;
+ gpu_service_->CreateOnscreenGLES2Context(
+ native_viewport_id_, Size::From(size_), Get(&cb));
+ surfaces_->CreateGLES2BoundSurface(
+ cb.Pass(), SurfaceId::From(onscreen_id_), Size::From(size_));
+ Draw(10);
+ }
+ virtual void OnBoundsChanged(mojo::RectPtr bounds) OVERRIDE {}
+ virtual void OnDestroyed() OVERRIDE {}
virtual void OnEvent(mojo::EventPtr event,
const mojo::Callback<void()>& callback) OVERRIDE {
callback.Run();
@@ -113,6 +136,7 @@ class SurfacesApp : public ApplicationDelegate,
private:
SurfacePtr surfaces_;
cc::SurfaceId onscreen_id_;
+ uint64_t native_viewport_id_;
scoped_ptr<cc::SurfaceIdAllocator> allocator_;
scoped_ptr<Embedder> embedder_;
ChildPtr child_one_;
@@ -123,6 +147,7 @@ class SurfacesApp : public ApplicationDelegate,
gfx::Size child_size_;
NativeViewportPtr viewport_;
+ GpuPtr gpu_service_;
DISALLOW_COPY_AND_ASSIGN(SurfacesApp);
};
« no previous file with comments | « mojo/examples/surfaces_app/embedder.cc ('k') | mojo/gles2/command_buffer_client_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698