OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2010, Google Inc. All rights reserved. |
| 3 * |
| 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are |
| 6 * met: |
| 7 * |
| 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. |
| 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ |
| 30 |
| 31 |
| 32 #include "config.h" |
| 33 |
| 34 #if USE(ACCELERATED_COMPOSITING) |
| 35 #include "LayerRendererSkia.h" |
| 36 #include "LayerSkia.h" |
| 37 #include "PlatformContextSkia.h" |
| 38 |
| 39 #include "skia/ext/platform_canvas.h" |
| 40 |
| 41 namespace WebCore { |
| 42 |
| 43 PassOwnPtr<LayerRendererSkia> LayerRendererSkia::create() |
| 44 { |
| 45 return new LayerRendererSkia(); |
| 46 } |
| 47 |
| 48 LayerRendererSkia::LayerRendererSkia() |
| 49 : m_rootLayer(0) |
| 50 , m_needsDisplay(false) |
| 51 { |
| 52 } |
| 53 |
| 54 LayerRendererSkia::~LayerRendererSkia() |
| 55 { |
| 56 } |
| 57 |
| 58 void LayerRendererSkia::drawLayersInCanvas(skia::PlatformCanvas* canvas, SkRect
clipRect) |
| 59 { |
| 60 if (!m_rootLayer) |
| 61 return; |
| 62 |
| 63 canvas->save(); |
| 64 canvas->clipRect(clipRect); |
| 65 |
| 66 // First composite the root layer into the canvas. |
| 67 canvas->drawBitmap(m_rootLayer->platformCanvas()->getDevice()->accessBitmap(
false), 0, 0, NULL); |
| 68 |
| 69 // Account for the scroll offset before compositing the remaining layers. |
| 70 // Note that the root layer's painting takes into account the scroll offset
already. |
| 71 canvas->translate(-m_scrollFrame.fLeft, -m_scrollFrame.fTop); |
| 72 |
| 73 float opacity = 1.0f; |
| 74 const Vector<RefPtr<LayerSkia>>& sublayers = m_rootLayer->getSublayers(); |
| 75 for (size_t ii = 0; ii < sublayers.size(); ii++) { |
| 76 drawLayerInCanvasRecursive(canvas, sublayers[ii].get(), opacity); |
| 77 } |
| 78 |
| 79 canvas->restore(); |
| 80 |
| 81 m_needsDisplay = false; |
| 82 } |
| 83 |
| 84 void LayerRendererSkia::updateLayerContents() |
| 85 { |
| 86 if (m_rootLayer) { |
| 87 updateLayerContentsRecursive(m_rootLayer.get()); |
| 88 } |
| 89 } |
| 90 |
| 91 void LayerRendererSkia::drawLayerInCanvasRecursive(skia::PlatformCanvas* canvas,
LayerSkia* layer, float opacity) |
| 92 { |
| 93 // Guarantees that the canvas is restored to a known state on destruction. |
| 94 SkAutoCanvasRestore autoRestoreCanvas(canvas, true); |
| 95 |
| 96 SkPoint position = layer->position(); |
| 97 SkPoint anchorPoint = layer->anchorPoint(); |
| 98 SkMatrix transform = layer->transform(); |
| 99 SkIRect bounds = layer->bounds(); |
| 100 |
| 101 canvas->translate(position.fX, position.fY); |
| 102 |
| 103 SkScalar tx = SkScalarMul(anchorPoint.fX, bounds.width()); |
| 104 SkScalar ty = SkScalarMul(anchorPoint.fY, bounds.height()); |
| 105 canvas->translate(tx, ty); |
| 106 canvas->concat(transform); |
| 107 canvas->translate(-tx, -ty); |
| 108 |
| 109 // The position we get is for the center of the layer but |
| 110 // drawBitmap starts at the upper-left corner and therefore |
| 111 // we need to adjust our transform. |
| 112 canvas->translate(-0.5f * bounds.width(), -0.5f * bounds.height()); |
| 113 |
| 114 SkPaint opacityPaint; |
| 115 opacity = opacity * layer->opacity(); |
| 116 opacityPaint.setAlpha(opacity * 255); |
| 117 |
| 118 canvas->drawBitmap(layer->platformCanvas()->getDevice()->accessBitmap(false)
, 0, 0, &opacityPaint); |
| 119 |
| 120 const Vector<RefPtr<LayerSkia>>& sublayers = layer->getSublayers(); |
| 121 for (size_t ii = 0; ii < sublayers.size(); ii++) { |
| 122 drawLayerInCanvasRecursive(canvas, sublayers[ii].get(), opacity); |
| 123 } |
| 124 } |
| 125 |
| 126 void LayerRendererSkia::updateLayerContentsRecursive(LayerSkia* layer) |
| 127 { |
| 128 layer->updateContents(); |
| 129 |
| 130 const Vector<RefPtr<LayerSkia>>& sublayers = layer->getSublayers(); |
| 131 for (size_t ii = 0; ii < sublayers.size(); ii++) { |
| 132 updateLayerContentsRecursive(sublayers[ii].get()); |
| 133 } |
| 134 } |
| 135 |
| 136 } // namespace WebCore |
| 137 |
| 138 #endif // USE(ACCELERATED_COMPOSITING) |
OLD | NEW |