Landing Recent QUIC changes until 8/19/2015 17:00 UTC.
[chromium-blink-merge.git] / cc / output / delegating_renderer.cc
bloba8fbbb70cde70ca28731103d67d9f6898fbd0252
1 // Copyright 2012 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/output/delegating_renderer.h"
7 #include <set>
8 #include <string>
9 #include <vector>
11 #include "base/trace_event/trace_event.h"
12 #include "cc/output/compositor_frame_ack.h"
13 #include "cc/output/context_provider.h"
14 #include "cc/quads/draw_quad.h"
15 #include "cc/quads/render_pass.h"
16 #include "cc/resources/resource_provider.h"
17 #include "gpu/command_buffer/client/context_support.h"
18 #include "gpu/command_buffer/client/gles2_interface.h"
21 namespace cc {
23 scoped_ptr<DelegatingRenderer> DelegatingRenderer::Create(
24 RendererClient* client,
25 const RendererSettings* settings,
26 OutputSurface* output_surface,
27 ResourceProvider* resource_provider) {
28 return make_scoped_ptr(new DelegatingRenderer(
29 client, settings, output_surface, resource_provider));
32 DelegatingRenderer::DelegatingRenderer(RendererClient* client,
33 const RendererSettings* settings,
34 OutputSurface* output_surface,
35 ResourceProvider* resource_provider)
36 : Renderer(client, settings),
37 output_surface_(output_surface),
38 resource_provider_(resource_provider) {
39 DCHECK(resource_provider_);
41 capabilities_.using_partial_swap = false;
42 capabilities_.max_texture_size = resource_provider_->max_texture_size();
43 capabilities_.best_texture_format = resource_provider_->best_texture_format();
44 capabilities_.allow_partial_texture_updates =
45 output_surface->capabilities().can_force_reclaim_resources;
47 if (!output_surface_->context_provider()) {
48 capabilities_.using_shared_memory_resources = true;
49 } else {
50 const ContextProvider::Capabilities& caps =
51 output_surface_->context_provider()->ContextCapabilities();
53 DCHECK(!caps.gpu.iosurface || caps.gpu.texture_rectangle);
55 capabilities_.using_egl_image = caps.gpu.egl_image_external;
56 capabilities_.using_image = caps.gpu.image;
58 capabilities_.allow_rasterize_on_demand = false;
59 capabilities_.max_msaa_samples = caps.gpu.max_samples;
63 DelegatingRenderer::~DelegatingRenderer() {}
65 const RendererCapabilitiesImpl& DelegatingRenderer::Capabilities() const {
66 return capabilities_;
69 void DelegatingRenderer::DrawFrame(RenderPassList* render_passes_in_draw_order,
70 float device_scale_factor,
71 const gfx::Rect& device_viewport_rect,
72 const gfx::Rect& device_clip_rect,
73 bool disable_picture_quad_image_filtering) {
74 TRACE_EVENT0("cc", "DelegatingRenderer::DrawFrame");
76 DCHECK(!delegated_frame_data_);
78 delegated_frame_data_ = make_scoped_ptr(new DelegatedFrameData);
79 DelegatedFrameData& out_data = *delegated_frame_data_;
80 out_data.device_scale_factor = device_scale_factor;
81 // Move the render passes and resources into the |out_frame|.
82 out_data.render_pass_list.swap(*render_passes_in_draw_order);
84 // Collect all resource ids in the render passes into a ResourceIdArray.
85 ResourceProvider::ResourceIdArray resources;
86 for (const auto& render_pass : out_data.render_pass_list) {
87 for (const auto& quad : render_pass->quad_list) {
88 for (ResourceId resource_id : quad->resources)
89 resources.push_back(resource_id);
92 resource_provider_->PrepareSendToParent(resources, &out_data.resource_list);
95 void DelegatingRenderer::SwapBuffers(const CompositorFrameMetadata& metadata) {
96 TRACE_EVENT0("cc,benchmark", "DelegatingRenderer::SwapBuffers");
97 CompositorFrame compositor_frame;
98 compositor_frame.metadata = metadata;
99 compositor_frame.delegated_frame_data = delegated_frame_data_.Pass();
100 output_surface_->SwapBuffers(&compositor_frame);
103 void DelegatingRenderer::ReceiveSwapBuffersAck(
104 const CompositorFrameAck& ack) {
105 resource_provider_->ReceiveReturnsFromParent(ack.resources);
108 void DelegatingRenderer::DidChangeVisibility() {
109 ContextProvider* context_provider = output_surface_->context_provider();
110 if (!visible()) {
111 TRACE_EVENT0("cc", "DelegatingRenderer::SetVisible dropping resources");
112 if (context_provider) {
113 context_provider->DeleteCachedResources();
114 context_provider->ContextGL()->Flush();
117 // We loop visibility to the GPU process, since that's what manages memory.
118 // That will allow it to feed us with memory allocations that we can act
119 // upon.
120 if (context_provider) {
121 context_provider->ContextSupport()->SetSurfaceVisible(visible());
123 // If we are not visible, we ask the context to aggressively free resources.
124 context_provider->ContextSupport()->SetAggressivelyFreeResources(
125 !visible());
129 } // namespace cc