OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2008 The Android Open Source Project | 2 * Copyright 2008 The Android Open Source Project |
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 "SkBitmapDevice.h" | 8 #include "SkBitmapDevice.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkCanvasPriv.h" | 10 #include "SkCanvasPriv.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "SkImageFilterCache.h" | 21 #include "SkImageFilterCache.h" |
22 #include "SkLatticeIter.h" | 22 #include "SkLatticeIter.h" |
23 #include "SkMatrixUtils.h" | 23 #include "SkMatrixUtils.h" |
24 #include "SkMetaData.h" | 24 #include "SkMetaData.h" |
25 #include "SkPaintPriv.h" | 25 #include "SkPaintPriv.h" |
26 #include "SkPatchUtils.h" | 26 #include "SkPatchUtils.h" |
27 #include "SkPicture.h" | 27 #include "SkPicture.h" |
28 #include "SkRasterClip.h" | 28 #include "SkRasterClip.h" |
29 #include "SkReadPixelsRec.h" | 29 #include "SkReadPixelsRec.h" |
30 #include "SkRRect.h" | 30 #include "SkRRect.h" |
| 31 #include "SkShadowPaintFilterCanvas.h" |
| 32 #include "SkShadowShader.h" |
31 #include "SkSmallAllocator.h" | 33 #include "SkSmallAllocator.h" |
32 #include "SkSpecialImage.h" | 34 #include "SkSpecialImage.h" |
33 #include "SkSurface_Base.h" | 35 #include "SkSurface_Base.h" |
34 #include "SkTextBlob.h" | 36 #include "SkTextBlob.h" |
35 #include "SkTextFormatParams.h" | 37 #include "SkTextFormatParams.h" |
36 #include "SkTLazy.h" | 38 #include "SkTLazy.h" |
37 #include "SkTraceEvent.h" | 39 #include "SkTraceEvent.h" |
38 | 40 |
39 #include <new> | 41 #include <new> |
40 | 42 |
(...skipping 3021 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3062 RETURN_ON_NULL(picture); | 3064 RETURN_ON_NULL(picture); |
3063 | 3065 |
3064 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawShadowedPicture()"); | 3066 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawShadowedPicture()"); |
3065 | 3067 |
3066 this->onDrawShadowedPicture(picture, matrix, paint); | 3068 this->onDrawShadowedPicture(picture, matrix, paint); |
3067 } | 3069 } |
3068 | 3070 |
3069 void SkCanvas::onDrawShadowedPicture(const SkPicture* picture, | 3071 void SkCanvas::onDrawShadowedPicture(const SkPicture* picture, |
3070 const SkMatrix* matrix, | 3072 const SkMatrix* matrix, |
3071 const SkPaint* paint) { | 3073 const SkPaint* paint) { |
3072 this->onDrawPicture(picture, matrix, paint); | 3074 if (!paint || paint->canComputeFastBounds()) { |
| 3075 SkRect bounds = picture->cullRect(); |
| 3076 if (paint) { |
| 3077 paint->computeFastBounds(bounds, &bounds); |
| 3078 } |
| 3079 if (matrix) { |
| 3080 matrix->mapRect(&bounds); |
| 3081 } |
| 3082 if (this->quickReject(bounds)) { |
| 3083 return; |
| 3084 } |
| 3085 } |
| 3086 |
| 3087 SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect()); |
| 3088 |
| 3089 for (int i = 0; i < fLights->numLights(); ++i) { |
| 3090 // skip over ambient lights; they don't cast shadows |
| 3091 // lights that have shadow maps do not need updating (because lights are
immutable) |
| 3092 |
| 3093 if (SkLights::Light::kAmbient_LightType == fLights->light(i).type() || |
| 3094 fLights->light(i).getShadowMap() != nullptr) { |
| 3095 continue; |
| 3096 } |
| 3097 |
| 3098 // TODO: compute the correct size of the depth map from the light proper
ties |
| 3099 // TODO: maybe add a kDepth_8_SkColorType |
| 3100 // TODO: find actual max depth of picture |
| 3101 SkISize shMapSize = SkShadowPaintFilterCanvas::ComputeDepthMapSize( |
| 3102 fLights->light(i), 255, |
| 3103 picture->cullRect().width(), |
| 3104 picture->cullRect().height()); |
| 3105 |
| 3106 SkImageInfo info = SkImageInfo::Make(shMapSize.fWidth, shMapSize.fHeight
, |
| 3107 kBGRA_8888_SkColorType, |
| 3108 kOpaque_SkAlphaType); |
| 3109 |
| 3110 // Create a new surface (that matches the backend of canvas) |
| 3111 // for each shadow map |
| 3112 sk_sp<SkSurface> surf(this->makeSurface(info)); |
| 3113 |
| 3114 // Wrap another SPFCanvas around the surface |
| 3115 sk_sp<SkShadowPaintFilterCanvas> depthMapCanvas = |
| 3116 sk_make_sp<SkShadowPaintFilterCanvas>(surf->getCanvas()); |
| 3117 |
| 3118 // set the depth map canvas to have the light we're drawing. |
| 3119 SkLights::Builder builder; |
| 3120 builder.add(fLights->light(i)); |
| 3121 sk_sp<SkLights> curLight = builder.finish(); |
| 3122 |
| 3123 depthMapCanvas->setLights(std::move(curLight)); |
| 3124 depthMapCanvas->drawPicture(picture); |
| 3125 |
| 3126 fLights->light(i).setShadowMap(surf->makeImageSnapshot()); |
| 3127 } |
| 3128 |
| 3129 sk_sp<SkImage> povDepthMap; |
| 3130 sk_sp<SkImage> diffuseMap; |
| 3131 |
| 3132 // TODO: pass the depth to the shader in vertices, or uniforms |
| 3133 // so we don't have to render depth and color separately |
| 3134 |
| 3135 // povDepthMap |
| 3136 { |
| 3137 SkLights::Builder builder; |
| 3138 builder.add(SkLights::Light(SkColor3f::Make(1.0f, 1.0f, 1.0f), |
| 3139 SkVector3::Make(0.0f, 0.0f, 1.0f))); |
| 3140 sk_sp<SkLights> povLight = builder.finish(); |
| 3141 |
| 3142 SkImageInfo info = SkImageInfo::Make(picture->cullRect().width(), |
| 3143 picture->cullRect().height(), |
| 3144 kBGRA_8888_SkColorType, |
| 3145 kOpaque_SkAlphaType); |
| 3146 |
| 3147 // Create a new surface (that matches the backend of canvas) |
| 3148 // to create the povDepthMap |
| 3149 sk_sp<SkSurface> surf(this->makeSurface(info)); |
| 3150 |
| 3151 // Wrap another SPFCanvas around the surface |
| 3152 sk_sp<SkShadowPaintFilterCanvas> depthMapCanvas = |
| 3153 sk_make_sp<SkShadowPaintFilterCanvas>(surf->getCanvas()); |
| 3154 |
| 3155 // set the depth map canvas to have the light as the user's POV |
| 3156 depthMapCanvas->setLights(std::move(povLight)); |
| 3157 |
| 3158 depthMapCanvas->drawPicture(picture); |
| 3159 |
| 3160 povDepthMap = surf->makeImageSnapshot(); |
| 3161 } |
| 3162 |
| 3163 // diffuseMap |
| 3164 { |
| 3165 SkImageInfo info = SkImageInfo::Make(picture->cullRect().width(), |
| 3166 picture->cullRect().height(), |
| 3167 kBGRA_8888_SkColorType, |
| 3168 kOpaque_SkAlphaType); |
| 3169 |
| 3170 sk_sp<SkSurface> surf(this->makeSurface(info)); |
| 3171 surf->getCanvas()->drawPicture(picture); |
| 3172 |
| 3173 diffuseMap = surf->makeImageSnapshot(); |
| 3174 } |
| 3175 |
| 3176 SkPaint shadowPaint; |
| 3177 |
| 3178 sk_sp<SkShader> povDepthShader = povDepthMap->makeShader(SkShader::kClamp_Ti
leMode, |
| 3179 SkShader::kClamp_Ti
leMode); |
| 3180 |
| 3181 sk_sp<SkShader> diffuseShader = diffuseMap->makeShader(SkShader::kClamp_Tile
Mode, |
| 3182 SkShader::kClamp_Tile
Mode); |
| 3183 |
| 3184 sk_sp<SkShader> shadowShader = SkShadowShader::Make(std::move(povDepthShader
), |
| 3185 std::move(diffuseShader)
, |
| 3186 std::move(fLights), |
| 3187 diffuseMap->width(), |
| 3188 diffuseMap->height()); |
| 3189 |
| 3190 shadowPaint.setShader(shadowShader); |
| 3191 |
| 3192 this->drawRect(SkRect::MakeIWH(diffuseMap->width(), diffuseMap->height()), s
hadowPaint); |
3073 } | 3193 } |
3074 #endif | 3194 #endif |
3075 | 3195 |
3076 /////////////////////////////////////////////////////////////////////////////// | 3196 /////////////////////////////////////////////////////////////////////////////// |
3077 /////////////////////////////////////////////////////////////////////////////// | 3197 /////////////////////////////////////////////////////////////////////////////// |
3078 | 3198 |
3079 SkCanvas::LayerIter::LayerIter(SkCanvas* canvas, bool skipEmptyClips) { | 3199 SkCanvas::LayerIter::LayerIter(SkCanvas* canvas, bool skipEmptyClips) { |
3080 static_assert(sizeof(fStorage) >= sizeof(SkDrawIter), "fStorage_too_small"); | 3200 static_assert(sizeof(fStorage) >= sizeof(SkDrawIter), "fStorage_too_small"); |
3081 | 3201 |
3082 SkASSERT(canvas); | 3202 SkASSERT(canvas); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3176 | 3296 |
3177 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 3297 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
3178 fCanvas->restoreToCount(fSaveCount); | 3298 fCanvas->restoreToCount(fSaveCount); |
3179 } | 3299 } |
3180 | 3300 |
3181 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API | 3301 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API |
3182 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p
rops) { | 3302 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p
rops) { |
3183 return this->makeSurface(info, props).release(); | 3303 return this->makeSurface(info, props).release(); |
3184 } | 3304 } |
3185 #endif | 3305 #endif |
OLD | NEW |