Chromium Code Reviews| Index: cc/CCDelegatingRenderer.cpp |
| diff --git a/cc/CCDelegatingRenderer.cpp b/cc/CCDelegatingRenderer.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0f09cb689b8416460ca9d61b2946ccde747670c1 |
| --- /dev/null |
| +++ b/cc/CCDelegatingRenderer.cpp |
| @@ -0,0 +1,183 @@ |
| +/* |
| + * Copyright (C) 2012 Google Inc. All rights reserved. |
| + * |
| + * Redistribution and use in source and binary forms, with or without |
| + * modification, are permitted provided that the following conditions |
| + * are met: |
| + * |
| + * 1. Redistributions of source code must retain the above copyright |
| + * notice, this list of conditions and the following disclaimer. |
| + * 2. Redistributions in binary form must reproduce the above copyright |
| + * notice, this list of conditions and the following disclaimer in the |
| + * documentation and/or other materials provided with the distribution. |
| + * |
| + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| + */ |
| + |
| +#include "config.h" |
| + |
| +#include <set> |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "cc/CCCheckerboardDrawQuad.h" |
| +#include "cc/CCDebugBorderDrawQuad.h" |
| +#include "cc/CCDelegatingRenderer.h" |
| +#include "cc/CCRenderPassDrawQuad.h" |
| +#include "cc/CCResourceProvider.h" |
| +#include "cc/CCSolidColorDrawQuad.h" |
| +#include "cc/CCTextureDrawQuad.h" |
| +#include "cc/CCTileDrawQuad.h" |
| +#include "cc/CCYUVVideoDrawQuad.h" |
| +#include "cc/web_compositor_frame.h" |
| +#include "CCSettings.h" |
| +#include "PlatformColor.h" |
| +#include "TraceEvent.h" |
| +#include <public/WebFloatRect.h> |
| +#include <public/WebRect.h> |
| +#include <public/WebSize.h> |
| +#include <wtf/text/StringHash.h> |
| +#ifdef LOG |
| +#undef LOG |
| +#endif |
| +#include "base/string_split.h" |
| +#include "base/string_util.h" |
| + |
| +using namespace WebKit; |
| + |
| +namespace WebCore { |
| + |
| +PassOwnPtr<CCDelegatingRenderer> CCDelegatingRenderer::create(CCRendererClient* client, CCResourceProvider* resourceProvider) |
| +{ |
| + OwnPtr<CCDelegatingRenderer> renderer(adoptPtr(new CCDelegatingRenderer(client, resourceProvider))); |
| + if (!renderer->initialize()) |
| + return nullptr; |
| + return renderer.release(); |
| +} |
| + |
| +CCDelegatingRenderer::CCDelegatingRenderer(CCRendererClient* client, CCResourceProvider* resourceProvider) |
| + : CCRenderer(client) |
| + , m_resourceProvider(resourceProvider) |
| + , m_visible(true) |
| +{ |
| + ASSERT(m_resourceProvider); |
| +} |
| + |
| +bool CCDelegatingRenderer::initialize() |
| +{ |
| + m_capabilities.usingPartialSwap = CCSettings::partialSwapEnabled(); |
|
danakj
2012/09/21 20:51:41
I don't think we want to ever partial swap with de
|
| + // FIXME: Throttling - we may want to only allow 1 outstanding frame (the |
| + // parent compositor can pipeline for us). |
| + m_capabilities.usingSwapCompleteCallback = true; |
| + m_capabilities.maxTextureSize = m_resourceProvider->maxTextureSize(); |
| + |
| + WebGraphicsContext3D* context = m_resourceProvider->graphicsContext3D(); |
| + bool supportsBGRA = false; |
| + if (context) { |
| + if (!context->makeContextCurrent()) |
| + return false; |
| + |
| + context->setContextLostCallback(this); |
| + context->pushGroupMarkerEXT("CompositorContext"); |
| + |
| + std::string extensionsString = UTF16ToASCII(context->getString(GraphicsContext3D::EXTENSIONS)); |
| + std::vector<std::string> extensionsList; |
| + base::SplitString(extensionsString, ' ', &extensionsList); |
| + std::set<std::string> extensions(extensionsList.begin(), extensionsList.end()); |
| + |
| + if (settings().acceleratePainting && extensions.count("GL_EXT_texture_format_BGRA8888") |
| + && extensions.count("GL_EXT_read_format_bgra")) |
| + m_capabilities.usingAcceleratedPainting = true; |
| + else |
| + m_capabilities.usingAcceleratedPainting = false; |
| + |
| + // FIXME: loop visibility to GPU process? |
| + m_capabilities.usingSetVisibility = extensions.count("GL_CHROMIUM_set_visibility"); |
| + |
| + if (extensions.count("GL_CHROMIUM_iosurface")) |
| + ASSERT(extensions.count("GL_ARB_texture_rectangle")); |
| + |
| + m_capabilities.usingGpuMemoryManager = extensions.count("GL_CHROMIUM_gpu_memory_manager"); |
| + // FIXME: doesn't belong here. |
| + /* |
| + if (m_capabilities.usingGpuMemoryManager) |
| + context->setMemoryAllocationChangedCallbackCHROMIUM(this); |
| + */ |
| + |
| + m_capabilities.usingEglImage = extensions.count("GL_OES_EGL_image_external"); |
| + supportsBGRA = extensions.count("GL_EXT_texture_format_BGRA8888"); |
| + } |
| + |
| + m_capabilities.bestTextureFormat = PlatformColor::bestTextureFormat(context, supportsBGRA); |
| + |
| + return true; |
| +} |
| + |
| +CCDelegatingRenderer::~CCDelegatingRenderer() |
| +{ |
| + ASSERT(CCProxy::isImplThread()); |
| + WebGraphicsContext3D* context = m_resourceProvider->graphicsContext3D(); |
| + if (context) |
| + context->setContextLostCallback(0); |
| +} |
| + |
| +void CCDelegatingRenderer::drawFrame(const CCRenderPassList& renderPassesInDrawOrder, const CCRenderPassIdHashMap&) |
| +{ |
| + TRACE_EVENT0("cc", "CCDelegatingRenderer::drawFrame"); |
| + WebCompositorOutputSurface* outputSurface = m_resourceProvider->context(); |
| + ASSERT(outputSurface); |
| + WebCompositorFrame frame; |
| + frame.render_passes.reserve(renderPassesInDrawOrder.size()); |
|
danakj
2012/09/21 20:51:41
What about just storing a pointer/reference to the
|
| + for (CCRenderPassList::const_iterator it = renderPassesInDrawOrder.begin(); it != renderPassesInDrawOrder.end(); ++it) |
| + frame.render_passes.push_back(*it); |
| + // TODO(piman): prepare resources for transfer, stash into frame. |
| + |
| + outputSurface->sendFrameToParentCompositor(frame); |
|
danakj
2012/09/21 20:51:41
Should this be in swapBuffers? Could it ever matte
|
| +} |
| + |
| +bool CCDelegatingRenderer::swapBuffers() |
| +{ |
| + return true; |
| +} |
| + |
| +void CCDelegatingRenderer::getFramebufferPixels(void *pixels, const IntRect&) |
| +{ |
| + // FIXME |
|
danakj
2012/09/21 20:51:41
Hm, in this case we're going to need a CCDirectRen
|
| +} |
| + |
| +bool CCDelegatingRenderer::isContextLost() |
| +{ |
| + WebGraphicsContext3D* context = m_resourceProvider->graphicsContext3D(); |
| + if (!context) |
| + return false; |
| + return (context->getGraphicsResetStatusARB() != GraphicsContext3D::NO_ERROR); |
| +} |
| + |
| +void CCDelegatingRenderer::onSendFrameToParentCompositorAck(const WebKit::WebCompositorFrameAck& ack) |
| +{ |
| + // TODO(piman): get recycled resources from ack, give back to CCResourceProvider. |
| + m_client->onSwapBuffersComplete(); |
| +} |
| + |
| +void CCDelegatingRenderer::setVisible(bool visible) |
| +{ |
| + if (m_visible == visible) |
| + return; |
| + m_visible = visible; |
| +} |
| + |
| +void CCDelegatingRenderer::onContextLost() |
| +{ |
| + m_client->didLoseContext(); |
| +} |
| + |
| +} |