| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/paint/NinePieceImagePainter.h" | 5 #include "core/paint/NinePieceImagePainter.h" |
| 6 | 6 |
| 7 #include "core/layout/ImageQualityController.h" | 7 #include "core/layout/ImageQualityController.h" |
| 8 #include "core/layout/LayoutBoxModelObject.h" | 8 #include "core/layout/LayoutBoxModelObject.h" |
| 9 #include "core/page/ChromeClient.h" | 9 #include "core/page/ChromeClient.h" |
| 10 #include "core/page/Page.h" | 10 #include "core/page/Page.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 draw_info.tile_rule.horizontal, | 46 draw_info.tile_rule.horizontal, |
| 47 draw_info.tile_rule.vertical, op); | 47 draw_info.tile_rule.vertical, op); |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 | 52 |
| 53 } // anonymous namespace | 53 } // anonymous namespace |
| 54 | 54 |
| 55 bool NinePieceImagePainter::Paint(GraphicsContext& graphics_context, | 55 bool NinePieceImagePainter::Paint(GraphicsContext& graphics_context, |
| 56 const LayoutBoxModelObject& layout_object, | 56 const ImageResourceObserver& observer, |
| 57 const Document& document, |
| 58 Node* node, |
| 57 const LayoutRect& rect, | 59 const LayoutRect& rect, |
| 58 const ComputedStyle& style, | 60 const ComputedStyle& style, |
| 59 const NinePieceImage& nine_piece_image, | 61 const NinePieceImage& nine_piece_image, |
| 60 SkBlendMode op) const { | 62 SkBlendMode op) { |
| 61 StyleImage* style_image = nine_piece_image.GetImage(); | 63 StyleImage* style_image = nine_piece_image.GetImage(); |
| 62 if (!style_image) | 64 if (!style_image) |
| 63 return false; | 65 return false; |
| 64 | 66 |
| 65 if (!style_image->IsLoaded()) | 67 if (!style_image->IsLoaded()) |
| 66 return true; // Never paint a nine-piece image incrementally, but don't | 68 return true; // Never paint a nine-piece image incrementally, but don't |
| 67 // paint the fallback borders either. | 69 // paint the fallback borders either. |
| 68 | 70 |
| 69 if (!style_image->CanRender()) | 71 if (!style_image->CanRender()) |
| 70 return false; | 72 return false; |
| 71 | 73 |
| 72 // FIXME: border-image is broken with full page zooming when tiling has to | 74 // FIXME: border-image is broken with full page zooming when tiling has to |
| 73 // happen, since the tiling function doesn't have any understanding of the | 75 // happen, since the tiling function doesn't have any understanding of the |
| 74 // zoom that is in effect on the tile. | 76 // zoom that is in effect on the tile. |
| 75 LayoutRect rect_with_outsets = rect; | 77 LayoutRect rect_with_outsets = rect; |
| 76 rect_with_outsets.Expand(style.ImageOutsets(nine_piece_image)); | 78 rect_with_outsets.Expand(style.ImageOutsets(nine_piece_image)); |
| 77 LayoutRect border_image_rect = rect_with_outsets; | 79 LayoutRect border_image_rect = rect_with_outsets; |
| 78 | 80 |
| 79 // NinePieceImage returns the image slices without effective zoom applied and | 81 // NinePieceImage returns the image slices without effective zoom applied and |
| 80 // thus we compute the nine piece grid on top of the image in unzoomed | 82 // thus we compute the nine piece grid on top of the image in unzoomed |
| 81 // coordinates. | 83 // coordinates. |
| 82 // | 84 // |
| 83 // FIXME: The default object size passed to imageSize() should be scaled by | 85 // FIXME: The default object size passed to imageSize() should be scaled by |
| 84 // the zoom factor passed in. In this case it means that borderImageRect | 86 // the zoom factor passed in. In this case it means that borderImageRect |
| 85 // should be passed in compensated by effective zoom, since the scale factor | 87 // should be passed in compensated by effective zoom, since the scale factor |
| 86 // is one. For generated images, the actual image data (gradient stops, etc.) | 88 // is one. For generated images, the actual image data (gradient stops, etc.) |
| 87 // are scaled to effective zoom instead so we must take care not to cause | 89 // are scaled to effective zoom instead so we must take care not to cause |
| 88 // scale of them again. | 90 // scale of them again. |
| 89 const Document& document = layout_object.GetDocument(); | |
| 90 IntSize image_size = RoundedIntSize( | 91 IntSize image_size = RoundedIntSize( |
| 91 style_image->ImageSize(document, 1, border_image_rect.Size())); | 92 style_image->ImageSize(document, 1, border_image_rect.Size())); |
| 92 RefPtr<Image> image = style_image->GetImage( | 93 RefPtr<Image> image = |
| 93 layout_object, document, layout_object.StyleRef(), image_size); | 94 style_image->GetImage(observer, document, style, image_size); |
| 94 | 95 |
| 95 double time = document.GetPage()->GetChromeClient().LastFrameTimeMonotonic(); | 96 double time = document.GetPage()->GetChromeClient().LastFrameTimeMonotonic(); |
| 96 InterpolationQuality interpolation_quality = | 97 InterpolationQuality interpolation_quality = |
| 97 ImageQualityController::GetImageQualityController() | 98 ImageQualityController::GetImageQualityController() |
| 98 ->ChooseInterpolationQuality(layout_object, layout_object.StyleRef(), | 99 ->ChooseInterpolationQuality(observer, style, document.GetSettings(), |
| 99 document.GetSettings(), image.Get(), | 100 image.Get(), nullptr, |
| 100 nullptr, rect_with_outsets.Size(), time); | 101 rect_with_outsets.Size(), time); |
| 101 InterpolationQuality previous_interpolation_quality = | 102 InterpolationQuality previous_interpolation_quality = |
| 102 graphics_context.ImageInterpolationQuality(); | 103 graphics_context.ImageInterpolationQuality(); |
| 103 graphics_context.SetImageInterpolationQuality(interpolation_quality); | 104 graphics_context.SetImageInterpolationQuality(interpolation_quality); |
| 104 | 105 |
| 105 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "PaintImage", | 106 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "PaintImage", |
| 106 "data", | 107 "data", InspectorPaintImageEvent::Data(node, *style_image)); |
| 107 InspectorPaintImageEvent::Data(layout_object, *style_image)); | |
| 108 | 108 |
| 109 PaintPieces(graphics_context, border_image_rect, style, nine_piece_image, | 109 PaintPieces(graphics_context, border_image_rect, style, nine_piece_image, |
| 110 image.Get(), image_size, op); | 110 image.Get(), image_size, op); |
| 111 | 111 |
| 112 graphics_context.SetImageInterpolationQuality(previous_interpolation_quality); | 112 graphics_context.SetImageInterpolationQuality(previous_interpolation_quality); |
| 113 return true; | 113 return true; |
| 114 } | 114 } |
| 115 | 115 |
| 116 } // namespace blink | 116 } // namespace blink |
| OLD | NEW |