OLD | NEW |
| (Empty) |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // | |
3 // The Chromium Authors can be found at | |
4 // http://src.chromium.org/svn/trunk/src/AUTHORS | |
5 // | |
6 // Redistribution and use in source and binary forms, with or without | |
7 // modification, are permitted provided that the following conditions are | |
8 // met: | |
9 // | |
10 // * Redistributions of source code must retain the above copyright | |
11 // notice, this list of conditions and the following disclaimer. | |
12 // * Redistributions in binary form must reproduce the above | |
13 // copyright notice, this list of conditions and the following disclaimer | |
14 // in the documentation and/or other materials provided with the | |
15 // distribution. | |
16 // * Neither the name of Google Inc. nor the names of its | |
17 // contributors may be used to endorse or promote products derived from | |
18 // this software without specific prior written permission. | |
19 // | |
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
31 | |
32 #include "config.h" | |
33 #include "platform/graphics/GraphicsContextClient.h" | |
34 | |
35 #include "platform/graphics/GraphicsContext.h" | |
36 #include "third_party/skia/include/core/SkCanvas.h" | |
37 #include "third_party/skia/include/core/SkShader.h" | |
38 | |
39 namespace blink { | |
40 | |
41 void GraphicsContextClient::willDrawRect(GraphicsContext* context, const SkRect&
rect, const SkPaint* paint, ImageType imageType, DrawType drawType) | |
42 { | |
43 if (context->isDrawingToLayer()) | |
44 return; | |
45 | |
46 SkRect deviceRect; | |
47 if (drawType == UntransformedUnclippedFill) { | |
48 deviceRect = rect; | |
49 } else { | |
50 // FIXME: Early out if rotate/skew. To be thorough, we could compute | |
51 // an enclsed rect, but that would probably be overkill. | |
52 const SkMatrix& ctm = context->getTotalMatrix(); | |
53 if (!ctm.rectStaysRect()) | |
54 return; | |
55 | |
56 if (context->hasComplexClip()) | |
57 return; | |
58 | |
59 ctm.mapRect(&deviceRect, rect); | |
60 SkIRect skIBounds; | |
61 if (!context->canvas()->getClipDeviceBounds(&skIBounds)) | |
62 return; | |
63 SkRect skBounds = SkRect::Make(skIBounds); | |
64 if (!deviceRect.intersect(skBounds)) | |
65 return; | |
66 } | |
67 | |
68 const SkImageInfo& imageInfo = context->canvas()->imageInfo(); | |
69 if (!deviceRect.contains(SkRect::MakeWH(imageInfo.width(), imageInfo.height(
)))) | |
70 return; | |
71 | |
72 bool isSourceOver = true; | |
73 unsigned alpha = 0xFF; | |
74 if (paint) { | |
75 if (drawType == FillOrStroke && paint->getStyle() == SkPaint::kStroke_St
yle) | |
76 return; | |
77 if (paint->getLooper() || paint->getImageFilter() || paint->getMaskFilte
r()) | |
78 return; | |
79 | |
80 SkXfermode* xfermode = paint->getXfermode(); | |
81 if (xfermode) { | |
82 SkXfermode::Mode mode; | |
83 if (xfermode->asMode(&mode)) { | |
84 isSourceOver = mode == SkXfermode::kSrcOver_Mode; | |
85 if (!isSourceOver && mode != SkXfermode::kSrc_Mode && mode != Sk
Xfermode::kClear_Mode) | |
86 return; // The code below only knows how to handle Src, SrcO
ver, and Clear | |
87 } else { | |
88 // unknown xfermode | |
89 return; | |
90 } | |
91 } | |
92 | |
93 if (isSourceOver) { | |
94 // With source over, we need to certify that alpha == 0xFF for all p
ixels | |
95 SkColorFilter* colorFilter = paint->getColorFilter(); | |
96 if (colorFilter && !(colorFilter->getFlags() & SkColorFilter::kAlpha
Unchanged_Flag)) | |
97 return; | |
98 | |
99 SkShader* shader = paint->getShader(); | |
100 if (shader) { | |
101 // Shader overrides bitmap and paint color, so we can end here | |
102 if (shader->isOpaque()) | |
103 willOverwriteCanvas(); | |
104 return; | |
105 } | |
106 } | |
107 | |
108 alpha = paint->getAlpha(); | |
109 } | |
110 | |
111 if (isSourceOver) { | |
112 // With source over, we need to certify that alpha == 0xFF for all pixel
s | |
113 if (imageType == NonOpaqueImage) | |
114 return; | |
115 if (imageType == NoImage && alpha < 0xFF) | |
116 return; | |
117 } | |
118 | |
119 willOverwriteCanvas(); | |
120 } | |
121 | |
122 } // blink | |
OLD | NEW |