Skip to content

Commit

Permalink
ash: Handle exported fast ink textures correctly.
Browse files Browse the repository at this point in the history
Exported textures should be considered lost when frame sink
is destroyed to prevent them from being deleted when still
in use.

This also removes the FastInkLayerTreeFrameSinkHolder class,
which is not needed and just adds an unnecessary layer of
indirect.

[email protected]

(cherry picked from commit 906a31b)

Bug: 764007
Test: manual
Change-Id: Idf2dd68e846cb70d821079b1873a02ec7b2a93e3
Reviewed-on: https://chromium-review.googlesource.com/669779
Commit-Queue: David Reveman <[email protected]>
Reviewed-by: Vladislav Kaznacheev <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#502417}
Reviewed-on: https://chromium-review.googlesource.com/671870
Reviewed-by: David Reveman <[email protected]>
Cr-Commit-Position: refs/branch-heads/3202@{crosswalk-project#310}
Cr-Branched-From: fa6a5d8-refs/heads/master@{#499098}
  • Loading branch information
reveman-chromium committed Sep 18, 2017
1 parent cb1bf5a commit ac0bf9c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 71 deletions.
70 changes: 15 additions & 55 deletions ash/fast_ink/fast_ink_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "cc/base/math_util.h"
#include "cc/output/compositor_frame.h"
#include "cc/output/layer_tree_frame_sink.h"
#include "cc/output/layer_tree_frame_sink_client.h"
#include "cc/quads/texture_draw_quad.h"
#include "components/viz/common/gpu/context_provider.h"
#include "gpu/command_buffer/client/gles2_interface.h"
Expand All @@ -30,58 +29,14 @@

namespace ash {

class FastInkLayerTreeFrameSinkHolder : public cc::LayerTreeFrameSinkClient {
public:
FastInkLayerTreeFrameSinkHolder(
FastInkView* view,
std::unique_ptr<cc::LayerTreeFrameSink> frame_sink)
: view_(view), frame_sink_(std::move(frame_sink)) {
frame_sink_->BindToClient(this);
}
~FastInkLayerTreeFrameSinkHolder() override {
frame_sink_->DetachFromClient();
}

cc::LayerTreeFrameSink* frame_sink() { return frame_sink_.get(); }

// Called before fast ink view is destroyed.
void OnFastInkViewDestroying() { view_ = nullptr; }

// Overridden from cc::LayerTreeFrameSinkClient:
void SetBeginFrameSource(viz::BeginFrameSource* source) override {}
void ReclaimResources(
const std::vector<viz::ReturnedResource>& resources) override {
if (view_)
view_->ReclaimResources(resources);
}
void SetTreeActivationCallback(const base::Closure& callback) override {}
void DidReceiveCompositorFrameAck() override {
if (view_)
view_->DidReceiveCompositorFrameAck();
}
void DidLoseLayerTreeFrameSink() override {}
void OnDraw(const gfx::Transform& transform,
const gfx::Rect& viewport,
bool resourceless_software_draw) override {}
void SetMemoryPolicy(const cc::ManagedMemoryPolicy& policy) override {}
void SetExternalTilePriorityConstraints(
const gfx::Rect& viewport_rect,
const gfx::Transform& transform) override {}

private:
FastInkView* view_;
std::unique_ptr<cc::LayerTreeFrameSink> frame_sink_;

DISALLOW_COPY_AND_ASSIGN(FastInkLayerTreeFrameSinkHolder);
};

// This struct contains the resources associated with a fast ink frame.
struct FastInkResource {
FastInkResource() {}
~FastInkResource() {
if (context_provider) {
gpu::gles2::GLES2Interface* gles2 = context_provider->ContextGL();
if (texture)
// Delete texture if not currently exported.
if (texture && !exported)
gles2->DeleteTextures(1, &texture);
if (image)
gles2->DestroyImageCHROMIUM(image);
Expand All @@ -91,6 +46,7 @@ struct FastInkResource {
uint32_t texture = 0;
uint32_t image = 0;
gpu::Mailbox mailbox;
bool exported = false;
};

// FastInkView
Expand Down Expand Up @@ -122,12 +78,12 @@ FastInkView::FastInkView(aura::Window* root_window) : weak_ptr_factory_(this) {
screen_to_buffer_transform_ =
widget_->GetNativeWindow()->GetHost()->GetRootTransform();

frame_sink_holder_ = base::MakeUnique<FastInkLayerTreeFrameSinkHolder>(
this, widget_->GetNativeView()->CreateLayerTreeFrameSink());
frame_sink_ = widget_->GetNativeView()->CreateLayerTreeFrameSink();
frame_sink_->BindToClient(this);
}

FastInkView::~FastInkView() {
frame_sink_holder_->OnFastInkViewDestroying();
frame_sink_->DetachFromClient();
}

void FastInkView::DidReceiveCompositorFrameAck() {
Expand All @@ -139,10 +95,13 @@ void FastInkView::DidReceiveCompositorFrameAck() {
void FastInkView::ReclaimResources(
const std::vector<viz::ReturnedResource>& resources) {
for (auto& entry : resources) {
auto it = resources_.find(entry.id);
DCHECK(it != resources_.end());
auto it = exported_resources_.find(entry.id);
DCHECK(it != exported_resources_.end());
std::unique_ptr<FastInkResource> resource = std::move(it->second);
resources_.erase(it);
exported_resources_.erase(it);

DCHECK(resource->exported);
resource->exported = false;

gpu::gles2::GLES2Interface* gles2 = resource->context_provider->ContextGL();
if (entry.sync_token.HasData())
Expand Down Expand Up @@ -399,9 +358,10 @@ void FastInkView::UpdateSurface() {
frame.resource_list.push_back(transferable_resource);
frame.render_pass_list.push_back(std::move(render_pass));

frame_sink_holder_->frame_sink()->SubmitCompositorFrame(std::move(frame));
resource->exported = true;
exported_resources_[transferable_resource.id] = std::move(resource);

resources_[transferable_resource.id] = std::move(resource);
frame_sink_->SubmitCompositorFrame(std::move(frame));

DCHECK(!pending_draw_surface_);
pending_draw_surface_ = true;
Expand Down
36 changes: 20 additions & 16 deletions ash/fast_ink/fast_ink_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base/containers/flat_map.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "cc/output/layer_tree_frame_sink_client.h"
#include "components/viz/common/resources/resource_id.h"
#include "ui/views/view.h"

Expand All @@ -26,23 +27,33 @@ namespace views {
class Widget;
}

namespace viz {
struct ReturnedResource;
}

namespace ash {
class FastInkLayerTreeFrameSinkHolder;
struct FastInkResource;

// FastInkView is a view supporting low-latency rendering.
class FastInkView : public views::View {
class FastInkView : public views::View, public cc::LayerTreeFrameSinkClient {
public:
// Creates a FastInkView filling the bounds of |root_window|.
// If |root_window| is resized (e.g. due to a screen size change),
// a new instance of FastInkView should be created.
explicit FastInkView(aura::Window* root_window);
~FastInkView() override;

// Overridden from cc::LayerTreeFrameSinkClient:
void SetBeginFrameSource(viz::BeginFrameSource* source) override {}
void ReclaimResources(
const std::vector<viz::ReturnedResource>& resources) override;
void SetTreeActivationCallback(const base::Closure& callback) override {}
void DidReceiveCompositorFrameAck() override;
void DidLoseLayerTreeFrameSink() override {}
void OnDraw(const gfx::Transform& transform,
const gfx::Rect& viewport,
bool resourceless_software_draw) override {}
void SetMemoryPolicy(const cc::ManagedMemoryPolicy& policy) override {}
void SetExternalTilePriorityConstraints(
const gfx::Rect& viewport_rect,
const gfx::Transform& transform) override {}

protected:
// Unions |rect| with the current damage rect.
void UpdateDamageRect(const gfx::Rect& rect);
Expand All @@ -53,14 +64,6 @@ class FastInkView : public views::View {
virtual void OnRedraw(gfx::Canvas& canvas) = 0;

private:
friend class FastInkLayerTreeFrameSinkHolder;

// Call this to indicate that the previous frame has been processed.
void DidReceiveCompositorFrameAck();

// Call this to return resources so they can be reused or freed.
void ReclaimResources(const std::vector<viz::ReturnedResource>& resources);

void UpdateBuffer();
void UpdateSurface();
void OnDidDrawSurface();
Expand All @@ -73,10 +76,11 @@ class FastInkView : public views::View {
gfx::Rect surface_damage_rect_;
bool needs_update_surface_ = false;
bool pending_draw_surface_ = false;
std::unique_ptr<FastInkLayerTreeFrameSinkHolder> frame_sink_holder_;
int next_resource_id_ = 1;
base::flat_map<viz::ResourceId, std::unique_ptr<FastInkResource>> resources_;
base::flat_map<viz::ResourceId, std::unique_ptr<FastInkResource>>
exported_resources_;
std::vector<std::unique_ptr<FastInkResource>> returned_resources_;
std::unique_ptr<cc::LayerTreeFrameSink> frame_sink_;
base::WeakPtrFactory<FastInkView> weak_ptr_factory_;

DISALLOW_COPY_AND_ASSIGN(FastInkView);
Expand Down

0 comments on commit ac0bf9c

Please sign in to comment.