Revved to chromium c06ba3f6d7a67bc04ae2f6c041c22a86bdcf372a refs/remotes/origin/HEAD
diff --git a/mojo/examples/BUILD.gn b/mojo/examples/BUILD.gn
index 7708161..bb42f4d 100644
--- a/mojo/examples/BUILD.gn
+++ b/mojo/examples/BUILD.gn
@@ -12,6 +12,7 @@
     "//mojo/examples/compositor_app",
     "//mojo/examples/content_handler_demo",
     "//mojo/examples/echo",
+    "//mojo/examples/pepper_container_app",
     "//mojo/examples/png_viewer",
     "//mojo/examples/sample_app",
     "//mojo/examples/surfaces_app",
diff --git a/mojo/examples/apptest/example_apptest.cc b/mojo/examples/apptest/example_apptest.cc
index ca3fda8..cd1c7d8 100644
--- a/mojo/examples/apptest/example_apptest.cc
+++ b/mojo/examples/apptest/example_apptest.cc
@@ -6,7 +6,6 @@
 #include "mojo/examples/apptest/example_client_impl.h"
 #include "mojo/examples/apptest/example_service.mojom.h"
 #include "mojo/public/c/system/main.h"
-#include "mojo/public/cpp/application/application_delegate.h"
 #include "mojo/public/cpp/application/application_impl.h"
 #include "mojo/public/cpp/bindings/callback.h"
 #include "mojo/public/cpp/environment/environment.h"
