Source/WebCore/ChangeLog

 12012-11-17 Alexandru Chiculita <achicu@adobe.com>
 2
 3 [Texmap][CSS Shaders] Reuse the precompiled shader for custom filters in TextureMapperGL
 4 https://bugs.webkit.org/show_bug.cgi?id=101801
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Added a HashMap in TextureMapperGL to store the precompiled versions of the shaders.
 9 Also added a new API on TextureMapper that receives a notification when the shader
 10 is no longer needed.
 11
 12 No new tests, the code is tested by existing tests.
 13
 14 * platform/graphics/filters/CustomFilterOperation.h:
 15 (WebCore::CustomFilterOperation::setProgram):
 16 (CustomFilterOperation): Made the constructor protected, so that we can overwrite the class in WK2.
 17 * platform/graphics/filters/CustomFilterValidatedProgram.cpp:
 18 (WebCore::CustomFilterValidatedProgram::validatedProgramInfo):
 19 (WebCore):
 20 * platform/graphics/filters/CustomFilterValidatedProgram.h:
 21 (CustomFilterValidatedProgram):
 22 * platform/graphics/texmap/TextureMapper.h:
 23 (WebCore):
 24 (TextureMapper):
 25 (WebCore::TextureMapper::removeCachedCustomFilterProgram):
 26 Function to be called by the platform code, when the shader is no longer
 27 needed. This implementation is empty and overridden in TextureMapperGL.
 28 * platform/graphics/texmap/TextureMapperGL.cpp:
 29 (WebCore::TextureMapperGL::removeCachedCustomFilterProgram):
 30 Removes the compiled shader from the cache. This is called from WK2 when the compiled shader
 31 is no longer needed.
 32 (WebCore):
 33 (WebCore::TextureMapperGL::drawUsingCustomFilter): The first time it uses a new
 34 shader it will cache the compiled version until removeCachedCustomFilterProgram is called.
 35 * platform/graphics/texmap/TextureMapperGL.h:
 36 (WebCore):
 37 (TextureMapperGL):
 38
1392012-11-16 Dimitri Glazkov <dglazkov@chromium.org>
240
341 [Chromium] Updated WebCore.gypi after r134939.

Source/WebCore/platform/graphics/filters/CustomFilterOperation.h

@@public:
4949 }
5050
5151 CustomFilterProgram* program() const { return m_program.get(); }
 52 void setProgram(PassRefPtr<CustomFilterProgram> program) { m_program = program; }
5253
5354 const CustomFilterParameterList& parameters() const { return m_parameters; }
5455

@@public:
6566 virtual bool blendingNeedsRendererSize() const { return true; }
6667
6768 virtual PassRefPtr<FilterOperation> blend(const FilterOperation* from, double progress, const LayoutSize&, bool blendToPassthrough = false);
 69
 70protected:
 71 CustomFilterOperation(PassRefPtr<CustomFilterProgram>, const CustomFilterParameterList&, unsigned meshRows, unsigned meshColumns, CustomFilterMeshBoxType, CustomFilterMeshType);
 72
6873private:
6974 virtual bool operator==(const FilterOperation& o) const
7075 {

@@private:
7984 && m_meshType == other->m_meshType
8085 && m_parameters == other->m_parameters;
8186 }
82 
83  CustomFilterOperation(PassRefPtr<CustomFilterProgram>, const CustomFilterParameterList&, unsigned meshRows, unsigned meshColumns, CustomFilterMeshBoxType, CustomFilterMeshType);
8487
8588 RefPtr<CustomFilterProgram> m_program;
8689 CustomFilterParameterList m_parameters;

Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp

@@CustomFilterValidatedProgram::~CustomFilterValidatedProgram()
512512 m_globalContext->removeValidatedProgram(this);
513513}
514514
 515CustomFilterProgramInfo CustomFilterValidatedProgram::validatedProgramInfo() const
 516{
 517 ASSERT(m_isInitialized);
 518 return CustomFilterProgramInfo(m_validatedVertexShader, m_validatedFragmentShader, m_programInfo.programType(), m_programInfo.mixSettings(), m_programInfo.meshType());
 519}
 520
