| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "PictureRenderer.h" | 8 #include "PictureRenderer.h" |
| 9 #include "picture_utils.h" | 9 #include "picture_utils.h" |
| 10 #include "SamplePipeControllers.h" | 10 #include "SamplePipeControllers.h" |
| 11 #include "SkBitmapHasher.h" | 11 #include "SkBitmapHasher.h" |
| 12 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
| 13 #include "SkData.h" | 13 #include "SkData.h" |
| 14 #include "SkDevice.h" | 14 #include "SkDevice.h" |
| 15 #include "SkDiscardableMemoryPool.h" | 15 #include "SkDiscardableMemoryPool.h" |
| 16 #include "SkGPipe.h" | 16 #include "SkGPipe.h" |
| 17 #if SK_SUPPORT_GPU | 17 #if SK_SUPPORT_GPU |
| 18 #include "gl/GrGLDefines.h" | 18 #include "gl/GrGLDefines.h" |
| 19 #include "SkGpuDevice.h" | 19 #include "SkGpuDevice.h" |
| 20 #endif | 20 #endif |
| 21 #include "SkGraphics.h" | 21 #include "SkGraphics.h" |
| 22 #include "SkImageEncoder.h" | 22 #include "SkImageEncoder.h" |
| 23 #include "SkMaskFilter.h" | 23 #include "SkMaskFilter.h" |
| 24 #include "SkMatrix.h" | 24 #include "SkMatrix.h" |
| 25 #include "SkMultiPictureDraw.h" | 25 #include "SkMultiPictureDraw.h" |
| 26 #include "SkOSFile.h" | 26 #include "SkOSFile.h" |
| 27 #include "SkPaintFilterCanvas.h" |
| 27 #include "SkPicture.h" | 28 #include "SkPicture.h" |
| 28 #include "SkPictureRecorder.h" | 29 #include "SkPictureRecorder.h" |
| 29 #include "SkPictureUtils.h" | 30 #include "SkPictureUtils.h" |
| 30 #include "SkPixelRef.h" | 31 #include "SkPixelRef.h" |
| 31 #include "SkPixelSerializer.h" | 32 #include "SkPixelSerializer.h" |
| 32 #include "SkScalar.h" | 33 #include "SkScalar.h" |
| 33 #include "SkStream.h" | 34 #include "SkStream.h" |
| 34 #include "SkString.h" | 35 #include "SkString.h" |
| 35 #include "SkSurface.h" | 36 #include "SkSurface.h" |
| 36 #include "SkTemplates.h" | 37 #include "SkTemplates.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 } | 81 } |
| 81 | 82 |
| 82 void PictureRenderer::CopyString(SkString* dest, const SkString* src) { | 83 void PictureRenderer::CopyString(SkString* dest, const SkString* src) { |
| 83 if (src) { | 84 if (src) { |
| 84 dest->set(*src); | 85 dest->set(*src); |
| 85 } else { | 86 } else { |
| 86 dest->reset(); | 87 dest->reset(); |
| 87 } | 88 } |
| 88 } | 89 } |
| 89 | 90 |
| 90 class FlagsDrawFilter : public SkDrawFilter { | 91 class FlagsFilterCanvas : public SkPaintFilterCanvas { |
| 91 public: | 92 public: |
| 92 FlagsDrawFilter(PictureRenderer::DrawFilterFlags* flags) : | 93 FlagsFilterCanvas(SkCanvas* canvas, PictureRenderer::DrawFilterFlags* flags) |
| 93 fFlags(flags) {} | 94 : INHERITED(canvas->imageInfo().width(), canvas->imageInfo().height()) |
| 95 , fFlags(flags) { |
| 96 this->addCanvas(canvas); |
| 97 } |
| 94 | 98 |
| 95 virtual bool filter(SkPaint* paint, Type t) { | 99 protected: |
| 100 void onFilterPaint(SkPaint* paint, Type t) const override { |
| 96 paint->setFlags(paint->getFlags() & ~fFlags[t] & SkPaint::kAllFlags); | 101 paint->setFlags(paint->getFlags() & ~fFlags[t] & SkPaint::kAllFlags); |
| 97 if (PictureRenderer::kMaskFilter_DrawFilterFlag & fFlags[t]) { | 102 if (PictureRenderer::kMaskFilter_DrawFilterFlag & fFlags[t]) { |
| 98 SkMaskFilter* maskFilter = paint->getMaskFilter(); | 103 SkMaskFilter* maskFilter = paint->getMaskFilter(); |
| 99 if (maskFilter) { | 104 if (maskFilter) { |
| 100 paint->setMaskFilter(NULL); | 105 paint->setMaskFilter(NULL); |
| 101 } | 106 } |
| 102 } | 107 } |
| 103 if (PictureRenderer::kHinting_DrawFilterFlag & fFlags[t]) { | 108 if (PictureRenderer::kHinting_DrawFilterFlag & fFlags[t]) { |
| 104 paint->setHinting(SkPaint::kNo_Hinting); | 109 paint->setHinting(SkPaint::kNo_Hinting); |
| 105 } else if (PictureRenderer::kSlightHinting_DrawFilterFlag & fFlags[t]) { | 110 } else if (PictureRenderer::kSlightHinting_DrawFilterFlag & fFlags[t]) { |
| 106 paint->setHinting(SkPaint::kSlight_Hinting); | 111 paint->setHinting(SkPaint::kSlight_Hinting); |
| 107 } | 112 } |
| 108 return true; | |
| 109 } | 113 } |
| 110 | 114 |
| 111 private: | 115 private: |
| 112 PictureRenderer::DrawFilterFlags* fFlags; | 116 const PictureRenderer::DrawFilterFlags* fFlags; |
| 117 |
| 118 typedef SkPaintFilterCanvas INHERITED; |
| 113 }; | 119 }; |
| 114 | 120 |
| 115 static void setUpFilter(SkCanvas* canvas, PictureRenderer::DrawFilterFlags* draw
Filters) { | |
| 116 if (drawFilters && !canvas->getDrawFilter()) { | |
| 117 canvas->setDrawFilter(SkNEW_ARGS(FlagsDrawFilter, (drawFilters)))->unref
(); | |
| 118 if (drawFilters[0] & PictureRenderer::kAAClip_DrawFilterFlag) { | |
| 119 canvas->setAllowSoftClip(false); | |
| 120 } | |
| 121 } | |
| 122 } | |
| 123 | |
| 124 SkCanvas* PictureRenderer::setupCanvas() { | 121 SkCanvas* PictureRenderer::setupCanvas() { |
| 125 const int width = this->getViewWidth(); | 122 const int width = this->getViewWidth(); |
| 126 const int height = this->getViewHeight(); | 123 const int height = this->getViewHeight(); |
| 127 return this->setupCanvas(width, height); | 124 return this->setupCanvas(width, height); |
| 128 } | 125 } |
| 129 | 126 |
| 130 SkCanvas* PictureRenderer::setupCanvas(int width, int height) { | 127 SkCanvas* PictureRenderer::setupCanvas(int width, int height) { |
| 131 SkCanvas* canvas; | 128 SkAutoTUnref<SkCanvas> canvas; |
| 129 |
| 132 switch(fDeviceType) { | 130 switch(fDeviceType) { |
| 133 case kBitmap_DeviceType: { | 131 case kBitmap_DeviceType: { |
| 134 SkBitmap bitmap; | 132 SkBitmap bitmap; |
| 135 sk_tools::setup_bitmap(&bitmap, width, height); | 133 sk_tools::setup_bitmap(&bitmap, width, height); |
| 136 canvas = SkNEW_ARGS(SkCanvas, (bitmap)); | 134 canvas.reset(SkNEW_ARGS(SkCanvas, (bitmap))); |
| 137 } | 135 } |
| 138 break; | 136 break; |
| 139 #if SK_SUPPORT_GPU | 137 #if SK_SUPPORT_GPU |
| 140 #if SK_ANGLE | 138 #if SK_ANGLE |
| 141 case kAngle_DeviceType: | 139 case kAngle_DeviceType: |
| 142 // fall through | 140 // fall through |
| 143 #endif | 141 #endif |
| 144 #if SK_MESA | 142 #if SK_MESA |
| 145 case kMesa_DeviceType: | 143 case kMesa_DeviceType: |
| 146 // fall through | 144 // fall through |
| (...skipping 11 matching lines...) Expand all Loading... |
| 158 desc.fSampleCnt = fSampleCount; | 156 desc.fSampleCnt = fSampleCount; |
| 159 target.reset(fGrContext->textureProvider()->createTexture(desc,
false, NULL, 0)); | 157 target.reset(fGrContext->textureProvider()->createTexture(desc,
false, NULL, 0)); |
| 160 } | 158 } |
| 161 | 159 |
| 162 uint32_t flags = fUseDFText ? SkSurfaceProps::kUseDistanceFieldFonts
_Flag : 0; | 160 uint32_t flags = fUseDFText ? SkSurfaceProps::kUseDistanceFieldFonts
_Flag : 0; |
| 163 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType
); | 161 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType
); |
| 164 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(target->asRende
rTarget(), &props)); | 162 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(target->asRende
rTarget(), &props)); |
| 165 if (!device) { | 163 if (!device) { |
| 166 return NULL; | 164 return NULL; |
| 167 } | 165 } |
| 168 canvas = SkNEW_ARGS(SkCanvas, (device)); | 166 canvas.reset(SkNEW_ARGS(SkCanvas, (device))); |
| 169 break; | 167 break; |
| 170 } | 168 } |
| 171 #endif | 169 #endif |
| 172 default: | 170 default: |
| 173 SkASSERT(0); | 171 SkASSERT(0); |
| 174 return NULL; | 172 return NULL; |
| 175 } | 173 } |
| 176 setUpFilter(canvas, fDrawFilters); | 174 |
| 175 if (fHasDrawFilters) { |
| 176 if (fDrawFilters[0] & PictureRenderer::kAAClip_DrawFilterFlag) { |
| 177 canvas->setAllowSoftClip(false); |
| 178 } |
| 179 |
| 180 canvas.reset(SkNEW_ARGS(FlagsFilterCanvas, (canvas.get(), fDrawFilters))
); |
| 181 } |
| 182 |
| 177 this->scaleToScaleFactor(canvas); | 183 this->scaleToScaleFactor(canvas); |
| 178 | 184 |
| 179 // Pictures often lie about their extent (i.e., claim to be 100x100 but | 185 // Pictures often lie about their extent (i.e., claim to be 100x100 but |
| 180 // only ever draw to 90x100). Clear here so the undrawn portion will have | 186 // only ever draw to 90x100). Clear here so the undrawn portion will have |
| 181 // a consistent color | 187 // a consistent color |
| 182 canvas->clear(SK_ColorTRANSPARENT); | 188 canvas->clear(SK_ColorTRANSPARENT); |
| 183 return canvas; | 189 return canvas.detach(); |
| 184 } | 190 } |
| 185 | 191 |
| 186 void PictureRenderer::scaleToScaleFactor(SkCanvas* canvas) { | 192 void PictureRenderer::scaleToScaleFactor(SkCanvas* canvas) { |
| 187 SkASSERT(canvas != NULL); | 193 SkASSERT(canvas != NULL); |
| 188 if (fScaleFactor != SK_Scalar1) { | 194 if (fScaleFactor != SK_Scalar1) { |
| 189 canvas->scale(fScaleFactor, fScaleFactor); | 195 canvas->scale(fScaleFactor, fScaleFactor); |
| 190 } | 196 } |
| 191 } | 197 } |
| 192 | 198 |
| 193 void PictureRenderer::end() { | 199 void PictureRenderer::end() { |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 case kNone_BBoxHierarchyType: | 819 case kNone_BBoxHierarchyType: |
| 814 return NULL; | 820 return NULL; |
| 815 case kRTree_BBoxHierarchyType: | 821 case kRTree_BBoxHierarchyType: |
| 816 return SkNEW(SkRTreeFactory); | 822 return SkNEW(SkRTreeFactory); |
| 817 } | 823 } |
| 818 SkASSERT(0); // invalid bbhType | 824 SkASSERT(0); // invalid bbhType |
| 819 return NULL; | 825 return NULL; |
| 820 } | 826 } |
| 821 | 827 |
| 822 } // namespace sk_tools | 828 } // namespace sk_tools |
| OLD | NEW |