@@ -25,28 +24,37 @@
 
 namespace {
 
-class ExampleServiceTest : public testing::Test {
+class ExampleApptest : public testing::Test {
  public:
-  ExampleServiceTest() {
+  ExampleApptest() {
     g_application_impl_hack->ConnectToService("mojo:mojo_example_service",
                                               &example_service_);
     example_service_.set_client(&example_client_);
   }
 
-  virtual ~ExampleServiceTest() override {}
+  virtual ~ExampleApptest() override {}
 
  protected:
   ExampleServicePtr example_service_;
   ExampleClientImpl example_client_;
 
  private:
-  MOJO_DISALLOW_COPY_AND_ASSIGN(ExampleServiceTest);
+  MOJO_DISALLOW_COPY_AND_ASSIGN(ExampleApptest);
 };
 
-TEST_F(ExampleServiceTest, Ping) {
+TEST_F(ExampleApptest, PongClientDirectly) {
+  // Test very basic standalone ExampleClient functionality.
+  ExampleClientImpl example_client;
+  EXPECT_EQ(0, example_client.last_pong_value());
+  example_client.Pong(1);
+  EXPECT_EQ(1, example_client.last_pong_value());
+}
+
+TEST_F(ExampleApptest, PingServiceToPongClient) {
+  // Test ExampleClient and ExampleService interaction.
   EXPECT_EQ(0, example_client_.last_pong_value());
   example_service_->Ping(1);
-  RunLoop::current()->Run();
+  EXPECT_TRUE(example_service_.WaitForIncomingMethodCall());
   EXPECT_EQ(1, example_client_.last_pong_value());
 }
 
@@ -54,18 +62,16 @@
 struct SetAndQuit : public Callback<void()>::Runnable {
   SetAndQuit(T* val, T result) : val_(val), result_(result) {}
   virtual ~SetAndQuit() {}
-  virtual void Run() const override {
-    *val_ = result_;
-    RunLoop::current()->Quit();
-  }
+  virtual void Run() const override { *val_ = result_; }
   T* val_;
   T result_;
 };
 
-TEST_F(ExampleServiceTest, RunCallback) {
+TEST_F(ExampleApptest, RunCallbackViaService) {
+  // Test ExampleService callback functionality.
   bool was_run = false;
   example_service_->RunCallback(SetAndQuit<bool>(&was_run, true));
-  RunLoop::current()->Run();
+  EXPECT_TRUE(example_service_.WaitForIncomingMethodCall());
   EXPECT_TRUE(was_run);
 }
 
@@ -75,15 +81,15 @@
 
 MojoResult MojoMain(MojoHandle shell_handle) {
   mojo::Environment env;
+  // TODO(msw): Destroy this ambient RunLoop before running tests.
+  //            Need to CancelWait() / PassMessagePipe() from the ShellPtr?
   mojo::RunLoop loop;
-
-  // TODO(tim): Perhaps the delegate should be the thing that provides
-  // the ExampleServiceTest with the ApplicationImpl somehow.
   mojo::ApplicationDelegate* delegate = new mojo::ExampleClientApplication();
   mojo::ApplicationImpl app(delegate, shell_handle);
   g_application_impl_hack = &app;
+  MOJO_CHECK(app.WaitForInitialize());
 
-  // TODO(msw): Get actual commandline arguments.
+  // TODO(msw): Plumb commandline arguments through app->args().
   int argc = 0;
   char** argv = NULL;
   testing::InitGoogleTest(&argc, argv);
diff --git a/mojo/examples/apptest/example_client_application.cc b/mojo/examples/apptest/example_client_application.cc
index 8ba5739..ca59eff 100644
--- a/mojo/examples/apptest/example_client_application.cc
+++ b/mojo/examples/apptest/example_client_application.cc
@@ -4,8 +4,6 @@
 
 #include "mojo/examples/apptest/example_client_application.h"
 
-#include "mojo/examples/apptest/example_client_impl.h"
-
 namespace mojo {
 
 ExampleClientApplication::ExampleClientApplication() {}
diff --git a/mojo/examples/apptest/example_client_impl.cc b/mojo/examples/apptest/example_client_impl.cc
index 9d539be..d794117 100644
--- a/mojo/examples/apptest/example_client_impl.cc
+++ b/mojo/examples/apptest/example_client_impl.cc
@@ -8,11 +8,11 @@
 namespace mojo {
 
 ExampleClientImpl::ExampleClientImpl() : last_pong_value_(0) {}
+
 ExampleClientImpl::~ExampleClientImpl() {}
 
 void ExampleClientImpl::Pong(uint16_t pong_value) {
   last_pong_value_ = pong_value;
-  RunLoop::current()->Quit();
 }
 
 }  // namespace mojo
diff --git a/mojo/examples/apptest/example_client_impl.h b/mojo/examples/apptest/example_client_impl.h
index 25d817a..ee835ca 100644
--- a/mojo/examples/apptest/example_client_impl.h
+++ b/mojo/examples/apptest/example_client_impl.h
@@ -10,19 +10,17 @@
 
 namespace mojo {
 
-class ApplicationConnection;
-
 class ExampleClientImpl : public InterfaceImpl<ExampleClient> {
  public:
-  explicit ExampleClientImpl();
+  ExampleClientImpl();
   virtual ~ExampleClientImpl();
 
   int16_t last_pong_value() const { return last_pong_value_; }
 
- private:
   // InterfaceImpl<ExampleClient> overrides.
   virtual void Pong(uint16_t pong_value) override;
 
+ private:
   int16_t last_pong_value_;
   MOJO_DISALLOW_COPY_AND_ASSIGN(ExampleClientImpl);
 };
diff --git a/mojo/examples/apptest/example_service_impl.cc b/mojo/examples/apptest/example_service_impl.cc
index b656ce0..b8e53d5 100644
--- a/mojo/examples/apptest/example_service_impl.cc
+++ b/mojo/examples/apptest/example_service_impl.cc
@@ -14,12 +14,10 @@
 
 void ExampleServiceImpl::Ping(uint16_t ping_value) {
   client()->Pong(ping_value);
-  RunLoop::current()->Quit();
 }
 
 void ExampleServiceImpl::RunCallback(const Callback<void()>& callback) {
   callback.Run();
-  RunLoop::current()->Quit();
 }
 
 }  // namespace mojo
diff --git a/mojo/examples/aura_demo/aura_demo.cc b/mojo/examples/aura_demo/aura_demo.cc
index 1895761..917ea61 100644
--- a/mojo/examples/aura_demo/aura_demo.cc
+++ b/mojo/examples/aura_demo/aura_demo.cc
@@ -8,10 +8,8 @@
 #include "base/bind.h"
 #include "base/macros.h"
 #include "mojo/application/application_runner_chromium.h"
-#include "mojo/aura/context_factory_mojo.h"
 #include "mojo/aura/screen_mojo.h"
 #include "mojo/aura/window_tree_host_mojo.h"
-#include "mojo/aura/window_tree_host_mojo_delegate.h"
 #include "mojo/public/c/system/main.h"
 #include "mojo/public/cpp/application/application_connection.h"
 #include "mojo/public/cpp/application/application_delegate.h"
@@ -107,10 +105,10 @@
 };
 
 class AuraDemo : public mojo::ApplicationDelegate,
-                 public mojo::WindowTreeHostMojoDelegate,
                  public mojo::ViewManagerDelegate {
  public:
-  AuraDemo() : window1_(NULL), window2_(NULL), window21_(NULL) {}
+  AuraDemo()
+      : shell_(nullptr), window1_(NULL), window2_(NULL), window21_(NULL) {}
   virtual ~AuraDemo() {}
 
  private:
@@ -123,7 +121,7 @@
     // TODO(beng): this function could be called multiple times!
     root_ = root;
 
-    window_tree_host_.reset(new mojo::WindowTreeHostMojo(root, this));
+    window_tree_host_.reset(new mojo::WindowTreeHostMojo(shell_, root));
     window_tree_host_->InitHost();
 
     window_tree_client_.reset(
@@ -157,17 +155,11 @@
     base::MessageLoop::current()->Quit();
   }
 
-  // WindowTreeHostMojoDelegate:
-  virtual void CompositorContentsChanged(const SkBitmap& bitmap) override {
-    root_->SetContents(bitmap);
-  }
-
   virtual void Initialize(mojo::ApplicationImpl* app) override {
+    shell_ = app->shell();
     view_manager_client_factory_.reset(
-        new mojo::ViewManagerClientFactory(app->shell(), this));
+        new mojo::ViewManagerClientFactory(shell_, this));
     aura::Env::CreateInstance(true);
-    context_factory_.reset(new mojo::ContextFactoryMojo);
-    aura::Env::GetInstance()->set_context_factory(context_factory_.get());
     screen_.reset(mojo::ScreenMojo::Create());
     gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
   }
@@ -178,9 +170,9 @@
     return true;
   }
 
-  scoped_ptr<DemoWindowTreeClient> window_tree_client_;
+  mojo::Shell* shell_;
 
-  scoped_ptr<ui::ContextFactory> context_factory_;
+  scoped_ptr<DemoWindowTreeClient> window_tree_client_;
 
   scoped_ptr<mojo::ScreenMojo> screen_;
 
diff --git a/mojo/examples/bitmap_uploader/BUILD.gn b/mojo/examples/bitmap_uploader/BUILD.gn
new file mode 100644
index 0000000..1ed540e
--- /dev/null
+++ b/mojo/examples/bitmap_uploader/BUILD.gn
@@ -0,0 +1,37 @@
+# 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.
+
+# GYP version: mojo/mojo_examples.gypi:mojo_bitmap_uploader
+source_set("bitmap_uploader") {
+  sources = [
+    "bitmap_uploader.cc",
+    "bitmap_uploader.h",
+  ]
+
+  public_deps = [
+    "//base",
+    "//cc/surfaces",
+    "//mojo/public/c/gles2",
+    "//mojo/services/public/interfaces/gpu",
+    "//mojo/services/public/interfaces/surfaces",
+    "//skia",
+    "//ui/gfx/geometry",
+  ]
+  deps = [
+    "//gpu",
+    "//mojo/application",
+    "//mojo/public/cpp/bindings:bindings",
+    "//mojo/public/interfaces/application",
+    "//mojo/services/public/cpp/geometry",
+    "//mojo/services/public/cpp/surfaces",
+    "//mojo/services/public/cpp/view_manager",
+    "//mojo/services/public/interfaces/geometry",
+    "//mojo/services/public/interfaces/input_events:input_events",
+    "//mojo/services/public/interfaces/surfaces:surface_id",
+    "//mojo/services/public/interfaces/view_manager",
+    "//mojo/services/public/interfaces/window_manager",
+    "//ui/events",
+    "//ui/gfx",
+  ]
+}
diff --git a/mojo/examples/bitmap_uploader/DEPS b/mojo/examples/bitmap_uploader/DEPS
new file mode 100644
index 0000000..a46d043
--- /dev/null
+++ b/mojo/examples/bitmap_uploader/DEPS
@@ -0,0 +1,10 @@
+include_rules = [
+  "+cc/surfaces/surface_id.h",
+  "+cc/surfaces/surface_id_allocator.h",
+  "+gpu/command_buffer/common/mailbox.h",
+  "+gpu/GLES2",
+  "+mojo/geometry",
+  "+third_party/khronos/GLES2",
+  "+third_party/skia/include",
+  "+ui/gfx",
+]
diff --git a/mojo/examples/bitmap_uploader/bitmap_uploader.cc b/mojo/examples/bitmap_uploader/bitmap_uploader.cc
new file mode 100644
index 0000000..facc58a
--- /dev/null
+++ b/mojo/examples/bitmap_uploader/bitmap_uploader.cc
@@ -0,0 +1,233 @@
+// 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 "mojo/examples/bitmap_uploader/bitmap_uploader.h"
+
+#ifndef GL_GLEXT_PROTOTYPES
+#define GL_GLEXT_PROTOTYPES
+#endif  // GL_GLEXT_PROTOTYPES
+
+#include "base/bind.h"
+#include "cc/surfaces/surface_id.h"
+#include "cc/surfaces/surface_id_allocator.h"
+#include "gpu/GLES2/gl2chromium.h"
+#include "gpu/GLES2/gl2extchromium.h"
+#include "gpu/command_buffer/common/mailbox.h"
+#include "mojo/public/c/gles2/gles2.h"
+#include "mojo/public/cpp/application/connect.h"
+#include "mojo/public/interfaces/application/shell.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/cpp/surfaces/surfaces_utils.h"
+#include "mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h"
+#include "third_party/khronos/GLES2/gl2.h"
+#include "ui/gfx/geometry/rect.h"
+
+namespace mojo {
+
+namespace {
+void LostContext(void*) {
+  DCHECK(false);
+}
+
+uint32_t TextureFormat() {
+  return SK_B32_SHIFT ? GL_RGBA : GL_BGRA_EXT;
+}
+}
+
+BitmapUploader::BitmapUploader(View* view)
+    : view_(view),
+      color_(SK_ColorTRANSPARENT),
+      next_resource_id_(1u),
+      weak_factory_(this) {
+}
+
+void BitmapUploader::Init(Shell* shell) {
+  ServiceProviderPtr surfaces_service_provider;
+  shell->ConnectToApplication("mojo:mojo_surfaces_service",
+                              GetProxy(&surfaces_service_provider));
+  ConnectToService(surfaces_service_provider.get(), &surfaces_service_);
+  ServiceProviderPtr gpu_service_provider;
+  shell->ConnectToApplication("mojo:mojo_native_viewport_service",
+                              GetProxy(&gpu_service_provider));
+  ConnectToService(gpu_service_provider.get(), &gpu_service_);
+
+  surfaces_service_->CreateSurfaceConnection(base::Bind(
+      &BitmapUploader::OnSurfaceConnectionCreated, weak_factory_.GetWeakPtr()));
+  CommandBufferPtr gles2_client;
+  gpu_service_->CreateOffscreenGLES2Context(GetProxy(&gles2_client));
+  gles2_context_ =
+      MojoGLES2CreateContext(gles2_client.PassMessagePipe().release().value(),
+                             &LostContext,
+                             NULL,
+                             Environment::GetDefaultAsyncWaiter());
+  MojoGLES2MakeCurrent(gles2_context_);
+}
+
+BitmapUploader::~BitmapUploader() {
+  MojoGLES2DestroyContext(gles2_context_);
+}
+
+void BitmapUploader::SetColor(SkColor color) {
+  if (color_ == color)
+    return;
+  color_ = color;
+  if (surface_)
+    Upload();
+}
+
+void BitmapUploader::SetBitmap(const SkBitmap& bitmap) {
+  bitmap_ = bitmap;
+  if (surface_)
+    Upload();
+}
+
+void BitmapUploader::Upload() {
+  const gfx::Size& size(view_->bounds().size());
+  if (size.IsEmpty()) {
+    view_->SetSurfaceId(SurfaceId::New());
+    return;
+  }
+  if (!surface_)  // Can't upload yet, store for later.
+    return;
+  if (id_.is_null() || size != surface_size_) {
+    if (!id_.is_null())
+      surface_->DestroySurface(SurfaceId::From(id_));
+    id_ = id_allocator_->GenerateId();
+    surface_->CreateSurface(SurfaceId::From(id_), Size::From(size));
+    view_->SetSurfaceId(SurfaceId::From(id_));
+    surface_size_ = size;
+  }
+
+  gfx::Rect bounds(size);
+  PassPtr pass = CreateDefaultPass(1, bounds);
+  FramePtr frame = Frame::New();
+  frame->resources.resize(0u);
+
+  pass->quads.resize(0u);
+  pass->shared_quad_states.push_back(CreateDefaultSQS(size));
+
+  MojoGLES2MakeCurrent(gles2_context_);
+  if (!bitmap_.isNull()) {
+    gfx::Size bitmap_size(bitmap_.width(), bitmap_.height());
+    GLuint texture_id = BindTextureForSize(bitmap_size);
+    bitmap_.lockPixels();
+    glTexSubImage2D(GL_TEXTURE_2D,
+                    0,
+                    0,
+                    0,
+                    bitmap_size.width(),
+                    bitmap_size.height(),
+                    TextureFormat(),
+                    GL_UNSIGNED_BYTE,
+                    bitmap_.getPixels());
+    bitmap_.unlockPixels();
+
+    gpu::Mailbox mailbox = gpu::Mailbox::Generate();
+    glProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
+    GLuint sync_point = glInsertSyncPointCHROMIUM();
+
+    TransferableResourcePtr resource = TransferableResource::New();
+    resource->id = next_resource_id_++;
+    resource_to_texture_id_map_[resource->id] = texture_id;
+    resource->format = mojo::RESOURCE_FORMAT_RGBA_8888;
+    resource->filter = GL_LINEAR;
+    resource->size = Size::From(bitmap_size);
+    MailboxHolderPtr mailbox_holder = MailboxHolder::New();
+    mailbox_holder->mailbox = Mailbox::From(mailbox);
+    mailbox_holder->texture_target = GL_TEXTURE_2D;
+    mailbox_holder->sync_point = sync_point;
+    resource->mailbox_holder = mailbox_holder.Pass();
+    resource->is_repeated = false;
+    resource->is_software = false;
+
+    QuadPtr quad = Quad::New();
+    quad->material = MATERIAL_TEXTURE_CONTENT;
+    quad->rect = Rect::From(bounds);
+    quad->opaque_rect = Rect::From(bounds);
+    quad->visible_rect = Rect::From(bounds);
+    quad->needs_blending = true;
+    quad->shared_quad_state_index = 0u;
+
+    TextureQuadStatePtr texture_state = TextureQuadState::New();
+    texture_state->resource_id = resource->id;
+    texture_state->premultiplied_alpha = true;
+    texture_state->uv_top_left = PointF::From(gfx::PointF(0.f, 0.f));
+    texture_state->uv_bottom_right = PointF::From(gfx::PointF(1.f, 1.f));
+    texture_state->background_color = Color::From(SkColor(SK_ColorTRANSPARENT));
+    for (int i = 0; i < 4; ++i)
+      texture_state->vertex_opacity.push_back(1.f);
+    texture_state->flipped = false;
+
+    frame->resources.push_back(resource.Pass());
+    quad->texture_quad_state = texture_state.Pass();
+    pass->quads.push_back(quad.Pass());
+  }
+
+  if (color_ != SK_ColorTRANSPARENT) {
+    QuadPtr quad = Quad::New();
+    quad->material = MATERIAL_SOLID_COLOR;
+    quad->rect = Rect::From(bounds);
+    quad->opaque_rect = Rect::From(gfx::Rect());
+    quad->visible_rect = Rect::From(bounds);
+    quad->needs_blending = true;
+    quad->shared_quad_state_index = 0u;
+
+    SolidColorQuadStatePtr color_state = SolidColorQuadState::New();
+    color_state->color = Color::From(color_);
+    color_state->force_anti_aliasing_off = false;
+
+    quad->solid_color_quad_state = color_state.Pass();
+    pass->quads.push_back(quad.Pass());
+  }
+
+  frame->passes.push_back(pass.Pass());
+
+  surface_->SubmitFrame(SurfaceId::From(id_), frame.Pass());
+}
+
+void BitmapUploader::ReturnResources(Array<ReturnedResourcePtr> resources) {
+  if (!resources.size())
+    return;
+  MojoGLES2MakeCurrent(gles2_context_);
+  // TODO(jamesr): Recycle.
+  for (size_t i = 0; i < resources.size(); ++i) {
+    ReturnedResourcePtr resource = resources[i].Pass();
+    DCHECK_EQ(1, resource->count);
+    glWaitSyncPointCHROMIUM(resource->sync_point);
+    uint32_t texture_id = resource_to_texture_id_map_[resource->id];
+    DCHECK_NE(0u, texture_id);
+    resource_to_texture_id_map_.erase(resource->id);
+    glDeleteTextures(1, &texture_id);
+  }
+}
+
+void BitmapUploader::OnSurfaceConnectionCreated(SurfacePtr surface,
+                                                uint32_t id_namespace) {
+  surface_ = surface.Pass();
+  surface_.set_client(this);
+  id_allocator_.reset(new cc::SurfaceIdAllocator(id_namespace));
+  if (color_ != SK_ColorTRANSPARENT || !bitmap_.isNull())
+    Upload();
+}
+
+uint32_t BitmapUploader::BindTextureForSize(const gfx::Size size) {
+  // TODO(jamesr): Recycle textures.
+  GLuint texture = 0u;
+  glGenTextures(1, &texture);
+  glBindTexture(GL_TEXTURE_2D, texture);
+  glTexImage2D(GL_TEXTURE_2D,
+               0,
+               TextureFormat(),
+               size.width(),
+               size.height(),
+               0,
+               TextureFormat(),
+               GL_UNSIGNED_BYTE,
+               0);
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+  return texture;
+}
+
+}  // namespace mojo
diff --git a/mojo/examples/bitmap_uploader/bitmap_uploader.h b/mojo/examples/bitmap_uploader/bitmap_uploader.h
new file mode 100644
index 0000000..56f37fe
--- /dev/null
+++ b/mojo/examples/bitmap_uploader/bitmap_uploader.h
@@ -0,0 +1,68 @@
+// 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.
+
+#ifndef MOJO_EXAMPLES_BITMAP_UPLOADER_BITMAP_UPLOADER_H_
+#define MOJO_EXAMPLES_BITMAP_UPLOADER_BITMAP_UPLOADER_H_
+
+#include "base/callback.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "cc/surfaces/surface_id.h"
+#include "mojo/public/c/gles2/gles2.h"
+#include "mojo/services/public/interfaces/gpu/gpu.mojom.h"
+#include "mojo/services/public/interfaces/surfaces/surfaces.mojom.h"
+#include "mojo/services/public/interfaces/surfaces/surfaces_service.mojom.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "ui/gfx/geometry/size.h"
+
+namespace cc {
+class SurfaceIdAllocator;
+}
+
+namespace mojo {
+class Shell;
+class View;
+
+// BitmapUploader is useful if you want to draw a bitmap or color in a View.
+class BitmapUploader : public SurfaceClient {
+ public:
+  explicit BitmapUploader(View* view);
+  virtual ~BitmapUploader();
+
+  void Init(Shell* shell);
+
+  void SetColor(SkColor color);
+  void SetBitmap(const SkBitmap& bitmap);
+
+ private:
+  void Upload();
+  void OnSurfaceConnectionCreated(SurfacePtr surface, uint32_t id_namespace);
+  uint32_t BindTextureForSize(const gfx::Size size);
+
+  // SurfaceClient implementation.
+  virtual void ReturnResources(Array<ReturnedResourcePtr> resources) override;
+
+  View* view_;
+  SurfacesServicePtr surfaces_service_;
+  GpuPtr gpu_service_;
+  MojoGLES2Context gles2_context_;
+
+  gfx::Size size_;
+  SkColor color_;
+  SkBitmap bitmap_;
+  SurfacePtr surface_;
+  cc::SurfaceId id_;
+  scoped_ptr<cc::SurfaceIdAllocator> id_allocator_;
+  gfx::Size surface_size_;
+  uint32_t next_resource_id_;
+  base::hash_map<uint32_t, uint32_t> resource_to_texture_id_map_;
+
+  base::WeakPtrFactory<BitmapUploader> weak_factory_;
+
+  DISALLOW_COPY_AND_ASSIGN(BitmapUploader);
+};
+
+}  // namespace mojo
+
+#endif  // MOJO_EXAMPLES_BITMAP_UPLOADER_BITMAP_UPLOADER_H_
diff --git a/mojo/examples/browser/browser.cc b/mojo/examples/browser/browser.cc
index 2a77f89..2f22d16 100644
--- a/mojo/examples/browser/browser.cc
+++ b/mojo/examples/browser/browser.cc
@@ -155,9 +155,7 @@
                 public ViewObserver {
  public:
   Browser()
-      : view_manager_(NULL),
-        root_(NULL),
-        widget_(NULL) {}
+      : shell_(nullptr), view_manager_(NULL), root_(NULL), widget_(NULL) {}
 
   virtual ~Browser() {
     if (root_)
@@ -167,8 +165,9 @@
  private:
   // Overridden from ApplicationDelegate:
   virtual void Initialize(ApplicationImpl* app) override {
+    shell_ = app->shell();
     view_manager_client_factory_.reset(
-        new ViewManagerClientFactory(app->shell(), this));
+        new ViewManagerClientFactory(shell_, this));
     views_init_.reset(new ViewsInit);
     app->ConnectToService("mojo:mojo_window_manager", &window_manager_);
  }
@@ -193,7 +192,7 @@
     widget_ = new views::Widget;
     views::Widget::InitParams params(
         views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
-    params.native_widget = new NativeWidgetViewManager(widget_, view);
+    params.native_widget = new NativeWidgetViewManager(widget_, shell_, view);
     params.delegate = widget_delegate;
     params.bounds = gfx::Rect(view->bounds().width(), view->bounds().height());
     widget_->Init(params);
@@ -252,6 +251,8 @@
     root_ = NULL;
   }
 
+  Shell* shell_;
+
   scoped_ptr<ViewsInit> views_init_;
 
   ViewManager* view_manager_;
diff --git a/mojo/examples/compositor_app/compositor_app.cc b/mojo/examples/compositor_app/compositor_app.cc
index 279fe75..516edbb 100644
--- a/mojo/examples/compositor_app/compositor_app.cc
+++ b/mojo/examples/compositor_app/compositor_app.cc
@@ -56,7 +56,7 @@
     CommandBufferPtr cb;
     // TODO(jamesr): Output to a surface instead.
     gpu_service_->CreateOnscreenGLES2Context(
-        native_viewport_id, Size::From(gfx::Size(800, 600)), Get(&cb));
+        native_viewport_id, Size::From(gfx::Size(800, 600)), GetProxy(&cb));
     host_.reset(new CompositorHost(cb.PassMessagePipe()));
   }
 
diff --git a/mojo/examples/embedded_app/BUILD.gn b/mojo/examples/embedded_app/BUILD.gn
index 3e82cbb..12cf1b9 100644
--- a/mojo/examples/embedded_app/BUILD.gn
+++ b/mojo/examples/embedded_app/BUILD.gn
@@ -12,6 +12,7 @@
   deps = [
     "//base",
     "//mojo/application",
+    "//mojo/examples/bitmap_uploader",
     "//mojo/examples/window_manager:bindings",
     "//mojo/public/c/system:for_shared_library",
     "//mojo/public/cpp/bindings",
diff --git a/mojo/examples/embedded_app/embedded_app.cc b/mojo/examples/embedded_app/embedded_app.cc
index da51fae..98c418e 100644
--- a/mojo/examples/embedded_app/embedded_app.cc
+++ b/mojo/examples/embedded_app/embedded_app.cc
@@ -8,6 +8,7 @@
 #include "base/message_loop/message_loop.h"
 #include "base/strings/string_number_conversions.h"
 #include "mojo/application/application_runner_chromium.h"
+#include "mojo/examples/bitmap_uploader/bitmap_uploader.h"
 #include "mojo/public/c/system/main.h"
 #include "mojo/public/cpp/application/application_connection.h"
 #include "mojo/public/cpp/application/application_delegate.h"
@@ -31,11 +32,18 @@
                            SK_ColorMAGENTA};
 
 struct Window {
-  Window(View* root, scoped_ptr<ServiceProvider> embedder_service_provider)
+  Window(View* root,
+         scoped_ptr<ServiceProvider> embedder_service_provider,
+         Shell* shell)
       : root(root),
-        embedder_service_provider(embedder_service_provider.Pass()) {}
+        embedder_service_provider(embedder_service_provider.Pass()),
+        bitmap_uploader(root) {
+    bitmap_uploader.Init(shell);
+  }
+
   View* root;
   scoped_ptr<ServiceProvider> embedder_service_provider;
+  BitmapUploader bitmap_uploader;
 };
 
 class EmbeddedApp
@@ -43,13 +51,14 @@
       public ViewManagerDelegate,
       public ViewObserver {
  public:
-  EmbeddedApp() { url::AddStandardScheme("mojo"); }
+  EmbeddedApp() : shell_(nullptr) { url::AddStandardScheme("mojo"); }
   virtual ~EmbeddedApp() {}
 
  private:
 
   // Overridden from ApplicationDelegate:
   virtual void Initialize(ApplicationImpl* app) override {
+    shell_ = app->shell();
     view_manager_client_factory_.reset(
         new ViewManagerClientFactory(app->shell(), this));
   }
@@ -66,8 +75,10 @@
                        ServiceProviderImpl* exported_services,
                        scoped_ptr<ServiceProvider> imported_services) override {
     root->AddObserver(this);
-    windows_[root->id()] = new Window(root, imported_services.Pass());
-    root->SetColor(kColors[next_color_++ % arraysize(kColors)]);
+    Window* window = new Window(root, imported_services.Pass(), shell_);
+    windows_[root->id()] = window;
+    window->bitmap_uploader.SetColor(
+        kColors[next_color_++ % arraysize(kColors)]);
   }
   virtual void OnViewManagerDisconnected(ViewManager* view_manager) override {
     base::MessageLoop::current()->Quit();
@@ -91,6 +102,7 @@
     }
   }
 
+  Shell* shell_;
   scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_;
 
   typedef std::map<Id, Window*> WindowMap;
diff --git a/mojo/examples/keyboard/keyboard.cc b/mojo/examples/keyboard/keyboard.cc
index 8eae684..3cd4a4e 100644
--- a/mojo/examples/keyboard/keyboard.cc
+++ b/mojo/examples/keyboard/keyboard.cc
@@ -51,7 +51,8 @@
                  public KeyboardDelegate {
  public:
   Keyboard()
-      : keyboard_service_factory_(this),
+      : shell_(nullptr),
+        keyboard_service_factory_(this),
         view_manager_(NULL),
         keyboard_service_(NULL),
         target_(0) {}
@@ -68,8 +69,9 @@
  private:
   // Overridden from ApplicationDelegate:
   virtual void Initialize(ApplicationImpl* app) override {
+    shell_ = app->shell();
     view_manager_client_factory_.reset(
-        new ViewManagerClientFactory(app->shell(), this));
+        new ViewManagerClientFactory(shell_, this));
   }
 
   virtual bool ConfigureIncomingConnection(
@@ -88,7 +90,7 @@
     views::Widget* widget = new views::Widget;
     views::Widget::InitParams params(
         views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
-    params.native_widget = new NativeWidgetViewManager(widget, view);
+    params.native_widget = new NativeWidgetViewManager(widget, shell_, view);
     params.delegate = widget_delegate;
     params.bounds = gfx::Rect(view->bounds().width(), view->bounds().height());
     widget->Init(params);
@@ -119,6 +121,8 @@
                                                  event_flags);
   }
 
+  Shell* shell_;
+
   InterfaceFactoryImplWithContext<KeyboardServiceImpl, Keyboard>
       keyboard_service_factory_;
 
diff --git a/mojo/examples/media_viewer/BUILD.gn b/mojo/examples/media_viewer/BUILD.gn
index b17d2d3..d322ca0 100644
--- a/mojo/examples/media_viewer/BUILD.gn
+++ b/mojo/examples/media_viewer/BUILD.gn
@@ -26,6 +26,7 @@
     "//mojo/services/public/interfaces/view_manager",
     "//mojo/views",
     "//skia",
+    "//ui/gfx",
     "//ui/gfx/geometry",
     "//ui/views",
   ]
diff --git a/mojo/examples/media_viewer/media_viewer.cc b/mojo/examples/media_viewer/media_viewer.cc
index 33cf200..533fe36 100644
--- a/mojo/examples/media_viewer/media_viewer.cc
+++ b/mojo/examples/media_viewer/media_viewer.cc
@@ -34,6 +34,7 @@
 #include "ui/gfx/canvas.h"
 #include "ui/gfx/geometry/insets.h"
 #include "ui/gfx/geometry/rect.h"
+#include "ui/gfx/image/image_skia.h"
 #include "ui/views/background.h"
 #include "ui/views/border.h"
 #include "ui/views/controls/button/button.h"
@@ -134,11 +135,12 @@
     virtual void ButtonPressed(ControlType type) = 0;
   };
 
-  ControlPanel(Delegate* delegate) : delegate_(delegate), buttons_() {}
+  explicit ControlPanel(Delegate* delegate)
+      : delegate_(delegate), shell_(nullptr), buttons_() {}
 
   virtual ~ControlPanel() {}
 
-  void Initialize(View* view) {
+  void Initialize(View* view, Shell* shell) {
     const char* kNames[] = { "Zoom In", "Actual Size", "Zoom Out" };
 
     views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView;
@@ -160,7 +162,7 @@
     views::Widget* widget = new views::Widget;
     views::Widget::InitParams params(
         views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
-    params.native_widget = new NativeWidgetViewManager(widget, view);
+    params.native_widget = new NativeWidgetViewManager(widget, shell, view);
     params.delegate = widget_delegate;
     params.bounds = gfx::Rect(view->bounds().width(), view->bounds().height());
     params.opacity = views::Widget::InitParams::OPAQUE_WINDOW;
@@ -181,6 +183,7 @@
   }
 
   Delegate* delegate_;
+  Shell* shell_;
   views::Button* buttons_[CONTROL_COUNT];
 
   DISALLOW_COPY_AND_ASSIGN(ControlPanel);
@@ -193,7 +196,8 @@
       public ViewObserver {
  public:
   MediaViewer()
-      : app_(NULL),
+      : shell_(nullptr),
+        app_(NULL),
         view_manager_(NULL),
         root_view_(NULL),
         control_view_(NULL),
@@ -213,6 +217,7 @@
 
   // Overridden from ApplicationDelegate:
   virtual void Initialize(ApplicationImpl* app) override {
+    shell_ = app->shell();
     view_manager_client_factory_.reset(
         new ViewManagerClientFactory(app->shell(), this));
     app_ = app;
@@ -248,7 +253,7 @@
     content_view_ = View::Create(view_manager_);
     root_view_->AddChild(content_view_);
 
-    control_panel_.Initialize(control_view_);
+    control_panel_.Initialize(control_view_, shell_);
 
     LayoutViews();
     root_view_->AddObserver(this);
@@ -297,6 +302,8 @@
     return it != handler_map_.end() ? it->second : std::string();
   }
 
+  Shell* shell_;
+
   scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_;
 
   ApplicationImpl* app_;
diff --git a/mojo/examples/nesting_app/BUILD.gn b/mojo/examples/nesting_app/BUILD.gn
index e25263f..86f611c 100644
--- a/mojo/examples/nesting_app/BUILD.gn
+++ b/mojo/examples/nesting_app/BUILD.gn
@@ -12,10 +12,8 @@
 
   deps = [
     "//base",
-    "//ui/gfx/geometry",
-    "//ui/gl",
-    "//url",
     "//mojo/application",
+    "//mojo/examples/bitmap_uploader",
     "//mojo/examples/window_manager:bindings",
     "//mojo/public/c/system:for_shared_library",
     "//mojo/public/cpp/bindings",
@@ -23,5 +21,8 @@
     "//mojo/services/public/cpp/view_manager",
     "//mojo/services/public/interfaces/geometry",
     "//mojo/services/public/interfaces/navigation",
+    "//ui/gfx/geometry",
+    "//ui/gl",
+    "//url",
   ]
 }
diff --git a/mojo/examples/nesting_app/nesting_app.cc b/mojo/examples/nesting_app/nesting_app.cc
index a7fb74e..e3bcbcd 100644
--- a/mojo/examples/nesting_app/nesting_app.cc
+++ b/mojo/examples/nesting_app/nesting_app.cc
@@ -7,6 +7,7 @@
 #include "base/message_loop/message_loop.h"
 #include "base/strings/stringprintf.h"
 #include "mojo/application/application_runner_chromium.h"
+#include "mojo/examples/bitmap_uploader/bitmap_uploader.h"
 #include "mojo/examples/window_manager/window_manager.mojom.h"
 #include "mojo/public/c/system/main.h"
 #include "mojo/public/cpp/application/application_connection.h"
@@ -37,12 +38,13 @@
       public ViewManagerDelegate,
       public ViewObserver {
  public:
-  NestingApp() : nested_(NULL) {}
+  NestingApp() : nested_(nullptr), shell_(nullptr) {}
   virtual ~NestingApp() {}
 
  private:
   // Overridden from ApplicationDelegate:
   virtual void Initialize(ApplicationImpl* app) override {
+    shell_ = app->shell();
     view_manager_client_factory_.reset(
         new ViewManagerClientFactory(app->shell(), this));
   }
@@ -61,7 +63,9 @@
                        ServiceProviderImpl* exported_services,
                        scoped_ptr<ServiceProvider> imported_services) override {
     root->AddObserver(this);
-    root->SetColor(SK_ColorCYAN);
+    bitmap_uploader_.reset(new BitmapUploader(root));
+    bitmap_uploader_->Init(shell_);
+    bitmap_uploader_->SetColor(SK_ColorCYAN);
 
     nested_ = View::Create(view_manager);
     root->AddChild(nested_);
@@ -85,7 +89,9 @@
   scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_;
 
   View* nested_;
+  Shell* shell_;
   IWindowManagerPtr window_manager_;
+  scoped_ptr<BitmapUploader> bitmap_uploader_;
 
   DISALLOW_COPY_AND_ASSIGN(NestingApp);
 };
diff --git a/mojo/examples/pepper_container_app/pepper_container_app.cc b/mojo/examples/pepper_container_app/pepper_container_app.cc
index 4b64441..82c35f0 100644
--- a/mojo/examples/pepper_container_app/pepper_container_app.cc
+++ b/mojo/examples/pepper_container_app/pepper_container_app.cc
@@ -92,7 +92,7 @@
     size->width = 600;
     // TODO(jamesr): Output a surface to the native viewport instead.
     gpu_service_->CreateOnscreenGLES2Context(
-        native_viewport_id_, size.Pass(), Get(&command_buffer));
+        native_viewport_id_, size.Pass(), GetProxy(&command_buffer));
     return command_buffer.PassMessagePipe();
   }
 
diff --git a/mojo/examples/png_viewer/BUILD.gn b/mojo/examples/png_viewer/BUILD.gn
index 9fc2315..e5265b3 100644
--- a/mojo/examples/png_viewer/BUILD.gn
+++ b/mojo/examples/png_viewer/BUILD.gn
@@ -12,6 +12,7 @@
 
   deps = [
     "//mojo/application",
+    "//mojo/examples/bitmap_uploader",
     "//mojo/examples/media_viewer:bindings",
     "//mojo/public/c/system:for_shared_library",
     "//mojo/public/cpp/bindings",
diff --git a/mojo/examples/png_viewer/png_viewer.cc b/mojo/examples/png_viewer/png_viewer.cc
index 792879a..bb6e321 100644
--- a/mojo/examples/png_viewer/png_viewer.cc
+++ b/mojo/examples/png_viewer/png_viewer.cc
@@ -9,6 +9,7 @@
 #include "base/message_loop/message_loop.h"
 #include "base/strings/string_tokenizer.h"
 #include "mojo/application/application_runner_chromium.h"
+#include "mojo/examples/bitmap_uploader/bitmap_uploader.h"
 #include "mojo/examples/media_viewer/media_viewer.mojom.h"
 #include "mojo/public/c/system/main.h"
 #include "mojo/public/cpp/application/application_connection.h"
@@ -59,7 +60,8 @@
           scoped_ptr<ServiceProvider> imported_services,
           Shell* shell)
       : imported_services_(imported_services.Pass()),
-        root_(NULL),
+        shell_(shell),
+        root_(nullptr),
         view_manager_client_factory_(shell, this),
         zoom_percentage_(kDefaultZoomPercentage) {
     exported_services->AddService(&view_manager_client_factory_);
@@ -78,7 +80,9 @@
                        scoped_ptr<ServiceProvider> imported_services) override {
     root_ = root;
     root_->AddObserver(this);
-    root_->SetColor(SK_ColorGRAY);
+    bitmap_uploader_.reset(new BitmapUploader(root_));
+    bitmap_uploader_->Init(shell_);
+    bitmap_uploader_->SetColor(SK_ColorGRAY);
     if (!bitmap_.isNull())
       DrawBitmap();
   }
@@ -138,7 +142,8 @@
         SkFloatToScalar(zoom_percentage_ * 1.0f / kDefaultZoomPercentage);
     canvas->scale(scale, scale);
     canvas->drawBitmap(bitmap_, 0, 0, &paint);
-    root_->SetContents(skia::GetTopDevice(*canvas)->accessBitmap(true));
+    bitmap_uploader_->SetBitmap(
+        skia::GetTopDevice(*canvas)->accessBitmap(true));
   }
 
   void ZoomIn() {
@@ -179,9 +184,11 @@
 
   SkBitmap bitmap_;
   scoped_ptr<ServiceProvider> imported_services_;
+  Shell* shell_;
   View* root_;
   ViewManagerClientFactory view_manager_client_factory_;
   uint16_t zoom_percentage_;
+  scoped_ptr<BitmapUploader> bitmap_uploader_;
 
   DISALLOW_COPY_AND_ASSIGN(PNGView);
 };
