forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request flutter#1031 from abarth/sky_scene_compositor
SceneBuilder should build a tree of layers
- Loading branch information
Showing
9 changed files
with
405 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# 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. | ||
|
||
source_set("compositor") { | ||
sources = [ | ||
"layer.cc", | ||
"layer.h", | ||
] | ||
|
||
deps = [ | ||
"//base", | ||
"//skia", | ||
"//sky/engine/wtf", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// 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/layer.h" | ||
|
||
#include "third_party/skia/include/core/SkColorFilter.h" | ||
|
||
namespace sky { | ||
|
||
Layer::Layer() { | ||
} | ||
|
||
Layer::~Layer() { | ||
} | ||
|
||
PictureLayer::PictureLayer() { | ||
} | ||
|
||
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 sky |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
// 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_H_ | ||
#define SKY_COMPOSITOR_H_ | ||
|
||
#include <memory> | ||
#include <vector> | ||
|
||
#include "base/macros.h" | ||
#include "sky/engine/wtf/PassRefPtr.h" | ||
#include "sky/engine/wtf/RefPtr.h" | ||
#include "third_party/skia/include/core/SkCanvas.h" | ||
#include "third_party/skia/include/core/SkColor.h" | ||
#include "third_party/skia/include/core/SkColorFilter.h" | ||
#include "third_party/skia/include/core/SkMatrix.h" | ||
#include "third_party/skia/include/core/SkPath.h" | ||
#include "third_party/skia/include/core/SkPicture.h" | ||
#include "third_party/skia/include/core/SkRect.h" | ||
#include "third_party/skia/include/core/SkRRect.h" | ||
#include "third_party/skia/include/core/SkXfermode.h" | ||
|
||
namespace sky { | ||
class ContainerLayer; | ||
|
||
class Layer { | ||
public: | ||
Layer(); | ||
virtual ~Layer(); | ||
|
||
virtual void Paint(SkCanvas* canvas) = 0; | ||
|
||
ContainerLayer* parent() const { return parent_; } | ||
void set_parent(ContainerLayer* parent) { parent_ = parent; } | ||
|
||
const SkRect& paint_bounds() const { return paint_bounds_; } | ||
void set_paint_bounds(const SkRect& paint_bounds) { paint_bounds_ = paint_bounds; } | ||
|
||
private: | ||
ContainerLayer* parent_; | ||
SkRect paint_bounds_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(Layer); | ||
}; | ||
|
||
class PictureLayer : public Layer { | ||
public: | ||
PictureLayer(); | ||
~PictureLayer() override; | ||
|
||
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; | ||
|
||
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 | ||
|
||
#endif // SKY_COMPOSITOR_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.