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.
Add texture support (eg video, camera) (flutter#4159)
- Loading branch information
1 parent
b41511e
commit 9a960f8
Showing
53 changed files
with
967 additions
and
18 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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2017 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 "flutter/flow/layers/texture_layer.h" | ||
|
||
#include "flutter/flow/texture.h" | ||
|
||
namespace flow { | ||
|
||
TextureLayer::TextureLayer() = default; | ||
|
||
TextureLayer::~TextureLayer() = default; | ||
|
||
void TextureLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) { | ||
set_paint_bounds(SkRect::MakeXYWH(offset_.x(), offset_.y(), size_.width(), | ||
size_.height())); | ||
} | ||
|
||
void TextureLayer::Paint(PaintContext& context) const { | ||
std::shared_ptr<Texture> texture = | ||
context.texture_registry.GetTexture(texture_id_); | ||
if (!texture) { | ||
return; | ||
} | ||
texture->Paint(context.canvas, paint_bounds()); | ||
} | ||
|
||
} // namespace flow |
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,39 @@ | ||
// Copyright 2017 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 FLUTTER_FLOW_LAYERS_TEXTURE_LAYER_H_ | ||
#define FLUTTER_FLOW_LAYERS_TEXTURE_LAYER_H_ | ||
|
||
#include "flutter/flow/layers/layer.h" | ||
#include "third_party/skia/include/core/SkSurface.h" | ||
#include "third_party/skia/include/gpu/GrBackendSurface.h" | ||
#include "third_party/skia/include/gpu/GrContext.h" | ||
#include "third_party/skia/include/gpu/GrTexture.h" | ||
#include "third_party/skia/include/gpu/GrTypes.h" | ||
|
||
namespace flow { | ||
|
||
class TextureLayer : public Layer { | ||
public: | ||
TextureLayer(); | ||
~TextureLayer() override; | ||
|
||
void set_offset(const SkPoint& offset) { offset_ = offset; } | ||
void set_size(const SkSize& size) { size_ = size; } | ||
void set_texture_id(int64_t texture_id) { texture_id_ = texture_id; } | ||
|
||
void Preroll(PrerollContext* context, const SkMatrix& matrix) override; | ||
void Paint(PaintContext& context) const override; | ||
|
||
private: | ||
SkPoint offset_; | ||
SkSize size_; | ||
int64_t texture_id_; | ||
|
||
FXL_DISALLOW_COPY_AND_ASSIGN(TextureLayer); | ||
}; | ||
|
||
} // namespace flow | ||
|
||
#endif // FLUTTER_FLOW_LAYERS_TEXTURE_LAYER_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2017 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 "flutter/flow/texture.h" | ||
|
||
namespace flow { | ||
|
||
TextureRegistry::TextureRegistry() = default; | ||
|
||
TextureRegistry::~TextureRegistry() = default; | ||
|
||
void TextureRegistry::RegisterTexture(std::shared_ptr<Texture> texture) { | ||
ASSERT_IS_GPU_THREAD | ||
mapping_[texture->Id()] = texture; | ||
} | ||
|
||
void TextureRegistry::UnregisterTexture(int64_t id) { | ||
ASSERT_IS_GPU_THREAD | ||
mapping_.erase(id); | ||
} | ||
|
||
void TextureRegistry::OnGrContextCreated() { | ||
ASSERT_IS_GPU_THREAD; | ||
for (auto& it : mapping_) { | ||
it.second->OnGrContextCreated(); | ||
} | ||
} | ||
|
||
void TextureRegistry::OnGrContextDestroyed() { | ||
ASSERT_IS_GPU_THREAD; | ||
for (auto& it : mapping_) { | ||
it.second->OnGrContextDestroyed(); | ||
} | ||
} | ||
|
||
std::shared_ptr<Texture> TextureRegistry::GetTexture(int64_t id) { | ||
ASSERT_IS_GPU_THREAD | ||
return mapping_[id]; | ||
} | ||
|
||
Texture::Texture(int64_t id) : id_(id) {} | ||
Texture::~Texture() = default; | ||
|
||
} // namespace flow |
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,68 @@ | ||
// Copyright 2017 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 FLUTTER_FLOW_TEXTURE_H_ | ||
#define FLUTTER_FLOW_TEXTURE_H_ | ||
|
||
#include <map> | ||
#include "flutter/common/threads.h" | ||
#include "lib/fxl/synchronization/waitable_event.h" | ||
#include "third_party/skia/include/core/SkCanvas.h" | ||
|
||
namespace flow { | ||
|
||
class Texture { | ||
protected: | ||
Texture(int64_t id); | ||
|
||
public: | ||
// Called from GPU thread. | ||
virtual ~Texture(); | ||
|
||
// Called from GPU thread. | ||
virtual void Paint(SkCanvas& canvas, const SkRect& bounds) = 0; | ||
|
||
// Called from GPU thread. | ||
virtual void OnGrContextCreated() = 0; | ||
|
||
// Called from GPU thread. | ||
virtual void OnGrContextDestroyed() = 0; | ||
|
||
int64_t Id() { return id_; } | ||
|
||
private: | ||
int64_t id_; | ||
|
||
FXL_DISALLOW_COPY_AND_ASSIGN(Texture); | ||
}; | ||
|
||
class TextureRegistry { | ||
public: | ||
TextureRegistry(); | ||
~TextureRegistry(); | ||
|
||
// Called from GPU thread. | ||
void RegisterTexture(std::shared_ptr<Texture> texture); | ||
|
||
// Called from GPU thread. | ||
void UnregisterTexture(int64_t id); | ||
|
||
// Called from GPU thread. | ||
std::shared_ptr<Texture> GetTexture(int64_t id); | ||
|
||
// Called from GPU thread. | ||
void OnGrContextCreated(); | ||
|
||
// Called from GPU thread. | ||
void OnGrContextDestroyed(); | ||
|
||
private: | ||
std::map<int64_t, std::shared_ptr<Texture>> mapping_; | ||
|
||
FXL_DISALLOW_COPY_AND_ASSIGN(TextureRegistry); | ||
}; | ||
|
||
} // namespace flow | ||
|
||
#endif // FLUTTER_FLOW_TEXTURE_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
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.