diff --git a/mojo/examples/sample_app/sample_app.cc b/mojo/examples/sample_app/sample_app.cc
index 6ffdb59..ca60ee0 100644
--- a/mojo/examples/sample_app/sample_app.cc
+++ b/mojo/examples/sample_app/sample_app.cc
@@ -71,7 +71,7 @@
     mojo::CommandBufferPtr command_buffer;
     // TODO(jamesr): Output to a surface instead.
     gpu_service_->CreateOnscreenGLES2Context(
-        native_viewport_id, size.Pass(), Get(&command_buffer));
+        native_viewport_id, size.Pass(), GetProxy(&command_buffer));
     gles2_client_.reset(new GLES2ClientImpl(command_buffer.Pass()));
   }
 
diff --git a/mojo/examples/surfaces_app/BUILD.gn b/mojo/examples/surfaces_app/BUILD.gn
index dc7df4d..448e954 100644
--- a/mojo/examples/surfaces_app/BUILD.gn
+++ b/mojo/examples/surfaces_app/BUILD.gn
@@ -29,10 +29,13 @@
     "//mojo/common",
     "//mojo/environment:chromium",
     "//mojo/public/c/system:for_shared_library",
-    "//mojo/services/public/interfaces/geometry",
+    "//mojo/public/cpp/system",
     "//mojo/services/public/cpp/geometry",
