Move //sky/compositor to //sky/viewer/compositor

This library is logically part of //sky/viewer and shouldn't clutter up the
top-level //sky directory.

TBR=eseidel@chromium.org

Review URL: https://codereview.chromium.org/1213683004.
This commit is contained in:
Adam Barth
2015-06-27 00:26:52 -07:00
parent df81cae4c2
commit a74a7c554e
25 changed files with 0 additions and 1115 deletions

View File

@@ -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",
]
}

View File

@@ -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<SkPicture> 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<mojo::GLTexture> Layer::GetTexture() {
return texture_.Pass();
}
} // namespace sky

View File

@@ -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<Layer> {
public:
explicit Layer(LayerClient* client);
void SetSize(const gfx::Size& size);
void Display();
scoped_ptr<mojo::GLTexture> GetTexture();
const gfx::Size& size() const { return size_; }
void set_rasterizer(scoped_ptr<Rasterizer> rasterizer) {
rasterizer_ = rasterizer.Pass();
}
private:
friend class base::RefCounted<Layer>;
~Layer();
skia::RefPtr<SkPicture> RecordPicture();
LayerClient* client_;
gfx::Size size_;
scoped_ptr<mojo::GLTexture> texture_;
scoped_ptr<Rasterizer> rasterizer_;
DISALLOW_COPY_AND_ASSIGN(Layer);
};
} // namespace sky
#endif // SKY_COMPOSITOR_LAYER_H_

View File

@@ -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

View File

@@ -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_

View File

@@ -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> 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<mojo::ReturnedResourcePtr> 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<mojo::Size, gfx::Size>::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

View File

@@ -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<mojo::GLContext>& gl_context() const {
return gl_context_owner_.context();
}
mojo::GaneshContext* ganesh_context() const {
return const_cast<mojo::GaneshContext*>(&ganesh_context_);
}
ResourceManager* resource_manager() const {
return const_cast<ResourceManager*>(&resource_manager_);
}
void SetNeedsAnimate();
void SetRootLayer(scoped_refptr<Layer> layer);
private:
enum State {
kReadyForFrame,
kWaitingForFrameAcknowldgement,
};
// SurfaceHolder::Client
void OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) override;
void ReturnResources(
mojo::Array<mojo::ReturnedResourcePtr> 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<Layer> root_layer_;
base::WeakPtrFactory<LayerHost> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(LayerHost);
};
} // namespace sky
#endif // SKY_COMPOSITOR_LAYER_HOST_H_

View File

@@ -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

View File

@@ -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_

View File

@@ -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<unsigned char> data;
SkBitmap bm;
if (!bm.installPixels(info, const_cast<void*>(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

View File

@@ -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_

View File

@@ -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

View File

@@ -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<mojo::GLTexture> Rasterize(SkPicture* picture) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(Rasterizer);
};
} // namespace sky
#endif // SKY_COMPOSITOR_RASTERIZER_H_

View File

@@ -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<unsigned char>* pixels) {
gfx::PNGCodec::EncodeBGRASkBitmap(bitmap_, true, pixels);
}
scoped_ptr<mojo::GLTexture> 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

View File

@@ -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<mojo::GLTexture> Rasterize(SkPicture* picture) override;
void GetPixelsForTesting(std::vector<unsigned char>* pixels);
private:
LayerHost* host_;
SkBitmap bitmap_;
DISALLOW_COPY_AND_ASSIGN(RasterizerBitmap);
};
} // namespace sky
#endif // SKY_COMPOSITOR_DISPLAY_RASTERIZER_BITMAP_H_

View File

@@ -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<mojo::GLTexture> 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

View File

@@ -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<mojo::GLTexture> Rasterize(SkPicture* picture) override;
private:
LayerHost* host_;
DISALLOW_COPY_AND_ASSIGN(RasterizerGanesh);
};
} // namespace sky
#endif // SKY_COMPOSITOR_DISPLAY_RASTERIZER_GANESH_H_

View File

@@ -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<mojo::GLContext> 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<mojo::GLTexture> ResourceManager::CreateTexture(
const gfx::Size& size) {
scoped_ptr<mojo::GLTexture> texture = texture_cache_.GetTexture(size);
if (texture)
return texture.Pass();
gl_context_->MakeCurrent();
return make_scoped_ptr(new mojo::GLTexture(
gl_context_, mojo::TypeConverter<mojo::Size, gfx::Size>::Convert(size)));
}
mojo::TransferableResourcePtr ResourceManager::CreateTransferableResource(
Layer* layer) {
scoped_ptr<mojo::GLTexture> 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<mojo::ReturnedResourcePtr> 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<mojo::GLTexture> 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

View File

@@ -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<mojo::GLContext> gl_context);
~ResourceManager();
scoped_ptr<mojo::GLTexture> CreateTexture(const gfx::Size& size);
mojo::TransferableResourcePtr CreateTransferableResource(Layer* layer);
void ReturnResources(mojo::Array<mojo::ReturnedResourcePtr> resources);
private:
base::WeakPtr<mojo::GLContext> gl_context_;
uint32_t next_resource_id_;
base::hash_map<uint32_t, mojo::GLTexture*> resource_to_texture_map_;
TextureCache texture_cache_;
DISALLOW_COPY_AND_ASSIGN(ResourceManager);
};
} // namespace sky
#endif // SKY_COMPOSITOR_RESOURCE_MANAGER_H_

View File

@@ -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

View File

@@ -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_

View File

@@ -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<mojo::ReturnedResourcePtr> resources) {
client_->ReturnResources(resources.Pass());
}
} // namespace sky

View File

@@ -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<mojo::ReturnedResourcePtr> 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<mojo::ReturnedResourcePtr> 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<mojo::ResourceReturner> returner_binding_;
base::WeakPtrFactory<SurfaceHolder> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(SurfaceHolder);
};
} // namespace sky
#endif // SKY_COMPOSITOR_SURFACE_HOLDER_H_

View File

@@ -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<mojo::GLTexture> TextureCache::GetTexture(const gfx::Size& size) {
if (size != size_) {
available_textures_.clear();
size_ = size;
}
if (available_textures_.empty())
return nullptr;
scoped_ptr<mojo::GLTexture> texture(available_textures_.back());
available_textures_.back() = nullptr;
available_textures_.pop_back();
return texture.Pass();
}
void TextureCache::PutTexture(scoped_ptr<mojo::GLTexture> texture) {
if (texture->size() != size_)
return;
available_textures_.push_back(texture.release());
}
} // namespace sky

View File

@@ -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<mojo::GLTexture> GetTexture(const gfx::Size& size);
void PutTexture(scoped_ptr<mojo::GLTexture> texture);
private:
gfx::Size size_;
ScopedVector<mojo::GLTexture> available_textures_;
DISALLOW_COPY_AND_ASSIGN(TextureCache);
};
} // namespace sky
#endif // SKY_COMPOSITOR_TEXTURE_CACHE_H_