Close the password bubble when navigating between tabs.
[chromium-blink-merge.git] / cc / surfaces / surface.cc
blob8f08d63d9275e9d77d6c1e0fa912b98524272237
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/surfaces/surface.h"
7 #include "cc/output/compositor_frame.h"
8 #include "cc/output/copy_output_request.h"
9 #include "cc/surfaces/surface_factory.h"
11 namespace cc {
13 // The frame index starts at 2 so that empty frames will be treated as
14 // completely damaged the first time they're drawn from.
15 static const int kFrameIndexStart = 2;
17 Surface::Surface(SurfaceId id, const gfx::Size& size, SurfaceFactory* factory)
18 : surface_id_(id),
19 size_(size),
20 factory_(factory),
21 frame_index_(kFrameIndexStart) {
24 Surface::~Surface() {
25 if (current_frame_) {
26 ReturnedResourceArray current_resources;
27 TransferableResource::ReturnResources(
28 current_frame_->delegated_frame_data->resource_list,
29 &current_resources);
30 factory_->UnrefResources(current_resources);
34 void Surface::QueueFrame(scoped_ptr<CompositorFrame> frame,
35 const base::Closure& callback) {
36 TakeLatencyInfo(&frame->metadata.latency_info);
37 scoped_ptr<CompositorFrame> previous_frame = current_frame_.Pass();
38 current_frame_ = frame.Pass();
39 factory_->ReceiveFromChild(
40 current_frame_->delegated_frame_data->resource_list);
41 ++frame_index_;
43 if (previous_frame) {
44 ReturnedResourceArray previous_resources;
45 TransferableResource::ReturnResources(
46 previous_frame->delegated_frame_data->resource_list,
47 &previous_resources);
48 factory_->UnrefResources(previous_resources);
50 if (!draw_callback_.is_null())
51 draw_callback_.Run();
52 draw_callback_ = callback;
55 void Surface::RequestCopyOfOutput(scoped_ptr<CopyOutputRequest> copy_request) {
56 // TODO(jbauman): Make this work.
57 copy_request->SendEmptyResult();
60 const CompositorFrame* Surface::GetEligibleFrame() {
61 return current_frame_.get();
64 void Surface::TakeLatencyInfo(std::vector<ui::LatencyInfo>* latency_info) {
65 if (!current_frame_)
66 return;
67 if (latency_info->empty()) {
68 current_frame_->metadata.latency_info.swap(*latency_info);
69 return;
71 std::copy(current_frame_->metadata.latency_info.begin(),
72 current_frame_->metadata.latency_info.end(),
73 std::back_inserter(*latency_info));
74 current_frame_->metadata.latency_info.clear();
77 void Surface::RunDrawCallbacks() {
78 if (!draw_callback_.is_null()) {
79 base::Closure callback = draw_callback_;
80 draw_callback_ = base::Closure();
81 callback.Run();
85 } // namespace cc