-    "//mojo/services/public/interfaces/surfaces",
     "//mojo/services/public/cpp/surfaces",
+    "//mojo/services/public/interfaces/geometry",
+    "//mojo/services/public/interfaces/gpu",
+    "//mojo/services/public/interfaces/surfaces",
+    "//mojo/services/public/interfaces/native_viewport",
   ]
 
   sources = [
@@ -53,17 +56,19 @@
     "//base",
     "//cc",
     "//cc/surfaces",
-    "//skia",
-    "//ui/gfx",
-    "//ui/gfx/geometry",
     "//mojo/application",
     "//mojo/common",
     "//mojo/environment:chromium",
     "//mojo/public/c/system:for_shared_library",
-    "//mojo/services/public/interfaces/geometry",
+    "//mojo/public/cpp/bindings",
     "//mojo/services/public/cpp/geometry",
-    "//mojo/services/public/interfaces/surfaces",
     "//mojo/services/public/cpp/surfaces",
+    "//mojo/services/public/interfaces/geometry",
+    "//mojo/services/public/interfaces/surfaces",
+    "//mojo/services/public/interfaces/surfaces:surface_id",
+    "//skia",
+    "//ui/gfx",
+    "//ui/gfx/geometry",
   ]
 
   sources = [
@@ -83,19 +88,25 @@
     "//base",
     "//cc",
     "//cc/surfaces",
-    "//skia",
-    "//ui/gfx",
-    "//ui/gfx/geometry",
-    "//mojo/common",
+    "//gpu/command_buffer/common",
     "//mojo/application",
+    "//mojo/common",
     "//mojo/environment:chromium",
     "//mojo/examples/sample_app:spinning_cube",
     "//mojo/public/c/system:for_shared_library",
+    "//mojo/public/cpp/bindings",
+    "//mojo/public/cpp/environment",
+    "//mojo/public/cpp/system",
     "//mojo/public/gles2:for_shared_library",
-    "//mojo/services/public/interfaces/geometry",
     "//mojo/services/public/cpp/geometry",
-    "//mojo/services/public/interfaces/surfaces",
     "//mojo/services/public/cpp/surfaces",
+    "//mojo/services/public/interfaces/geometry",
+    "//mojo/services/public/interfaces/gpu",
+    "//mojo/services/public/interfaces/surfaces",
+    "//mojo/services/public/interfaces/surfaces:surface_id",
+    "//skia",
+    "//ui/gfx",
+    "//ui/gfx/geometry",
   ]
 
   sources = [
@@ -109,6 +120,8 @@
   deps = [
     "//cc",
     "//skia",
+    "//ui/gfx",
+    "//ui/gfx/geometry",
   ]
 
   sources = [
diff --git a/mojo/examples/surfaces_app/DEPS b/mojo/examples/surfaces_app/DEPS
index 23379ad..acce9a2 100644
--- a/mojo/examples/surfaces_app/DEPS
+++ b/mojo/examples/surfaces_app/DEPS
@@ -3,6 +3,7 @@
   "-cc/blink",
   "+gpu/GLES2",
   "+gpu/command_buffer/client",
+  "+gpu/command_buffer/common",
   "+third_party/khronos/GLES2",
   "+third_party/skia/include",
   "+ui/gfx",
diff --git a/mojo/examples/surfaces_app/child_gl_app.cc b/mojo/examples/surfaces_app/child_gl_app.cc
index 9646db4..b84826b 100644
--- a/mojo/examples/surfaces_app/child_gl_app.cc
+++ b/mojo/examples/surfaces_app/child_gl_app.cc
@@ -39,7 +39,7 @@
   virtual void Create(ApplicationConnection* connection,
                       InterfaceRequest<Child> request) override {
     CommandBufferPtr command_buffer;
-    gpu_service_->CreateOffscreenGLES2Context(Get(&command_buffer));
+    gpu_service_->CreateOffscreenGLES2Context(GetProxy(&command_buffer));
     BindToRequest(
         new ChildGLImpl(surfaces_service_connection_, command_buffer.Pass()),
         &request);
diff --git a/mojo/examples/surfaces_app/child_gl_impl.cc b/mojo/examples/surfaces_app/child_gl_impl.cc
index 72374fb..77b3823 100644
--- a/mojo/examples/surfaces_app/child_gl_impl.cc
+++ b/mojo/examples/surfaces_app/child_gl_impl.cc
@@ -16,6 +16,8 @@
 #include "cc/quads/texture_draw_quad.h"
 #include "gpu/GLES2/gl2chromium.h"
 #include "gpu/GLES2/gl2extchromium.h"
+#include "gpu/command_buffer/common/mailbox.h"
+#include "gpu/command_buffer/common/mailbox_holder.h"
 #include "mojo/examples/surfaces_app/surfaces_util.h"
 #include "mojo/public/cpp/application/application_connection.h"
 #include "mojo/public/cpp/environment/environment.h"
diff --git a/mojo/examples/wget/wget.cc b/mojo/examples/wget/wget.cc
index f7c03bb..09c4f7b 100644
--- a/mojo/examples/wget/wget.cc
+++ b/mojo/examples/wget/wget.cc
@@ -80,7 +80,7 @@
     std::string url((args.size() > 1) ? args[1].get() : PromptForURL());
     printf("Loading: %s\n", url.c_str());
 
-    network_service_->CreateURLLoader(Get(&url_loader_));
+    network_service_->CreateURLLoader(GetProxy(&url_loader_));
 
     URLRequestPtr request(URLRequest::New());
     request->url = url;
diff --git a/mojo/examples/window_manager/debug_panel.cc b/mojo/examples/window_manager/debug_panel.cc
index c65785c..7d86cfe 100644
--- a/mojo/examples/window_manager/debug_panel.cc
+++ b/mojo/examples/window_manager/debug_panel.cc
@@ -24,23 +24,27 @@
 
 }  // namespace
 
-DebugPanel::DebugPanel(Delegate* delegate, View* view)
+DebugPanel::DebugPanel(Delegate* delegate, Shell* shell, View* view)
     : delegate_(delegate),
       view_(view),
-      navigation_target_label_(new views::Label(
-          base::ASCIIToUTF16("Navigation target:"))),
-      navigation_target_new_(new views::RadioButton(
-          base::ASCIIToUTF16("New window"), kNavigationTargetGroupId)),
-      navigation_target_source_(new views::RadioButton(
-          base::ASCIIToUTF16("Source window"), kNavigationTargetGroupId)),
-      navigation_target_default_(new views::RadioButton(
-          base::ASCIIToUTF16("Default"), kNavigationTargetGroupId)),
-      colored_square_(new views::BlueButton(
-          this, base::ASCIIToUTF16("Local nav test"))),
-      close_last_(new views::BlueButton(
-          this, base::ASCIIToUTF16("Close last window"))),
-      cross_app_(new views::BlueButton(
-          this, base::ASCIIToUTF16("Cross-app nav test"))) {
+      navigation_target_label_(
+          new views::Label(base::ASCIIToUTF16("Navigation target:"))),
+      navigation_target_new_(
+          new views::RadioButton(base::ASCIIToUTF16("New window"),
+                                 kNavigationTargetGroupId)),
+      navigation_target_source_(
+          new views::RadioButton(base::ASCIIToUTF16("Source window"),
+                                 kNavigationTargetGroupId)),
+      navigation_target_default_(
+          new views::RadioButton(base::ASCIIToUTF16("Default"),
+                                 kNavigationTargetGroupId)),
+      colored_square_(
+          new views::BlueButton(this, base::ASCIIToUTF16("Local nav test"))),
+      close_last_(
+          new views::BlueButton(this, base::ASCIIToUTF16("Close last window"))),
+      cross_app_(
+          new views::BlueButton(this,
+                                base::ASCIIToUTF16("Cross-app nav test"))) {
   navigation_target_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
   navigation_target_default_->SetChecked(true);
 
@@ -59,7 +63,7 @@
   views::Widget* widget = new views::Widget();
   views::Widget::InitParams params(
       views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
-  params.native_widget = new NativeWidgetViewManager(widget, view);
+  params.native_widget = new NativeWidgetViewManager(widget, shell, view);
   params.delegate = widget_delegate;
   params.bounds = gfx::Rect(view->bounds().size());
   widget->Init(params);
diff --git a/mojo/examples/window_manager/debug_panel.h b/mojo/examples/window_manager/debug_panel.h
index 160e400..eec3067 100644
--- a/mojo/examples/window_manager/debug_panel.h
+++ b/mojo/examples/window_manager/debug_panel.h
@@ -20,13 +20,11 @@
 
 namespace mojo {
 
+class Shell;
 class View;
 
 namespace examples {
 
-namespace {
-}
-
 // A panel of controls intended to demonstrate the functionality of the window
 // manager.
 class DebugPanel : public views::LayoutManager, public views::ButtonListener {
@@ -42,7 +40,7 @@
     virtual ~Delegate(){}
   };
 
-  DebugPanel(Delegate* delegate, View* view);
+  DebugPanel(Delegate* delegate, Shell* shell, View* view);
   virtual ~DebugPanel();
 
   Target navigation_target() const;
@@ -57,6 +55,7 @@
   void Navigate(const std::string& url);
 
   Delegate* delegate_;
+  Shell* shell_;
   View* view_;
 
   views::Label* navigation_target_label_;
diff --git a/mojo/examples/window_manager/window_manager.cc b/mojo/examples/window_manager/window_manager.cc
index 2cb5458..fbbf074 100644
--- a/mojo/examples/window_manager/window_manager.cc
+++ b/mojo/examples/window_manager/window_manager.cc
@@ -340,7 +340,8 @@
       public ui::EventHandler {
  public:
   WindowManager()
-      : window_manager_factory_(this),
+      : shell_(nullptr),
+        window_manager_factory_(this),
         launcher_ui_(NULL),
         view_manager_(NULL),
         window_manager_app_(new WindowManagerApp(this, this)),
@@ -408,6 +409,7 @@
 
   // Overridden from ApplicationDelegate:
   virtual void Initialize(ApplicationImpl* app) override {
+    shell_ = app->shell();
     app_ = app;
     views_init_.reset(new ViewsInit);
     window_manager_app_->Initialize(app);
@@ -558,7 +560,7 @@
                          kTextfieldHeight);
     view->SetBounds(bounds);
 
-    debug_panel_ = new DebugPanel(this, view);
+    debug_panel_ = new DebugPanel(this, shell_, view);
     return view->id();
   }
 
@@ -573,6 +575,8 @@
     return windows_.end();
   }
 
+  Shell* shell_;
+
   InterfaceFactoryImplWithContext<WindowManagerConnection, WindowManager>
       window_manager_factory_;
 
diff --git a/mojo/examples/wm_flow/BUILD.gn b/mojo/examples/wm_flow/BUILD.gn
index ef665c0..50ce507 100644
--- a/mojo/examples/wm_flow/BUILD.gn
+++ b/mojo/examples/wm_flow/BUILD.gn
@@ -66,6 +66,7 @@
     ":embeddee_bindings",
     "//base",
     "//mojo/application",
+    "//mojo/examples/bitmap_uploader",
     "//mojo/public/c/system:for_shared_library",
     "//mojo/services/public/cpp/view_manager",
     "//mojo/services/window_manager:lib",
@@ -85,6 +86,7 @@
     ":embeddee_bindings",
     "//base",
     "//mojo/application",
+    "//mojo/examples/bitmap_uploader",
     "//mojo/public/c/system:for_shared_library",
     "//mojo/services/public/cpp/view_manager",
     "//mojo/services/window_manager:lib",
diff --git a/mojo/examples/wm_flow/app/app.cc b/mojo/examples/wm_flow/app/app.cc
index f2bea10..658433c 100644
--- a/mojo/examples/wm_flow/app/app.cc
+++ b/mojo/examples/wm_flow/app/app.cc
@@ -2,9 +2,13 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
+#include <map>
+
 #include "base/bind.h"
 #include "base/macros.h"
+#include "base/stl_util.h"
 #include "mojo/application/application_runner_chromium.h"
+#include "mojo/examples/bitmap_uploader/bitmap_uploader.h"
 #include "mojo/examples/wm_flow/app/embedder.mojom.h"
 #include "mojo/examples/wm_flow/embedded/embeddee.mojom.h"
 #include "mojo/public/c/system/main.h"
@@ -51,12 +55,15 @@
                   public mojo::ViewManagerDelegate,
                   public mojo::ViewObserver {
  public:
-  WMFlowApp() : embed_count_(0) {}
-  virtual ~WMFlowApp() {}
+  WMFlowApp() : shell_(nullptr), embed_count_(0) {}
+  virtual ~WMFlowApp() { STLDeleteValues(&uploaders_); }
 
  private:
+  typedef std::map<mojo::View*, mojo::BitmapUploader*> ViewToUploader;
+
   // Overridden from Application:
   virtual void Initialize(mojo::ApplicationImpl* app) override {
+    shell_ = app->shell();
     view_manager_client_factory_.reset(
         new mojo::ViewManagerClientFactory(app->shell(), this));
     view_manager_context_.reset(new mojo::ViewManagerContext(app));
@@ -79,7 +86,10 @@
       mojo::ServiceProviderImpl* exported_services,
       scoped_ptr<mojo::ServiceProvider> imported_services) override {
     root->AddObserver(this);
-    root->SetColor(kColors[embed_count_++ % arraysize(kColors)]);
+    mojo::BitmapUploader* uploader = new mojo::BitmapUploader(root);
+    uploaders_[root] = uploader;
+    uploader->Init(shell_);
+    uploader->SetColor(kColors[embed_count_++ % arraysize(kColors)]);
 
     mojo::View* embed = mojo::View::Create(view_manager);
     root->AddChild(embed);
@@ -98,7 +108,9 @@
                                     base::Unretained(this)));
   }
   virtual void OnViewManagerDisconnected(
-      mojo::ViewManager* view_manager) override {}
+      mojo::ViewManager* view_manager) override {
+    STLDeleteValues(&uploaders_);
+  }
 
   // Overridden from mojo::ViewObserver:
   virtual void OnViewInputEvent(mojo::View* view,
@@ -109,6 +121,10 @@
     }
   }
   virtual void OnViewDestroyed(mojo::View* view) override {
+    if (uploaders_.find(view) != uploaders_.end()) {
+      delete uploaders_[view];
+      uploaders_.erase(view);
+    }
     --embed_count_;
     view->RemoveObserver(this);
   }
@@ -121,11 +137,13 @@
     view_manager_context_->Embed("mojo:mojo_wm_flow_app");
   }
 
+  mojo::Shell* shell_;
   int embed_count_;
   scoped_ptr<mojo::ViewManagerClientFactory> view_manager_client_factory_;
   mojo::InterfaceFactoryImpl<EmbedderImpl> embedder_factory_;
   scoped_ptr<mojo::ViewManagerContext> view_manager_context_;
   EmbeddeePtr embeddee_;
+  ViewToUploader uploaders_;
 
   DISALLOW_COPY_AND_ASSIGN(WMFlowApp);
 };
diff --git a/mojo/examples/wm_flow/embedded/embedded.cc b/mojo/examples/wm_flow/embedded/embedded.cc
index f69aa90..d328501 100644
--- a/mojo/examples/wm_flow/embedded/embedded.cc
+++ b/mojo/examples/wm_flow/embedded/embedded.cc
@@ -5,6 +5,7 @@
 #include "base/bind.h"
 #include "base/macros.h"
 #include "mojo/application/application_runner_chromium.h"
+#include "mojo/examples/bitmap_uploader/bitmap_uploader.h"
 #include "mojo/examples/wm_flow/app/embedder.mojom.h"
 #include "mojo/examples/wm_flow/embedded/embeddee.mojom.h"
 #include "mojo/public/cpp/application/application_connection.h"
@@ -41,12 +42,13 @@
 class WMFlowEmbedded : public mojo::ApplicationDelegate,
                        public mojo::ViewManagerDelegate {
  public:
-  WMFlowEmbedded() {}
+  WMFlowEmbedded() : shell_(nullptr) {}
   virtual ~WMFlowEmbedded() {}
 
  private:
   // Overridden from Application:
   virtual void Initialize(mojo::ApplicationImpl* app) override {
+    shell_ = app->shell();
     view_manager_client_factory_.reset(
         new mojo::ViewManagerClientFactory(app->shell(), this));
   }
@@ -62,7 +64,9 @@
       mojo::View* root,
       mojo::ServiceProviderImpl* exported_services,
       scoped_ptr<mojo::ServiceProvider> imported_services) override {
-    root->SetColor(SK_ColorMAGENTA);
+    bitmap_uploader_.reset(new mojo::BitmapUploader(root));
+    bitmap_uploader_->Init(shell_);
+    bitmap_uploader_->SetColor(SK_ColorMAGENTA);
 
     exported_services->AddService(&embeddee_factory_);
     mojo::ConnectToService(imported_services.get(), &embedder_);
@@ -76,9 +80,11 @@
     printf("HelloWorld() ack'ed\n");
   }
 
+  mojo::Shell* shell_;
   scoped_ptr<mojo::ViewManagerClientFactory> view_manager_client_factory_;
   EmbedderPtr embedder_;
   mojo::InterfaceFactoryImpl<EmbeddeeImpl> embeddee_factory_;
+  scoped_ptr<mojo::BitmapUploader> bitmap_uploader_;
 
   DISALLOW_COPY_AND_ASSIGN(WMFlowEmbedded);
 };
