OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | |
boliu
2012/12/08 19:47:16
This file and its header file have the Google lice
danakj
2012/12/08 19:50:03
Oh, no it was not, I copy/pasted that in, and didn
| |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions | |
6 * are met: | |
7 * | |
8 * 1. Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * 2. Redistributions in binary form must reproduce the above copyright | |
11 * notice, this list of conditions and the following disclaimer in the | |
12 * documentation and/or other materials provided with the distribution. | |
13 * | |
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | |
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | |
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 */ | |
25 | |
26 #include "cc/delegating_renderer.h" | |
27 | |
28 #include <set> | |
29 #include <string> | |
30 #include <vector> | |
31 | |
32 #include "base/debug/trace_event.h" | |
33 #include "base/string_split.h" | |
34 #include "base/string_util.h" | |
35 #include "cc/checkerboard_draw_quad.h" | |
36 #include "cc/compositor_frame_ack.h" | |
37 #include "cc/debug_border_draw_quad.h" | |
38 #include "cc/render_pass.h" | |
39 #include "cc/render_pass_draw_quad.h" | |
40 #include "cc/resource_provider.h" | |
41 #include "cc/solid_color_draw_quad.h" | |
42 #include "cc/texture_draw_quad.h" | |
43 #include "cc/tile_draw_quad.h" | |
44 #include "cc/yuv_video_draw_quad.h" | |
45 #include "third_party/khronos/GLES2/gl2ext.h" | |
46 | |
47 using WebKit::WebGraphicsContext3D; | |
48 | |
49 namespace cc { | |
50 | |
51 scoped_ptr<DelegatingRenderer> DelegatingRenderer::Create( | |
52 RendererClient* client, ResourceProvider* resource_provider) { | |
53 scoped_ptr<DelegatingRenderer> renderer( | |
54 new DelegatingRenderer(client, resource_provider)); | |
55 if (!renderer->Initialize()) | |
56 return scoped_ptr<DelegatingRenderer>(); | |
57 return renderer.Pass(); | |
58 } | |
59 | |
60 DelegatingRenderer::DelegatingRenderer( | |
61 RendererClient* client, ResourceProvider* resource_provider) | |
62 : Renderer(client), | |
63 resource_provider_(resource_provider), | |
64 visible_(true) { | |
65 DCHECK(resource_provider_); | |
66 } | |
67 | |
68 bool DelegatingRenderer::Initialize() { | |
69 capabilities_.usingPartialSwap = false; | |
70 // TODO(danakj): Throttling - we may want to only allow 1 outstanding frame, | |
71 // but the parent compositor may pipeline for us. | |
72 // TODO(danakj): Can we use this in single-thread mode? | |
73 capabilities_.usingSwapCompleteCallback = true; | |
74 capabilities_.maxTextureSize = resource_provider_->maxTextureSize(); | |
75 capabilities_.bestTextureFormat = resource_provider_->bestTextureFormat(); | |
76 capabilities_.allowPartialTextureUpdates = false; | |
77 | |
78 WebGraphicsContext3D* context3d = resource_provider_->graphicsContext3D(); | |
79 | |
80 if (!context3d) { | |
81 // Software compositing. | |
82 return true; | |
83 } | |
84 | |
85 if (!context3d->makeContextCurrent()) | |
86 return false; | |
87 | |
88 context3d->setContextLostCallback(this); | |
89 context3d->pushGroupMarkerEXT("CompositorContext"); | |
90 | |
91 std::string extensionsString = | |
92 UTF16ToASCII(context3d->getString(GL_EXTENSIONS)); | |
93 | |
94 std::vector<std::string> extensions; | |
95 base::SplitString(extensionsString, ' ', &extensions); | |
96 | |
97 // TODO(danakj): We need non-GPU-specific paths for these things. This | |
98 // renderer shouldn't need to use context3d extensions directly. | |
99 bool hasReadBGRA = true; | |
100 bool hasSetVisibility = true; | |
101 bool hasIOSurface = true; | |
102 bool hasARBTextureRect = true; | |
103 bool hasGpuMemoryManager = true; | |
104 bool hasEGLImage = true; | |
105 for (size_t i = 0; i < extensions.size(); ++i) { | |
106 if (extensions[i] == "GL_EXT_read_format_bgra") | |
107 hasReadBGRA = true; | |
108 else if (extensions[i] == "GL_CHROMIUM_set_visibility") | |
109 hasSetVisibility = true; | |
110 else if (extensions[i] == "GL_CHROMIUM_iosurface") | |
111 hasIOSurface = true; | |
112 else if (extensions[i] == "GL_ARB_texture_rectangle") | |
113 hasARBTextureRect = true; | |
114 else if (extensions[i] == "GL_CHROMIUM_gpu_memory_manager") | |
115 hasGpuMemoryManager = true; | |
116 else if (extensions[i] == "GL_OES_EGL_image_external") | |
117 hasEGLImage = true; | |
118 } | |
119 | |
120 if (hasIOSurface) | |
121 DCHECK(hasARBTextureRect); | |
122 | |
123 capabilities_.usingAcceleratedPainting = | |
124 settings().acceleratePainting && | |
125 capabilities_.bestTextureFormat == GL_BGRA_EXT && | |
126 hasReadBGRA; | |
127 | |
128 // TODO(piman): loop visibility to GPU process? | |
129 capabilities_.usingSetVisibility = hasSetVisibility; | |
130 | |
131 // TODO(danakj): Support GpuMemoryManager. | |
132 capabilities_.usingGpuMemoryManager = false; | |
133 | |
134 capabilities_.usingEglImage = hasEGLImage; | |
135 | |
136 return true; | |
137 } | |
138 | |
139 DelegatingRenderer::~DelegatingRenderer() { | |
140 WebGraphicsContext3D* context3d = resource_provider_->graphicsContext3D(); | |
141 if (context3d) | |
142 context3d->setContextLostCallback(NULL); | |
143 } | |
144 | |
145 const RendererCapabilities& DelegatingRenderer::capabilities() const { | |
146 return capabilities_; | |
147 } | |
148 | |
149 void DelegatingRenderer::drawFrame(RenderPassList& render_passes_in_draw_order, | |
150 RenderPassIdHashMap& render_passes_by_id) { | |
151 TRACE_EVENT0("cc", "DelegatingRenderer::drawFrame"); | |
152 NOTIMPLEMENTED(); | |
153 } | |
154 | |
155 bool DelegatingRenderer::swapBuffers() { | |
156 return true; | |
157 } | |
158 | |
159 void DelegatingRenderer::getFramebufferPixels(void *pixels, | |
160 const gfx::Rect& rect) { | |
161 NOTIMPLEMENTED(); | |
162 } | |
163 | |
164 void DelegatingRenderer::receiveCompositorFrameAck( | |
165 const CompositorFrameAck& ack) { | |
166 resource_provider_->receiveFromParent(ack.resources); | |
167 m_client->onSwapBuffersComplete(); | |
168 } | |
169 | |
170 | |
171 bool DelegatingRenderer::isContextLost() { | |
172 WebGraphicsContext3D* context3d = resource_provider_->graphicsContext3D(); | |
173 if (!context3d) | |
174 return false; | |
175 return context3d->getGraphicsResetStatusARB() != GL_NO_ERROR; | |
176 } | |
177 | |
178 void DelegatingRenderer::setVisible(bool visible) { | |
179 visible_ = visible; | |
180 } | |
181 | |
182 void DelegatingRenderer::onContextLost() { | |
183 m_client->didLoseOutputSurface(); | |
184 } | |
185 | |
186 } // namespace cc | |
OLD | NEW |