OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkPixelXorXfermode.h" | 8 #include "SkPixelXorXfermode.h" |
9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
10 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 113 |
114 fragBuilder->codeAppend("}"); | 114 fragBuilder->codeAppend("}"); |
115 | 115 |
116 fragBuilder->codeAppendf("%s = vec4(red/255.0, green/255.0, blue/255.0, 1.0)
;", outputColor); | 116 fragBuilder->codeAppendf("%s = vec4(red/255.0, green/255.0, blue/255.0, 1.0)
;", outputColor); |
117 } | 117 } |
118 | 118 |
119 class GLPixelXorFP; | 119 class GLPixelXorFP; |
120 | 120 |
121 class PixelXorFP : public GrFragmentProcessor { | 121 class PixelXorFP : public GrFragmentProcessor { |
122 public: | 122 public: |
123 static const GrFragmentProcessor* Create(SkColor opColor, const GrFragmentPr
ocessor* dst) { | 123 static const GrFragmentProcessor* Create(SkPMColor opColor, const GrFragment
Processor* dst) { |
124 return new PixelXorFP(opColor, dst); | 124 return new PixelXorFP(opColor, dst); |
125 } | 125 } |
126 | 126 |
127 ~PixelXorFP() override {}; | 127 ~PixelXorFP() override {}; |
128 | 128 |
129 const char* name() const override { return "PixelXor"; } | 129 const char* name() const override { return "PixelXor"; } |
130 | 130 |
131 SkString dumpInfo() const override { | 131 SkString dumpInfo() const override { |
132 SkString str; | 132 SkString str; |
133 str.appendf("Color: 0x%08x", fOpColor); | 133 str.appendf("Color: 0x%08x", fOpColor); |
134 return str; | 134 return str; |
135 } | 135 } |
136 | 136 |
137 SkColor opColor() const { return fOpColor; } | 137 SkPMColor opColor() const { return fOpColor; } |
138 | 138 |
139 private: | 139 private: |
140 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; | 140 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
141 | 141 |
142 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b)
const override; | 142 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b)
const override; |
143 | 143 |
144 bool onIsEqual(const GrFragmentProcessor& fpBase) const override { | 144 bool onIsEqual(const GrFragmentProcessor& fpBase) const override { |
145 const PixelXorFP& fp = fpBase.cast<PixelXorFP>(); | 145 const PixelXorFP& fp = fpBase.cast<PixelXorFP>(); |
146 return fOpColor == fp.fOpColor; | 146 return fOpColor == fp.fOpColor; |
147 } | 147 } |
148 | 148 |
149 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { | 149 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { |
150 inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); | 150 inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); |
151 } | 151 } |
152 | 152 |
153 PixelXorFP(SkColor opColor, const GrFragmentProcessor* dst) | 153 PixelXorFP(SkPMColor opColor, const GrFragmentProcessor* dst) |
154 : fOpColor(opColor) { | 154 : fOpColor(opColor) { |
155 this->initClassID<PixelXorFP>(); | 155 this->initClassID<PixelXorFP>(); |
156 | 156 |
157 SkASSERT(dst); | 157 SkASSERT(dst); |
158 SkDEBUGCODE(int dstIndex = )this->registerChildProcessor(dst); | 158 SkDEBUGCODE(int dstIndex = )this->registerChildProcessor(dst); |
159 SkASSERT(0 == dstIndex); | 159 SkASSERT(0 == dstIndex); |
160 } | 160 } |
161 | 161 |
162 SkColor fOpColor; | 162 SkPMColor fOpColor; |
163 | 163 |
164 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 164 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
165 typedef GrFragmentProcessor INHERITED; | 165 typedef GrFragmentProcessor INHERITED; |
166 }; | 166 }; |
167 | 167 |
168 /////////////////////////////////////////////////////////////////////////////// | 168 /////////////////////////////////////////////////////////////////////////////// |
169 | 169 |
170 class GLPixelXorFP : public GrGLSLFragmentProcessor { | 170 class GLPixelXorFP : public GrGLSLFragmentProcessor { |
171 public: | 171 public: |
172 GLPixelXorFP(const PixelXorFP&) {} | 172 GLPixelXorFP(const PixelXorFP&) {} |
(...skipping 13 matching lines...) Expand all Loading... |
186 add_pixelxor_code(fragBuilder, args.fInputColor, dstColor.c_str(), | 186 add_pixelxor_code(fragBuilder, args.fInputColor, dstColor.c_str(), |
187 args.fOutputColor, kOpColorUni); | 187 args.fOutputColor, kOpColorUni); |
188 } | 188 } |
189 | 189 |
190 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuil
der*) { } | 190 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuil
der*) { } |
191 | 191 |
192 protected: | 192 protected: |
193 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& pro
c) override { | 193 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& pro
c) override { |
194 const PixelXorFP& pixXor = proc.cast<PixelXorFP>(); | 194 const PixelXorFP& pixXor = proc.cast<PixelXorFP>(); |
195 pdman.set3f(fOpColorUni, | 195 pdman.set3f(fOpColorUni, |
196 SkColorGetR(pixXor.opColor())/255.0f, | 196 SkGetPackedR32(pixXor.opColor())/255.0f, |
197 SkColorGetG(pixXor.opColor())/255.0f, | 197 SkGetPackedG32(pixXor.opColor())/255.0f, |
198 SkColorGetB(pixXor.opColor())/255.0f); | 198 SkGetPackedB32(pixXor.opColor())/255.0f); |
199 } | 199 } |
200 | 200 |
201 private: | 201 private: |
202 GrGLSLProgramDataManager::UniformHandle fOpColorUni; | 202 GrGLSLProgramDataManager::UniformHandle fOpColorUni; |
203 | 203 |
204 typedef GrGLSLFragmentProcessor INHERITED; | 204 typedef GrGLSLFragmentProcessor INHERITED; |
205 }; | 205 }; |
206 | 206 |
207 /////////////////////////////////////////////////////////////////////////////// | 207 /////////////////////////////////////////////////////////////////////////////// |
208 | 208 |
209 GrGLSLFragmentProcessor* PixelXorFP::onCreateGLSLInstance() const { | 209 GrGLSLFragmentProcessor* PixelXorFP::onCreateGLSLInstance() const { |
210 return new GLPixelXorFP(*this); | 210 return new GLPixelXorFP(*this); |
211 } | 211 } |
212 | 212 |
213 void PixelXorFP::onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBui
lder* b) const { | 213 void PixelXorFP::onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBui
lder* b) const { |
214 GLPixelXorFP::GenKey(*this, caps, b); | 214 GLPixelXorFP::GenKey(*this, caps, b); |
215 } | 215 } |
216 | 216 |
217 const GrFragmentProcessor* PixelXorFP::TestCreate(GrProcessorTestData* d) { | 217 const GrFragmentProcessor* PixelXorFP::TestCreate(GrProcessorTestData* d) { |
218 SkColor color = d->fRandom->nextU(); | 218 SkColor color = d->fRandom->nextU(); |
219 | 219 |
220 SkAutoTUnref<const GrFragmentProcessor> dst(GrProcessorUnitTest::CreateChild
FP(d)); | 220 SkAutoTUnref<const GrFragmentProcessor> dst(GrProcessorUnitTest::CreateChild
FP(d)); |
221 return new PixelXorFP(color, dst); | 221 return new PixelXorFP(SkPreMultiplyColor(color), dst); |
222 } | 222 } |
223 | 223 |
224 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(PixelXorFP); | 224 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(PixelXorFP); |
225 | 225 |
226 /////////////////////////////////////////////////////////////////////////////// | 226 /////////////////////////////////////////////////////////////////////////////// |
227 // Xfer Processor | 227 // Xfer Processor |
228 /////////////////////////////////////////////////////////////////////////////// | 228 /////////////////////////////////////////////////////////////////////////////// |
229 | 229 |
230 class PixelXorXP : public GrXferProcessor { | 230 class PixelXorXP : public GrXferProcessor { |
231 public: | 231 public: |
232 PixelXorXP(const DstTexture* dstTexture, bool hasMixedSamples, SkColor opCol
or) | 232 PixelXorXP(const DstTexture* dstTexture, bool hasMixedSamples, SkPMColor opC
olor) |
233 : INHERITED(dstTexture, true, hasMixedSamples) | 233 : INHERITED(dstTexture, true, hasMixedSamples) |
234 , fOpColor(opColor) { | 234 , fOpColor(opColor) { |
235 this->initClassID<PixelXorXP>(); | 235 this->initClassID<PixelXorXP>(); |
236 } | 236 } |
237 | 237 |
238 const char* name() const override { return "PixelXor"; } | 238 const char* name() const override { return "PixelXor"; } |
239 | 239 |
240 GrGLSLXferProcessor* createGLSLInstance() const override; | 240 GrGLSLXferProcessor* createGLSLInstance() const override; |
241 | 241 |
242 SkColor opColor() const { return fOpColor; } | 242 SkPMColor opColor() const { return fOpColor; } |
243 | 243 |
244 private: | 244 private: |
245 GrXferProcessor::OptFlags onGetOptimizations(const GrPipelineOptimizations&
optimizations, | 245 GrXferProcessor::OptFlags onGetOptimizations(const GrPipelineOptimizations&
optimizations, |
246 bool doesStencilWrite, | 246 bool doesStencilWrite, |
247 GrColor* overrideColor, | 247 GrColor* overrideColor, |
248 const GrCaps& caps) const overr
ide { | 248 const GrCaps& caps) const overr
ide { |
249 return GrXferProcessor::kNone_OptFlags; | 249 return GrXferProcessor::kNone_OptFlags; |
250 } | 250 } |
251 | 251 |
252 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b)
const override; | 252 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b)
const override; |
253 | 253 |
254 bool onIsEqual(const GrXferProcessor& xpBase) const override { | 254 bool onIsEqual(const GrXferProcessor& xpBase) const override { |
255 const PixelXorXP& xp = xpBase.cast<PixelXorXP>(); | 255 const PixelXorXP& xp = xpBase.cast<PixelXorXP>(); |
256 | 256 |
257 return fOpColor == xp.fOpColor; | 257 return fOpColor == xp.fOpColor; |
258 } | 258 } |
259 | 259 |
260 SkColor fOpColor; | 260 SkPMColor fOpColor; |
261 | 261 |
262 typedef GrXferProcessor INHERITED; | 262 typedef GrXferProcessor INHERITED; |
263 }; | 263 }; |
264 | 264 |
265 /////////////////////////////////////////////////////////////////////////////// | 265 /////////////////////////////////////////////////////////////////////////////// |
266 | 266 |
267 class GLPixelXorXP : public GrGLSLXferProcessor { | 267 class GLPixelXorXP : public GrGLSLXferProcessor { |
268 public: | 268 public: |
269 GLPixelXorXP(const PixelXorXP& pixelXorXP) { } | 269 GLPixelXorXP(const PixelXorXP& pixelXorXP) { } |
270 | 270 |
(...skipping 18 matching lines...) Expand all Loading... |
289 add_pixelxor_code(fragBuilder, srcColor, dstColor, outColor, kOpColorUni
); | 289 add_pixelxor_code(fragBuilder, srcColor, dstColor, outColor, kOpColorUni
); |
290 | 290 |
291 // Apply coverage. | 291 // Apply coverage. |
292 INHERITED::DefaultCoverageModulation(fragBuilder, srcCoverage, dstColor,
outColor, | 292 INHERITED::DefaultCoverageModulation(fragBuilder, srcCoverage, dstColor,
outColor, |
293 outColorSecondary, proc); | 293 outColorSecondary, proc); |
294 } | 294 } |
295 | 295 |
296 void onSetData(const GrGLSLProgramDataManager& pdman, | 296 void onSetData(const GrGLSLProgramDataManager& pdman, |
297 const GrXferProcessor& processor) override { | 297 const GrXferProcessor& processor) override { |
298 const PixelXorXP& pixelXor = processor.cast<PixelXorXP>(); | 298 const PixelXorXP& pixelXor = processor.cast<PixelXorXP>(); |
299 pdman.set3f(fOpColorUni, | 299 pdman.set3f(fOpColorUni, |
300 SkColorGetR(pixelXor.opColor())/255.0f, | 300 SkGetPackedR32(pixelXor.opColor())/255.0f, |
301 SkColorGetG(pixelXor.opColor())/255.0f, | 301 SkGetPackedG32(pixelXor.opColor())/255.0f, |
302 SkColorGetB(pixelXor.opColor())/255.0f); | 302 SkGetPackedB32(pixelXor.opColor())/255.0f); |
303 }; | 303 }; |
304 | 304 |
305 GrGLSLProgramDataManager::UniformHandle fOpColorUni; | 305 GrGLSLProgramDataManager::UniformHandle fOpColorUni; |
306 | 306 |
307 typedef GrGLSLXferProcessor INHERITED; | 307 typedef GrGLSLXferProcessor INHERITED; |
308 }; | 308 }; |
309 | 309 |
310 /////////////////////////////////////////////////////////////////////////////// | 310 /////////////////////////////////////////////////////////////////////////////// |
311 | 311 |
312 void PixelXorXP::onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBui
lder* b) const { | 312 void PixelXorXP::onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBui
lder* b) const { |
313 GLPixelXorXP::GenKey(*this, caps, b); | 313 GLPixelXorXP::GenKey(*this, caps, b); |
314 } | 314 } |
315 | 315 |
316 GrGLSLXferProcessor* PixelXorXP::createGLSLInstance() const { return new GLPixel
XorXP(*this); } | 316 GrGLSLXferProcessor* PixelXorXP::createGLSLInstance() const { return new GLPixel
XorXP(*this); } |
317 | 317 |
318 /////////////////////////////////////////////////////////////////////////////// | 318 /////////////////////////////////////////////////////////////////////////////// |
319 | 319 |
320 class GrPixelXorXPFactory : public GrXPFactory { | 320 class GrPixelXorXPFactory : public GrXPFactory { |
321 public: | 321 public: |
322 static GrXPFactory* Create(SkColor opColor) { | 322 static GrXPFactory* Create(SkPMColor opColor) { |
323 return new GrPixelXorXPFactory(opColor); | 323 return new GrPixelXorXPFactory(opColor); |
324 } | 324 } |
325 | 325 |
326 void getInvariantBlendedColor(const GrProcOptInfo& colorPOI, | 326 void getInvariantBlendedColor(const GrProcOptInfo& colorPOI, |
327 GrXPFactory::InvariantBlendedColor* blendedCol
or) const override { | 327 GrXPFactory::InvariantBlendedColor* blendedCol
or) const override { |
328 blendedColor->fWillBlendWithDst = true; | 328 blendedColor->fWillBlendWithDst = true; |
329 blendedColor->fKnownColorFlags = kNone_GrColorComponentFlags; | 329 blendedColor->fKnownColorFlags = kNone_GrColorComponentFlags; |
330 } | 330 } |
331 | 331 |
332 private: | 332 private: |
333 GrPixelXorXPFactory(SkColor opColor) | 333 GrPixelXorXPFactory(SkPMColor opColor) |
334 : fOpColor(opColor) { | 334 : fOpColor(opColor) { |
335 this->initClassID<GrPixelXorXPFactory>(); | 335 this->initClassID<GrPixelXorXPFactory>(); |
336 } | 336 } |
337 | 337 |
338 GrXferProcessor* onCreateXferProcessor(const GrCaps& caps, | 338 GrXferProcessor* onCreateXferProcessor(const GrCaps& caps, |
339 const GrPipelineOptimizations& optimi
zations, | 339 const GrPipelineOptimizations& optimi
zations, |
340 bool hasMixedSamples, | 340 bool hasMixedSamples, |
341 const DstTexture* dstTexture) const o
verride { | 341 const DstTexture* dstTexture) const o
verride { |
342 return new PixelXorXP(dstTexture, hasMixedSamples, fOpColor); | 342 return new PixelXorXP(dstTexture, hasMixedSamples, fOpColor); |
343 } | 343 } |
344 | 344 |
345 bool willReadDstColor(const GrCaps& caps, | 345 bool willReadDstColor(const GrCaps& caps, |
346 const GrPipelineOptimizations& optimizations, | 346 const GrPipelineOptimizations& optimizations, |
347 bool hasMixedSamples) const override { | 347 bool hasMixedSamples) const override { |
348 return true; | 348 return true; |
349 } | 349 } |
350 | 350 |
351 bool onIsEqual(const GrXPFactory& xpfBase) const override { | 351 bool onIsEqual(const GrXPFactory& xpfBase) const override { |
352 const GrPixelXorXPFactory& xpf = xpfBase.cast<GrPixelXorXPFactory>(); | 352 const GrPixelXorXPFactory& xpf = xpfBase.cast<GrPixelXorXPFactory>(); |
353 return fOpColor == xpf.fOpColor; | 353 return fOpColor == xpf.fOpColor; |
354 } | 354 } |
355 | 355 |
356 GR_DECLARE_XP_FACTORY_TEST; | 356 GR_DECLARE_XP_FACTORY_TEST; |
357 | 357 |
358 SkColor fOpColor; | 358 SkPMColor fOpColor; |
359 | 359 |
360 typedef GrXPFactory INHERITED; | 360 typedef GrXPFactory INHERITED; |
361 }; | 361 }; |
362 | 362 |
363 GR_DEFINE_XP_FACTORY_TEST(GrPixelXorXPFactory); | 363 GR_DEFINE_XP_FACTORY_TEST(GrPixelXorXPFactory); |
364 | 364 |
365 const GrXPFactory* GrPixelXorXPFactory::TestCreate(GrProcessorTestData* d) { | 365 const GrXPFactory* GrPixelXorXPFactory::TestCreate(GrProcessorTestData* d) { |
366 SkColor color = d->fRandom->nextU(); | 366 SkColor color = d->fRandom->nextU(); |
367 | 367 |
368 return GrPixelXorXPFactory::Create(color); | 368 return GrPixelXorXPFactory::Create(SkPreMultiplyColor(color)); |
369 } | 369 } |
370 | 370 |
371 /////////////////////////////////////////////////////////////////////////////// | 371 /////////////////////////////////////////////////////////////////////////////// |
372 | 372 |
373 bool SkPixelXorXfermode::asFragmentProcessor(const GrFragmentProcessor** output, | 373 bool SkPixelXorXfermode::asFragmentProcessor(const GrFragmentProcessor** output, |
374 const GrFragmentProcessor* dst) const { | 374 const GrFragmentProcessor* dst) con
st { |
375 if (output) { | 375 if (output) { |
376 *output = PixelXorFP::Create(fOpColor, dst); | 376 *output = PixelXorFP::Create(fOpColor, dst); |
377 } | 377 } |
378 return true; | 378 return true; |
379 } | 379 } |
380 | 380 |
381 bool SkPixelXorXfermode::asXPFactory(GrXPFactory** xpf) const { | 381 bool SkPixelXorXfermode::asXPFactory(GrXPFactory** xpf) const { |
382 if (xpf) { | 382 if (xpf) { |
383 *xpf = GrPixelXorXPFactory::Create(fOpColor); | 383 *xpf = GrPixelXorXPFactory::Create(fOpColor); |
384 } | 384 } |
385 return true; | 385 return true; |
386 } | 386 } |
387 | 387 |
388 #endif | 388 #endif |
OLD | NEW |