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/debug/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
= false;
46 if (!output_surface_
->context_provider()) {
47 capabilities_
.using_shared_memory_resources
= true;
49 const ContextProvider::Capabilities
& caps
=
50 output_surface_
->context_provider()->ContextCapabilities();
52 DCHECK(!caps
.gpu
.iosurface
|| caps
.gpu
.texture_rectangle
);
54 capabilities_
.using_egl_image
= caps
.gpu
.egl_image_external
;
55 capabilities_
.using_image
= caps
.gpu
.image
;
57 capabilities_
.allow_rasterize_on_demand
= false;
61 DelegatingRenderer::~DelegatingRenderer() {}
63 const RendererCapabilitiesImpl
& DelegatingRenderer::Capabilities() const {
67 static ResourceProvider::ResourceId
AppendToArray(
68 ResourceProvider::ResourceIdArray
* array
,
69 ResourceProvider::ResourceId id
) {
74 void DelegatingRenderer::DrawFrame(RenderPassList
* render_passes_in_draw_order
,
75 float device_scale_factor
,
76 const gfx::Rect
& device_viewport_rect
,
77 const gfx::Rect
& device_clip_rect
,
78 bool disable_picture_quad_image_filtering
) {
79 TRACE_EVENT0("cc", "DelegatingRenderer::DrawFrame");
81 DCHECK(!delegated_frame_data_
);
83 delegated_frame_data_
= make_scoped_ptr(new DelegatedFrameData
);
84 DelegatedFrameData
& out_data
= *delegated_frame_data_
;
85 out_data
.device_scale_factor
= device_scale_factor
;
86 // Move the render passes and resources into the |out_frame|.
87 out_data
.render_pass_list
.swap(*render_passes_in_draw_order
);
89 // Collect all resource ids in the render passes into a ResourceIdArray.
90 ResourceProvider::ResourceIdArray resources
;
91 DrawQuad::ResourceIteratorCallback append_to_array
=
92 base::Bind(&AppendToArray
, &resources
);
93 for (const auto& render_pass
: out_data
.render_pass_list
) {
94 for (const auto& quad
: render_pass
->quad_list
)
95 quad
->IterateResources(append_to_array
);
97 resource_provider_
->PrepareSendToParent(resources
, &out_data
.resource_list
);
100 void DelegatingRenderer::SwapBuffers(const CompositorFrameMetadata
& metadata
) {
101 TRACE_EVENT0("cc,benchmark", "DelegatingRenderer::SwapBuffers");
102 CompositorFrame compositor_frame
;
103 compositor_frame
.metadata
= metadata
;
104 compositor_frame
.delegated_frame_data
= delegated_frame_data_
.Pass();
105 output_surface_
->SwapBuffers(&compositor_frame
);
108 void DelegatingRenderer::ReceiveSwapBuffersAck(
109 const CompositorFrameAck
& ack
) {
110 resource_provider_
->ReceiveReturnsFromParent(ack
.resources
);
113 void DelegatingRenderer::DidChangeVisibility() {
114 ContextProvider
* context_provider
= output_surface_
->context_provider();
116 TRACE_EVENT0("cc", "DelegatingRenderer::SetVisible dropping resources");
117 resource_provider_
->ReleaseCachedData();
118 if (context_provider
) {
119 context_provider
->DeleteCachedResources();
120 context_provider
->ContextGL()->Flush();
123 // We loop visibility to the GPU process, since that's what manages memory.
124 // That will allow it to feed us with memory allocations that we can act
126 if (context_provider
)
127 context_provider
->ContextSupport()->SetSurfaceVisible(visible());