| 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 "SkGpuDevice.h" | 8 #include "SkGpuDevice.h" |
| 9 | 9 |
| 10 #include "effects/GrBicubicEffect.h" | 10 #include "effects/GrBicubicEffect.h" |
| (...skipping 1945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1956 desc.fConfig = kSkia8888_GrPixelConfig; | 1956 desc.fConfig = kSkia8888_GrPixelConfig; |
| 1957 // TODO: need to deal with sample count | 1957 // TODO: need to deal with sample count |
| 1958 | 1958 |
| 1959 bool needsRendering = !fContext->getLayerCache()->lock(layer, desc); | 1959 bool needsRendering = !fContext->getLayerCache()->lock(layer, desc); |
| 1960 if (NULL == layer->texture()) { | 1960 if (NULL == layer->texture()) { |
| 1961 continue; | 1961 continue; |
| 1962 } | 1962 } |
| 1963 | 1963 |
| 1964 layerInfo->fBM = SkNEW(SkBitmap); // fBM is allocated so Replacemen
tInfo can be POD | 1964 layerInfo->fBM = SkNEW(SkBitmap); // fBM is allocated so Replacemen
tInfo can be POD |
| 1965 wrap_texture(layer->texture(), | 1965 wrap_texture(layer->texture(), |
| 1966 layer->rect().isEmpty() ? desc.fWidth : layer->texture(
)->width(), | 1966 !layer->isAtlased() ? desc.fWidth : layer->texture()->w
idth(), |
| 1967 layer->rect().isEmpty() ? desc.fHeight : layer->texture
()->height(), | 1967 !layer->isAtlased() ? desc.fHeight : layer->texture()->
height(), |
| 1968 layerInfo->fBM); | 1968 layerInfo->fBM); |
| 1969 | 1969 |
| 1970 SkASSERT(info.fPaint); | 1970 SkASSERT(info.fPaint); |
| 1971 layerInfo->fPaint = info.fPaint; | 1971 layerInfo->fPaint = info.fPaint; |
| 1972 | 1972 |
| 1973 if (layer->rect().isEmpty()) { | 1973 layerInfo->fSrcRect = SkIRect::MakeXYWH(layer->rect().fLeft, |
| 1974 layerInfo->fSrcRect = SkIRect::MakeWH(desc.fWidth, desc.fHeight)
; | 1974 layer->rect().fTop, |
| 1975 } else { | 1975 layer->rect().width(), |
| 1976 layerInfo->fSrcRect = SkIRect::MakeXYWH(layer->rect().fLeft, | 1976 layer->rect().height()); |
| 1977 layer->rect().fTop, | 1977 |
| 1978 layer->rect().width(), | |
| 1979 layer->rect().height()); | |
| 1980 } | |
| 1981 | 1978 |
| 1982 if (needsRendering) { | 1979 if (needsRendering) { |
| 1983 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect
( | 1980 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect
( |
| 1984 layer->texture()->asRenderTa
rget(), | 1981 layer->texture()->asRenderTa
rget(), |
| 1985 SkSurface::kStandard_TextRen
derMode, | 1982 SkSurface::kStandard_TextRen
derMode, |
| 1986 SkSurface::kDontClear_Render
TargetFlag)); | 1983 SkSurface::kDontClear_Render
TargetFlag)); |
| 1987 | 1984 |
| 1988 SkCanvas* canvas = surface->getCanvas(); | 1985 SkCanvas* canvas = surface->getCanvas(); |
| 1989 | 1986 |
| 1990 if (!layer->rect().isEmpty()) { | 1987 // Add a rect clip to make sure the rendering doesn't |
| 1991 // Add a rect clip to make sure the rendering doesn't | 1988 // extend beyond the boundaries of the atlased sub-rect |
| 1992 // extend beyond the boundaries of the atlased sub-rect | 1989 SkRect bound = SkRect::Make(layerInfo->fSrcRect); |
| 1993 SkRect bound = SkRect::MakeXYWH(SkIntToScalar(layer->rect().
fLeft), | 1990 canvas->clipRect(bound); |
| 1994 SkIntToScalar(layer->rect().
fTop), | 1991 |
| 1995 SkIntToScalar(layer->rect().
width()), | 1992 if (layer->isAtlased()) { |
| 1996 SkIntToScalar(layer->rect().
height())); | |
| 1997 canvas->clipRect(bound); | |
| 1998 // Since 'clear' doesn't respect the clip we need to draw a
rect | 1993 // Since 'clear' doesn't respect the clip we need to draw a
rect |
| 1999 // TODO: ensure none of the atlased layers contain a clear c
all! | 1994 // TODO: ensure none of the atlased layers contain a clear c
all! |
| 2000 SkPaint paint; | 1995 SkPaint paint; |
| 2001 paint.setColor(SK_ColorTRANSPARENT); | 1996 paint.setColor(SK_ColorTRANSPARENT); |
| 2002 canvas->drawRect(bound, paint); | 1997 canvas->drawRect(bound, paint); |
| 2003 } else { | 1998 } else { |
| 2004 canvas->clear(SK_ColorTRANSPARENT); | 1999 canvas->clear(SK_ColorTRANSPARENT); |
| 2005 } | 2000 } |
| 2006 | 2001 |
| 2007 canvas->setMatrix(info.fCTM); | 2002 // info.fCTM maps the layer's top/left to the origin. |
| 2008 | 2003 // If this layer is atlased the top/left corner needs |
| 2009 if (!layer->rect().isEmpty()) { | 2004 // to be offset to some arbitrary location in the backing |
| 2010 // info.fCTM maps the layer's top/left to the origin. | 2005 // texture. |
| 2011 // Since this layer is atlased the top/left corner needs | 2006 canvas->translate(bound.fLeft, bound.fTop); |
| 2012 // to be offset to some arbitrary location in the backing | 2007 canvas->concat(info.fCTM); |
| 2013 // texture. | |
| 2014 canvas->translate(SkIntToScalar(layer->rect().fLeft), | |
| 2015 SkIntToScalar(layer->rect().fTop)); | |
| 2016 } | |
| 2017 | 2008 |
| 2018 SkPictureRangePlayback rangePlayback(picture, | 2009 SkPictureRangePlayback rangePlayback(picture, |
| 2019 info.fSaveLayerOpID, | 2010 info.fSaveLayerOpID, |
| 2020 info.fRestoreOpID); | 2011 info.fRestoreOpID); |
| 2021 rangePlayback.draw(canvas, NULL); | 2012 rangePlayback.draw(canvas, NULL); |
| 2022 | 2013 |
| 2023 canvas->flush(); | 2014 canvas->flush(); |
| 2024 } | 2015 } |
| 2025 } | 2016 } |
| 2026 } | 2017 } |
| 2027 | 2018 |
| 2028 // Playback using new layers | 2019 // Playback using new layers |
| 2029 SkPictureReplacementPlayback playback(picture, &replacements, ops.get()); | 2020 SkPictureReplacementPlayback playback(picture, &replacements, ops.get()); |
| 2030 | 2021 |
| 2031 playback.draw(canvas, NULL); | 2022 playback.draw(canvas, NULL); |
| 2032 | 2023 |
| 2033 // unlock the layers | 2024 // unlock the layers |
| 2034 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { | 2025 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { |
| 2035 GrCachedLayer* layer = fContext->getLayerCache()->findLayer(picture, i); | 2026 GrCachedLayer* layer = fContext->getLayerCache()->findLayer(picture, i); |
| 2036 fContext->getLayerCache()->unlock(layer); | 2027 fContext->getLayerCache()->unlock(layer); |
| 2037 } | 2028 } |
| 2038 | 2029 |
| 2039 return true; | 2030 return true; |
| 2040 } | 2031 } |
| OLD | NEW |