Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | |
| 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 "config.h" | |
| 27 | |
| 28 #include <set> | |
| 29 #include <string> | |
| 30 #include <vector> | |
| 31 | |
| 32 #include "cc/CCCheckerboardDrawQuad.h" | |
| 33 #include "cc/CCDebugBorderDrawQuad.h" | |
| 34 #include "cc/CCDelegatingRenderer.h" | |
| 35 #include "cc/CCRenderPassDrawQuad.h" | |
| 36 #include "cc/CCResourceProvider.h" | |
| 37 #include "cc/CCSolidColorDrawQuad.h" | |
| 38 #include "cc/CCTextureDrawQuad.h" | |
| 39 #include "cc/CCTileDrawQuad.h" | |
| 40 #include "cc/CCYUVVideoDrawQuad.h" | |
| 41 #include "cc/web_compositor_frame.h" | |
| 42 #include "CCSettings.h" | |
| 43 #include "PlatformColor.h" | |
| 44 #include "TraceEvent.h" | |
| 45 #include <public/WebFloatRect.h> | |
| 46 #include <public/WebRect.h> | |
| 47 #include <public/WebSize.h> | |
| 48 #include <wtf/text/StringHash.h> | |
| 49 #ifdef LOG | |
| 50 #undef LOG | |
| 51 #endif | |
| 52 #include "base/string_split.h" | |
| 53 #include "base/string_util.h" | |
| 54 | |
| 55 using namespace WebKit; | |
| 56 | |
| 57 namespace WebCore { | |
| 58 | |
| 59 PassOwnPtr<CCDelegatingRenderer> CCDelegatingRenderer::create(CCRendererClient* client, CCResourceProvider* resourceProvider) | |
| 60 { | |
| 61 OwnPtr<CCDelegatingRenderer> renderer(adoptPtr(new CCDelegatingRenderer(clie nt, resourceProvider))); | |
| 62 if (!renderer->initialize()) | |
| 63 return nullptr; | |
| 64 return renderer.release(); | |
| 65 } | |
| 66 | |
| 67 CCDelegatingRenderer::CCDelegatingRenderer(CCRendererClient* client, CCResourceP rovider* resourceProvider) | |
| 68 : CCRenderer(client) | |
| 69 , m_resourceProvider(resourceProvider) | |
| 70 , m_visible(true) | |
| 71 { | |
| 72 ASSERT(m_resourceProvider); | |
| 73 } | |
| 74 | |
| 75 bool CCDelegatingRenderer::initialize() | |
| 76 { | |
| 77 m_capabilities.usingPartialSwap = CCSettings::partialSwapEnabled(); | |
|
danakj
2012/09/21 20:51:41
I don't think we want to ever partial swap with de
| |
| 78 // FIXME: Throttling - we may want to only allow 1 outstanding frame (the | |
| 79 // parent compositor can pipeline for us). | |
| 80 m_capabilities.usingSwapCompleteCallback = true; | |
| 81 m_capabilities.maxTextureSize = m_resourceProvider->maxTextureSize(); | |
| 82 | |
| 83 WebGraphicsContext3D* context = m_resourceProvider->graphicsContext3D(); | |
| 84 bool supportsBGRA = false; | |
| 85 if (context) { | |
| 86 if (!context->makeContextCurrent()) | |
| 87 return false; | |
| 88 | |
| 89 context->setContextLostCallback(this); | |
| 90 context->pushGroupMarkerEXT("CompositorContext"); | |
| 91 | |
| 92 std::string extensionsString = UTF16ToASCII(context->getString(GraphicsCon text3D::EXTENSIONS)); | |
| 93 std::vector<std::string> extensionsList; | |
| 94 base::SplitString(extensionsString, ' ', &extensionsList); | |
| 95 std::set<std::string> extensions(extensionsList.begin(), extensionsList.en d()); | |
| 96 | |
| 97 if (settings().acceleratePainting && extensions.count("GL_EXT_texture_form at_BGRA8888") | |
| 98 && extensions.count("GL_EXT_read_format_bgra")) | |
| 99 m_capabilities.usingAcceleratedPainting = true; | |
| 100 else | |
| 101 m_capabilities.usingAcceleratedPainting = false; | |
| 102 | |
| 103 // FIXME: loop visibility to GPU process? | |
| 104 m_capabilities.usingSetVisibility = extensions.count("GL_CHROMIUM_set_visi bility"); | |
| 105 | |
| 106 if (extensions.count("GL_CHROMIUM_iosurface")) | |
| 107 ASSERT(extensions.count("GL_ARB_texture_rectangle")); | |
| 108 | |
| 109 m_capabilities.usingGpuMemoryManager = extensions.count("GL_CHROMIUM_gpu_m emory_manager"); | |
| 110 // FIXME: doesn't belong here. | |
| 111 /* | |
| 112 if (m_capabilities.usingGpuMemoryManager) | |
| 113 context->setMemoryAllocationChangedCallbackCHROMIUM(this); | |
| 114 */ | |
| 115 | |
| 116 m_capabilities.usingEglImage = extensions.count("GL_OES_EGL_image_external "); | |
| 117 supportsBGRA = extensions.count("GL_EXT_texture_format_BGRA8888"); | |
| 118 } | |
| 119 | |
| 120 m_capabilities.bestTextureFormat = PlatformColor::bestTextureFormat(context, supportsBGRA); | |
| 121 | |
| 122 return true; | |
| 123 } | |
| 124 | |
| 125 CCDelegatingRenderer::~CCDelegatingRenderer() | |
| 126 { | |
| 127 ASSERT(CCProxy::isImplThread()); | |
| 128 WebGraphicsContext3D* context = m_resourceProvider->graphicsContext3D(); | |
| 129 if (context) | |
| 130 context->setContextLostCallback(0); | |
| 131 } | |
| 132 | |
| 133 void CCDelegatingRenderer::drawFrame(const CCRenderPassList& renderPassesInDrawO rder, const CCRenderPassIdHashMap&) | |
| 134 { | |
| 135 TRACE_EVENT0("cc", "CCDelegatingRenderer::drawFrame"); | |
| 136 WebCompositorOutputSurface* outputSurface = m_resourceProvider->context(); | |
| 137 ASSERT(outputSurface); | |
| 138 WebCompositorFrame frame; | |
| 139 frame.render_passes.reserve(renderPassesInDrawOrder.size()); | |
|
danakj
2012/09/21 20:51:41
What about just storing a pointer/reference to the
| |
| 140 for (CCRenderPassList::const_iterator it = renderPassesInDrawOrder.begin(); it != renderPassesInDrawOrder.end(); ++it) | |
| 141 frame.render_passes.push_back(*it); | |
| 142 // TODO(piman): prepare resources for transfer, stash into frame. | |
| 143 | |
| 144 outputSurface->sendFrameToParentCompositor(frame); | |
|
danakj
2012/09/21 20:51:41
Should this be in swapBuffers? Could it ever matte
| |
| 145 } | |
| 146 | |
| 147 bool CCDelegatingRenderer::swapBuffers() | |
| 148 { | |
| 149 return true; | |
| 150 } | |
| 151 | |
| 152 void CCDelegatingRenderer::getFramebufferPixels(void *pixels, const IntRect&) | |
| 153 { | |
| 154 // FIXME | |
|
danakj
2012/09/21 20:51:41
Hm, in this case we're going to need a CCDirectRen
| |
| 155 } | |
| 156 | |
| 157 bool CCDelegatingRenderer::isContextLost() | |
| 158 { | |
| 159 WebGraphicsContext3D* context = m_resourceProvider->graphicsContext3D(); | |
| 160 if (!context) | |
| 161 return false; | |
| 162 return (context->getGraphicsResetStatusARB() != GraphicsContext3D::NO_ERROR) ; | |
| 163 } | |
| 164 | |
| 165 void CCDelegatingRenderer::onSendFrameToParentCompositorAck(const WebKit::WebCom positorFrameAck& ack) | |
| 166 { | |
| 167 // TODO(piman): get recycled resources from ack, give back to CCResourceProv ider. | |
| 168 m_client->onSwapBuffersComplete(); | |
| 169 } | |
| 170 | |
| 171 void CCDelegatingRenderer::setVisible(bool visible) | |
| 172 { | |
| 173 if (m_visible == visible) | |
| 174 return; | |
| 175 m_visible = visible; | |
| 176 } | |
| 177 | |
| 178 void CCDelegatingRenderer::onContextLost() | |
| 179 { | |
| 180 m_client->didLoseContext(); | |
| 181 } | |
| 182 | |
| 183 } | |
| OLD | NEW |