Remove deprecated extension notification from AppWindow
[chromium-blink-merge.git] / cc / layers / delegated_frame_provider.cc
blobce9ac596d065bb9a558a48091d1bcfd2840e3da9
1 // Copyright 2013 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/layers/delegated_frame_provider.h"
7 #include "cc/layers/delegated_frame_resource_collection.h"
8 #include "cc/layers/delegated_renderer_layer.h"
9 #include "cc/output/delegated_frame_data.h"
10 #include "cc/quads/render_pass_draw_quad.h"
12 namespace cc {
14 DelegatedFrameProvider::DelegatedFrameProvider(
15 const scoped_refptr<DelegatedFrameResourceCollection>& resource_collection,
16 scoped_ptr<DelegatedFrameData> frame)
17 : resource_collection_(resource_collection) {
18 RenderPass* root_pass = frame->render_pass_list.back();
19 frame_size_ = root_pass->output_rect.size();
20 DCHECK(!frame_size_.IsEmpty());
21 SetFrameData(frame.Pass());
24 DelegatedFrameProvider::~DelegatedFrameProvider() {
25 ReturnedResourceArray returned;
26 TransferableResource::ReturnResources(frame_->resource_list, &returned);
27 resource_collection_->UnrefResources(returned);
30 void DelegatedFrameProvider::AddObserver(DelegatedRendererLayer* layer) {
31 #if DCHECK_IS_ON
32 for (size_t i = 0; i < observers_.size(); ++i)
33 DCHECK(observers_[i].layer != layer);
34 #endif
36 observers_.push_back(Observer(layer, gfx::RectF(frame_size_)));
38 DCHECK(frame_) << "Must have a frame when given to a DelegatedRendererLayer.";
41 void DelegatedFrameProvider::RemoveObserver(DelegatedRendererLayer* layer) {
42 bool found_observer = false;
43 for (size_t i = 0; i < observers_.size(); ++i) {
44 if (observers_[i].layer != layer)
45 continue;
46 observers_.erase(observers_.begin() + i);
47 found_observer = true;
48 break;
50 DCHECK(found_observer);
53 void DelegatedFrameProvider::SetFrameData(
54 scoped_ptr<DelegatedFrameData> frame) {
55 DCHECK(frame);
56 DCHECK_NE(0u, frame->render_pass_list.size());
58 if (frame_) {
59 ReturnedResourceArray returned;
60 TransferableResource::ReturnResources(frame_->resource_list, &returned);
61 resource_collection_->UnrefResources(returned);
64 frame_ = frame.Pass();
66 resource_collection_->ReceivedResources(frame_->resource_list);
67 resource_collection_->RefResources(frame_->resource_list);
69 RenderPass* root_pass = frame_->render_pass_list.back();
70 DCHECK_EQ(frame_size_.ToString(), root_pass->output_rect.size().ToString())
71 << "All frames in a single DelegatedFrameProvider must have the same "
72 << "size. Use a new frame provider for frames of a different size.";
74 for (size_t i = 0; i < observers_.size(); ++i) {
75 observers_[i].damage =
76 gfx::UnionRects(observers_[i].damage, root_pass->damage_rect);
77 observers_[i].layer->ProviderHasNewFrame();
81 DelegatedFrameData* DelegatedFrameProvider::GetFrameDataAndRefResources(
82 DelegatedRendererLayer* observer,
83 gfx::RectF* damage) {
85 bool found_observer = false;
86 for (size_t i = 0; i < observers_.size(); ++i) {
87 if (observers_[i].layer != observer)
88 continue;
89 *damage = observers_[i].damage;
90 // The observer is now responsible for the damage.
91 observers_[i].damage = gfx::RectF();
92 found_observer = true;
94 DCHECK(found_observer);
96 resource_collection_->RefResources(frame_->resource_list);
97 return frame_.get();
100 ReturnCallback
101 DelegatedFrameProvider::GetReturnResourcesCallbackForImplThread() {
102 return resource_collection_->GetReturnResourcesCallbackForImplThread();
105 void DelegatedFrameProvider::UnrefResourcesOnMainThread(
106 const ReturnedResourceArray& returned) {
107 resource_collection_->UnrefResources(returned);
110 } // namespace cc