515521#if !PLATFORM(BLACKBERRY) && !USE(TEXTURE_MAPPER)
516522void CustomFilterValidatedProgram::platformInit()
517523{

Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.h

@@public:
8282 ~CustomFilterValidatedProgram();
8383
8484 const CustomFilterProgramInfo& programInfo() const { return m_programInfo; }
 85 CustomFilterProgramInfo validatedProgramInfo() const;
 86
8587 PassRefPtr<CustomFilterCompiledProgram> compiledProgram();
8688
8789 const String& validatedVertexShader() const

Source/WebCore/platform/graphics/texmap/TextureMapper.h

4848namespace WebCore {
4949
5050class BitmapTexturePool;
 51class CustomFilterProgram;
5152class TextureMapper;
5253
5354// A 2D texture that can be the target of software or GL rendering.

@@public:
154155
155156 virtual PassRefPtr<BitmapTexture> acquireTextureFromPool(const IntSize&);
156157
 158#if ENABLE(CSS_SHADERS)
 159 virtual void removeCachedCustomFilterProgram(CustomFilterProgram*) { }
 160#endif
 161
157162protected:
158163 explicit TextureMapper(AccelerationMode);
159164

Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp

@@static void prepareFilterProgram(TextureMapperShaderProgram* program, const Filt
921921}
922922
923923#if ENABLE(CSS_SHADERS)
 924void TextureMapperGL::removeCachedCustomFilterProgram(CustomFilterProgram* program)
 925{
 926 m_customFilterPrograms.remove(program);
 927}
 928
924929bool TextureMapperGL::drawUsingCustomFilter(BitmapTexture& target, const BitmapTexture& source, const FilterOperation& filter)
925930{
926931 RefPtr<CustomFilterRenderer> renderer;

@@bool TextureMapperGL::drawUsingCustomFilter(BitmapTexture& target, const BitmapT
932937 RefPtr<CustomFilterProgram> program = customFilter->program();
933938 renderer = CustomFilterRenderer::create(m_context3D, program->programType(), customFilter->parameters(),
934939 customFilter->meshRows(), customFilter->meshColumns(), customFilter->meshBoxType(), customFilter->meshType());
935  // FIXME: Optimize this by keeping a reference to the program across frames.
936  // https://bugs.webkit.org/show_bug.cgi?id=101801
937  RefPtr<CustomFilterCompiledProgram> compiledProgram = CustomFilterCompiledProgram::create(m_context3D, program->vertexShaderString(), program->fragmentShaderString(), program->programType());
 940 RefPtr<CustomFilterCompiledProgram> compiledProgram;
 941 CustomFilterProgramMap::iterator iter = m_customFilterPrograms.find(program.get());
 942 if (iter == m_customFilterPrograms.end()) {
 943 compiledProgram = CustomFilterCompiledProgram::create(m_context3D, program->vertexShaderString(), program->fragmentShaderString(), program->programType());
 944 m_customFilterPrograms.set(program.get(), compiledProgram);
 945 } else
 946 compiledProgram = iter->value;
938947 renderer->setCompiledProgram(compiledProgram.release());
939948 break;
940949 }

Source/WebCore/platform/graphics/texmap/TextureMapperGL.h

3030
3131namespace WebCore {
3232
 33class CustomFilterProgram;
 34class CustomFilterCompiledProgram;
3335class TextureMapperGLData;
3436class GraphicsContext;
3537class TextureMapperShaderProgram;

@@public:
7476#endif
7577#if ENABLE(CSS_SHADERS)
7678 bool drawUsingCustomFilter(BitmapTexture& targetTexture, const BitmapTexture& sourceTexture, const FilterOperation&);
 79 virtual void removeCachedCustomFilterProgram(CustomFilterProgram*);
7780#endif
7881
7982 void setEnableEdgeDistanceAntialiasing(bool enabled) { m_enableEdgeDistanceAntialiasing = enabled; }

@@private:
128131 ClipStack m_clipStack;
129132 bool m_enableEdgeDistanceAntialiasing;
130133
 134#if ENABLE(CSS_SHADERS)
 135 typedef HashMap<CustomFilterProgram*, RefPtr<CustomFilterCompiledProgram> > CustomFilterProgramMap;
 136 CustomFilterProgramMap m_customFilterPrograms;
 137#endif
 138
131139 friend class BitmapTextureGL;
132140};
133141

Source/WebKit2/ChangeLog

 12012-11-17 Alexandru Chiculita <achicu@adobe.com>
 2
 3 [Texmap][CSS Shaders] Reuse the precompiled shader for custom filters in TextureMapperGL
 4 https://bugs.webkit.org/show_bug.cgi?id=101801
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Changed the encoding code for ValidatedCustomFilterOperation to only encode the ID of the program.
 9 LayerTreeCoordinator makes sure to send the programs in full before the encoder runs.
 10 LayerTreeRenderer will maintain a HashMap from these IDs to the real CustomFilterProgram.
 11 The UI process will also receive a message from the WebProcess when the shader is no longer in needed.
 12 LayerTreeRenderer calls the TextureMapper's removeCachedCustomFilterProgram to notify
 13 about the removed CustomFilterProgram.
 14
 15 * Shared/CoordinatedGraphics/CoordinatedGraphicsArgumentCoders.cpp:
 16 (CoreIPC::::encode):
 17 (CoreIPC::::decode):
 18 (CoreIPC):
 19 * Shared/CoordinatedGraphics/CoordinatedGraphicsArgumentCoders.h:
 20 (WebCore):
 21 * Shared/CoordinatedGraphics/WebCustomFilterOperation.h: Added.
 22 (WebCore):
 23 (WebCustomFilterOperation):
 24 (WebCore::WebCustomFilterOperation::create):
 25 (WebCore::WebCustomFilterOperation::programId):
 26 (WebCore::WebCustomFilterOperation::WebCustomFilterOperation):
 27 * Shared/CoordinatedGraphics/WebCustomFilterProgramProxy.h:
 28 (WebKit::WebCustomFilterProgramProxy::create):
 29 (WebKit::WebCustomFilterProgramProxy::WebCustomFilterProgramProxy):
 30 * UIProcess/CoordinatedGraphics/LayerTreeCoordinatorProxy.cpp:
 31 (WebKit):
 32 (WebKit::LayerTreeCoordinatorProxy::removeCustomFilterProgram):
 33 (WebKit::LayerTreeCoordinatorProxy::createCustomFilterProgram):
 34 * UIProcess/CoordinatedGraphics/LayerTreeCoordinatorProxy.h:
 35 (LayerTreeCoordinatorProxy):
 36 * UIProcess/CoordinatedGraphics/LayerTreeCoordinatorProxy.messages.in:
 37 * UIProcess/CoordinatedGraphics/LayerTreeRenderer.cpp:
 38 (WebKit::LayerTreeRenderer::setLayerFilters):
 39 (WebKit):
 40 (WebKit::LayerTreeRenderer::injectCachedCustomFilterPrograms):
 41 (WebKit::LayerTreeRenderer::createCustomFilterProgram):
 42 (WebKit::LayerTreeRenderer::removeCustomFilterProgram):
 43 * UIProcess/CoordinatedGraphics/LayerTreeRenderer.h:
 44 (WebCore):
 45 (LayerTreeRenderer):
 46 * WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.cpp:
 47 (WebKit::LayerTreeCoordinator::checkCustomFilterProgramProxies):
 48 (WebKit::LayerTreeCoordinator::removeCustomFilterProgramProxy):
 49
1502012-11-16 Viatcheslav Ostapenko <v.ostapenko@samsung.com>
251
352 [EFL][WK2] White flicker when scrolling big pages with dark background on slower hardware.

Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsArgumentCoders.cpp

5252#endif
5353
5454#if ENABLE(CSS_SHADERS)
 55#include "WebCustomFilterOperation.h"
5556#include "WebCustomFilterProgram.h"
 57#include "WebCustomFilterProgramProxy.h"
5658#include <WebCore/CustomFilterArrayParameter.h>
5759#include <WebCore/CustomFilterConstants.h>
5860#include <WebCore/CustomFilterNumberParameter.h>
5961#include <WebCore/CustomFilterOperation.h>
6062#include <WebCore/CustomFilterProgram.h>
 63#include <WebCore/CustomFilterProgramInfo.h>
6164#include <WebCore/CustomFilterTransformParameter.h>
6265#include <WebCore/CustomFilterValidatedProgram.h>
6366#include <WebCore/ValidatedCustomFilterOperation.h>

@@void ArgumentCoder<WebCore::FilterOperations>::encode(ArgumentEncoder& encoder,
142145 break;
143146 case FilterOperation::VALIDATED_CUSTOM: {
144147 const ValidatedCustomFilterOperation* customOperation = static_cast<const ValidatedCustomFilterOperation*>(filter);
145 
146148 ASSERT(customOperation->validatedProgram());
147149 RefPtr<CustomFilterValidatedProgram> program = customOperation->validatedProgram();
148150 ASSERT(program->isInitialized());
149151 ASSERT(program->platformCompiledProgram());
150  // FIXME: We should only serialize the object if it was not serialized before,
151  // otherwise only the ID of the program should be written to the stream.
152  // https://bugs.webkit.org/show_bug.cgi?id=101801
153  encoder << program->validatedVertexShader();
154  encoder << program->validatedFragmentShader();
 152 ASSERT(program->platformCompiledProgram()->client());
 153 WebCustomFilterProgramProxy* customFilterProgramProxy = static_cast<WebCustomFilterProgramProxy*>(program->platformCompiledProgram()->client());
155154 const CustomFilterProgramInfo& programInfo = program->programInfo();
156  encoder.encodeEnum(programInfo.programType());
157  const CustomFilterProgramMixSettings& mixSettings = programInfo.mixSettings();
158  encoder.encodeEnum(mixSettings.blendMode);
159  encoder.encodeEnum(mixSettings.compositeOperator);
 155 // FIXME: CustomFilterOperation should not need the meshType, it should just be encoded in the program itself.
 156 // https://bugs.webkit.org/show_bug.cgi?id=102529
160157 encoder.encodeEnum(programInfo.meshType());
161 
 158 encoder << customFilterProgramProxy->id();
162159 CustomFilterParameterList parameters = customOperation->parameters();
163160 encoder << static_cast<uint32_t>(parameters.size());
164161 for (size_t i = 0; i < parameters.size(); ++i) {

@@bool ArgumentCoder<WebCore::FilterOperations>::decode(ArgumentDecoder* decoder,
264261 ASSERT_NOT_REACHED();
265262 break;
266263 case FilterOperation::VALIDATED_CUSTOM: {
267  String vertexShaderString;
268  String fragmentShaderString;
269  CustomFilterProgramType programType;
270  CustomFilterProgramMixSettings mixSettings;
 264 // FIXME: CustomFilterOperation should not need the meshType.
 265 // https://bugs.webkit.org/show_bug.cgi?id=102529
271266 CustomFilterMeshType meshType;
272  if (!decoder->decode(vertexShaderString))
273  return false;
274  if (!decoder->decode(fragmentShaderString))
275  return false;
276  if (!decoder->decodeEnum(programType))
277  return false;
278  if (!decoder->decodeEnum(mixSettings.blendMode))
279  return false;
280  if (!decoder->decodeEnum(mixSettings.compositeOperator))
281  return false;
282267 if (!decoder->decodeEnum(meshType))
283268 return false;
284  RefPtr<CustomFilterProgram> program = WebCustomFilterProgram::create(vertexShaderString, fragmentShaderString, programType, mixSettings, meshType);
 269 int programId = 0;
 270 if (!decoder->decode(programId))
 271 return false;
285272
286273 uint32_t parametersSize;
287274 if (!decoder->decodeUInt32(parametersSize))

@@bool ArgumentCoder<WebCore::FilterOperations>::decode(ArgumentDecoder* decoder,
347334 if (!decoder->decodeEnum(meshBoxType))
348335 return false;
349336
350  // At this point the Shaders are already validated, so we just use CustomFilterOperation for transportation.
351  filter = CustomFilterOperation::create(program.release(), parameters, meshRows, meshColumns, meshBoxType, meshType);
 337 // At this point the Shaders are already validated, so we just use WebCustomFilterOperation for transportation.
 338 filter = WebCustomFilterOperation::create(0, programId, parameters, meshRows, meshColumns, meshBoxType, meshType);
352339 break;
353340 }
354341#endif

@@bool ArgumentCoder<WebCore::FilterOperations>::decode(ArgumentDecoder* decoder,
364351}
365352#endif
366353
 354#if ENABLE(CSS_SHADERS)
 355void ArgumentCoder<WebCore::CustomFilterProgramInfo>::encode(ArgumentEncoder& encoder, const CustomFilterProgramInfo& programInfo)
 356{
 357 encoder << programInfo.vertexShaderString();
 358 encoder << programInfo.fragmentShaderString();
 359 encoder.encodeEnum(programInfo.programType());
 360 encoder.encodeEnum(programInfo.meshType());
 361 const CustomFilterProgramMixSettings& mixSettings = programInfo.mixSettings();
 362 encoder.encodeEnum(mixSettings.blendMode);
 363 encoder.encodeEnum(mixSettings.compositeOperator);
 364}
 365
 366bool ArgumentCoder<WebCore::CustomFilterProgramInfo>::decode(ArgumentDecoder* decoder, CustomFilterProgramInfo& programInfo)
 367{
 368 String vertexShaderString;
 369 String fragmentShaderString;
 370 CustomFilterProgramType programType;
 371 CustomFilterMeshType meshType;
 372 CustomFilterProgramMixSettings mixSettings;
 373 if (!decoder->decode(vertexShaderString))
 374 return false;
 375 if (!decoder->decode(fragmentShaderString))
 376 return false;
 377 if (!decoder->decodeEnum(programType))
 378 return false;
 379 if (!decoder->decodeEnum(meshType))
 380 return false;
 381 if (!decoder->decodeEnum(mixSettings.blendMode))
 382 return false;
 383 if (!decoder->decodeEnum(mixSettings.compositeOperator))
 384 return false;
 385 programInfo = CustomFilterProgramInfo(vertexShaderString, fragmentShaderString, programType, mixSettings, meshType);
 386 return true;
 387}
 388#endif // ENABLE(CSS_SHADERS)
 389
367390void ArgumentCoder<TransformOperations>::encode(ArgumentEncoder& encoder, const TransformOperations& transformOperations)
368391{
369392 encoder << static_cast<uint32_t>(transformOperations.size());

Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsArgumentCoders.h

@@struct Length;
4343class FilterOperations;
4444#endif
4545
 46#if ENABLE(CSS_SHADERS)
 47class CustomFilterProgramInfo;
 48#endif
 49
4650#if USE(GRAPHICS_SURFACE)
4751struct GraphicsSurfaceToken;
4852#endif

@@template<> struct ArgumentCoder<WebCore::FilterOperations> {
7276};
7377#endif
7478
 79#if ENABLE(CSS_SHADERS)
 80template<> struct ArgumentCoder<WebCore::CustomFilterProgramInfo> {
 81 static void encode(ArgumentEncoder&, const WebCore::CustomFilterProgramInfo&);
 82 static bool decode(ArgumentDecoder*, WebCore::CustomFilterProgramInfo&);
 83};
 84#endif
 85
7586template<> struct ArgumentCoder<WebCore::TransformOperations> {
7687 static void encode(ArgumentEncoder&, const WebCore::TransformOperations&);
7788 static bool decode(ArgumentDecoder*, WebCore::TransformOperations&);

Source/WebKit2/Shared/CoordinatedGraphics/WebCustomFilterOperation.h

 1/*
 2 * Copyright (C) 2012 Adobe Systems Incorporated. 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
 9 * copyright notice, this list of conditions and the following
 10 * disclaimer.
 11 * 2. Redistributions in binary form must reproduce the above
 12 * copyright notice, this list of conditions and the following
 13 * disclaimer in the documentation and/or other materials
 14 * provided with the distribution.
 15 *
 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
 21 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
 25 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
 26 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 27 * SUCH DAMAGE.
 28 */
 29
 30#ifndef WebCustomFilterOperation_h
 31#define WebCustomFilterOperation_h
 32
 33#if ENABLE(CSS_SHADERS)
 34#include "CustomFilterOperation.h"
 35
 36namespace WebCore {
 37
 38// This class is only adding the programId on top of CustomFilterOperation. The argument decoder has no
 39// context, so we cannot search in our cached CustomFilterPrograms while decoding. In that case
 40// it will just store the programId and no CustomFilterProgram instance. The receiver is supposed to
 41// iterate on this structure and inject the right CustomFilterPrograms.
 42
 43class WebCustomFilterOperation : public CustomFilterOperation {
 44public:
 45 static PassRefPtr<WebCustomFilterOperation> create(PassRefPtr<CustomFilterProgram> program, int programId, const CustomFilterParameterList& sortedParameters, unsigned meshRows, unsigned meshColumns, CustomFilterMeshBoxType meshBoxType, CustomFilterMeshType meshType)
 46 {
 47 return adoptRef(new WebCustomFilterOperation(program, programId, sortedParameters, meshRows, meshColumns, meshBoxType, meshType));
 48 }
 49
 50 int programId() const { return m_programId; }
 51
 52private:
 53 WebCustomFilterOperation(PassRefPtr<CustomFilterProgram> program, int programId, const CustomFilterParameterList& sortedParameters, unsigned meshRows, unsigned meshColumns, CustomFilterMeshBoxType meshBoxType, CustomFilterMeshType meshType)
 54 : CustomFilterOperation(program, sortedParameters, meshRows, meshColumns, meshBoxType, meshType)
 55 , m_programId(programId)
 56 {
 57 }
 58
 59 int m_programId;
 60};
 61
 62} // namespace WebCore
 63
 64#endif // ENABLE(CSS_SHADERS)
 65
 66#endif // CustomFilterOperation_h

Source/WebKit2/Shared/CoordinatedGraphics/WebCustomFilterProgramProxy.h

@@public:
5656 using RefCounted<WebCustomFilterProgramProxy>::ref;
5757 using RefCounted<WebCustomFilterProgramProxy>::deref;
5858
59  static PassRefPtr<WebCustomFilterProgramProxy> create(WebCustomFilterProgramProxyClient* client)
 59 static PassRefPtr<WebCustomFilterProgramProxy> create()
6060 {
61  return adoptRef(new WebCustomFilterProgramProxy(client));
 61 return adoptRef(new WebCustomFilterProgramProxy());
6262 }
6363
6464 int id() const { return m_id; }

@@public:
7373 WebCustomFilterProgramProxyClient* client() const { return m_client; }
7474
7575private:
76  WebCustomFilterProgramProxy(WebCustomFilterProgramProxyClient* client)
77  : m_client(client)
 76 WebCustomFilterProgramProxy()
 77 : m_client(0)
7878 , m_id(s_nextId++)
7979 {
8080 }

Source/WebKit2/UIProcess/CoordinatedGraphics/LayerTreeCoordinatorProxy.cpp

3030#include "WebPageProxy.h"
3131#include "WebProcessProxy.h"
3232
 33#if ENABLE(CSS_SHADERS)
 34#include "CustomFilterProgramInfo.h"
 35#endif
 36
3337namespace WebKit {
3438
3539using namespace WebCore;

@@void LayerTreeCoordinatorProxy::setCompositingLayerFilters(WebLayerID id, const
115119}
116120#endif
117121
 122#if ENABLE(CSS_SHADERS)
 123void LayerTreeCoordinatorProxy::removeCustomFilterProgram(int id)
 124{
 125 dispatchUpdate(bind(&LayerTreeRenderer::removeCustomFilterProgram, m_renderer.get(), id));
 126}
 127void LayerTreeCoordinatorProxy::createCustomFilterProgram(int id, const WebCore::CustomFilterProgramInfo& programInfo)
 128{
 129 dispatchUpdate(bind(&LayerTreeRenderer::createCustomFilterProgram, m_renderer.get(), id, programInfo));
 130}
 131#endif
 132
118133void LayerTreeCoordinatorProxy::didRenderFrame(const WebCore::IntSize& contentsSize, const WebCore::IntRect& coveredRect)
119134{
120135 dispatchUpdate(bind(&LayerTreeRenderer::flushLayerChanges, m_renderer.get()));

Source/WebKit2/UIProcess/CoordinatedGraphics/LayerTreeCoordinatorProxy.h

@@public:
5757#if ENABLE(CSS_FILTERS)
5858 void setCompositingLayerFilters(WebLayerID, const WebCore::FilterOperations&);
5959#endif
 60#if ENABLE(CSS_SHADERS)
 61 void createCustomFilterProgram(int id, const WebCore::CustomFilterProgramInfo&);
 62 void removeCustomFilterProgram(int id);
 63#endif
6064 void deleteCompositingLayer(WebLayerID);
6165 void setRootCompositingLayer(WebLayerID);
6266 void setContentsSize(const WebCore::FloatSize&);

Source/WebKit2/UIProcess/CoordinatedGraphics/LayerTreeCoordinatorProxy.messages.in

@@messages -> LayerTreeCoordinatorProxy {
2424#if ENABLE(CSS_FILTERS)
2525 SetCompositingLayerFilters(uint32_t id, WebCore::FilterOperations filters)
2626#endif
 27#if ENABLE(CSS_SHADERS)
 28 CreateCustomFilterProgram(int id, WebCore::CustomFilterProgramInfo programInfo)
 29 RemoveCustomFilterProgram(int id)
 30#endif
2731 SetRootCompositingLayer(uint32_t id)
2832 DeleteCompositingLayer(uint32_t id)
2933 CreateTileForLayer(uint32_t layerID, int tileID, WebCore::IntRect tileRect, WebKit::SurfaceUpdateInfo updateInfo)

Source/WebKit2/UIProcess/CoordinatedGraphics/LayerTreeRenderer.cpp

3737#include <wtf/Atomics.h>
3838#include <wtf/MainThread.h>
3939
 40#if ENABLE(CSS_SHADERS)
 41#include "CustomFilterProgram.h"
 42#include "CustomFilterProgramInfo.h"
 43#include "WebCustomFilterOperation.h"
 44#include "WebCustomFilterProgram.h"
 45#endif
 46
4047namespace WebKit {
4148
4249using namespace WebCore;

@@void LayerTreeRenderer::setLayerFilters(WebLayerID id, const FilterOperations& f
283290 ASSERT(it != m_layers.end());
284291
285292 GraphicsLayer* layer = it->value;
 293#if ENABLE(CSS_SHADERS)
 294 if (filters.hasCustomFilter()) {
 295 layer->setFilters(injectCachedCustomFilterPrograms(filters));
 296 return;
 297 }
 298#endif
286299 layer->setFilters(filters);
287300}
288301#endif
289302
 303#if ENABLE(CSS_SHADERS)
 304FilterOperations LayerTreeRenderer::injectCachedCustomFilterPrograms(const FilterOperations& filters) const
 305{
 306 FilterOperations outputFilters;
 307 for (size_t i = 0; i < filters.size(); ++i) {
 308 FilterOperation* operation = filters.operations().at(i).get();
 309 if (operation->getOperationType() != FilterOperation::CUSTOM) {
 310 outputFilters.operations().append(operation);
 311 continue;
 312 }
 313 WebCustomFilterOperation* customOperation = static_cast<WebCustomFilterOperation*>(operation);
 314 ASSERT(!customOperation->program());
 315 CustomFilterProgramMap::const_iterator iter = m_customFilterPrograms.find(customOperation->programId());
 316 if (iter == m_customFilterPrograms.end()) {
 317 ASSERT_NOT_REACHED();
 318 continue;
 319 }
 320 customOperation->setProgram(iter->value.get());
 321 outputFilters.operations().append(operation);
 322 }
 323 return outputFilters;
 324}
 325
 326void LayerTreeRenderer::createCustomFilterProgram(int id, const WebCore::CustomFilterProgramInfo& programInfo)
 327{
 328 ASSERT(!m_customFilterPrograms.contains(id));
 329 m_customFilterPrograms.set(id, WebCustomFilterProgram::create(programInfo.vertexShaderString(), programInfo.fragmentShaderString(), programInfo.programType(), programInfo.mixSettings(), programInfo.meshType()));
 330}
 331
 332void LayerTreeRenderer::removeCustomFilterProgram(int id)
 333{
 334 CustomFilterProgramMap::iterator iter = m_customFilterPrograms.find(id);
 335 if (iter == m_customFilterPrograms.end()) {
 336 ASSERT_NOT_REACHED();
 337 return;
 338 }
 339 if (m_textureMapper)
 340 m_textureMapper->removeCachedCustomFilterProgram(iter->value.get());
 341 m_customFilterPrograms.remove(iter);
 342}
 343#endif // ENABLE(CSS_SHADERS)
 344
290345void LayerTreeRenderer::setLayerState(WebLayerID id, const WebLayerInfo& layerInfo)
291346{
292347 ensureLayer(id);

Source/WebKit2/UIProcess/CoordinatedGraphics/LayerTreeRenderer.h

3838#include <wtf/HashSet.h>
3939#include <wtf/ThreadingPrimitives.h>
4040
 41namespace WebCore {
 42class CustomFilterProgram;
 43class CustomFilterProgramInfo;
 44}
 45
4146namespace WebKit {
4247
4348class CoordinatedBackingStore;

@@public:
8489#if ENABLE(CSS_FILTERS)
8590 void setLayerFilters(WebLayerID, const WebCore::FilterOperations&);
8691#endif
 92#if ENABLE(CSS_SHADERS)
 93 WebCore::FilterOperations injectCachedCustomFilterPrograms(const WebCore::FilterOperations& filters) const;
 94 void createCustomFilterProgram(int id, const WebCore::CustomFilterProgramInfo&);
 95 void removeCustomFilterProgram(int id);
 96#endif
8797
8898 void createTile(WebLayerID, int, float scale);
8999 void removeTile(WebLayerID, int);

@@private:
171181 WebCore::TextureMapper::AccelerationMode m_accelerationMode;
172182 WebCore::Color m_backgroundColor;
173183 bool m_setDrawsBackground;
 184
 185#if ENABLE(CSS_SHADERS)
 186 typedef HashMap<int, RefPtr<WebCore::CustomFilterProgram> > CustomFilterProgramMap;
 187 CustomFilterProgramMap m_customFilterPrograms;
 188#endif
174189};
175190
176191};

Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.cpp

@@void LayerTreeCoordinator::checkCustomFilterProgramProxies(const FilterOperation
355355 const ValidatedCustomFilterOperation* customOperation = static_cast<const ValidatedCustomFilterOperation*>(operation);
356356 ASSERT(customOperation->validatedProgram()->isInitialized());
357357 TextureMapperPlatformCompiledProgram* program = customOperation->validatedProgram()->platformCompiledProgram();
358  if (!program->client())
359  program->setClient(WebCustomFilterProgramProxy::create(this));
 358
 359 RefPtr<WebCustomFilterProgramProxy> customFilterProgramProxy;
 360 if (program->client())
 361 customFilterProgramProxy = static_cast<WebCustomFilterProgramProxy*>(program->client());
360362 else {
361  WebCustomFilterProgramProxy* customFilterProgramProxy = static_cast<WebCustomFilterProgramProxy*>(program->client());
362  if (!customFilterProgramProxy->client()) {
363  // Just in case the LayerTreeCoordinator was destroyed and recreated.
364  customFilterProgramProxy->setClient(this);
365  } else {
366  // If the client was not disconnected then this coordinator must be the client for it.
367  ASSERT(customFilterProgramProxy->client() == this);
368  }
 363 customFilterProgramProxy = WebCustomFilterProgramProxy::create();
 364 program->setClient(customFilterProgramProxy);
 365 }
 366
 367 if (!customFilterProgramProxy->client()) {
 368 customFilterProgramProxy->setClient(this);
 369 m_webPage->send(Messages::LayerTreeCoordinatorProxy::CreateCustomFilterProgram(customFilterProgramProxy->id(), customOperation->validatedProgram()->validatedProgramInfo()));
 370 } else {
 371 // If the client was not disconnected then this coordinator must be the client for it.
 372 ASSERT(customFilterProgramProxy->client() == this);
369373 }
370374 }
371375}

@@void LayerTreeCoordinator::removeCustomFilterProgramProxy(WebCustomFilterProgram
375379 // At this time the shader is not needed anymore, so we remove it from our set and
376380 // send a message to the other process to delete it.
377381 m_customFilterPrograms.remove(customFilterProgramProxy);
378  // FIXME: Send a message to delete the object on the UI process.
379  // https://bugs.webkit.org/show_bug.cgi?id=101801
 382 m_webPage->send(Messages::LayerTreeCoordinatorProxy::RemoveCustomFilterProgram(customFilterProgramProxy->id()));
380383}
381384
382385void LayerTreeCoordinator::disconnectCustomFilterPrograms()