diff --git a/mojo/examples/wm_flow/wm/frame_controller.cc b/mojo/examples/wm_flow/wm/frame_controller.cc
index 7ed1dac..40ff041 100644
--- a/mojo/examples/wm_flow/wm/frame_controller.cc
+++ b/mojo/examples/wm_flow/wm/frame_controller.cc
@@ -95,6 +95,7 @@
 // FrameController, public:
 
 FrameController::FrameController(
+    mojo::Shell* shell,
     mojo::View* view,
     mojo::View** app_view,
     aura::client::ActivationClient* activation_client,
@@ -117,7 +118,8 @@
   frame_view_->AddPreTargetHandler(frame_event_handler_.get());
   views::Widget::InitParams params(
       views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
-  params.native_widget = new mojo::NativeWidgetViewManager(widget_, view_);
+  params.native_widget =
+      new mojo::NativeWidgetViewManager(widget_, shell, view_);
   params.bounds = gfx::Rect(view_->bounds().size());
   widget_->Init(params);
   widget_->SetContentsView(frame_view_);
diff --git a/mojo/examples/wm_flow/wm/frame_controller.h b/mojo/examples/wm_flow/wm/frame_controller.h
index 2c7d9e9..0add0a1 100644
--- a/mojo/examples/wm_flow/wm/frame_controller.h
+++ b/mojo/examples/wm_flow/wm/frame_controller.h
@@ -17,6 +17,7 @@
 
 namespace mojo {
 class NativeWidgetViewManager;
+class Shell;
 class View;
 class WindowManagerApp;
 }
@@ -31,7 +32,8 @@
 // to any events targeted at it.
 class FrameController : mojo::ViewObserver {
  public:
-  FrameController(mojo::View* view,
+  FrameController(mojo::Shell* shell,
+                  mojo::View* view,
                   mojo::View** app_view,
                   aura::client::ActivationClient* activation_client,
                   mojo::WindowManagerApp* window_manager_app);
diff --git a/mojo/examples/wm_flow/wm/wm.cc b/mojo/examples/wm_flow/wm/wm.cc
index f2787fc..56d8b39 100644
--- a/mojo/examples/wm_flow/wm/wm.cc
+++ b/mojo/examples/wm_flow/wm/wm.cc
@@ -91,7 +91,8 @@
                  public mojo::ViewObserver {
  public:
   SimpleWM()
-      : window_manager_app_(new mojo::WindowManagerApp(this, this)),
+      : shell_(nullptr),
+        window_manager_app_(new mojo::WindowManagerApp(this, this)),
         view_manager_(NULL),
         root_(NULL),
         window_container_(NULL),
@@ -101,6 +102,7 @@
  private:
   // Overridden from mojo::ApplicationDelegate:
   virtual void Initialize(mojo::ApplicationImpl* impl) override {
+    shell_ = impl->shell();
     window_manager_app_->Initialize(impl);
   }
   virtual bool ConfigureIncomingConnection(
@@ -175,11 +177,13 @@
 
     aura::client::ActivationClient* client = aura::client::GetActivationClient(
         window_manager_app_->host()->window());
-    new FrameController(frame_view, app_view, client,
-                        window_manager_app_.get());
+    new FrameController(
+        shell_, frame_view, app_view, client, window_manager_app_.get());
     return frame_view;
   }
 
+  mojo::Shell* shell_;
+
   scoped_ptr<mojo::WindowManagerApp> window_manager_app_;
 
   mojo::ViewManager* view_manager_;