diff --git a/engine/src/flutter/compositor/BUILD.gn b/engine/src/flutter/compositor/BUILD.gn deleted file mode 100644 index 27f59b0a1d..0000000000 --- a/engine/src/flutter/compositor/BUILD.gn +++ /dev/null @@ -1,55 +0,0 @@ -# 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. - -source_set("compositor") { - sources = [ - "layer.cc", - "layer.h", - "layer_client.cc", - "layer_client.h", - "layer_host.cc", - "layer_host.h", - "layer_host_client.cc", - "layer_host_client.h", - "picture_serializer.cc", - "picture_serializer.h", - "rasterizer.cc", - "rasterizer.h", - "rasterizer_bitmap.cc", - "rasterizer_bitmap.h", - "rasterizer_ganesh.cc", - "rasterizer_ganesh.h", - "resource_manager.cc", - "resource_manager.h", - "surface_allocator.cc", - "surface_allocator.h", - "surface_holder.cc", - "surface_holder.h", - "texture_cache.cc", - "texture_cache.h", - ] - - deps = [ - "//base", - "//mojo/application", - "//mojo/converters/geometry", - "//mojo/converters/surfaces", - "//mojo/gpu", - "//mojo/public/c/gles2", - "//mojo/public/cpp/bindings", - "//mojo/public/cpp/environment", - "//mojo/public/cpp/system", - "//mojo/public/cpp/utility", - "//mojo/public/interfaces/application", - "//mojo/services/geometry/public/interfaces", - "//mojo/services/surfaces/public/cpp", - "//mojo/services/surfaces/public/interfaces", - "//mojo/services/surfaces/public/interfaces:surface_id", - "//mojo/skia", - "//skia", - "//third_party/libpng", - "//ui/gfx", - "//ui/gfx/geometry", - ] -} diff --git a/engine/src/flutter/compositor/layer.cc b/engine/src/flutter/compositor/layer.cc deleted file mode 100644 index 5c05fdf5c6..0000000000 --- a/engine/src/flutter/compositor/layer.cc +++ /dev/null @@ -1,57 +0,0 @@ -// 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 "sky/compositor/layer.h" - -#include "base/trace_event/trace_event.h" -#include "sky/compositor/layer_host.h" -#include "sky/compositor/picture_serializer.h" -#include "sky/compositor/rasterizer.h" -#include "third_party/skia/include/core/SkCanvas.h" -#include "third_party/skia/include/core/SkPictureRecorder.h" - -namespace sky { - -Layer::Layer(LayerClient* client) : client_(client) { -} - -Layer::~Layer() { -} - -void Layer::SetSize(const gfx::Size& size) { - size_ = size; -} - -void Layer::Display() { - TRACE_EVENT0("sky", "Layer::Display"); - DCHECK(rasterizer_); - auto picture = RecordPicture(); - -#if 0 - SerializePicture( - "/data/data/org.chromium.mojo.shell/cache/layer0.skp", picture.get()); -#endif - - texture_ = rasterizer_->Rasterize(picture.get()); -} - -skia::RefPtr Layer::RecordPicture() { - TRACE_EVENT0("sky", "Layer::RecordPicture"); - - SkRTreeFactory factory; - SkPictureRecorder recorder; - - auto canvas = skia::SharePtr(recorder.beginRecording( - size_.width(), size_.height(), &factory, - SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag)); - - client_->PaintContents(canvas.get(), gfx::Rect(size_)); - return skia::AdoptRef(recorder.endRecordingAsPicture()); -} - -scoped_ptr Layer::GetTexture() { - return texture_.Pass(); -} - -} // namespace sky diff --git a/engine/src/flutter/compositor/layer.h b/engine/src/flutter/compositor/layer.h deleted file mode 100644 index 761d2bdbf8..0000000000 --- a/engine/src/flutter/compositor/layer.h +++ /dev/null @@ -1,51 +0,0 @@ -// 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 SKY_COMPOSITOR_LAYER_H_ -#define SKY_COMPOSITOR_LAYER_H_ - -#include "base/memory/ref_counted.h" -#include "mojo/gpu/gl_texture.h" -#include "skia/ext/refptr.h" -#include "sky/compositor/layer_client.h" -#include "sky/compositor/rasterizer.h" -#include "third_party/skia/include/core/SkPicture.h" -#include "ui/gfx/geometry/rect.h" - -namespace sky { - -class LayerHost; - -class Layer : public base::RefCounted { - public: - explicit Layer(LayerClient* client); - - void SetSize(const gfx::Size& size); - void Display(); - - scoped_ptr GetTexture(); - - const gfx::Size& size() const { return size_; } - - void set_rasterizer(scoped_ptr rasterizer) { - rasterizer_ = rasterizer.Pass(); - } - - private: - friend class base::RefCounted; - ~Layer(); - - skia::RefPtr RecordPicture(); - - LayerClient* client_; - gfx::Size size_; - scoped_ptr texture_; - scoped_ptr rasterizer_; - - DISALLOW_COPY_AND_ASSIGN(Layer); -}; - -} // namespace sky - -#endif // SKY_COMPOSITOR_LAYER_H_ diff --git a/engine/src/flutter/compositor/layer_client.cc b/engine/src/flutter/compositor/layer_client.cc deleted file mode 100644 index 229482af62..0000000000 --- a/engine/src/flutter/compositor/layer_client.cc +++ /dev/null @@ -1,12 +0,0 @@ -// 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 "sky/compositor/layer_client.h" - -namespace sky { - -LayerClient::~LayerClient() { -} - -} // namespace sky diff --git a/engine/src/flutter/compositor/layer_client.h b/engine/src/flutter/compositor/layer_client.h deleted file mode 100644 index c0673fae73..0000000000 --- a/engine/src/flutter/compositor/layer_client.h +++ /dev/null @@ -1,26 +0,0 @@ -// 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 SKY_COMPOSITOR_LAYER_CLIENT_H_ -#define SKY_COMPOSITOR_LAYER_CLIENT_H_ - -class SkCanvas; - -namespace gfx { -class Rect; -} - -namespace sky { - -class LayerClient { - public: - virtual void PaintContents(SkCanvas* canvas, const gfx::Rect& clip) = 0; - - protected: - virtual ~LayerClient(); -}; - -} // namespace sky - -#endif // SKY_COMPOSITOR_LAYER_CLIENT_H_ diff --git a/engine/src/flutter/compositor/layer_host.cc b/engine/src/flutter/compositor/layer_host.cc deleted file mode 100644 index bf4661805e..0000000000 --- a/engine/src/flutter/compositor/layer_host.cc +++ /dev/null @@ -1,151 +0,0 @@ -// 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 "sky/compositor/layer_host.h" - -#include "base/message_loop/message_loop.h" -#include "base/trace_event/trace_event.h" -#include "mojo/converters/geometry/geometry_type_converters.h" -#include "mojo/gpu/gl_context.h" -#include "mojo/services/surfaces/public/cpp/surfaces_utils.h" -#include "mojo/skia/ganesh_context.h" -#include "sky/compositor/layer.h" - -namespace sky { - -LayerHost::LayerHost(LayerHostClient* client) - : client_(client), - state_(kReadyForFrame), - frame_requested_(false), - surface_holder_(this, client->GetShell()), - gl_context_owner_(client->GetShell()), - ganesh_context_(gl_context()), - resource_manager_(gl_context()), - weak_factory_(this) { -} - -LayerHost::~LayerHost() { -} - -void LayerHost::SetNeedsAnimate() { - if (frame_requested_) - return; - frame_requested_ = true; - if (state_ == kReadyForFrame) - BeginFrameSoon(); -} - -void LayerHost::SetRootLayer(scoped_refptr layer) { - DCHECK(!root_layer_.get()); - root_layer_ = layer; -} - -void LayerHost::OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) { - client_->OnSurfaceIdAvailable(surface_id.Pass()); -} - -void LayerHost::ReturnResources( - mojo::Array resources) { - resource_manager_.ReturnResources(resources.Pass()); -} - -void LayerHost::BeginFrameSoon() { - base::MessageLoop::current()->PostTask( - FROM_HERE, - base::Bind(&LayerHost::BeginFrame, weak_factory_.GetWeakPtr())); -} - -void LayerHost::BeginFrame() { - TRACE_EVENT0("sky", "LayerHost::BeginFrame"); - - DCHECK(frame_requested_); - frame_requested_ = false; - - DCHECK_EQ(state_, kReadyForFrame); - state_ = kWaitingForFrameAcknowldgement; - - client_->BeginFrame(base::TimeTicks::Now()); - - // If the root layer is empty, there's no reason to draw into it. (In fact, - // Ganesh will get upset if we try.) Instead, we just schedule the ack that - // the frame is complete. - if (root_layer_->size().IsEmpty()) { - base::MessageLoop::current()->PostTask( - FROM_HERE, - base::Bind(&LayerHost::DidCompleteFrame, weak_factory_.GetWeakPtr())); - return; - } - - { - mojo::GaneshContext::Scope scope(&ganesh_context_); - ganesh_context_.gr()->resetContext(); - root_layer_->Display(); - } - - Upload(root_layer_.get()); -} - -void LayerHost::Upload(Layer* layer) { - TRACE_EVENT0("sky", "LayerHost::Upload"); - - gfx::Size size = layer->size(); - surface_holder_.SetSize(size); - - mojo::FramePtr frame = mojo::Frame::New(); - frame->resources.resize(0u); - - mojo::Rect bounds; - bounds.width = size.width(); - bounds.height = size.height(); - mojo::PassPtr pass = mojo::CreateDefaultPass(1, bounds); - pass->quads.resize(0u); - pass->shared_quad_states.push_back(mojo::CreateDefaultSQS( - mojo::TypeConverter::Convert(size))); - - mojo::TransferableResourcePtr resource = - resource_manager_.CreateTransferableResource(layer); - - mojo::QuadPtr quad = mojo::Quad::New(); - quad->material = mojo::MATERIAL_TEXTURE_CONTENT; - - mojo::RectPtr rect = mojo::Rect::New(); - rect->width = size.width(); - rect->height = size.height(); - quad->rect = rect.Clone(); - quad->opaque_rect = rect.Clone(); - quad->visible_rect = rect.Clone(); - quad->needs_blending = true; - quad->shared_quad_state_index = 0u; - - mojo::TextureQuadStatePtr texture_state = mojo::TextureQuadState::New(); - texture_state->resource_id = resource->id; - texture_state->premultiplied_alpha = true; - texture_state->uv_top_left = mojo::PointF::New(); - texture_state->uv_bottom_right = mojo::PointF::New(); - texture_state->uv_bottom_right->x = 1.f; - texture_state->uv_bottom_right->y = 1.f; - texture_state->background_color = mojo::Color::New(); - texture_state->background_color->rgba = 0; - 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()); - - frame->passes.push_back(pass.Pass()); - surface_holder_.SubmitFrame( - frame.Pass(), - base::Bind(&LayerHost::DidCompleteFrame, weak_factory_.GetWeakPtr())); -} - -void LayerHost::DidCompleteFrame() { - DCHECK_EQ(state_, kWaitingForFrameAcknowldgement); - state_ = kReadyForFrame; - if (frame_requested_) - BeginFrame(); -} - -} // namespace sky diff --git a/engine/src/flutter/compositor/layer_host.h b/engine/src/flutter/compositor/layer_host.h deleted file mode 100644 index 36bf2df53a..0000000000 --- a/engine/src/flutter/compositor/layer_host.h +++ /dev/null @@ -1,77 +0,0 @@ -// 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 SKY_COMPOSITOR_LAYER_HOST_H_ -#define SKY_COMPOSITOR_LAYER_HOST_H_ - -#include "base/memory/ref_counted.h" -#include "base/memory/scoped_ptr.h" -#include "base/memory/weak_ptr.h" -#include "mojo/gpu/gl_context_owner.h" -#include "mojo/skia/ganesh_context.h" -#include "sky/compositor/layer_host_client.h" -#include "sky/compositor/resource_manager.h" -#include "sky/compositor/surface_holder.h" - -namespace sky { -class ResourceManager; -class Layer; -class LayerHostClient; - -class LayerHost : public SurfaceHolder::Client { - public: - explicit LayerHost(LayerHostClient* client); - ~LayerHost() override; - - LayerHostClient* client() const { return client_; } - - const base::WeakPtr& gl_context() const { - return gl_context_owner_.context(); - } - - mojo::GaneshContext* ganesh_context() const { - return const_cast(&ganesh_context_); - } - - ResourceManager* resource_manager() const { - return const_cast(&resource_manager_); - } - - void SetNeedsAnimate(); - void SetRootLayer(scoped_refptr layer); - - private: - enum State { - kReadyForFrame, - kWaitingForFrameAcknowldgement, - }; - - // SurfaceHolder::Client - void OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) override; - void ReturnResources( - mojo::Array resources) override; - - void BeginFrameSoon(); - void BeginFrame(); - - void Upload(Layer* layer); - void DidCompleteFrame(); - - LayerHostClient* client_; - State state_; - bool frame_requested_; - SurfaceHolder surface_holder_; - mojo::GLContextOwner gl_context_owner_; - mojo::GaneshContext ganesh_context_; - ResourceManager resource_manager_; - scoped_refptr root_layer_; - - base::WeakPtrFactory weak_factory_; - - DISALLOW_COPY_AND_ASSIGN(LayerHost); -}; - -} // namespace sky - -#endif // SKY_COMPOSITOR_LAYER_HOST_H_ diff --git a/engine/src/flutter/compositor/layer_host_client.cc b/engine/src/flutter/compositor/layer_host_client.cc deleted file mode 100644 index 13a25b0282..0000000000 --- a/engine/src/flutter/compositor/layer_host_client.cc +++ /dev/null @@ -1,12 +0,0 @@ -// 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 "sky/compositor/layer_host_client.h" - -namespace sky { - -LayerHostClient::~LayerHostClient() { -} - -} // namespace sky diff --git a/engine/src/flutter/compositor/layer_host_client.h b/engine/src/flutter/compositor/layer_host_client.h deleted file mode 100644 index f2146d64d6..0000000000 --- a/engine/src/flutter/compositor/layer_host_client.h +++ /dev/null @@ -1,29 +0,0 @@ -// 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 SKY_COMPOSITOR_LAYER_HOST_CLIENT_H_ -#define SKY_COMPOSITOR_LAYER_HOST_CLIENT_H_ - -#include "base/time/time.h" -#include "mojo/services/surfaces/public/interfaces/surface_id.mojom.h" - -namespace mojo { -class Shell; -} - -namespace sky { - -class LayerHostClient { - public: - virtual mojo::Shell* GetShell() = 0; - virtual void BeginFrame(base::TimeTicks frame_time) = 0; - virtual void OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) = 0; - - protected: - virtual ~LayerHostClient(); -}; - -} // namespace sky - -#endif // SKY_COMPOSITOR_LAYER_HOST_CLIENT_H_ diff --git a/engine/src/flutter/compositor/picture_serializer.cc b/engine/src/flutter/compositor/picture_serializer.cc deleted file mode 100644 index 47117e718a..0000000000 --- a/engine/src/flutter/compositor/picture_serializer.cc +++ /dev/null @@ -1,36 +0,0 @@ -// 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/compositor/picture_serializer.h" - -#include "third_party/skia/include/core/SkData.h" -#include "third_party/skia/include/core/SkPixelSerializer.h" -#include "third_party/skia/include/core/SkStream.h" -#include "ui/gfx/codec/png_codec.h" - -namespace sky { - -class PngPixelSerializer : public SkPixelSerializer { - public: - bool onUseEncodedData(const void*, size_t) override { return true; } - SkData* onEncodePixels(const SkImageInfo& info, const void* pixels, - size_t row_bytes) override { - std::vector data; - - SkBitmap bm; - if (!bm.installPixels(info, const_cast(pixels), row_bytes)) - return nullptr; - if (!gfx::PNGCodec::EncodeBGRASkBitmap(bm, false, &data)) - return nullptr; - return SkData::NewWithCopy(&data.front(), data.size()); - } -}; - -void SerializePicture(const char* file_name, SkPicture* picture) { - SkFILEWStream stream(file_name); - PngPixelSerializer serializer; - picture->serialize(&stream, &serializer); -} - -} // namespace sky diff --git a/engine/src/flutter/compositor/picture_serializer.h b/engine/src/flutter/compositor/picture_serializer.h deleted file mode 100644 index e2b192db7f..0000000000 --- a/engine/src/flutter/compositor/picture_serializer.h +++ /dev/null @@ -1,16 +0,0 @@ -// 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_COMPOSITOR_PICTURE_SERIALIZER_H_ -#define SKY_COMPOSITOR_PICTURE_SERIALIZER_H_ - -#include "third_party/skia/include/core/SkPicture.h" - -namespace sky { - -void SerializePicture(const char* file_name, SkPicture*); - -} // namespace sky - -#endif // SKY_COMPOSITOR_PICTURE_SERIALIZER_H_ diff --git a/engine/src/flutter/compositor/rasterizer.cc b/engine/src/flutter/compositor/rasterizer.cc deleted file mode 100644 index e0eb2d5c18..0000000000 --- a/engine/src/flutter/compositor/rasterizer.cc +++ /dev/null @@ -1,15 +0,0 @@ -// 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/compositor/rasterizer.h" - -namespace sky { - -Rasterizer::Rasterizer() { -} - -Rasterizer::~Rasterizer() { -} - -} // namespace sky diff --git a/engine/src/flutter/compositor/rasterizer.h b/engine/src/flutter/compositor/rasterizer.h deleted file mode 100644 index 7b1a4fad5a..0000000000 --- a/engine/src/flutter/compositor/rasterizer.h +++ /dev/null @@ -1,28 +0,0 @@ -// 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_COMPOSITOR_RASTERIZER_H_ -#define SKY_COMPOSITOR_RASTERIZER_H_ - -#include "base/memory/scoped_ptr.h" -#include "mojo/gpu/gl_texture.h" - -class SkPicture; - -namespace sky { - -class Rasterizer { - public: - Rasterizer(); - virtual ~Rasterizer(); - - virtual scoped_ptr Rasterize(SkPicture* picture) = 0; - - private: - DISALLOW_COPY_AND_ASSIGN(Rasterizer); -}; - -} // namespace sky - -#endif // SKY_COMPOSITOR_RASTERIZER_H_ diff --git a/engine/src/flutter/compositor/rasterizer_bitmap.cc b/engine/src/flutter/compositor/rasterizer_bitmap.cc deleted file mode 100644 index ee926f212d..0000000000 --- a/engine/src/flutter/compositor/rasterizer_bitmap.cc +++ /dev/null @@ -1,43 +0,0 @@ -// 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/compositor/rasterizer_bitmap.h" - -#include "sky/compositor/layer_client.h" -#include "sky/compositor/layer_host.h" -#include "third_party/skia/include/core/SkBitmapDevice.h" -#include "third_party/skia/include/core/SkCanvas.h" -#include "third_party/skia/include/core/SkPicture.h" -#include "ui/gfx/codec/png_codec.h" -#include "ui/gfx/geometry/rect.h" - -namespace sky { - -RasterizerBitmap::RasterizerBitmap(LayerHost* host) : host_(host) { - DCHECK(host_); -} - -RasterizerBitmap::~RasterizerBitmap() { -} - -void RasterizerBitmap::GetPixelsForTesting(std::vector* pixels) { - gfx::PNGCodec::EncodeBGRASkBitmap(bitmap_, true, pixels); -} - -scoped_ptr RasterizerBitmap::Rasterize(SkPicture* picture) { - auto size = picture->cullRect(); - bitmap_.allocN32Pixels(size.width(), size.height()); - - SkBitmapDevice device(bitmap_); - SkCanvas canvas(&device); - // Draw red so we can see when we fail to paint. - canvas.drawColor(SK_ColorRED); - canvas.drawPicture(picture); - canvas.flush(); - - return host_->resource_manager()->CreateTexture( - gfx::Size(size.width(), size.height())); -} - -} // namespace sky diff --git a/engine/src/flutter/compositor/rasterizer_bitmap.h b/engine/src/flutter/compositor/rasterizer_bitmap.h deleted file mode 100644 index 22886233ab..0000000000 --- a/engine/src/flutter/compositor/rasterizer_bitmap.h +++ /dev/null @@ -1,31 +0,0 @@ -// 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_COMPOSITOR_DISPLAY_RASTERIZER_BITMAP_H_ -#define SKY_COMPOSITOR_DISPLAY_RASTERIZER_BITMAP_H_ - -#include "sky/compositor/rasterizer.h" -#include "third_party/skia/include/core/SkBitmap.h" - -namespace sky { -class LayerHost; - -class RasterizerBitmap : public Rasterizer { - public: - explicit RasterizerBitmap(LayerHost* host); - ~RasterizerBitmap() override; - - scoped_ptr Rasterize(SkPicture* picture) override; - void GetPixelsForTesting(std::vector* pixels); - - private: - LayerHost* host_; - SkBitmap bitmap_; - - DISALLOW_COPY_AND_ASSIGN(RasterizerBitmap); -}; - -} // namespace sky - -#endif // SKY_COMPOSITOR_DISPLAY_RASTERIZER_BITMAP_H_ diff --git a/engine/src/flutter/compositor/rasterizer_ganesh.cc b/engine/src/flutter/compositor/rasterizer_ganesh.cc deleted file mode 100644 index 46ac59be5d..0000000000 --- a/engine/src/flutter/compositor/rasterizer_ganesh.cc +++ /dev/null @@ -1,38 +0,0 @@ -// 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/compositor/rasterizer_ganesh.h" - -#include "base/trace_event/trace_event.h" -#include "mojo/skia/ganesh_surface.h" -#include "sky/compositor/layer_host.h" -#include "third_party/skia/include/core/SkCanvas.h" -#include "third_party/skia/include/core/SkPicture.h" - -namespace sky { - -RasterizerGanesh::RasterizerGanesh(LayerHost* host) : host_(host) { - DCHECK(host_); -} - -RasterizerGanesh::~RasterizerGanesh() { -} - -scoped_ptr RasterizerGanesh::Rasterize(SkPicture* picture) { - TRACE_EVENT0("sky", "RasterizerGanesh::Rasterize"); - - SkRect cull_rect = picture->cullRect(); - gfx::Size size(cull_rect.width(), cull_rect.height()); - - mojo::GaneshSurface surface(host_->ganesh_context(), - host_->resource_manager()->CreateTexture(size)); - - SkCanvas* canvas = surface.canvas(); - canvas->drawPicture(picture); - canvas->flush(); - - return surface.TakeTexture(); -} - -} // namespace sky diff --git a/engine/src/flutter/compositor/rasterizer_ganesh.h b/engine/src/flutter/compositor/rasterizer_ganesh.h deleted file mode 100644 index 6ee23f518a..0000000000 --- a/engine/src/flutter/compositor/rasterizer_ganesh.h +++ /dev/null @@ -1,28 +0,0 @@ -// 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_COMPOSITOR_DISPLAY_RASTERIZER_GANESH_H_ -#define SKY_COMPOSITOR_DISPLAY_RASTERIZER_GANESH_H_ - -#include "sky/compositor/rasterizer.h" - -namespace sky { -class LayerHost; - -class RasterizerGanesh : public Rasterizer { - public: - explicit RasterizerGanesh(LayerHost* host); - ~RasterizerGanesh() override; - - scoped_ptr Rasterize(SkPicture* picture) override; - - private: - LayerHost* host_; - - DISALLOW_COPY_AND_ASSIGN(RasterizerGanesh); -}; - -} // namespace sky - -#endif // SKY_COMPOSITOR_DISPLAY_RASTERIZER_GANESH_H_ diff --git a/engine/src/flutter/compositor/resource_manager.cc b/engine/src/flutter/compositor/resource_manager.cc deleted file mode 100644 index 9a5eecd249..0000000000 --- a/engine/src/flutter/compositor/resource_manager.cc +++ /dev/null @@ -1,93 +0,0 @@ -// 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 "sky/compositor/resource_manager.h" - -#ifndef GL_GLEXT_PROTOTYPES -#define GL_GLEXT_PROTOTYPES -#endif - -#include "base/logging.h" -#include "base/stl_util.h" -#include "gpu/GLES2/gl2chromium.h" -#include "gpu/GLES2/gl2extchromium.h" -#include "mojo/converters/geometry/geometry_type_converters.h" -#include "mojo/gpu/gl_context.h" -#include "mojo/gpu/gl_texture.h" -#include "mojo/public/c/gles2/gles2.h" -#include "sky/compositor/layer.h" - -namespace sky { - -ResourceManager::ResourceManager(base::WeakPtr gl_context) - : gl_context_(gl_context), next_resource_id_(0) { -} - -ResourceManager::~ResourceManager() { - STLDeleteContainerPairSecondPointers(resource_to_texture_map_.begin(), - resource_to_texture_map_.end()); -} - -scoped_ptr ResourceManager::CreateTexture( - const gfx::Size& size) { - scoped_ptr texture = texture_cache_.GetTexture(size); - if (texture) - return texture.Pass(); - gl_context_->MakeCurrent(); - return make_scoped_ptr(new mojo::GLTexture( - gl_context_, mojo::TypeConverter::Convert(size))); -} - -mojo::TransferableResourcePtr ResourceManager::CreateTransferableResource( - Layer* layer) { - scoped_ptr texture = layer->GetTexture(); - mojo::Size size = texture->size(); - - gl_context_->MakeCurrent(); - glBindTexture(GL_TEXTURE_2D, texture->texture_id()); - GLbyte mailbox[GL_MAILBOX_SIZE_CHROMIUM]; - glGenMailboxCHROMIUM(mailbox); - glProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox); - GLuint sync_point = glInsertSyncPointCHROMIUM(); - - mojo::TransferableResourcePtr resource = mojo::TransferableResource::New(); - resource->id = next_resource_id_++; - resource_to_texture_map_[resource->id] = texture.release(); - resource->format = mojo::RESOURCE_FORMAT_RGBA_8888; - resource->filter = GL_LINEAR; - resource->size = size.Clone(); - resource->is_repeated = false; - resource->is_software = false; - - mojo::MailboxHolderPtr mailbox_holder = mojo::MailboxHolder::New(); - mailbox_holder->mailbox = mojo::Mailbox::New(); - for (int i = 0; i < GL_MAILBOX_SIZE_CHROMIUM; ++i) - mailbox_holder->mailbox->name.push_back(mailbox[i]); - mailbox_holder->texture_target = GL_TEXTURE_2D; - mailbox_holder->sync_point = sync_point; - resource->mailbox_holder = mailbox_holder.Pass(); - - return resource.Pass(); -} - -void ResourceManager::ReturnResources( - mojo::Array resources) { - DCHECK(resources.size()); - - gl_context_->MakeCurrent(); - for (size_t i = 0u; i < resources.size(); ++i) { - mojo::ReturnedResourcePtr resource = resources[i].Pass(); - DCHECK_EQ(1, resource->count); - auto iter = resource_to_texture_map_.find(resource->id); - if (iter == resource_to_texture_map_.end()) - continue; - scoped_ptr texture(iter->second); - DCHECK_NE(0u, texture->texture_id()); - resource_to_texture_map_.erase(iter); - glWaitSyncPointCHROMIUM(resource->sync_point); - texture_cache_.PutTexture(texture.Pass()); - } -} - -} // namespace examples diff --git a/engine/src/flutter/compositor/resource_manager.h b/engine/src/flutter/compositor/resource_manager.h deleted file mode 100644 index e6fd329dd4..0000000000 --- a/engine/src/flutter/compositor/resource_manager.h +++ /dev/null @@ -1,49 +0,0 @@ -// 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 SKY_COMPOSITOR_RESOURCE_MANAGER_H_ -#define SKY_COMPOSITOR_RESOURCE_MANAGER_H_ - -#include "base/containers/hash_tables.h" -#include "base/memory/scoped_ptr.h" -#include "base/memory/scoped_vector.h" -#include "base/memory/weak_ptr.h" -#include "mojo/services/surfaces/public/interfaces/surfaces.mojom.h" -#include "sky/compositor/texture_cache.h" - -namespace gfx { -class Size; -} - -namespace mojo { -class GLContext; -class GLTexture; -} - -namespace sky { -class Layer; -class LayerHost; - -class ResourceManager { - public: - explicit ResourceManager(base::WeakPtr gl_context); - ~ResourceManager(); - - scoped_ptr CreateTexture(const gfx::Size& size); - - mojo::TransferableResourcePtr CreateTransferableResource(Layer* layer); - void ReturnResources(mojo::Array resources); - - private: - base::WeakPtr gl_context_; - uint32_t next_resource_id_; - base::hash_map resource_to_texture_map_; - TextureCache texture_cache_; - - DISALLOW_COPY_AND_ASSIGN(ResourceManager); -}; - -} // namespace sky - -#endif // SKY_COMPOSITOR_RESOURCE_MANAGER_H_ diff --git a/engine/src/flutter/compositor/surface_allocator.cc b/engine/src/flutter/compositor/surface_allocator.cc deleted file mode 100644 index 7b3d381b41..0000000000 --- a/engine/src/flutter/compositor/surface_allocator.cc +++ /dev/null @@ -1,26 +0,0 @@ -// 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 "sky/compositor/surface_allocator.h" - -#include "base/logging.h" - -namespace sky { - -SurfaceAllocator::SurfaceAllocator(uint32_t id_namespace) - : id_namespace_(id_namespace), next_id_(1) { - DCHECK(id_namespace); -} - -SurfaceAllocator::~SurfaceAllocator() { -} - -mojo::SurfaceIdPtr SurfaceAllocator::CreateSurfaceId() { - auto id = mojo::SurfaceId::New(); - id->local = next_id_++; - id->id_namespace = id_namespace_; - return id.Pass(); -} - -} // namespace sky diff --git a/engine/src/flutter/compositor/surface_allocator.h b/engine/src/flutter/compositor/surface_allocator.h deleted file mode 100644 index 5da7c6f11e..0000000000 --- a/engine/src/flutter/compositor/surface_allocator.h +++ /dev/null @@ -1,29 +0,0 @@ -// 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 SKY_COMPOSITOR_SURFACE_ALLOCATOR_H_ -#define SKY_COMPOSITOR_SURFACE_ALLOCATOR_H_ - -#include "base/basictypes.h" -#include "mojo/services/surfaces/public/interfaces/surface_id.mojom.h" - -namespace sky { - -class SurfaceAllocator { - public: - SurfaceAllocator(uint32_t id_namespace); - ~SurfaceAllocator(); - - mojo::SurfaceIdPtr CreateSurfaceId(); - - private: - uint32_t id_namespace_; - uint32_t next_id_; - - DISALLOW_COPY_AND_ASSIGN(SurfaceAllocator); -}; - -} // namespace sky - -#endif // SKY_COMPOSITOR_SURFACE_ALLOCATOR_H_ diff --git a/engine/src/flutter/compositor/surface_holder.cc b/engine/src/flutter/compositor/surface_holder.cc deleted file mode 100644 index 3b130cee56..0000000000 --- a/engine/src/flutter/compositor/surface_holder.cc +++ /dev/null @@ -1,79 +0,0 @@ -// 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 "sky/compositor/surface_holder.h" - -#include "base/bind.h" -#include "base/message_loop/message_loop.h" -#include "mojo/converters/geometry/geometry_type_converters.h" -#include "mojo/public/cpp/application/connect.h" -#include "mojo/public/interfaces/application/shell.mojom.h" -#include "sky/compositor/surface_allocator.h" - -namespace sky { - -SurfaceHolder::Client::~Client() { -} - -SurfaceHolder::SurfaceHolder(Client* client, mojo::Shell* shell) - : client_(client), - id_namespace_(0u), - local_id_(0u), - returner_binding_(this), - weak_factory_(this) { - mojo::ServiceProviderPtr service_provider; - shell->ConnectToApplication("mojo:surfaces_service", - mojo::GetProxy(&service_provider), nullptr); - mojo::ConnectToService(service_provider.get(), &surface_); - surface_->GetIdNamespace( - base::Bind(&SurfaceHolder::SetIdNamespace, base::Unretained(this))); - mojo::ResourceReturnerPtr returner_ptr; - returner_binding_.Bind(GetProxy(&returner_ptr)); - surface_->SetResourceReturner(returner_ptr.Pass()); -} - -SurfaceHolder::~SurfaceHolder() { - if (local_id_ != 0u) - surface_->DestroySurface(local_id_); -} - -void SurfaceHolder::SubmitFrame(mojo::FramePtr frame, - const base::Closure& callback) { - surface_->SubmitFrame(local_id_, frame.Pass(), callback); -} - -void SurfaceHolder::SetSize(const gfx::Size& size) { - if (local_id_ != 0u && size_ == size) - return; - - if (local_id_ != 0u) - surface_->DestroySurface(local_id_); - - local_id_++; - surface_->CreateSurface(local_id_); - size_ = size; - - if (id_namespace_ != 0u) - SetQualifiedId(); -} - -void SurfaceHolder::SetQualifiedId() { - auto qualified_id = mojo::SurfaceId::New(); - qualified_id->id_namespace = id_namespace_; - qualified_id->local = local_id_; - client_->OnSurfaceIdAvailable(qualified_id.Pass()); -} - -void SurfaceHolder::SetIdNamespace(uint32_t id_namespace) { - id_namespace_ = id_namespace; - if (local_id_ != 0u) - SetQualifiedId(); -} - -void SurfaceHolder::ReturnResources( - mojo::Array resources) { - client_->ReturnResources(resources.Pass()); -} - -} // namespace sky diff --git a/engine/src/flutter/compositor/surface_holder.h b/engine/src/flutter/compositor/surface_holder.h deleted file mode 100644 index 607d2e4af1..0000000000 --- a/engine/src/flutter/compositor/surface_holder.h +++ /dev/null @@ -1,62 +0,0 @@ -// 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 SKY_COMPOSITOR_SURFACE_HOLDER_H_ -#define SKY_COMPOSITOR_SURFACE_HOLDER_H_ - -#include "base/callback_forward.h" -#include "base/memory/scoped_ptr.h" -#include "base/memory/weak_ptr.h" -#include "mojo/services/surfaces/public/interfaces/surface_id.mojom.h" -#include "mojo/services/surfaces/public/interfaces/surfaces.mojom.h" -#include "ui/gfx/geometry/rect.h" - -namespace mojo { -class Shell; -} - -namespace sky { -class SurfaceAllocator; - -class SurfaceHolder : public mojo::ResourceReturner { - public: - class Client { - public: - virtual void OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) = 0; - virtual void ReturnResources( - mojo::Array resources) = 0; - - protected: - virtual ~Client(); - }; - - explicit SurfaceHolder(Client* client, mojo::Shell* shell); - ~SurfaceHolder() override; - - void SetSize(const gfx::Size& size); - void SubmitFrame(mojo::FramePtr frame, const base::Closure& callback); - - private: - // mojo::ResourceReturner - void ReturnResources( - mojo::Array resources) override; - - void SetIdNamespace(uint32_t id_namespace); - void SetQualifiedId(); - - Client* client_; - gfx::Size size_; - uint32_t id_namespace_; - uint32_t local_id_; - mojo::SurfacePtr surface_; - mojo::Binding returner_binding_; - - base::WeakPtrFactory weak_factory_; - - DISALLOW_COPY_AND_ASSIGN(SurfaceHolder); -}; - -} // namespace sky - -#endif // SKY_COMPOSITOR_SURFACE_HOLDER_H_ diff --git a/engine/src/flutter/compositor/texture_cache.cc b/engine/src/flutter/compositor/texture_cache.cc deleted file mode 100644 index 05fa7d58eb..0000000000 --- a/engine/src/flutter/compositor/texture_cache.cc +++ /dev/null @@ -1,37 +0,0 @@ -// 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/compositor/texture_cache.h" - -#include "mojo/converters/geometry/geometry_type_converters.h" -#include "mojo/gpu/gl_texture.h" - -namespace sky { - -TextureCache::TextureCache() { -} - -TextureCache::~TextureCache() { -} - -scoped_ptr TextureCache::GetTexture(const gfx::Size& size) { - if (size != size_) { - available_textures_.clear(); - size_ = size; - } - if (available_textures_.empty()) - return nullptr; - scoped_ptr texture(available_textures_.back()); - available_textures_.back() = nullptr; - available_textures_.pop_back(); - return texture.Pass(); -} - -void TextureCache::PutTexture(scoped_ptr texture) { - if (texture->size() != size_) - return; - available_textures_.push_back(texture.release()); -} - -} // namespace sky diff --git a/engine/src/flutter/compositor/texture_cache.h b/engine/src/flutter/compositor/texture_cache.h deleted file mode 100644 index 056112e0fa..0000000000 --- a/engine/src/flutter/compositor/texture_cache.h +++ /dev/null @@ -1,35 +0,0 @@ -// 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_COMPOSITOR_TEXTURE_CACHE_H_ -#define SKY_COMPOSITOR_TEXTURE_CACHE_H_ - -#include "base/memory/scoped_ptr.h" -#include "base/memory/scoped_vector.h" -#include "ui/gfx/geometry/size.h" - -namespace mojo { -class GLTexture; -} - -namespace sky { - -class TextureCache { - public: - TextureCache(); - ~TextureCache(); - - scoped_ptr GetTexture(const gfx::Size& size); - void PutTexture(scoped_ptr texture); - - private: - gfx::Size size_; - ScopedVector available_textures_; - - DISALLOW_COPY_AND_ASSIGN(TextureCache); -}; - -} // namespace sky - -#endif // SKY_COMPOSITOR_TEXTURE_CACHE_H_