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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/CrossfadeGeneratedImage.cpp

Issue 2712083002: color: Remove blink pre-conversion code (Closed)
Patch Set: Rebase Created 3 years, 9 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) 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2011 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 23 matching lines...) Expand all
34 PassRefPtr<Image> toImage, 34 PassRefPtr<Image> toImage,
35 float percentage, 35 float percentage,
36 IntSize crossfadeSize, 36 IntSize crossfadeSize,
37 const IntSize& size) 37 const IntSize& size)
38 : GeneratedImage(size), 38 : GeneratedImage(size),
39 m_fromImage(fromImage), 39 m_fromImage(fromImage),
40 m_toImage(toImage), 40 m_toImage(toImage),
41 m_percentage(percentage), 41 m_percentage(percentage),
42 m_crossfadeSize(crossfadeSize) {} 42 m_crossfadeSize(crossfadeSize) {}
43 43
44 void CrossfadeGeneratedImage::drawCrossfade( 44 void CrossfadeGeneratedImage::drawCrossfade(PaintCanvas* canvas,
45 PaintCanvas* canvas, 45 const PaintFlags& flags,
46 const PaintFlags& flags, 46 ImageClampingMode clampMode) {
47 ImageClampingMode clampMode,
48 const ColorBehavior& colorBehavior) {
49 FloatRect fromImageRect(FloatPoint(), FloatSize(m_fromImage->size())); 47 FloatRect fromImageRect(FloatPoint(), FloatSize(m_fromImage->size()));
50 FloatRect toImageRect(FloatPoint(), FloatSize(m_toImage->size())); 48 FloatRect toImageRect(FloatPoint(), FloatSize(m_toImage->size()));
51 FloatRect destRect((FloatPoint()), FloatSize(m_crossfadeSize)); 49 FloatRect destRect((FloatPoint()), FloatSize(m_crossfadeSize));
52 50
53 // TODO(junov): The various effects encoded into paint should probably be 51 // TODO(junov): The various effects encoded into paint should probably be
54 // applied here instead of inside the layer. This probably faulty behavior 52 // applied here instead of inside the layer. This probably faulty behavior
55 // was maintained in order to preserve pre-existing behavior while refactoring 53 // was maintained in order to preserve pre-existing behavior while refactoring
56 // this code. This should be investigated further. crbug.com/472634 54 // this code. This should be investigated further. crbug.com/472634
57 PaintFlags layerFlags; 55 PaintFlags layerFlags;
58 layerFlags.setBlendMode(flags.getBlendMode()); 56 layerFlags.setBlendMode(flags.getBlendMode());
59 PaintCanvasAutoRestore ar(canvas, false); 57 PaintCanvasAutoRestore ar(canvas, false);
60 canvas->saveLayer(nullptr, &layerFlags); 58 canvas->saveLayer(nullptr, &layerFlags);
61 59
62 PaintFlags imageFlags(flags); 60 PaintFlags imageFlags(flags);
63 imageFlags.setBlendMode(SkBlendMode::kSrcOver); 61 imageFlags.setBlendMode(SkBlendMode::kSrcOver);
64 int imageAlpha = clampedAlphaForBlending(1 - m_percentage); 62 int imageAlpha = clampedAlphaForBlending(1 - m_percentage);
65 imageFlags.setAlpha(imageAlpha > 255 ? 255 : imageAlpha); 63 imageFlags.setAlpha(imageAlpha > 255 ? 255 : imageAlpha);
66 imageFlags.setAntiAlias(flags.isAntiAlias()); 64 imageFlags.setAntiAlias(flags.isAntiAlias());
67 // TODO(junov): This code should probably be propagating the 65 // TODO(junov): This code should probably be propagating the
68 // RespectImageOrientationEnum from CrossfadeGeneratedImage::draw(). Code was 66 // RespectImageOrientationEnum from CrossfadeGeneratedImage::draw(). Code was
69 // written this way during refactoring to avoid modifying existing behavior, 67 // written this way during refactoring to avoid modifying existing behavior,
70 // but this warrants further investigation. crbug.com/472634 68 // but this warrants further investigation. crbug.com/472634
71 m_fromImage->draw(canvas, imageFlags, destRect, fromImageRect, 69 m_fromImage->draw(canvas, imageFlags, destRect, fromImageRect,
72 DoNotRespectImageOrientation, clampMode, colorBehavior); 70 DoNotRespectImageOrientation, clampMode);
73 imageFlags.setBlendMode(SkBlendMode::kPlus); 71 imageFlags.setBlendMode(SkBlendMode::kPlus);
74 imageAlpha = clampedAlphaForBlending(m_percentage); 72 imageAlpha = clampedAlphaForBlending(m_percentage);
75 imageFlags.setAlpha(imageAlpha > 255 ? 255 : imageAlpha); 73 imageFlags.setAlpha(imageAlpha > 255 ? 255 : imageAlpha);
76 m_toImage->draw(canvas, imageFlags, destRect, toImageRect, 74 m_toImage->draw(canvas, imageFlags, destRect, toImageRect,
77 DoNotRespectImageOrientation, clampMode, colorBehavior); 75 DoNotRespectImageOrientation, clampMode);
78 } 76 }
79 77
80 void CrossfadeGeneratedImage::draw(PaintCanvas* canvas, 78 void CrossfadeGeneratedImage::draw(PaintCanvas* canvas,
81 const PaintFlags& flags, 79 const PaintFlags& flags,
82 const FloatRect& dstRect, 80 const FloatRect& dstRect,
83 const FloatRect& srcRect, 81 const FloatRect& srcRect,
84 RespectImageOrientationEnum, 82 RespectImageOrientationEnum,
85 ImageClampingMode clampMode, 83 ImageClampingMode clampMode) {
86 const ColorBehavior& colorBehavior) {
87 // Draw nothing if either of the images hasn't loaded yet. 84 // Draw nothing if either of the images hasn't loaded yet.
88 if (m_fromImage == Image::nullImage() || m_toImage == Image::nullImage()) 85 if (m_fromImage == Image::nullImage() || m_toImage == Image::nullImage())
89 return; 86 return;
90 87
91 PaintCanvasAutoRestore ar(canvas, true); 88 PaintCanvasAutoRestore ar(canvas, true);
92 canvas->clipRect(dstRect); 89 canvas->clipRect(dstRect);
93 canvas->translate(dstRect.x(), dstRect.y()); 90 canvas->translate(dstRect.x(), dstRect.y());
94 if (dstRect.size() != srcRect.size()) 91 if (dstRect.size() != srcRect.size())
95 canvas->scale(dstRect.width() / srcRect.width(), 92 canvas->scale(dstRect.width() / srcRect.width(),
96 dstRect.height() / srcRect.height()); 93 dstRect.height() / srcRect.height());
97 canvas->translate(-srcRect.x(), -srcRect.y()); 94 canvas->translate(-srcRect.x(), -srcRect.y());
98 95
99 drawCrossfade(canvas, flags, clampMode, colorBehavior); 96 drawCrossfade(canvas, flags, clampMode);
100 } 97 }
101 98
102 void CrossfadeGeneratedImage::drawTile(GraphicsContext& context, 99 void CrossfadeGeneratedImage::drawTile(GraphicsContext& context,
103 const FloatRect& srcRect) { 100 const FloatRect& srcRect) {
104 // Draw nothing if either of the images hasn't loaded yet. 101 // Draw nothing if either of the images hasn't loaded yet.
105 if (m_fromImage == Image::nullImage() || m_toImage == Image::nullImage()) 102 if (m_fromImage == Image::nullImage() || m_toImage == Image::nullImage())
106 return; 103 return;
107 104
108 PaintFlags flags = context.fillFlags(); 105 PaintFlags flags = context.fillFlags();
109 flags.setBlendMode(SkBlendMode::kSrcOver); 106 flags.setBlendMode(SkBlendMode::kSrcOver);
110 flags.setAntiAlias(context.shouldAntialias()); 107 flags.setAntiAlias(context.shouldAntialias());
111 FloatRect destRect((FloatPoint()), FloatSize(m_crossfadeSize)); 108 FloatRect destRect((FloatPoint()), FloatSize(m_crossfadeSize));
112 flags.setFilterQuality(context.computeFilterQuality(this, destRect, srcRect)); 109 flags.setFilterQuality(context.computeFilterQuality(this, destRect, srcRect));
113 drawCrossfade(context.canvas(), flags, ClampImageToSourceRect, 110 drawCrossfade(context.canvas(), flags, ClampImageToSourceRect);
114 context.getColorBehavior());
115 } 111 }
116 112
117 } // namespace blink 113 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698