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

Side by Side Diff: Source/platform/graphics/filters/FEBlend.cpp

Issue 604373003: [WIP] Supporting arm_neon_optional flag for blink platform. Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 1 month 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) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org>
4 * Copyright (C) 2005 Eric Seidel <eric@webkit.org> 4 * Copyright (C) 2005 Eric Seidel <eric@webkit.org>
5 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> 5 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
6 * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies) 6 * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
7 * Copyright (C) 2013 Google Inc. All rights reserved. 7 * Copyright (C) 2013 Google Inc. All rights reserved.
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 10 matching lines...) Expand all
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA. 22 * Boston, MA 02110-1301, USA.
23 */ 23 */
24 24
25 #include "config.h" 25 #include "config.h"
26 #include "platform/graphics/filters/FEBlend.h" 26 #include "platform/graphics/filters/FEBlend.h"
27 27
28 #include "SkBitmapSource.h" 28 #include "SkBitmapSource.h"
29 #include "SkXfermodeImageFilter.h" 29 #include "SkXfermodeImageFilter.h"
30 #include "platform/graphics/GraphicsContext.h" 30 #include "platform/graphics/GraphicsContext.h"
31 #if HAVE(ARM_NEON_INTRINSICS)
31 #include "platform/graphics/cpu/arm/filters/FEBlendNEON.h" 32 #include "platform/graphics/cpu/arm/filters/FEBlendNEON.h"
33 #endif
32 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" 34 #include "platform/graphics/filters/SkiaImageFilterBuilder.h"
33 #include "platform/graphics/skia/NativeImageSkia.h" 35 #include "platform/graphics/skia/NativeImageSkia.h"
34 #include "platform/graphics/skia/SkiaUtils.h" 36 #include "platform/graphics/skia/SkiaUtils.h"
35 #include "platform/text/TextStream.h" 37 #include "platform/text/TextStream.h"
36 #include "wtf/Uint8ClampedArray.h" 38 #include "wtf/Uint8ClampedArray.h"
37 39
38 typedef unsigned char (*BlendType)(unsigned char colorA, unsigned char colorB, u nsigned char alphaA, unsigned char alphaB); 40 typedef unsigned char (*BlendType)(unsigned char colorA, unsigned char colorB, u nsigned char alphaA, unsigned char alphaB);
39 41
40 namespace blink { 42 namespace blink {
41 43
(...skipping 14 matching lines...) Expand all
56 } 58 }
57 59
58 bool FEBlend::setBlendMode(WebBlendMode mode) 60 bool FEBlend::setBlendMode(WebBlendMode mode)
59 { 61 {
60 if (m_mode == mode) 62 if (m_mode == mode)
61 return false; 63 return false;
62 m_mode = mode; 64 m_mode = mode;
63 return true; 65 return true;
64 } 66 }
65 67
66 #if HAVE(ARM_NEON_INTRINSICS) 68
67 bool FEBlend::applySoftwareNEON() 69 void FEBlend::applySoftwareInternal()
68 { 70 {
69 if (m_mode != WebBlendModeNormal 71 ImageBuffer* resultImage = createImageBufferResult();
70 && m_mode != WebBlendModeMultiply 72 if (!resultImage)
71 && m_mode != WebBlendModeScreen 73 return;
72 && m_mode != WebBlendModeDarken
73 && m_mode != WebBlendModeLighten)
74 return false;
75
76 Uint8ClampedArray* dstPixelArray = createPremultipliedImageResult();
77 if (!dstPixelArray)
78 return true;
79 74
80 FilterEffect* in = inputEffect(0); 75 FilterEffect* in = inputEffect(0);
81 FilterEffect* in2 = inputEffect(1); 76 FilterEffect* in2 = inputEffect(1);
82 77
83 IntRect effectADrawingRect = requestedRegionOfInputImageData(in->absolutePai ntRect());
84 RefPtr<Uint8ClampedArray> srcPixelArrayA = in->asPremultipliedImage(effectAD rawingRect);
85
86 IntRect effectBDrawingRect = requestedRegionOfInputImageData(in2->absolutePa intRect());
87 RefPtr<Uint8ClampedArray> srcPixelArrayB = in2->asPremultipliedImage(effectB DrawingRect);
88
89 unsigned pixelArrayLength = srcPixelArrayA->length();
90 ASSERT(pixelArrayLength == srcPixelArrayB->length());
91
92 if (pixelArrayLength >= 8) {
93 platformApplyNEON(srcPixelArrayA->data(), srcPixelArrayB->data(), dstPix elArray->data(), pixelArrayLength);
94 } else {
95 // If there is just one pixel we expand it to two.
96 ASSERT(pixelArrayLength > 0);
97 uint32_t sourceA[2] = {0, 0};
98 uint32_t sourceBAndDest[2] = {0, 0};
99
100 sourceA[0] = reinterpret_cast<uint32_t*>(srcPixelArrayA->data())[0];
101 sourceBAndDest[0] = reinterpret_cast<uint32_t*>(srcPixelArrayB->data())[ 0];
102 platformApplyNEON(reinterpret_cast<uint8_t*>(sourceA), reinterpret_cast< uint8_t*>(sourceBAndDest), reinterpret_cast<uint8_t*>(sourceBAndDest), 8);
103 reinterpret_cast<uint32_t*>(dstPixelArray->data())[0] = sourceBAndDest[0 ];
104 }
105 return true;
106 }
107 #endif
108
109 void FEBlend::applySoftware()
110 {
111 #if HAVE(ARM_NEON_INTRINSICS)
112 if (applySoftwareNEON())
113 return;
114 #endif
115
116 FilterEffect* in = inputEffect(0);
117 FilterEffect* in2 = inputEffect(1);
118
119 ImageBuffer* resultImage = createImageBufferResult();
120 if (!resultImage)
121 return;
122 GraphicsContext* filterContext = resultImage->context(); 78 GraphicsContext* filterContext = resultImage->context();
123 79
124 ImageBuffer* imageBuffer = in->asImageBuffer(); 80 ImageBuffer* imageBuffer = in->asImageBuffer();
125 ImageBuffer* imageBuffer2 = in2->asImageBuffer(); 81 ImageBuffer* imageBuffer2 = in2->asImageBuffer();
126 ASSERT(imageBuffer); 82 ASSERT(imageBuffer);
127 ASSERT(imageBuffer2); 83 ASSERT(imageBuffer2);
128 84
129 filterContext->drawImageBuffer(imageBuffer2, drawingRegionOfInputImage(in2-> absolutePaintRect())); 85 filterContext->drawImageBuffer(imageBuffer2, drawingRegionOfInputImage(in2-> absolutePaintRect()));
130 filterContext->drawImageBuffer(imageBuffer, drawingRegionOfInputImage(in->ab solutePaintRect()), 0, CompositeSourceOver, m_mode); 86 filterContext->drawImageBuffer(imageBuffer, drawingRegionOfInputImage(in->ab solutePaintRect()), 0, CompositeSourceOver, m_mode);
131 } 87 }
132 88
89 void FEBlend::applySoftware()
90 {
91 WTF_CPU_ARM_NEON_WRAP(applySoftwareInternal)();
92 }
93
133 PassRefPtr<SkImageFilter> FEBlend::createImageFilter(SkiaImageFilterBuilder* bui lder) 94 PassRefPtr<SkImageFilter> FEBlend::createImageFilter(SkiaImageFilterBuilder* bui lder)
134 { 95 {
135 RefPtr<SkImageFilter> foreground(builder->build(inputEffect(0), operatingCol orSpace())); 96 RefPtr<SkImageFilter> foreground(builder->build(inputEffect(0), operatingCol orSpace()));
136 RefPtr<SkImageFilter> background(builder->build(inputEffect(1), operatingCol orSpace())); 97 RefPtr<SkImageFilter> background(builder->build(inputEffect(1), operatingCol orSpace()));
137 RefPtr<SkXfermode> mode(adoptRef(SkXfermode::Create(WebCoreCompositeToSkiaCo mposite(CompositeSourceOver, m_mode)))); 98 RefPtr<SkXfermode> mode(adoptRef(SkXfermode::Create(WebCoreCompositeToSkiaCo mposite(CompositeSourceOver, m_mode))));
138 SkImageFilter::CropRect cropRect = getCropRect(builder->cropOffset()); 99 SkImageFilter::CropRect cropRect = getCropRect(builder->cropOffset());
139 return adoptRef(SkXfermodeImageFilter::Create(mode.get(), background.get(), foreground.get(), &cropRect)); 100 return adoptRef(SkXfermodeImageFilter::Create(mode.get(), background.get(), foreground.get(), &cropRect));
140 } 101 }
141 102
142 TextStream& FEBlend::externalRepresentation(TextStream& ts, int indent) const 103 TextStream& FEBlend::externalRepresentation(TextStream& ts, int indent) const
143 { 104 {
144 writeIndent(ts, indent); 105 writeIndent(ts, indent);
145 ts << "[feBlend"; 106 ts << "[feBlend";
146 FilterEffect::externalRepresentation(ts); 107 FilterEffect::externalRepresentation(ts);
147 ts << " mode=\"" << (m_mode == WebBlendModeNormal ? "normal" : compositeOper atorName(CompositeSourceOver, m_mode)) << "\"]\n"; 108 ts << " mode=\"" << (m_mode == WebBlendModeNormal ? "normal" : compositeOper atorName(CompositeSourceOver, m_mode)) << "\"]\n";
148 inputEffect(0)->externalRepresentation(ts, indent + 1); 109 inputEffect(0)->externalRepresentation(ts, indent + 1);
149 inputEffect(1)->externalRepresentation(ts, indent + 1); 110 inputEffect(1)->externalRepresentation(ts, indent + 1);
150 return ts; 111 return ts;
151 } 112 }
152 113
153 } // namespace blink 114 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/graphics/filters/FEBlend.h ('k') | Source/platform/graphics/filters/FEComposite.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698