提交 b44a86c0 编写于 作者: C Chinmay Garde

PictureLayers cache the contents of their pictures if the pictures

dont mutate from frame to frame
上级 1ea0b74b
...@@ -4,10 +4,26 @@ ...@@ -4,10 +4,26 @@
source_set("compositor") { source_set("compositor") {
sources = [ sources = [
"layer_tree.cc", "clip_path_layer.cc",
"layer_tree.h", "clip_path_layer.h",
"clip_rect_layer.cc",
"clip_rect_layer.h",
"clip_rrect_layer.cc",
"clip_rrect_layer.h",
"color_filter_layer.cc",
"color_filter_layer.h",
"container_layer.cc",
"container_layer.h",
"layer.cc", "layer.cc",
"layer.h", "layer.h",
"layer_tree.cc",
"layer_tree.h",
"opacity_layer.cc",
"opacity_layer.h",
"picture_layer.cc",
"picture_layer.h",
"transform_layer.cc",
"transform_layer.h",
] ]
deps = [ deps = [
......
// 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/clip_path_layer.h"
namespace sky {
namespace compositor {
ClipPathLayer::ClipPathLayer() {
}
ClipPathLayer::~ClipPathLayer() {
}
void ClipPathLayer::Paint(GrContext* context, SkCanvas* canvas) {
canvas->saveLayer(&clip_path_.getBounds(), nullptr);
canvas->clipPath(clip_path_);
PaintChildren(context, canvas);
canvas->restore();
}
} // namespace compositor
} // namespace sky
// 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_CLIP_PATH_LAYER_H_
#define SKY_COMPOSITOR_CLIP_PATH_LAYER_H_
#include "sky/compositor/container_layer.h"
namespace sky {
namespace compositor {
class ClipPathLayer : public ContainerLayer {
public:
ClipPathLayer();
~ClipPathLayer() override;
void set_clip_path(const SkPath& clip_path) { clip_path_ = clip_path; }
void Paint(GrContext* context, SkCanvas* canvas) override;
private:
SkPath clip_path_;
DISALLOW_COPY_AND_ASSIGN(ClipPathLayer);
};
} // namespace compositor
} // namespace sky
#endif // SKY_COMPOSITOR_CLIP_PATH_LAYER_H_
// 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/clip_rect_layer.h"
namespace sky {
namespace compositor {
ClipRectLayer::ClipRectLayer() {
}
ClipRectLayer::~ClipRectLayer() {
}
void ClipRectLayer::Paint(GrContext* context, SkCanvas* canvas) {
canvas->save();
canvas->clipRect(clip_rect_);
PaintChildren(context, canvas);
canvas->restore();
}
} // namespace compositor
} // namespace sky
// 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_CLIP_RECT_LAYER_H_
#define SKY_COMPOSITOR_CLIP_RECT_LAYER_H_
#include "sky/compositor/container_layer.h"
namespace sky {
namespace compositor {
class ClipRectLayer : public ContainerLayer {
public:
ClipRectLayer();
~ClipRectLayer() override;
void set_clip_rect(const SkRect& clip_rect) { clip_rect_ = clip_rect; }
void Paint(GrContext* context, SkCanvas* canvas) override;
private:
SkRect clip_rect_;
DISALLOW_COPY_AND_ASSIGN(ClipRectLayer);
};
} // namespace compositor
} // namespace sky
#endif // SKY_COMPOSITOR_CLIP_RECT_LAYER_H_
// 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/clip_rrect_layer.h"
namespace sky {
namespace compositor {
ClipRRectLayer::ClipRRectLayer() {
}
ClipRRectLayer::~ClipRRectLayer() {
}
void ClipRRectLayer::Paint(GrContext* context, SkCanvas* canvas) {
canvas->saveLayer(&clip_rrect_.getBounds(), nullptr);
canvas->clipRRect(clip_rrect_);
PaintChildren(context, canvas);
canvas->restore();
}
} // namespace compositor
} // namespace sky
// 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_CLIP_RRECT_LAYER_H_
#define SKY_COMPOSITOR_CLIP_RRECT_LAYER_H_
#include "sky/compositor/container_layer.h"
namespace sky {
namespace compositor {
class ClipRRectLayer : public ContainerLayer {
public:
ClipRRectLayer();
~ClipRRectLayer() override;
void set_clip_rrect(const SkRRect& clip_rrect) { clip_rrect_ = clip_rrect; }
void Paint(GrContext* context, SkCanvas* canvas) override;
private:
SkRRect clip_rrect_;
DISALLOW_COPY_AND_ASSIGN(ClipRRectLayer);
};
} // namespace compositor
} // namespace sky
#endif // SKY_COMPOSITOR_CLIP_RRECT_LAYER_H_
// 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/color_filter_layer.h"
namespace sky {
namespace compositor {
ColorFilterLayer::ColorFilterLayer() {
}
ColorFilterLayer::~ColorFilterLayer() {
}
void ColorFilterLayer::Paint(GrContext* context, SkCanvas* canvas) {
RefPtr<SkColorFilter> color_filter =
adoptRef(SkColorFilter::CreateModeFilter(color_, transfer_mode_));
SkPaint paint;
paint.setColorFilter(color_filter.get());
canvas->saveLayer(&paint_bounds(), &paint);
PaintChildren(context, canvas);
canvas->restore();
}
} // namespace compositor
} // namespace sky
// 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_COLOR_FILTER_LAYER_H_
#define SKY_COMPOSITOR_COLOR_FILTER_LAYER_H_
#include "sky/compositor/container_layer.h"
namespace sky {
namespace compositor {
class ColorFilterLayer : public ContainerLayer {
public:
ColorFilterLayer();
~ColorFilterLayer() override;
void set_color(SkColor color) { color_ = color; }
void set_transfer_mode(SkXfermode::Mode transfer_mode) {
transfer_mode_ = transfer_mode;
}
void Paint(GrContext* context, SkCanvas* canvas) override;
private:
SkColor color_;
SkXfermode::Mode transfer_mode_;
DISALLOW_COPY_AND_ASSIGN(ColorFilterLayer);
};
} // namespace compositor
} // namespace sky
#endif // SKY_COMPOSITOR_COLOR_FILTER_LAYER_H_
// 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/container_layer.h"
namespace sky {
namespace compositor {
ContainerLayer::ContainerLayer() {
}
ContainerLayer::~ContainerLayer() {
}
void ContainerLayer::Add(std::unique_ptr<Layer> layer) {
layer->set_parent(this);
layers_.push_back(std::move(layer));
}
void ContainerLayer::PaintChildren(GrContext* context, SkCanvas* canvas) const {
for (auto& layer : layers_)
layer->Paint(context, canvas);
}
} // namespace compositor
} // namespace sky
// 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_CONTAINER_LAYER_H_
#define SKY_COMPOSITOR_CONTAINER_LAYER_H_
#include "sky/compositor/layer.h"
namespace sky {
namespace compositor {
class ContainerLayer : public Layer {
public:
ContainerLayer();
~ContainerLayer() override;
void Add(std::unique_ptr<Layer> layer);
void PaintChildren(GrContext* context, SkCanvas* canvas) const;
private:
std::vector<std::unique_ptr<Layer>> layers_;
DISALLOW_COPY_AND_ASSIGN(ContainerLayer);
};
} // namespace compositor
} // namespace sky
#endif // SKY_COMPOSITOR_CONTAINER_LAYER_H_
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "third_party/skia/include/core/SkColorFilter.h" #include "third_party/skia/include/core/SkColorFilter.h"
namespace sky { namespace sky {
namespace compositor {
Layer::Layer() { Layer::Layer() {
} }
...@@ -14,117 +15,9 @@ Layer::Layer() { ...@@ -14,117 +15,9 @@ Layer::Layer() {
Layer::~Layer() { Layer::~Layer() {
} }
PictureLayer::PictureLayer() { SkMatrix Layer::model_view_matrix(const SkMatrix& model_matrix) const {
} return model_matrix;
PictureLayer::~PictureLayer() {
}
void PictureLayer::Paint(SkCanvas* canvas) {
canvas->save();
canvas->translate(offset_.x(), offset_.y());
canvas->drawPicture(picture_.get());
canvas->restore();
}
ContainerLayer::ContainerLayer() {
}
ContainerLayer::~ContainerLayer() {
}
void ContainerLayer::Add(std::unique_ptr<Layer> layer) {
layer->set_parent(this);
layers_.push_back(std::move(layer));
}
void ContainerLayer::PaintChildren(SkCanvas* canvas) {
for (auto& layer : layers_)
layer->Paint(canvas);
}
TransformLayer::TransformLayer() {
}
TransformLayer::~TransformLayer() {
}
void TransformLayer::Paint(SkCanvas* canvas) {
canvas->save();
canvas->concat(transform_);
PaintChildren(canvas);
canvas->restore();
}
ClipRectLayer::ClipRectLayer() {
}
ClipRectLayer::~ClipRectLayer() {
}
void ClipRectLayer::Paint(SkCanvas* canvas) {
canvas->save();
canvas->clipRect(clip_rect_);
PaintChildren(canvas);
canvas->restore();
}
ClipRRectLayer::ClipRRectLayer() {
}
ClipRRectLayer::~ClipRRectLayer() {
}
void ClipRRectLayer::Paint(SkCanvas* canvas) {
canvas->saveLayer(&clip_rrect_.getBounds(), nullptr);
canvas->clipRRect(clip_rrect_);
PaintChildren(canvas);
canvas->restore();
}
ClipPathLayer::ClipPathLayer() {
}
ClipPathLayer::~ClipPathLayer() {
}
void ClipPathLayer::Paint(SkCanvas* canvas) {
canvas->saveLayer(&clip_path_.getBounds(), nullptr);
canvas->clipPath(clip_path_);
PaintChildren(canvas);
canvas->restore();
}
OpacityLayer::OpacityLayer() {
}
OpacityLayer::~OpacityLayer() {
}
void OpacityLayer::Paint(SkCanvas* canvas) {
SkColor color = SkColorSetARGB(alpha_, 0, 0, 0);
RefPtr<SkColorFilter> colorFilter = adoptRef(SkColorFilter::CreateModeFilter(color, SkXfermode::kSrcOver_Mode));
SkPaint paint;
paint.setColorFilter(colorFilter.get());
canvas->saveLayer(&paint_bounds(), &paint);
PaintChildren(canvas);
canvas->restore();
}
ColorFilterLayer::ColorFilterLayer() {
}
ColorFilterLayer::~ColorFilterLayer() {
}
void ColorFilterLayer::Paint(SkCanvas* canvas) {
RefPtr<SkColorFilter> color_filter =
adoptRef(SkColorFilter::CreateModeFilter(color_, transfer_mode_));
SkPaint paint;
paint.setColorFilter(color_filter.get());
canvas->saveLayer(&paint_bounds(), &paint);
PaintChildren(canvas);
canvas->restore();
} }
} // namespace compositor
} // namespace sky } // namespace sky
...@@ -22,20 +22,27 @@ ...@@ -22,20 +22,27 @@
#include "third_party/skia/include/core/SkXfermode.h" #include "third_party/skia/include/core/SkXfermode.h"
namespace sky { namespace sky {
class ContainerLayer; namespace compositor {
class ContainerLayer;
class Layer { class Layer {
public: public:
Layer(); Layer();
virtual ~Layer(); virtual ~Layer();
virtual void Paint(SkCanvas* canvas) = 0; virtual void Paint(GrContext* context, SkCanvas* canvas) = 0;
virtual SkMatrix model_view_matrix(const SkMatrix& model_matrix) const;
ContainerLayer* parent() const { return parent_; } ContainerLayer* parent() const { return parent_; }
void set_parent(ContainerLayer* parent) { parent_ = parent; } void set_parent(ContainerLayer* parent) { parent_ = parent; }
const SkRect& paint_bounds() const { return paint_bounds_; } const SkRect& paint_bounds() const { return paint_bounds_; }
void set_paint_bounds(const SkRect& paint_bounds) { paint_bounds_ = paint_bounds; }
void set_paint_bounds(const SkRect& paint_bounds) {
paint_bounds_ = paint_bounds;
}
private: private:
ContainerLayer* parent_; ContainerLayer* parent_;
...@@ -44,134 +51,7 @@ class Layer { ...@@ -44,134 +51,7 @@ class Layer {
DISALLOW_COPY_AND_ASSIGN(Layer); DISALLOW_COPY_AND_ASSIGN(Layer);
}; };
class PictureLayer : public Layer { } // namespace compositor
public:
PictureLayer();
~PictureLayer() override;
SkPicture* picture() const { return picture_.get(); }
void Paint(SkCanvas* canvas) override;
void set_offset(const SkPoint& offset) { offset_ = offset; }
void set_picture(PassRefPtr<SkPicture> picture) { picture_ = picture; }
private:
SkPoint offset_;
RefPtr<SkPicture> picture_;
DISALLOW_COPY_AND_ASSIGN(PictureLayer);
};
class ContainerLayer : public Layer {
public:
ContainerLayer();
~ContainerLayer() override;
const std::vector<std::unique_ptr<Layer>>& layers() const { return layers_; }
void Add(std::unique_ptr<Layer> layer);
void PaintChildren(SkCanvas* canvas);
private:
std::vector<std::unique_ptr<Layer>> layers_;
DISALLOW_COPY_AND_ASSIGN(ContainerLayer);
};
class TransformLayer : public ContainerLayer {
public:
TransformLayer();
~TransformLayer() override;
void Paint(SkCanvas* canvas) override;
void set_transform(const SkMatrix& transform) { transform_ = transform; }
private:
SkMatrix transform_;
DISALLOW_COPY_AND_ASSIGN(TransformLayer);
};
class ClipRectLayer : public ContainerLayer {
public:
ClipRectLayer();
~ClipRectLayer() override;
void Paint(SkCanvas* canvas) override;
void set_clip_rect(const SkRect& clip_rect) { clip_rect_ = clip_rect; }
private:
SkRect clip_rect_;
DISALLOW_COPY_AND_ASSIGN(ClipRectLayer);
};
class ClipRRectLayer : public ContainerLayer {
public:
ClipRRectLayer();
~ClipRRectLayer() override;
void Paint(SkCanvas* canvas) override;
void set_clip_rrect(const SkRRect& clip_rrect) { clip_rrect_ = clip_rrect; }
private:
SkRRect clip_rrect_;
DISALLOW_COPY_AND_ASSIGN(ClipRRectLayer);
};
class ClipPathLayer : public ContainerLayer {
public:
ClipPathLayer();
~ClipPathLayer() override;
void Paint(SkCanvas* canvas) override;
void set_clip_path(const SkPath& clip_path) { clip_path_ = clip_path; }
private:
SkPath clip_path_;
DISALLOW_COPY_AND_ASSIGN(ClipPathLayer);
};
class OpacityLayer : public ContainerLayer {
public:
OpacityLayer();
~OpacityLayer() override;
void Paint(SkCanvas* canvas) override;
void set_alpha(int alpha) { alpha_ = alpha; }
private:
int alpha_;
DISALLOW_COPY_AND_ASSIGN(OpacityLayer);
};
class ColorFilterLayer : public ContainerLayer {
public:
ColorFilterLayer();
~ColorFilterLayer() override;
void Paint(SkCanvas* canvas) override;
void set_color(SkColor color) { color_ = color; }
void set_transfer_mode(SkXfermode::Mode transfer_mode) { transfer_mode_ = transfer_mode; }
private:
SkColor color_;
SkXfermode::Mode transfer_mode_;
DISALLOW_COPY_AND_ASSIGN(ColorFilterLayer);
};
} // namespace sky } // namespace sky
#endif // SKY_COMPOSITOR_LAYER_H_ #endif // SKY_COMPOSITOR_LAYER_H_
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "sky/compositor/layer.h" #include "sky/compositor/layer.h"
namespace sky { namespace sky {
namespace compositor {
LayerTree::LayerTree() { LayerTree::LayerTree() {
} }
...@@ -14,4 +15,5 @@ LayerTree::LayerTree() { ...@@ -14,4 +15,5 @@ LayerTree::LayerTree() {
LayerTree::~LayerTree() { LayerTree::~LayerTree() {
} }
} // namespace compositor
} // namespace sky } // namespace sky
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "third_party/skia/include/core/SkSize.h" #include "third_party/skia/include/core/SkSize.h"
namespace sky { namespace sky {
namespace compositor {
class LayerTree { class LayerTree {
public: public:
...@@ -19,20 +20,23 @@ class LayerTree { ...@@ -19,20 +20,23 @@ class LayerTree {
~LayerTree(); ~LayerTree();
Layer* root_layer() const { return root_layer_.get(); } Layer* root_layer() const { return root_layer_.get(); }
void set_root_layer(std::unique_ptr<Layer> root_layer) { void set_root_layer(std::unique_ptr<Layer> root_layer) {
root_layer_ = std::move(root_layer); root_layer_ = std::move(root_layer);
} }
const SkISize& frame_size() const { return frame_size_; } const SkISize& frame_size() const { return frame_size_; }
void set_frame_size(const SkISize& frame_size) { frame_size_ = frame_size; } void set_frame_size(const SkISize& frame_size) { frame_size_ = frame_size; }
private: private:
SkISize frame_size_; // Physical pixels. SkISize frame_size_; // Physical pixels.
std::unique_ptr<Layer> root_layer_; std::unique_ptr<Layer> root_layer_;
DISALLOW_COPY_AND_ASSIGN(LayerTree); DISALLOW_COPY_AND_ASSIGN(LayerTree);
}; };
} // namespace compositor
} // namespace sky } // namespace sky
#endif // SKY_COMPOSITOR_LAYER_TREE_H_ #endif // SKY_COMPOSITOR_LAYER_TREE_H_
// 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/opacity_layer.h"
namespace sky {
namespace compositor {
OpacityLayer::OpacityLayer() {
}
OpacityLayer::~OpacityLayer() {
}
void OpacityLayer::Paint(GrContext* context, SkCanvas* canvas) {
SkColor color = SkColorSetARGB(alpha_, 0, 0, 0);
RefPtr<SkColorFilter> colorFilter = adoptRef(
SkColorFilter::CreateModeFilter(color, SkXfermode::kSrcOver_Mode));
SkPaint paint;
paint.setColorFilter(colorFilter.get());
canvas->saveLayer(&paint_bounds(), &paint);
PaintChildren(context, canvas);
canvas->restore();
}
} // namespace compositor
} // namespace sky
// 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_OPACITY_LAYER_H_
#define SKY_COMPOSITOR_OPACITY_LAYER_H_
#include "sky/compositor/container_layer.h"
namespace sky {
namespace compositor {
class OpacityLayer : public ContainerLayer {
public:
OpacityLayer();
~OpacityLayer() override;
void set_alpha(int alpha) { alpha_ = alpha; }
void Paint(GrContext* context, SkCanvas* canvas) override;
private:
int alpha_;
DISALLOW_COPY_AND_ASSIGN(OpacityLayer);
};
} // namespace compositor
} // namespace sky
#endif // SKY_COMPOSITOR_OPACITY_LAYER_H_
// 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_layer.h"
#include "base/logging.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/include/core/SkSurface.h"
namespace sky {
namespace compositor {
PictureLayer::PictureLayer() : last_picture_id_(UINT32_MAX) {
}
PictureLayer::~PictureLayer() {
}
SkMatrix PictureLayer::model_view_matrix(const SkMatrix& model_matrix) const {
SkMatrix modelView = model_matrix;
modelView.postTranslate(offset_.x(), offset_.y());
return modelView;
}
static void ImageReleaseProc(SkImage::ReleaseContext texture) {
DCHECK(texture);
reinterpret_cast<GrTexture*>(texture)->unref();
}
static RefPtr<SkImage> ImageFromPicture(GrContext* context,
SkPicture* picture,
const SkRect& paintBounds) {
// Step 1: Create a texture from the context's texture provider
GrSurfaceDesc desc;
desc.fWidth = paintBounds.width();
desc.fHeight = paintBounds.height();
desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fConfig = kRGBA_8888_GrPixelConfig;
GrTexture* texture = context->textureProvider()->createTexture(desc, true);
if (!texture) {
// The texture provider could not allocate a texture backing. Render
// directly to the surface from the picture till the memory pressure
// subsides
return nullptr;
}
// Step 2: Create a backend render target description for the created texture
GrBackendTextureDesc backendDesc;
backendDesc.fConfig = desc.fConfig;
backendDesc.fWidth = desc.fWidth;
backendDesc.fHeight = desc.fHeight;
backendDesc.fSampleCnt = desc.fSampleCnt;
backendDesc.fFlags = kRenderTarget_GrBackendTextureFlag;
backendDesc.fConfig = desc.fConfig;
backendDesc.fTextureHandle = texture->getTextureHandle();
// Step 3: Render the picture into the offscreen texture
GrRenderTarget* renderTarget = texture->asRenderTarget();
DCHECK(renderTarget);
PassRefPtr<SkSurface> surface =
adoptRef(SkSurface::NewRenderTargetDirect(renderTarget));
DCHECK(surface);
SkCanvas* canvas = surface->getCanvas();
DCHECK(canvas);
canvas->drawPicture(picture);
// Step 4: Create an image representation from the texture
RefPtr<SkImage> image = adoptRef(SkImage::NewFromTexture(
context, backendDesc, kPremul_SkAlphaType, &ImageReleaseProc, texture));
return image;
}
void PictureLayer::Paint(GrContext* context, SkCanvas* canvas) {
DCHECK(picture_);
if (last_picture_id_ == picture_->uniqueID()) {
// The last picture painted was the same as this one. Cache this into an
// offscreen surface and render that instead
if (!cached_image_) {
// Generate the cached image
cached_image_ = ImageFromPicture(context, picture_.get(), paint_bounds());
}
} else {
// Release the cached image if one is present
cached_image_.release();
}
last_picture_id_ = picture_->uniqueID();
if (cached_image_) {
canvas->drawImage(cached_image_.get(), offset_.x(), offset_.y());
} else {
canvas->save();
canvas->translate(offset_.x(), offset_.y());
canvas->drawPicture(picture_.get());
canvas->restore();
}
}
} // namespace compositor
} // namespace sky
// 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_LAYER_H_
#define SKY_COMPOSITOR_PICTURE_LAYER_H_
#include "sky/compositor/layer.h"
namespace sky {
namespace compositor {
class PictureLayer : public Layer {
public:
PictureLayer();
~PictureLayer() override;
void set_offset(const SkPoint& offset) { offset_ = offset; }
void set_picture(PassRefPtr<SkPicture> picture) { picture_ = picture; }
SkMatrix model_view_matrix(const SkMatrix& model_matrix) const override;
void Paint(GrContext* context, SkCanvas* canvas) override;
private:
SkPoint offset_;
RefPtr<SkPicture> picture_;
RefPtr<SkImage> cached_image_;
uint32_t last_picture_id_;
DISALLOW_COPY_AND_ASSIGN(PictureLayer);
};
} // namespace compositor
} // namespace sky
#endif // SKY_COMPOSITOR_PICTURE_LAYER_H_
// 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/transform_layer.h"
namespace sky {
namespace compositor {
TransformLayer::TransformLayer() {
}
TransformLayer::~TransformLayer() {
}
SkMatrix TransformLayer::model_view_matrix(const SkMatrix& model_matrix) const {
SkMatrix modelView = model_matrix;
modelView.postConcat(transform_);
return modelView;
}
void TransformLayer::Paint(GrContext* context, SkCanvas* canvas) {
canvas->save();
canvas->concat(transform_);
PaintChildren(context, canvas);
canvas->restore();
}
} // namespace compositor
} // namespace sky
// 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_TRANSFORM_LAYER_H_
#define SKY_COMPOSITOR_TRANSFORM_LAYER_H_
#include "sky/compositor/container_layer.h"
namespace sky {
namespace compositor {
class TransformLayer : public ContainerLayer {
public:
TransformLayer();
~TransformLayer() override;
void set_transform(const SkMatrix& transform) { transform_ = transform; }
SkMatrix model_view_matrix(const SkMatrix& model_matrix) const override;
void Paint(GrContext* context, SkCanvas* canvas) override;
private:
SkMatrix transform_;
DISALLOW_COPY_AND_ASSIGN(TransformLayer);
};
} // namespace compositor
} // namespace sky
#endif // SKY_COMPOSITOR_TRANSFORM_LAYER_H_
...@@ -9,23 +9,20 @@ ...@@ -9,23 +9,20 @@
namespace blink { namespace blink {
PassRefPtr<Scene> Scene::create(std::unique_ptr<sky::Layer> rootLayer) PassRefPtr<Scene> Scene::create(
{ std::unique_ptr<sky::compositor::Layer> rootLayer) {
ASSERT(rootLayer); ASSERT(rootLayer);
return adoptRef(new Scene(std::move(rootLayer))); return adoptRef(new Scene(std::move(rootLayer)));
} }
Scene::Scene(std::unique_ptr<sky::Layer> rootLayer) Scene::Scene(std::unique_ptr<sky::compositor::Layer> rootLayer)
: m_layerTree(new sky::LayerTree()) : m_layerTree(new sky::compositor::LayerTree()) {
{ m_layerTree->set_root_layer(std::move(rootLayer));
m_layerTree->set_root_layer(std::move(rootLayer));
} }
Scene::~Scene() Scene::~Scene() {}
{
}
std::unique_ptr<sky::LayerTree> Scene::takeLayerTree() { std::unique_ptr<sky::compositor::LayerTree> Scene::takeLayerTree() {
return std::move(m_layerTree); return std::move(m_layerTree);
} }
......
...@@ -17,17 +17,19 @@ ...@@ -17,17 +17,19 @@
namespace blink { namespace blink {
class Scene : public RefCounted<Scene>, public DartWrappable { class Scene : public RefCounted<Scene>, public DartWrappable {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public:
~Scene() override;
static PassRefPtr<Scene> create(std::unique_ptr<sky::Layer> rootLayer);
std::unique_ptr<sky::LayerTree> takeLayerTree(); public:
~Scene() override;
static PassRefPtr<Scene> create(
std::unique_ptr<sky::compositor::Layer> rootLayer);
private: std::unique_ptr<sky::compositor::LayerTree> takeLayerTree();
explicit Scene(std::unique_ptr<sky::Layer> rootLayer);
std::unique_ptr<sky::LayerTree> m_layerTree; private:
explicit Scene(std::unique_ptr<sky::compositor::Layer> rootLayer);
std::unique_ptr<sky::compositor::LayerTree> m_layerTree;
}; };
} // namespace blink } // namespace blink
......
...@@ -6,6 +6,14 @@ ...@@ -6,6 +6,14 @@
#include "sky/engine/core/painting/Matrix.h" #include "sky/engine/core/painting/Matrix.h"
#include "third_party/skia/include/core/SkColorFilter.h" #include "third_party/skia/include/core/SkColorFilter.h"
#include "sky/compositor/transform_layer.h"
#include "sky/compositor/clip_path_layer.h"
#include "sky/compositor/clip_rect_layer.h"
#include "sky/compositor/clip_rrect_layer.h"
#include "sky/compositor/color_filter_layer.h"
#include "sky/compositor/container_layer.h"
#include "sky/compositor/opacity_layer.h"
#include "sky/compositor/picture_layer.h"
namespace blink { namespace blink {
...@@ -24,35 +32,35 @@ void SceneBuilder::pushTransform(const Float32List& matrix4, ExceptionState& es) ...@@ -24,35 +32,35 @@ void SceneBuilder::pushTransform(const Float32List& matrix4, ExceptionState& es)
SkMatrix sk_matrix = toSkMatrix(matrix4, es); SkMatrix sk_matrix = toSkMatrix(matrix4, es);
if (es.had_exception()) if (es.had_exception())
return; return;
std::unique_ptr<sky::TransformLayer> layer(new sky::TransformLayer()); std::unique_ptr<sky::compositor::TransformLayer> layer(new sky::compositor::TransformLayer());
layer->set_transform(sk_matrix); layer->set_transform(sk_matrix);
addLayer(std::move(layer)); addLayer(std::move(layer));
} }
void SceneBuilder::pushClipRect(const Rect& rect) void SceneBuilder::pushClipRect(const Rect& rect)
{ {
std::unique_ptr<sky::ClipRectLayer> layer(new sky::ClipRectLayer()); std::unique_ptr<sky::compositor::ClipRectLayer> layer(new sky::compositor::ClipRectLayer());
layer->set_clip_rect(rect.sk_rect); layer->set_clip_rect(rect.sk_rect);
addLayer(std::move(layer)); addLayer(std::move(layer));
} }
void SceneBuilder::pushClipRRect(const RRect* rrect, const Rect& bounds) void SceneBuilder::pushClipRRect(const RRect* rrect, const Rect& bounds)
{ {
std::unique_ptr<sky::ClipRRectLayer> layer(new sky::ClipRRectLayer()); std::unique_ptr<sky::compositor::ClipRRectLayer> layer(new sky::compositor::ClipRRectLayer());
layer->set_clip_rrect(rrect->rrect()); layer->set_clip_rrect(rrect->rrect());
addLayer(std::move(layer)); addLayer(std::move(layer));
} }
void SceneBuilder::pushClipPath(const CanvasPath* path, const Rect& bounds) void SceneBuilder::pushClipPath(const CanvasPath* path, const Rect& bounds)
{ {
std::unique_ptr<sky::ClipPathLayer> layer(new sky::ClipPathLayer()); std::unique_ptr<sky::compositor::ClipPathLayer> layer(new sky::compositor::ClipPathLayer());
layer->set_clip_path(path->path()); layer->set_clip_path(path->path());
addLayer(std::move(layer)); addLayer(std::move(layer));
} }
void SceneBuilder::pushOpacity(int alpha, const Rect& bounds) void SceneBuilder::pushOpacity(int alpha, const Rect& bounds)
{ {
std::unique_ptr<sky::OpacityLayer> layer(new sky::OpacityLayer()); std::unique_ptr<sky::compositor::OpacityLayer> layer(new sky::compositor::OpacityLayer());
layer->set_paint_bounds(bounds.sk_rect); layer->set_paint_bounds(bounds.sk_rect);
layer->set_alpha(alpha); layer->set_alpha(alpha);
addLayer(std::move(layer)); addLayer(std::move(layer));
...@@ -60,14 +68,14 @@ void SceneBuilder::pushOpacity(int alpha, const Rect& bounds) ...@@ -60,14 +68,14 @@ void SceneBuilder::pushOpacity(int alpha, const Rect& bounds)
void SceneBuilder::pushColorFilter(SkColor color, SkXfermode::Mode transferMode, const Rect& bounds) void SceneBuilder::pushColorFilter(SkColor color, SkXfermode::Mode transferMode, const Rect& bounds)
{ {
std::unique_ptr<sky::ColorFilterLayer> layer(new sky::ColorFilterLayer()); std::unique_ptr<sky::compositor::ColorFilterLayer> layer(new sky::compositor::ColorFilterLayer());
layer->set_paint_bounds(bounds.sk_rect); layer->set_paint_bounds(bounds.sk_rect);
layer->set_color(color); layer->set_color(color);
layer->set_transfer_mode(transferMode); layer->set_transfer_mode(transferMode);
addLayer(std::move(layer)); addLayer(std::move(layer));
} }
void SceneBuilder::addLayer(std::unique_ptr<sky::ContainerLayer> layer) void SceneBuilder::addLayer(std::unique_ptr<sky::compositor::ContainerLayer> layer)
{ {
DCHECK(layer); DCHECK(layer);
if (!m_rootLayer) { if (!m_rootLayer) {
...@@ -79,7 +87,7 @@ void SceneBuilder::addLayer(std::unique_ptr<sky::ContainerLayer> layer) ...@@ -79,7 +87,7 @@ void SceneBuilder::addLayer(std::unique_ptr<sky::ContainerLayer> layer)
} }
if (!m_currentLayer) if (!m_currentLayer)
return; return;
sky::ContainerLayer* newLayer = layer.get(); sky::compositor::ContainerLayer* newLayer = layer.get();
m_currentLayer->Add(std::move(layer)); m_currentLayer->Add(std::move(layer));
m_currentLayer = newLayer; m_currentLayer = newLayer;
} }
...@@ -95,7 +103,7 @@ void SceneBuilder::addPicture(const Offset& offset, Picture* picture, const Rect ...@@ -95,7 +103,7 @@ void SceneBuilder::addPicture(const Offset& offset, Picture* picture, const Rect
{ {
if (!m_currentLayer) if (!m_currentLayer)
return; return;
std::unique_ptr<sky::PictureLayer> layer(new sky::PictureLayer()); std::unique_ptr<sky::compositor::PictureLayer> layer(new sky::compositor::PictureLayer());
layer->set_offset(SkPoint::Make(offset.sk_size.width(), offset.sk_size.height())); layer->set_offset(SkPoint::Make(offset.sk_size.width(), offset.sk_size.height()));
layer->set_picture(picture->toSkia()); layer->set_picture(picture->toSkia());
layer->set_paint_bounds(paintBounds.sk_rect); layer->set_paint_bounds(paintBounds.sk_rect);
......
...@@ -48,11 +48,11 @@ public: ...@@ -48,11 +48,11 @@ public:
private: private:
explicit SceneBuilder(const Rect& bounds); explicit SceneBuilder(const Rect& bounds);
void addLayer(std::unique_ptr<sky::ContainerLayer> layer); void addLayer(std::unique_ptr<sky::compositor::ContainerLayer> layer);
SkRect m_rootPaintBounds; SkRect m_rootPaintBounds;
std::unique_ptr<sky::ContainerLayer> m_rootLayer; std::unique_ptr<sky::compositor::ContainerLayer> m_rootLayer;
sky::ContainerLayer* m_currentLayer; sky::compositor::ContainerLayer* m_currentLayer;
}; };
} // namespace blink } // namespace blink
......
...@@ -65,8 +65,8 @@ void View::handleInputEvent(PassRefPtr<Event> event) ...@@ -65,8 +65,8 @@ void View::handleInputEvent(PassRefPtr<Event> event)
m_eventCallback->handleEvent(event.get()); m_eventCallback->handleEvent(event.get());
} }
std::unique_ptr<sky::LayerTree> View::beginFrame(base::TimeTicks frameTime) std::unique_ptr<sky::compositor::LayerTree> View::beginFrame(
{ base::TimeTicks frameTime) {
if (!m_frameCallback) if (!m_frameCallback)
return nullptr; return nullptr;
double frameTimeMS = (frameTime - base::TimeTicks()).InMillisecondsF(); double frameTimeMS = (frameTime - base::TimeTicks()).InMillisecondsF();
......
...@@ -47,7 +47,8 @@ public: ...@@ -47,7 +47,8 @@ public:
void setDisplayMetrics(const SkyDisplayMetrics& metrics); void setDisplayMetrics(const SkyDisplayMetrics& metrics);
void handleInputEvent(PassRefPtr<Event> event); void handleInputEvent(PassRefPtr<Event> event);
std::unique_ptr<sky::LayerTree> beginFrame(base::TimeTicks frameTime); std::unique_ptr<sky::compositor::LayerTree> beginFrame(
base::TimeTicks frameTime);
private: private:
explicit View(const base::Closure& scheduleFrameCallback); explicit View(const base::Closure& scheduleFrameCallback);
......
...@@ -66,7 +66,8 @@ void SkyView::RunFromSnapshot(const WebString& name, ...@@ -66,7 +66,8 @@ void SkyView::RunFromSnapshot(const WebString& name,
dart_controller_->RunFromSnapshot(snapshot.Pass()); dart_controller_->RunFromSnapshot(snapshot.Pass());
} }
std::unique_ptr<sky::LayerTree> SkyView::BeginFrame(base::TimeTicks frame_time) { std::unique_ptr<sky::compositor::LayerTree> SkyView::BeginFrame(
base::TimeTicks frame_time) {
return view_->beginFrame(frame_time); return view_->beginFrame(frame_time);
} }
......
...@@ -35,7 +35,8 @@ class SkyView { ...@@ -35,7 +35,8 @@ class SkyView {
const SkyDisplayMetrics& display_metrics() const { return display_metrics_; } const SkyDisplayMetrics& display_metrics() const { return display_metrics_; }
void SetDisplayMetrics(const SkyDisplayMetrics& metrics); void SetDisplayMetrics(const SkyDisplayMetrics& metrics);
std::unique_ptr<sky::LayerTree> BeginFrame(base::TimeTicks frame_time); std::unique_ptr<sky::compositor::LayerTree> BeginFrame(
base::TimeTicks frame_time);
void CreateView(const String& name); void CreateView(const String& name);
......
...@@ -53,7 +53,7 @@ void Rasterizer::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) { ...@@ -53,7 +53,7 @@ void Rasterizer::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) {
CHECK(surface_) << "GLSurface required."; CHECK(surface_) << "GLSurface required.";
} }
void Rasterizer::Draw(scoped_ptr<LayerTree> layer_tree) { void Rasterizer::Draw(scoped_ptr<compositor::LayerTree> layer_tree) {
TRACE_EVENT0("sky", "Rasterizer::Draw"); TRACE_EVENT0("sky", "Rasterizer::Draw");
if (!surface_) if (!surface_)
...@@ -71,7 +71,7 @@ void Rasterizer::Draw(scoped_ptr<LayerTree> layer_tree) { ...@@ -71,7 +71,7 @@ void Rasterizer::Draw(scoped_ptr<LayerTree> layer_tree) {
SkCanvas* canvas = ganesh_surface_->canvas(); SkCanvas* canvas = ganesh_surface_->canvas();
canvas->clear(SK_ColorBLACK); canvas->clear(SK_ColorBLACK);
layer_tree->root_layer()->Paint(canvas); layer_tree->root_layer()->Paint(ganesh_context_->gr(), canvas);
canvas->flush(); canvas->flush();
surface_->SwapBuffers(); surface_->SwapBuffers();
......
...@@ -34,7 +34,7 @@ class Rasterizer : public GPUDelegate { ...@@ -34,7 +34,7 @@ class Rasterizer : public GPUDelegate {
void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) override; void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) override;
void OnOutputSurfaceDestroyed() override; void OnOutputSurfaceDestroyed() override;
void Draw(scoped_ptr<LayerTree> layer_tree) override; void Draw(scoped_ptr<compositor::LayerTree> layer_tree) override;
private: private:
void EnsureGLContext(); void EnsureGLContext();
......
...@@ -21,7 +21,7 @@ class GPUDelegate { ...@@ -21,7 +21,7 @@ class GPUDelegate {
public: public:
virtual void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) = 0; virtual void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) = 0;
virtual void OnOutputSurfaceDestroyed() = 0; virtual void OnOutputSurfaceDestroyed() = 0;
virtual void Draw(scoped_ptr<LayerTree> layer_tree) = 0; virtual void Draw(scoped_ptr<compositor::LayerTree> layer_tree) = 0;
protected: protected:
virtual ~GPUDelegate(); virtual ~GPUDelegate();
......
...@@ -71,7 +71,7 @@ void Animator::BeginFrame(int64_t time_stamp) { ...@@ -71,7 +71,7 @@ void Animator::BeginFrame(int64_t time_stamp) {
base::TimeTicks frame_time = time_stamp ? base::TimeTicks frame_time = time_stamp ?
base::TimeTicks::FromInternalValue(time_stamp) : base::TimeTicks::Now(); base::TimeTicks::FromInternalValue(time_stamp) : base::TimeTicks::Now();
scoped_ptr<LayerTree> layer_tree = scoped_ptr<compositor::LayerTree> layer_tree =
make_scoped_ptr(engine_->BeginFrame(frame_time).release()); make_scoped_ptr(engine_->BeginFrame(frame_time).release());
if (!layer_tree) { if (!layer_tree) {
......
...@@ -96,13 +96,15 @@ void Engine::Init() { ...@@ -96,13 +96,15 @@ void Engine::Init() {
blink::initialize(g_platform_impl); blink::initialize(g_platform_impl);
} }
std::unique_ptr<LayerTree> Engine::BeginFrame(base::TimeTicks frame_time) { std::unique_ptr<compositor::LayerTree> Engine::BeginFrame(
base::TimeTicks frame_time) {
TRACE_EVENT0("sky", "Engine::BeginFrame"); TRACE_EVENT0("sky", "Engine::BeginFrame");
if (!sky_view_) if (!sky_view_)
return nullptr; return nullptr;
std::unique_ptr<LayerTree> layer_tree = sky_view_->BeginFrame(frame_time); std::unique_ptr<compositor::LayerTree> layer_tree =
sky_view_->BeginFrame(frame_time);
if (layer_tree) { if (layer_tree) {
layer_tree->set_frame_size(SkISize::Make(physical_size_.width(), layer_tree->set_frame_size(SkISize::Make(physical_size_.width(),
physical_size_.height())); physical_size_.height()));
......
...@@ -55,7 +55,7 @@ class Engine : public UIDelegate, ...@@ -55,7 +55,7 @@ class Engine : public UIDelegate,
static void Init(); static void Init();
std::unique_ptr<LayerTree> BeginFrame(base::TimeTicks frame_time); std::unique_ptr<compositor::LayerTree> BeginFrame(base::TimeTicks frame_time);
void StartDartTracing(); void StartDartTracing();
void StopDartTracing(mojo::ScopedDataPipeProducerHandle producer); void StopDartTracing(mojo::ScopedDataPipeProducerHandle producer);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册