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"
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"
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;
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;
62 DelegatingRenderer::~DelegatingRenderer() {}
64 const RendererCapabilitiesImpl
& DelegatingRenderer::Capabilities() const {
68 static ResourceProvider::ResourceId
AppendToArray(
69 ResourceProvider::ResourceIdArray
* array
,
70 ResourceProvider::ResourceId id
) {
75 void DelegatingRenderer::DrawFrame(RenderPassList
* render_passes_in_draw_order
,
76 float device_scale_factor
,
77 const gfx::Rect
& device_viewport_rect
,
78 const gfx::Rect
& device_clip_rect
,
79 bool disable_picture_quad_image_filtering
) {
80 TRACE_EVENT0("cc", "DelegatingRenderer::DrawFrame");
82 DCHECK(!delegated_frame_data_
);
84 delegated_frame_data_
= make_scoped_ptr(new DelegatedFrameData
);
85 DelegatedFrameData
& out_data
= *delegated_frame_data_
;
86 out_data
.device_scale_factor
= device_scale_factor
;
87 // Move the render passes and resources into the |out_frame|.
88 out_data
.render_pass_list
.swap(*render_passes_in_draw_order
);
90 // Collect all resource ids in the render passes into a ResourceIdArray.
91 ResourceProvider::ResourceIdArray resources
;
92 DrawQuad::ResourceIteratorCallback append_to_array
=
93 base::Bind(&AppendToArray
, &resources
);
94 for (const auto& render_pass
: out_data
.render_pass_list
) {
95 for (const auto& quad
: render_pass
->quad_list
)
96 quad
->IterateResources(append_to_array
);
98 resource_provider_
->PrepareSendToParent(resources
, &out_data
.resource_list
);
101 void DelegatingRenderer::SwapBuffers(const CompositorFrameMetadata
& metadata
) {
102 TRACE_EVENT0("cc,benchmark", "DelegatingRenderer::SwapBuffers");
103 CompositorFrame compositor_frame
;
104 compositor_frame
.metadata
= metadata
;
105 compositor_frame
.delegated_frame_data
= delegated_frame_data_
.Pass();
106 output_surface_
->SwapBuffers(&compositor_frame
);
109 void DelegatingRenderer::ReceiveSwapBuffersAck(
110 const CompositorFrameAck
& ack
) {
111 resource_provider_
->ReceiveReturnsFromParent(ack
.resources
);
114 void DelegatingRenderer::DidChangeVisibility() {
115 ContextProvider
* context_provider
= output_surface_
->context_provider();
117 TRACE_EVENT0("cc", "DelegatingRenderer::SetVisible dropping resources");
118 resource_provider_
->ReleaseCachedData();
119 if (context_provider
) {
120 context_provider
->DeleteCachedResources();
121 context_provider
->ContextGL()->Flush();
124 // We loop visibility to the GPU process, since that's what manages memory.
125 // That will allow it to feed us with memory allocations that we can act
127 if (context_provider
)
128 context_provider
->ContextSupport()->SetSurfaceVisible(visible());