Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: Source/core/platform/graphics/skia/NativeImageSkia.cpp

Issue 23947005: Implement CSS luminance masking using skia SkLumaMaskXfermode class. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2008, Google Inc. All rights reserved. 2 * Copyright (c) 2008, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 27 matching lines...) Expand all
38 #include "core/platform/graphics/FloatSize.h" 38 #include "core/platform/graphics/FloatSize.h"
39 #include "core/platform/graphics/GraphicsContext.h" 39 #include "core/platform/graphics/GraphicsContext.h"
40 #include "core/platform/graphics/Image.h" 40 #include "core/platform/graphics/Image.h"
41 #include "core/platform/graphics/chromium/DeferredImageDecoder.h" 41 #include "core/platform/graphics/chromium/DeferredImageDecoder.h"
42 #include "core/platform/graphics/skia/SkiaUtils.h" 42 #include "core/platform/graphics/skia/SkiaUtils.h"
43 #include "skia/ext/image_operations.h" 43 #include "skia/ext/image_operations.h"
44 #include "third_party/skia/include/core/SkMatrix.h" 44 #include "third_party/skia/include/core/SkMatrix.h"
45 #include "third_party/skia/include/core/SkPaint.h" 45 #include "third_party/skia/include/core/SkPaint.h"
46 #include "third_party/skia/include/core/SkScalar.h" 46 #include "third_party/skia/include/core/SkScalar.h"
47 #include "third_party/skia/include/core/SkShader.h" 47 #include "third_party/skia/include/core/SkShader.h"
48 #include "third_party/skia/include/effects/SkLumaXfermode.h"
48 49
49 #include <limits> 50 #include <limits>
50 #include <math.h> 51 #include <math.h>
51 52
52 namespace WebCore { 53 namespace WebCore {
53 54
54 static bool nearlyIntegral(float value) 55 static bool nearlyIntegral(float value)
55 { 56 {
56 return fabs(value - floorf(value)) < std::numeric_limits<float>::epsilon(); 57 return fabs(value - floorf(value)) < std::numeric_limits<float>::epsilon();
57 } 58 }
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 318
318 static bool hasNon90rotation(GraphicsContext* context) 319 static bool hasNon90rotation(GraphicsContext* context)
319 { 320 {
320 return !context->getTotalMatrix().rectStaysRect(); 321 return !context->getTotalMatrix().rectStaysRect();
321 } 322 }
322 323
323 void NativeImageSkia::draw(GraphicsContext* context, const SkRect& srcRect, cons t SkRect& destRect, PassRefPtr<SkXfermode> compOp) const 324 void NativeImageSkia::draw(GraphicsContext* context, const SkRect& srcRect, cons t SkRect& destRect, PassRefPtr<SkXfermode> compOp) const
324 { 325 {
325 TRACE_EVENT0("skia", "NativeImageSkia::draw"); 326 TRACE_EVENT0("skia", "NativeImageSkia::draw");
326 SkPaint paint; 327 SkPaint paint;
327 paint.setXfermode(compOp.get()); 328 if (context->drawLuminanceMask()) {
eseidel 2013/09/19 15:10:37 I believe blink style says {} are avoided when the
329 paint.setXfermode(SkLumaMaskXfermode::Create(SkXfermode::kSrcOver_Mode)) ;
330 } else {
331 paint.setXfermode(compOp.get());
332 }
328 paint.setAlpha(context->getNormalizedAlpha()); 333 paint.setAlpha(context->getNormalizedAlpha());
329 paint.setLooper(context->drawLooper()); 334 paint.setLooper(context->drawLooper());
330 // only antialias if we're rotated or skewed 335 // only antialias if we're rotated or skewed
331 paint.setAntiAlias(hasNon90rotation(context)); 336 paint.setAntiAlias(hasNon90rotation(context));
332 337
333 ResamplingMode resampling; 338 ResamplingMode resampling;
334 if (context->isAccelerated()) { 339 if (context->isAccelerated()) {
335 resampling = LinearResampling; 340 resampling = LinearResampling;
336 } else if (context->printing()) { 341 } else if (context->printing()) {
337 resampling = NoResampling; 342 resampling = NoResampling;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 // origin of the destination rect, which is what WebKit expects. Skia uses 459 // origin of the destination rect, which is what WebKit expects. Skia uses
455 // the coordinate system origin as the base for the pattern. If WebKit wants 460 // the coordinate system origin as the base for the pattern. If WebKit wants
456 // a shifted image, it will shift it from there using the shaderTransform. 461 // a shifted image, it will shift it from there using the shaderTransform.
457 float adjustedX = phase.x() + normSrcRect.x() * scale.width(); 462 float adjustedX = phase.x() + normSrcRect.x() * scale.width();
458 float adjustedY = phase.y() + normSrcRect.y() * scale.height(); 463 float adjustedY = phase.y() + normSrcRect.y() * scale.height();
459 shaderTransform.postTranslate(SkFloatToScalar(adjustedX), SkFloatToScalar(ad justedY)); 464 shaderTransform.postTranslate(SkFloatToScalar(adjustedX), SkFloatToScalar(ad justedY));
460 shader->setLocalMatrix(shaderTransform); 465 shader->setLocalMatrix(shaderTransform);
461 466
462 SkPaint paint; 467 SkPaint paint;
463 paint.setShader(shader.get()); 468 paint.setShader(shader.get());
464 paint.setXfermode(WebCoreCompositeToSkiaComposite(compositeOp, blendMode).ge t()); 469 if (context->drawLuminanceMask()) {
470 paint.setXfermode(SkLumaMaskXfermode::Create(SkXfermode::kSrcOver_Mode)) ;
471 } else {
472 paint.setXfermode(WebCoreCompositeToSkiaComposite(compositeOp, blendMode ).get());
473 }
465 474
466 paint.setFilterBitmap(resampling == LinearResampling); 475 paint.setFilterBitmap(resampling == LinearResampling);
467 if (useBicubicFilter) 476 if (useBicubicFilter)
468 paint.setFilterLevel(SkPaint::kHigh_FilterLevel); 477 paint.setFilterLevel(SkPaint::kHigh_FilterLevel);
469 478
470 context->drawRect(destRect, paint); 479 context->drawRect(destRect, paint);
471 } 480 }
472 481
473 bool NativeImageSkia::shouldCacheResampling(const SkISize& scaledImageSize, cons t SkIRect& scaledImageSubset) const 482 bool NativeImageSkia::shouldCacheResampling(const SkISize& scaledImageSize, cons t SkIRect& scaledImageSubset) const
474 { 483 {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 SkIRect NativeImageSkia::ImageResourceInfo::rectInSubset(const SkIRect& otherSca ledImageSubset) 545 SkIRect NativeImageSkia::ImageResourceInfo::rectInSubset(const SkIRect& otherSca ledImageSubset)
537 { 546 {
538 if (!scaledImageSubset.contains(otherScaledImageSubset)) 547 if (!scaledImageSubset.contains(otherScaledImageSubset))
539 return SkIRect::MakeEmpty(); 548 return SkIRect::MakeEmpty();
540 SkIRect subsetRect = otherScaledImageSubset; 549 SkIRect subsetRect = otherScaledImageSubset;
541 subsetRect.offset(-scaledImageSubset.x(), -scaledImageSubset.y()); 550 subsetRect.offset(-scaledImageSubset.x(), -scaledImageSubset.y());
542 return subsetRect; 551 return subsetRect;
543 } 552 }
544 553
545 } // namespace WebCore 554 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/platform/graphics/GraphicsContextState.h ('k') | Source/core/rendering/RenderBoxModelObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698