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 18 matching lines...) Expand all Loading... | |
29 #include "SkReadPixelsRec.h" | 29 #include "SkReadPixelsRec.h" |
30 #include "SkRRect.h" | 30 #include "SkRRect.h" |
31 #include "SkSmallAllocator.h" | 31 #include "SkSmallAllocator.h" |
32 #include "SkSpecialImage.h" | 32 #include "SkSpecialImage.h" |
33 #include "SkSurface_Base.h" | 33 #include "SkSurface_Base.h" |
34 #include "SkTextBlob.h" | 34 #include "SkTextBlob.h" |
35 #include "SkTextFormatParams.h" | 35 #include "SkTextFormatParams.h" |
36 #include "SkTLazy.h" | 36 #include "SkTLazy.h" |
37 #include "SkTraceEvent.h" | 37 #include "SkTraceEvent.h" |
38 | 38 |
39 #include <new> | 39 #include <new> |
robertphillips
2016/08/08 14:18:31
put with others
vjiaoblack
2016/08/08 15:48:32
Done.
| |
40 #include <SkShadowPaintFilterCanvas.h> | |
jvanverth1
2016/08/08 14:15:47
No <>, put up with the other Sk includes.
vjiaoblack
2016/08/08 15:48:32
Done.
| |
40 | 41 |
41 #if SK_SUPPORT_GPU | 42 #if SK_SUPPORT_GPU |
42 #include "GrContext.h" | 43 #include "GrContext.h" |
43 #include "GrRenderTarget.h" | 44 #include "GrRenderTarget.h" |
44 #include "SkGrPriv.h" | 45 #include "SkGrPriv.h" |
robertphillips
2016/08/08 14:18:32
put with the Sk headers ?
vjiaoblack
2016/08/08 15:48:32
Done.
| |
46 #include "SkShadowShader.h" | |
47 | |
45 #endif | 48 #endif |
46 | 49 |
47 #define RETURN_ON_NULL(ptr) do { if (nullptr == (ptr)) return; } while (0) | 50 #define RETURN_ON_NULL(ptr) do { if (nullptr == (ptr)) return; } while (0) |
48 | 51 |
49 //#define SK_SUPPORT_PRECHECK_CLIPRECT | 52 //#define SK_SUPPORT_PRECHECK_CLIPRECT |
50 | 53 |
51 /* | 54 /* |
52 * Return true if the drawing this rect would hit every pixels in the canvas. | 55 * Return true if the drawing this rect would hit every pixels in the canvas. |
53 * | 56 * |
54 * Returns false if | 57 * Returns false if |
(...skipping 3003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3058 #ifdef SK_EXPERIMENTAL_SHADOWING | 3061 #ifdef SK_EXPERIMENTAL_SHADOWING |
3059 void SkCanvas::drawShadowedPicture(const SkPicture* picture, | 3062 void SkCanvas::drawShadowedPicture(const SkPicture* picture, |
3060 const SkMatrix* matrix, | 3063 const SkMatrix* matrix, |
3061 const SkPaint* paint) { | 3064 const SkPaint* paint) { |
3062 RETURN_ON_NULL(picture); | 3065 RETURN_ON_NULL(picture); |
3063 | 3066 |
3064 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawShadowedPicture()"); | 3067 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawShadowedPicture()"); |
3065 | 3068 |
3066 this->onDrawShadowedPicture(picture, matrix, paint); | 3069 this->onDrawShadowedPicture(picture, matrix, paint); |
3067 } | 3070 } |
3068 | 3071 |
robertphillips
2016/08/08 14:18:32
put with Gr headers ?
vjiaoblack
2016/08/08 15:48:32
Done.
| |
3072 #include "GrDrawContext.h" | |
jvanverth1
2016/08/08 14:15:47
This belongs at the top of the file in the SK_SUPP
robertphillips
2016/08/08 14:18:31
Need to handle matrix parameter too
vjiaoblack
2016/08/08 15:48:31
Done.
vjiaoblack
2016/08/08 15:48:32
Done.
| |
3069 void SkCanvas::onDrawShadowedPicture(const SkPicture* picture, | 3073 void SkCanvas::onDrawShadowedPicture(const SkPicture* picture, |
3070 const SkMatrix* matrix, | 3074 const SkMatrix* matrix, |
3071 const SkPaint* paint) { | 3075 const SkPaint* paint) { |
3072 this->onDrawPicture(picture, matrix, paint); | 3076 for (int i = 0; i < fLights->numLights(); ++i) { |
3077 // skip over ambient lights; they don't cast shadows | |
3078 // lights that have shadow maps do not need updating (because lights are immutable) | |
3079 | |
3080 if (SkLights::Light::kAmbient_LightType == fLights->light(i).type() || | |
3081 fLights->light(i).getShadowMap() != nullptr) { | |
3082 continue; | |
3083 } | |
3084 | |
3085 // TODO: compute the correct size of the depth map from the light proper ties | |
3086 // TODO: maybe add a kDepth_8_SkColorType | |
3087 // TODO: find actual max depth of picture | |
3088 SkISize shMapSize = SkShadowPaintFilterCanvas:: | |
robertphillips
2016/08/08 14:18:32
put the method name on the same line as its class
vjiaoblack
2016/08/08 15:48:31
Done.
| |
3089 ComputeDepthMapSize(fLights->light(i), 255, | |
3090 picture->cullRect().width(), | |
3091 picture->cullRect().height()); | |
3092 | |
3093 SkImageInfo info = SkImageInfo::Make(shMapSize.fWidth, shMapSize.fHeight , | |
3094 kBGRA_8888_SkColorType, | |
3095 kOpaque_SkAlphaType); | |
3096 | |
3097 // Create a new surface (that matches the backend of canvas) | |
3098 // for each shadow map | |
3099 sk_sp<SkSurface> surf(this->makeSurface(info)); | |
3100 | |
3101 // Wrap another SPFCanvas around the surface | |
3102 sk_sp<SkShadowPaintFilterCanvas> depthMapCanvas = | |
3103 sk_make_sp<SkShadowPaintFilterCanvas>(surf->getCanvas()); | |
3104 | |
3105 // set the depth map canvas to have the light we're drawing. | |
3106 SkLights::Builder builder; | |
3107 builder.add(fLights->light(i)); | |
3108 sk_sp<SkLights> curLight = builder.finish(); | |
3109 | |
3110 depthMapCanvas->setLights(std::move(curLight)); | |
3111 depthMapCanvas->drawPicture(picture); | |
3112 | |
3113 fLights->light(i).setShadowMap(surf->makeImageSnapshot()); | |
3114 } | |
3115 | |
3116 sk_sp<SkImage> povDepthMap; | |
3117 sk_sp<SkImage> diffuseMap; | |
3118 | |
3119 // TODO: pass the depth to the shader in vertices, or uniforms | |
3120 // so we don't have to render depth and color separately | |
3121 | |
3122 // povDepthMap | |
3123 { | |
3124 SkLights::Builder builder; | |
3125 builder.add(SkLights::Light(SkColor3f::Make(1.0f, 1.0f, 1.0f), | |
3126 SkVector3::Make(0.0f, 0.0f, 1.0f))); | |
3127 sk_sp<SkLights> povLight = builder.finish(); | |
3128 | |
3129 SkImageInfo info = SkImageInfo::Make(picture->cullRect().width(), | |
3130 picture->cullRect().height(), | |
3131 kBGRA_8888_SkColorType, | |
3132 kOpaque_SkAlphaType); | |
3133 | |
3134 // Create a new surface (that matches the backend of canvas) | |
3135 // to create the povDepthMap | |
3136 sk_sp<SkSurface> surf(this->makeSurface(info)); | |
3137 | |
3138 // Wrap another SPFCanvas around the surface | |
3139 sk_sp<SkShadowPaintFilterCanvas> depthMapCanvas = | |
3140 sk_make_sp<SkShadowPaintFilterCanvas>(surf->getCanvas()); | |
3141 | |
3142 // set the depth map canvas to have the light as the user's POV | |
3143 depthMapCanvas->setLights(std::move(povLight)); | |
3144 | |
3145 depthMapCanvas->drawPicture(picture); | |
3146 | |
3147 povDepthMap = surf->makeImageSnapshot(); | |
3148 } | |
3149 | |
3150 // diffuseMap | |
3151 { | |
3152 SkImageInfo info = SkImageInfo::Make(picture->cullRect().width(), | |
3153 picture->cullRect().height(), | |
3154 kBGRA_8888_SkColorType, | |
3155 kOpaque_SkAlphaType); | |
3156 | |
3157 sk_sp<SkSurface> surf(this->makeSurface(info)); | |
3158 surf->getCanvas()->drawPicture(picture); | |
3159 | |
3160 diffuseMap = surf->makeImageSnapshot(); | |
3161 } | |
3162 | |
robertphillips
2016/08/08 14:18:31
handle nullptr parameter here
vjiaoblack
2016/08/08 15:48:31
Done.
| |
3163 SkPaint paint2 = *paint; | |
3164 | |
3165 sk_sp<SkShader> povDepthShader = povDepthMap->makeShader(SkShader::kClamp_Ti leMode, | |
robertphillips
2016/08/08 14:18:31
line up
vjiaoblack
2016/08/08 15:48:32
Done.
| |
3166 SkShader::kClamp_TileM ode); | |
3167 | |
3168 sk_sp<SkShader> diffuseShader = diffuseMap->makeShader(SkShader::kClamp_Tile Mode, | |
robertphillips
2016/08/08 14:18:32
line up
vjiaoblack
2016/08/08 15:48:32
Done.
| |
3169 SkShader::kClamp_TileMod e); | |
3170 | |
3171 sk_sp<SkShader> shadowShader = SkShadowShader::Make(std::move(povDepthShader ), | |
3172 std::move(diffuseShader) , | |
3173 std::move(fLights), | |
3174 diffuseMap->width(), | |
3175 diffuseMap->height()); | |
3176 | |
3177 paint2.setShader(shadowShader); | |
3178 | |
3179 this->drawRect(SkRect::MakeIWH(diffuseMap->width(), diffuseMap->height()), p aint2); | |
robertphillips
2016/08/08 14:18:32
extra \ns
vjiaoblack
2016/08/08 15:48:32
Done.
| |
3180 | |
3181 | |
3182 | |
3073 } | 3183 } |
3074 #endif | 3184 #endif |
3075 | 3185 |
3076 /////////////////////////////////////////////////////////////////////////////// | 3186 /////////////////////////////////////////////////////////////////////////////// |
3077 /////////////////////////////////////////////////////////////////////////////// | 3187 /////////////////////////////////////////////////////////////////////////////// |
3078 | 3188 |
3079 SkCanvas::LayerIter::LayerIter(SkCanvas* canvas, bool skipEmptyClips) { | 3189 SkCanvas::LayerIter::LayerIter(SkCanvas* canvas, bool skipEmptyClips) { |
3080 static_assert(sizeof(fStorage) >= sizeof(SkDrawIter), "fStorage_too_small"); | 3190 static_assert(sizeof(fStorage) >= sizeof(SkDrawIter), "fStorage_too_small"); |
3081 | 3191 |
3082 SkASSERT(canvas); | 3192 SkASSERT(canvas); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3176 | 3286 |
3177 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 3287 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
3178 fCanvas->restoreToCount(fSaveCount); | 3288 fCanvas->restoreToCount(fSaveCount); |
3179 } | 3289 } |
3180 | 3290 |
3181 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API | 3291 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API |
3182 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) { | 3292 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) { |
3183 return this->makeSurface(info, props).release(); | 3293 return this->makeSurface(info, props).release(); |
3184 } | 3294 } |
3185 #endif | 3295 #endif |
OLD | NEW |