Changeset 115838 in webkit
- Timestamp:
- May 2, 2012 8:30:29 AM (12 years ago)
- Location:
- trunk/Source
- Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r115829 r115838 1 2012-05-02 No'am Rosenthal <noam.rosenthal@nokia.com> 2 3 [Texmap] Enable css filters in TextureMapperGL 4 https://bugs.webkit.org/show_bug.cgi?id=75778 5 6 Reviewed by Jocelyn Turcotte. 7 8 Added support for color filters in TextureMapperGL. Blur and shadow would be done in a 9 different patch. 10 11 Modified BitmapTexture::applyFilters to return a texture, since GL cannot paint a texture 12 into itself. 13 Created a shader map for standard filters, since all of them work more or less the same way 14 with a single uniform. Added the colorization shaders based on the W3C filter spec, as 15 already implemented in FEFilterRenderer.cpp and FEColorMatrix.cpp. 16 We use two swapping textures to render the filters. 17 18 Covered by tests in css3/filters. 19 20 * platform/graphics/texmap/TextureMapper.cpp: 21 (WebCore::TextureMapper::acquireTextureFromPool): 22 * platform/graphics/texmap/TextureMapper.h: 23 (WebCore::BitmapTexture::applyFilters): 24 * platform/graphics/texmap/TextureMapperGL.cpp: 25 (WebCore::BitmapTextureGL::updateContents): 26 (WebCore): 27 (WebCore::TextureMapperGL::drawFiltered): 28 (WebCore::BitmapTextureGL::applyFilters): 29 (WebCore::BitmapTextureGL::bind): 30 * platform/graphics/texmap/TextureMapperGL.h: 31 (TextureMapperGL): 32 (BitmapTextureGL): 33 * platform/graphics/texmap/TextureMapperImageBuffer.cpp: 34 (WebCore::BitmapTextureImageBuffer::applyFilters): 35 * platform/graphics/texmap/TextureMapperImageBuffer.h: 36 (BitmapTextureImageBuffer): 37 * platform/graphics/texmap/TextureMapperLayer.cpp: 38 (WebCore::applyFilters): 39 (WebCore::TextureMapperLayer::syncCompositingStateSelf): 40 * platform/graphics/texmap/TextureMapperShaderManager.cpp: 41 (WebCore::TextureMapperShaderManager::~TextureMapperShaderManager): 42 (WebCore): 43 (WebCore::StandardFilterProgram::~StandardFilterProgram): 44 (WebCore::StandardFilterProgram::StandardFilterProgram): 45 (WebCore::StandardFilterProgram::create): 46 (WebCore::StandardFilterProgram::prepare): 47 (WebCore::TextureMapperShaderManager::getShaderForFilter): 48 * platform/graphics/texmap/TextureMapperShaderManager.h: 49 (WebCore): 50 (StandardFilterProgram): 51 (WebCore::StandardFilterProgram::vertexAttrib): 52 (WebCore::StandardFilterProgram::texCoordAttrib): 53 (WebCore::StandardFilterProgram::textureUniform): 54 (TextureMapperShaderManager): 55 1 56 2012-05-02 Philippe Normand <pnormand@igalia.com> 2 57 -
trunk/Source/WebCore/platform/graphics/texmap/TextureMapper.cpp
r110979 r115838 49 49 } 50 50 51 selectedTexture->reset(size );51 selectedTexture->reset(size, BitmapTexture::SupportsAlpha); 52 52 return selectedTexture; 53 53 } -
trunk/Source/WebCore/platform/graphics/texmap/TextureMapper.h
r113859 r115838 88 88 89 89 #if ENABLE(CSS_FILTERS) 90 virtual void applyFilters(const BitmapTexture& contentTexture, const FilterOperations&) {}90 virtual PassRefPtr<BitmapTexture> applyFilters(const BitmapTexture& contentTexture, const FilterOperations&) { return this; } 91 91 #endif 92 92 -
trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp
r115576 r115838 504 504 505 505 updateContents(imageData, targetRect, offset, bytesPerLine); 506 507 } 506 } 507 508 #if ENABLE(CSS_FILTERS) 509 void TextureMapperGL::drawFiltered(const BitmapTexture& sourceTexture, const BitmapTexture& contentTexture, const FilterOperation& filter) 510 { 511 // For standard filters, we always draw the whole texture without transformations. 512 RefPtr<StandardFilterProgram> program = data().sharedGLData().textureMapperShaderManager.getShaderForFilter(filter); 513 if (!program) { 514 drawTexture(sourceTexture, FloatRect(FloatPoint::zero(), sourceTexture.size()), TransformationMatrix(), 1, 0); 515 return; 516 } 517 GL_CMD(glEnableVertexAttribArray(program->vertexAttrib())); 518 GL_CMD(glEnableVertexAttribArray(program->texCoordAttrib())); 519 GL_CMD(glActiveTexture(GL_TEXTURE0)); 520 GL_CMD(glBindTexture(GL_TEXTURE_2D, static_cast<const BitmapTextureGL&>(sourceTexture).id())); 521 glUniform1i(program->textureUniform(), 0); 522 const GLfloat targetVertices[] = {-1, -1, 1, -1, 1, 1, -1, 1}; 523 const GLfloat sourceVertices[] = {0, 0, 1, 0, 1, 1, 0, 1}; 524 GL_CMD(glVertexAttribPointer(program->vertexAttrib(), 2, GL_FLOAT, GL_FALSE, 0, targetVertices)); 525 GL_CMD(glVertexAttribPointer(program->texCoordAttrib(), 2, GL_FLOAT, GL_FALSE, 0, sourceVertices)); 526 GL_CMD(glDisable(GL_BLEND)); 527 GL_CMD(glDrawArrays(GL_TRIANGLE_FAN, 0, 4)); 528 GL_CMD(glDisableVertexAttribArray(program->vertexAttrib())); 529 GL_CMD(glDisableVertexAttribArray(program->texCoordAttrib())); 530 } 531 532 PassRefPtr<BitmapTexture> BitmapTextureGL::applyFilters(const BitmapTexture& contentTexture, const FilterOperations& filters) 533 { 534 RefPtr<BitmapTexture> previousSurface = m_textureMapper->data().currentSurface; 535 536 RefPtr<BitmapTexture> source = this; 537 RefPtr<BitmapTexture> target = m_textureMapper->acquireTextureFromPool(m_textureSize); 538 for (int i = 0; i < filters.size(); ++i) { 539 const FilterOperation* filter = filters.at(i); 540 ASSERT(filter); 541 542 m_textureMapper->bindSurface(target.get()); 543 m_textureMapper->drawFiltered(i ? *source.get() : contentTexture, contentTexture, *filter); 544 std::swap(source, target); 545 } 546 547 m_textureMapper->bindSurface(previousSurface.get()); 548 return source; 549 } 550 #endif 508 551 509 552 static inline TransformationMatrix createProjectionMatrix(const IntSize& size, bool mirrored) -
trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.h
r115574 r115838 66 66 virtual AccelerationMode accelerationMode() const { return OpenGLMode; } 67 67 68 #if ENABLE(CSS_FILTERS) 69 void drawFiltered(const BitmapTexture& sourceTexture, const BitmapTexture& contentTexture, const FilterOperation&); 70 #endif 71 72 68 73 private: 69 74 … … 117 122 virtual bool isBackedByOpenGL() const { return true; } 118 123 124 #if ENABLE(CSS_FILTERS) 125 virtual PassRefPtr<BitmapTexture> applyFilters(const BitmapTexture& contentTexture, const FilterOperations&); 126 #endif 127 119 128 private: 120 129 GLuint m_id; -
trunk/Source/WebCore/platform/graphics/texmap/TextureMapperImageBuffer.cpp
r115123 r115838 111 111 112 112 #if ENABLE(CSS_FILTERS) 113 voidBitmapTextureImageBuffer::applyFilters(const BitmapTexture& contentTexture, const FilterOperations& filters)113 PassRefPtr<BitmapTexture> BitmapTextureImageBuffer::applyFilters(const BitmapTexture& contentTexture, const FilterOperations& filters) 114 114 { 115 115 RefPtr<FilterEffectRenderer> renderer = FilterEffectRenderer::create(); … … 123 123 renderer->apply(); 124 124 m_image->context()->drawImageBuffer(renderer->output(), ColorSpaceDeviceRGB, renderer->outputRect()); 125 return this; 125 126 } 126 127 #endif -
trunk/Source/WebCore/platform/graphics/texmap/TextureMapperImageBuffer.h
r113678 r115838 38 38 virtual void updateContents(const void*, const IntRect& target, const IntPoint& sourceOffset, int bytesPerLine); 39 39 #if ENABLE(CSS_FILTERS) 40 voidapplyFilters(const BitmapTexture&, const FilterOperations&);40 PassRefPtr<BitmapTexture> applyFilters(const BitmapTexture&, const FilterOperations&); 41 41 #endif 42 42 -
trunk/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp
r115629 r115838 305 305 } 306 306 307 filterSurface->applyFilters(*source, filters); 308 return filterSurface; 307 return filterSurface->applyFilters(*source, filters); 309 308 } 310 309 #endif … … 443 442 m_state.opacity = graphicsLayer->opacity(); 444 443 #if ENABLE(CSS_FILTERS) 445 m_state.filters = graphicsLayer->filters(); 444 if (changeMask & FilterChange) 445 m_state.filters = graphicsLayer->filters(); 446 446 #endif 447 447 m_fixedToViewport = graphicsLayer->fixedToViewport(); -
trunk/Source/WebCore/platform/graphics/texmap/TextureMapperShaderManager.cpp
r110438 r115838 207 207 TextureMapperShaderManager::~TextureMapperShaderManager() 208 208 { 209 m_textureMapperShaderProgramMap.clear(); 210 } 211 209 } 210 211 #if ENABLE(CSS_FILTERS) 212 StandardFilterProgram::~StandardFilterProgram() 213 { 214 glDetachShader(m_id, m_vertexShader); 215 glDeleteShader(m_vertexShader); 216 glDetachShader(m_id, m_fragmentShader); 217 glDeleteShader(m_fragmentShader); 218 glDeleteProgram(m_id); 219 } 220 221 StandardFilterProgram::StandardFilterProgram(FilterOperation::OperationType type) 222 : m_id(0) 223 { 224 const char* vertexShaderSource = 225 VERTEX_SHADER( 226 attribute vec4 a_vertex; 227 attribute vec4 a_texCoord; 228 varying highp vec2 v_texCoord; 229 void main(void) 230 { 231 v_texCoord = vec2(a_texCoord); 232 gl_Position = a_vertex; 233 } 234 ); 235 236 #define STANDARD_FILTER(x...) \ 237 OES2_PRECISION_DEFINITIONS\ 238 OES2_FRAGMENT_SHADER_DEFAULT_PRECISION\ 239 "varying highp vec2 v_texCoord;\n"\ 240 "uniform highp float u_amount;\n"\ 241 "uniform sampler2D u_texture;\n"\ 242 #x\ 243 "void main(void)\n { gl_FragColor = shade(texture2D(u_texture, v_texCoord)); }" 244 245 const char* fragmentShaderSource = 0; 246 switch (type) { 247 case FilterOperation::GRAYSCALE: 248 fragmentShaderSource = STANDARD_FILTER( 249 lowp vec4 shade(lowp vec4 color) 250 { 251 lowp float amount = 1.0 - u_amount; 252 return vec4((0.2126 + 0.7874 * amount) * color.r + (0.7152 - 0.7152 * amount) * color.g + (0.0722 - 0.0722 * amount) * color.b, 253 (0.2126 - 0.2126 * amount) * color.r + (0.7152 + 0.2848 * amount) * color.g + (0.0722 - 0.0722 * amount) * color.b, 254 (0.2126 - 0.2126 * amount) * color.r + (0.7152 - 0.7152 * amount) * color.g + (0.0722 + 0.9278 * amount) * color.b, 255 color.a); 256 } 257 ); 258 break; 259 case FilterOperation::SEPIA: 260 fragmentShaderSource = STANDARD_FILTER( 261 lowp vec4 shade(lowp vec4 color) 262 { 263 lowp float amount = 1.0 - u_amount; 264 return vec4((0.393 + 0.607 * amount) * color.r + (0.769 - 0.769 * amount) * color.g + (0.189 - 0.189 * amount) * color.b, 265 (0.349 - 0.349 * amount) * color.r + (0.686 + 0.314 * amount) * color.g + (0.168 - 0.168 * amount) * color.b, 266 (0.272 - 0.272 * amount) * color.r + (0.534 - 0.534 * amount) * color.g + (0.131 + 0.869 * amount) * color.b, 267 color.a); 268 } 269 ); 270 break; 271 case FilterOperation::SATURATE: 272 fragmentShaderSource = STANDARD_FILTER( 273 lowp vec4 shade(lowp vec4 color) 274 { 275 return vec4((0.213 + 0.787 * u_amount) * color.r + (0.715 - 0.715 * u_amount) * color.g + (0.072 - 0.072 * u_amount) * color.b, 276 (0.213 - 0.213 * u_amount) * color.r + (0.715 + 0.285 * u_amount) * color.g + (0.072 - 0.072 * u_amount) * color.b, 277 (0.213 - 0.213 * u_amount) * color.r + (0.715 - 0.715 * u_amount) * color.g + (0.072 + 0.928 * u_amount) * color.b, 278 color.a); 279 } 280 ); 281 break; 282 case FilterOperation::HUE_ROTATE: 283 fragmentShaderSource = STANDARD_FILTER( 284 lowp vec4 shade(lowp vec4 color) 285 { 286 highp float pi = 3.14159265358979323846; 287 highp float c = cos(u_amount * pi / 180.0); 288 highp float s = sin(u_amount * pi / 180.0); 289 return vec4(color.r * (0.213 + c * 0.787 - s * 0.213) + color.g * (0.715 - c * 0.715 - s * 0.715) + color.b * (0.072 - c * 0.072 + s * 0.928), 290 color.r * (0.213 - c * 0.213 + s * 0.143) + color.g * (0.715 + c * 0.285 + s * 0.140) + color.b * (0.072 - c * 0.072 - s * 0.283), 291 color.r * (0.213 - c * 0.213 - s * 0.787) + color.g * (0.715 - c * 0.715 + s * 0.715) + color.b * (0.072 + c * 0.928 + s * 0.072), 292 color.a); 293 } 294 ); 295 break; 296 case FilterOperation::INVERT: 297 fragmentShaderSource = STANDARD_FILTER( 298 lowp float invert(lowp float n) { return (1.0 - n) * u_amount + n * (1.0 - u_amount); } 299 lowp vec4 shade(lowp vec4 color) 300 { 301 return vec4(invert(color.r), invert(color.g), invert(color.b), color.a); 302 } 303 ); 304 break; 305 case FilterOperation::BRIGHTNESS: 306 fragmentShaderSource = STANDARD_FILTER( 307 lowp vec4 shade(lowp vec4 color) 308 { 309 return vec4(color.rgb * (1.0 + u_amount), color.a); 310 } 311 ); 312 break; 313 case FilterOperation::CONTRAST: 314 fragmentShaderSource = STANDARD_FILTER( 315 lowp float contrast(lowp float n) { return (n - 0.5) * u_amount + 0.5; } 316 lowp vec4 shade(lowp vec4 color) 317 { 318 return vec4(contrast(color.r), contrast(color.g), contrast(color.b), color.a); 319 } 320 ); 321 break; 322 case FilterOperation::OPACITY: 323 fragmentShaderSource = STANDARD_FILTER( 324 lowp vec4 shade(lowp vec4 color) 325 { 326 return vec4(color.r, color.g, color.b, color.a * u_amount); 327 } 328 ); 329 break; 330 default: 331 break; 332 } 333 334 if (!fragmentShaderSource) 335 return; 336 GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER); 337 GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); 338 glShaderSource(vertexShader, 1, &vertexShaderSource, 0); 339 glShaderSource(fragmentShader, 1, &fragmentShaderSource, 0); 340 GLchar log[100]; 341 GLint len; 342 GLuint programID = glCreateProgram(); 343 glCompileShader(vertexShader); 344 glCompileShader(fragmentShader); 345 glGetShaderInfoLog(fragmentShader, 100, &len, log); 346 glAttachShader(programID, vertexShader); 347 glAttachShader(programID, fragmentShader); 348 glLinkProgram(programID); 349 350 m_vertexAttrib = glGetAttribLocation(programID, "a_vertex"); 351 m_texCoordAttrib = glGetAttribLocation(programID, "a_texCoord"); 352 m_textureUniformLocation = glGetUniformLocation(programID, "u_texture"); 353 switch (type) { 354 case FilterOperation::GRAYSCALE: 355 case FilterOperation::SEPIA: 356 case FilterOperation::SATURATE: 357 case FilterOperation::HUE_ROTATE: 358 case FilterOperation::INVERT: 359 case FilterOperation::BRIGHTNESS: 360 case FilterOperation::CONTRAST: 361 case FilterOperation::OPACITY: 362 m_uniformLocations.amount = glGetUniformLocation(programID, "u_amount"); 363 break; 364 default: 365 break; 366 } 367 m_id = programID; 368 m_vertexShader = vertexShader; 369 m_fragmentShader = fragmentShader; 370 } 371 372 PassRefPtr<StandardFilterProgram> StandardFilterProgram::create(FilterOperation::OperationType type) 373 { 374 RefPtr<StandardFilterProgram> program = adoptRef(new StandardFilterProgram(type)); 375 if (!program->m_id) 376 return 0; 377 378 return program; 379 } 380 381 void StandardFilterProgram::prepare(const FilterOperation& operation) 382 { 383 double amount = 0; 384 switch (operation.getOperationType()) { 385 case FilterOperation::GRAYSCALE: 386 case FilterOperation::SEPIA: 387 case FilterOperation::SATURATE: 388 case FilterOperation::HUE_ROTATE: 389 amount = static_cast<const BasicColorMatrixFilterOperation&>(operation).amount(); 390 break; 391 case FilterOperation::INVERT: 392 case FilterOperation::BRIGHTNESS: 393 case FilterOperation::CONTRAST: 394 case FilterOperation::OPACITY: 395 amount = static_cast<const BasicComponentTransferFilterOperation&>(operation).amount(); 396 break; 397 default: 398 break; 399 } 400 glUseProgram(m_id); 401 glUniform1f(m_uniformLocations.amount, amount); 402 } 403 404 PassRefPtr<StandardFilterProgram> TextureMapperShaderManager::getShaderForFilter(const FilterOperation& filter) 405 { 406 RefPtr<StandardFilterProgram> program; 407 FilterOperation::OperationType type = filter.getOperationType(); 408 FilterMap::iterator iterator = m_filterMap.find(type); 409 if (iterator == m_filterMap.end()) { 410 program = StandardFilterProgram::create(type); 411 if (!program) 412 return 0; 413 414 m_filterMap.add(type, program); 415 } else 416 program = iterator->second; 417 418 program->prepare(filter); 419 return program; 420 } 421 422 #endif 212 423 }; 213 424 -
trunk/Source/WebCore/platform/graphics/texmap/TextureMapperShaderManager.h
r113746 r115838 31 31 #include <wtf/PassRefPtr.h> 32 32 #include <wtf/RefPtr.h> 33 34 #if ENABLE(CSS_FILTERS) 35 #include "FilterOperations.h" 36 #endif 33 37 34 38 namespace WebCore { … … 65 69 GLint m_opacityVariable; 66 70 }; 71 72 #if ENABLE(CSS_FILTERS) 73 class StandardFilterProgram : public RefCounted<StandardFilterProgram> { 74 public: 75 virtual ~StandardFilterProgram(); 76 virtual void prepare(const FilterOperation&); 77 static PassRefPtr<StandardFilterProgram> create(FilterOperation::OperationType); 78 GLuint vertexAttrib() const { return m_vertexAttrib; } 79 GLuint texCoordAttrib() const { return m_texCoordAttrib; } 80 GLuint textureUniform() const { return m_textureUniformLocation; } 81 private: 82 StandardFilterProgram(FilterOperation::OperationType); 83 GLuint m_id; 84 GLuint m_vertexShader; 85 GLuint m_fragmentShader; 86 GLuint m_vertexAttrib; 87 GLuint m_texCoordAttrib; 88 GLuint m_textureUniformLocation; 89 union { 90 GLuint amount; 91 GLuint stddev; 92 struct { 93 GLuint stddev; 94 GLuint color; 95 GLuint offset; 96 } shadow; 97 } m_uniformLocations; 98 }; 99 #endif 67 100 68 101 class TextureMapperShaderProgramSimple : public TextureMapperShaderProgram { … … 102 135 virtual ~TextureMapperShaderManager(); 103 136 137 PassRefPtr<StandardFilterProgram> getShaderForFilter(const FilterOperation&); 138 104 139 PassRefPtr<TextureMapperShaderProgram> getShaderProgram(ShaderType shaderType) 105 140 { … … 129 164 typedef HashMap<ShaderType, RefPtr<TextureMapperShaderProgram>, DefaultHash<int>::Hash, HashTraits<int> > TextureMapperShaderProgramMap; 130 165 TextureMapperShaderProgramMap m_textureMapperShaderProgramMap; 166 167 #if ENABLE(CSS_FILTERS) 168 typedef HashMap<FilterOperation::OperationType, RefPtr<StandardFilterProgram>, DefaultHash<int>::Hash, HashTraits<int> > FilterMap; 169 FilterMap m_filterMap; 170 #endif 171 131 172 }; 132 173 -
trunk/Source/WebKit2/ChangeLog
r115831 r115838 1 2012-05-02 No'am Rosenthal <noam.rosenthal@nokia.com> 2 3 [Texmap] Enable css filters in TextureMapperGL 4 https://bugs.webkit.org/show_bug.cgi?id=75778 5 6 Add the plumbing in the ui-side compositing code in Qt to support filters. 7 Serialize the filter operations for a layer when it's changed. 8 9 Reviewed by Jocelyn Turcotte. 10 11 * Shared/WebCoreArgumentCoders.cpp: 12 (CoreIPC): 13 (CoreIPC::::encode): 14 (CoreIPC::::decode): 15 * Shared/WebCoreArgumentCoders.h: 16 (WebCore): 17 * UIProcess/LayerTreeHostProxy.cpp: 18 (WebKit): 19 (WebKit::LayerTreeHostProxy::setCompositingLayerFilters): 20 * UIProcess/LayerTreeHostProxy.h: 21 (LayerTreeHostProxy): 22 * UIProcess/LayerTreeHostProxy.messages.in: 23 * UIProcess/WebLayerTreeRenderer.cpp: 24 (WebKit): 25 (WebKit::WebLayerTreeRenderer::setLayerFilters): 26 * UIProcess/WebLayerTreeRenderer.h: 27 (WebLayerTreeRenderer): 28 * WebProcess/WebCoreSupport/WebGraphicsLayer.cpp: 29 (WebCore): 30 (WebCore::WebGraphicsLayer::didChangeFilters): 31 (WebCore::WebGraphicsLayer::setFilters): 32 (WebCore::WebGraphicsLayer::syncFilters): 33 (WebCore::WebGraphicsLayer::syncCompositingStateForThisLayerOnly): 34 * WebProcess/WebCoreSupport/WebGraphicsLayer.h: 35 (WebGraphicsLayerClient): 36 (WebGraphicsLayer): 37 * WebProcess/WebPage/qt/LayerTreeHostQt.cpp: 38 (WebKit): 39 (WebKit::LayerTreeHostQt::syncLayerFilters): 40 * WebProcess/WebPage/qt/LayerTreeHostQt.h: 41 (LayerTreeHostQt): 42 1 43 2012-05-02 Simon Hausmann <simon.hausmann@nokia.com> 2 44 -
trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.cpp
r113974 r115838 62 62 #endif 63 63 64 #if USE(UI_SIDE_COMPOSITING) && ENABLE(CSS_FILTERS) 65 #include <WebCore/FilterOperations.h> 66 #endif 67 64 68 using namespace WebCore; 65 69 using namespace WebKit; … … 1242 1246 #endif 1243 1247 1248 #if USE(UI_SIDE_COMPOSITING) && ENABLE(CSS_FILTERS) 1249 void ArgumentCoder<WebCore::FilterOperations>::encode(ArgumentEncoder* encoder, const WebCore::FilterOperations& filters) 1250 { 1251 encoder->encodeUInt32(filters.size()); 1252 for (size_t i = 0; i < filters.size(); ++i) { 1253 const FilterOperation* filter = filters.at(i); 1254 FilterOperation::OperationType type = filter->getOperationType(); 1255 encoder->encodeEnum(type); 1256 switch (type) { 1257 case FilterOperation::GRAYSCALE: 1258 case FilterOperation::SEPIA: 1259 case FilterOperation::SATURATE: 1260 case FilterOperation::HUE_ROTATE: 1261 encoder->encodeDouble(static_cast<const BasicColorMatrixFilterOperation*>(filter)->amount()); 1262 break; 1263 case FilterOperation::INVERT: 1264 case FilterOperation::BRIGHTNESS: 1265 case FilterOperation::CONTRAST: 1266 case FilterOperation::OPACITY: 1267 encoder->encodeDouble(static_cast<const BasicComponentTransferFilterOperation*>(filter)->amount()); 1268 break; 1269 case FilterOperation::BLUR: 1270 ArgumentCoder<Length>::encode(encoder, static_cast<const BlurFilterOperation*>(filter)->stdDeviation()); 1271 break; 1272 case FilterOperation::DROP_SHADOW: { 1273 const DropShadowFilterOperation* shadow = static_cast<const DropShadowFilterOperation*>(filter); 1274 ArgumentCoder<IntPoint>::encode(encoder, shadow->location()); 1275 encoder->encodeInt32(shadow->stdDeviation()); 1276 ArgumentCoder<Color>::encode(encoder, shadow->color()); 1277 break; 1278 } 1279 default: 1280 break; 1281 } 1282 } 1283 } 1284 1285 bool ArgumentCoder<WebCore::FilterOperations>::decode(ArgumentDecoder* decoder, WebCore::FilterOperations& filters) 1286 { 1287 uint32_t size; 1288 if (!decoder->decodeUInt32(size)) 1289 return false; 1290 1291 Vector<RefPtr<FilterOperation> >& operations = filters.operations(); 1292 1293 for (size_t i = 0; i < size; ++i) { 1294 FilterOperation::OperationType type; 1295 RefPtr<FilterOperation> filter; 1296 if (!decoder->decodeEnum(type)) 1297 return false; 1298 1299 switch (type) { 1300 case FilterOperation::GRAYSCALE: 1301 case FilterOperation::SEPIA: 1302 case FilterOperation::SATURATE: 1303 case FilterOperation::HUE_ROTATE: { 1304 double value; 1305 if (!decoder->decodeDouble(value)) 1306 return false; 1307 filter = BasicColorMatrixFilterOperation::create(value, type); 1308 break; 1309 } 1310 case FilterOperation::INVERT: 1311 case FilterOperation::BRIGHTNESS: 1312 case FilterOperation::CONTRAST: 1313 case FilterOperation::OPACITY: { 1314 double value; 1315 if (!decoder->decodeDouble(value)) 1316 return false; 1317 filter = BasicComponentTransferFilterOperation::create(value, type); 1318 break; 1319 } 1320 case FilterOperation::BLUR: { 1321 Length length; 1322 if (!ArgumentCoder<Length>::decode(decoder, length)) 1323 return false; 1324 filter = BlurFilterOperation::create(length, type); 1325 break; 1326 } 1327 case FilterOperation::DROP_SHADOW: { 1328 IntPoint location; 1329 int32_t stdDeviation; 1330 Color color; 1331 if (!ArgumentCoder<IntPoint>::decode(decoder, location)) 1332 return false; 1333 if (!decoder->decodeInt32(stdDeviation)) 1334 return false; 1335 if (!ArgumentCoder<Color>::decode(decoder, color)) 1336 return false; 1337 filter = DropShadowFilterOperation::create(location, stdDeviation, color, type); 1338 break; 1339 } 1340 default: 1341 break; 1342 } 1343 1344 if (filter) 1345 operations.append(filter); 1346 } 1347 1348 return true; 1349 } 1244 1350 #endif 1245 1351 1352 #endif 1353 1246 1354 } // namespace CoreIPC -
trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.h
r113974 r115838 86 86 #endif 87 87 88 #if USE(UI_SIDE_COMPOSITING) && ENABLE(CSS_FILTERS) 89 namespace WebCore { 90 class FilterOperations; 91 } 92 #endif 93 88 94 namespace CoreIPC { 89 95 … … 302 308 #endif 303 309 310 #if USE(UI_SIDE_COMPOSITING) && ENABLE(CSS_FILTERS) 311 template<> struct ArgumentCoder<WebCore::FilterOperations> { 312 static void encode(ArgumentEncoder*, const WebCore::FilterOperations&); 313 static bool decode(ArgumentDecoder*, WebCore::FilterOperations&); 314 }; 315 #endif 316 304 317 #if USE(ACCELERATED_COMPOSITING) 305 318 template<> struct ArgumentCoder<WebCore::KeyframeValueList> { -
trunk/Source/WebKit2/UIProcess/LayerTreeHostProxy.cpp
r115696 r115838 106 106 } 107 107 108 #if ENABLE(CSS_FILTERS) 109 void LayerTreeHostProxy::setCompositingLayerFilters(WebLayerID id, const FilterOperations& filters) 110 { 111 dispatchUpdate(bind(&WebLayerTreeRenderer::setLayerFilters, m_renderer.get(), id, filters)); 112 } 113 #endif 114 108 115 void LayerTreeHostProxy::didRenderFrame() 109 116 { -
trunk/Source/WebKit2/UIProcess/LayerTreeHostProxy.h
r115696 r115838 51 51 void setCompositingLayerState(WebLayerID, const WebLayerInfo&); 52 52 void setCompositingLayerChildren(WebLayerID, const Vector<WebLayerID>&); 53 #if ENABLE(CSS_FILTERS) 54 void setCompositingLayerFilters(WebLayerID, const WebCore::FilterOperations&); 55 #endif 53 56 void deleteCompositingLayer(WebLayerID); 54 57 void setRootCompositingLayer(WebLayerID); -
trunk/Source/WebKit2/UIProcess/LayerTreeHostProxy.messages.in
r113791 r115838 22 22 SetCompositingLayerState(uint32_t id, WebKit::WebLayerInfo layerInfo) 23 23 SetCompositingLayerChildren(uint32_t id, Vector<uint32_t> children) 24 #if ENABLE(CSS_FILTERS) 25 SetCompositingLayerFilters(uint32_t id, WebCore::FilterOperations filters) 26 #endif 24 27 SetRootCompositingLayer(uint32_t id) 25 28 DeleteCompositingLayer(uint32_t id) -
trunk/Source/WebKit2/UIProcess/WebLayerTreeRenderer.cpp
r115696 r115838 214 214 } 215 215 216 #if ENABLE(CSS_FILTERS) 217 void WebLayerTreeRenderer::setLayerFilters(WebLayerID id, const FilterOperations& filters) 218 { 219 ensureLayer(id); 220 LayerMap::iterator it = m_layers.find(id); 221 ASSERT(it != m_layers.end()); 222 223 GraphicsLayer* layer = it->second; 224 layer->setFilters(filters); 225 } 226 #endif 227 216 228 void WebLayerTreeRenderer::setLayerState(WebLayerID id, const WebLayerInfo& layerInfo) 217 229 { -
trunk/Source/WebKit2/UIProcess/WebLayerTreeRenderer.h
r115696 r115838 78 78 void setLayerChildren(WebLayerID, const Vector<WebLayerID>&); 79 79 void setLayerState(WebLayerID, const WebLayerInfo&); 80 #if ENABLE(CSS_FILTERS) 81 void setLayerFilters(WebLayerID, const WebCore::FilterOperations&); 82 #endif 83 80 84 void createTile(WebLayerID, int, float scale); 81 85 void removeTile(WebLayerID, int); -
trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebGraphicsLayer.cpp
r114705 r115838 75 75 } 76 76 77 #if ENABLE(CSS_FILTERS) 78 void WebGraphicsLayer::didChangeFilters() 79 { 80 m_shouldSyncFilters = true; 81 if (client()) 82 client()->notifySyncRequired(this); 83 } 84 #endif 85 77 86 void WebGraphicsLayer::setShouldUpdateVisibleRect() 78 87 { … … 309 318 setContentsToImage(image.get()); 310 319 } 320 321 #if ENABLE(CSS_FILTERS) 322 bool WebGraphicsLayer::setFilters(const FilterOperations& newFilters) 323 { 324 if (filters() == newFilters) 325 return true; 326 didChangeFilters(); 327 return GraphicsLayer::setFilters(newFilters); 328 } 329 #endif 330 311 331 312 332 void WebGraphicsLayer::setContentsToImage(Image* image) … … 413 433 m_webGraphicsLayerClient->syncLayerChildren(m_id, childIDs); 414 434 } 435 436 #if ENABLE(CSS_FILTERS) 437 void WebGraphicsLayer::syncFilters() 438 { 439 if (!m_shouldSyncFilters) 440 return; 441 m_shouldSyncFilters = false; 442 m_webGraphicsLayerClient->syncLayerFilters(m_id, filters()); 443 } 444 #endif 415 445 416 446 void WebGraphicsLayer::syncLayerState() … … 453 483 syncChildren(); 454 484 syncLayerState(); 485 #if ENABLE(CSS_FILTERS) 486 syncFilters(); 487 #endif 455 488 updateContentBuffers(); 456 489 } -
trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebGraphicsLayer.h
r113791 r115838 58 58 virtual void syncLayerState(WebLayerID, const WebLayerInfo&) = 0; 59 59 virtual void syncLayerChildren(WebLayerID, const Vector<WebLayerID>&) = 0; 60 #if ENABLE(CSS_FILTERS) 61 virtual void syncLayerFilters(WebLayerID, const WebCore::FilterOperations&) = 0; 62 #endif 60 63 virtual void attachLayer(WebCore::WebGraphicsLayer*) = 0; 61 64 virtual void detachLayer(WebCore::WebGraphicsLayer*) = 0; … … 105 108 virtual void syncCompositingState(const FloatRect&); 106 109 virtual void syncCompositingStateForThisLayerOnly(); 110 #if ENABLE(CSS_FILTERS) 111 bool setFilters(const FilterOperations&); 112 #endif 107 113 108 114 void setRootLayer(bool); … … 139 145 void syncChildren(); 140 146 void syncLayerState(); 147 #if ENABLE(CSS_FILTERS) 148 void syncFilters(); 149 #endif 141 150 void ensureImageBackingStore(); 142 151 … … 158 167 bool m_shouldSyncLayerState: 1; 159 168 bool m_shouldSyncChildren: 1; 169 bool m_shouldSyncFilters: 1; 160 170 bool m_fixedToViewport : 1; 161 171 … … 164 174 void didChangeLayerState(); 165 175 void didChangeChildren(); 176 #if ENABLE(CSS_FILTERS) 177 void didChangeFilters(); 178 #endif 179 166 180 void createBackingStore(); 167 181 -
trunk/Source/WebKit2/WebProcess/WebPage/qt/LayerTreeHostQt.cpp
r115310 r115838 257 257 } 258 258 259 #if ENABLE(CSS_FILTERS) 260 void LayerTreeHostQt::syncLayerFilters(WebLayerID id, const FilterOperations& filters) 261 { 262 m_shouldSyncFrame = true; 263 m_webPage->send(Messages::LayerTreeHostProxy::SetCompositingLayerFilters(id, filters)); 264 } 265 #endif 266 259 267 void LayerTreeHostQt::attachLayer(WebGraphicsLayer* layer) 260 268 { -
trunk/Source/WebKit2/WebProcess/WebPage/qt/LayerTreeHostQt.h
r115310 r115838 77 77 virtual void syncLayerState(WebLayerID, const WebLayerInfo&); 78 78 virtual void syncLayerChildren(WebLayerID, const Vector<WebLayerID>&); 79 #if ENABLE(CSS_FILTERS) 80 virtual void syncLayerFilters(WebLayerID, const WebCore::FilterOperations&); 81 #endif 79 82 virtual void attachLayer(WebCore::WebGraphicsLayer*); 80 83 virtual void detachLayer(WebCore::WebGraphicsLayer*);
Note: See TracChangeset
for help on using the changeset viewer.