1 /* 2 * Copyright 2012 The Android Open Source Project 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkDeviceImageFilterProxy_DEFINED 9 #define SkDeviceImageFilterProxy_DEFINED 10 11 #include "SkBitmapDevice.h" 12 #include "SkDevice.h" 13 #include "SkImageFilter.h" 14 #include "SkSurfaceProps.h" 15 16 class SkDeviceImageFilterProxy : public SkImageFilter::Proxy { 17 public: SkDeviceImageFilterProxy(SkBaseDevice * device,const SkSurfaceProps & props)18 SkDeviceImageFilterProxy(SkBaseDevice* device, const SkSurfaceProps& props) 19 : fDevice(device) 20 , fProps(props.flags(), kUnknown_SkPixelGeometry) 21 {} 22 createDevice(int w,int h)23 SkBaseDevice* createDevice(int w, int h) override { 24 SkBaseDevice::CreateInfo cinfo(SkImageInfo::MakeN32Premul(w, h), 25 SkBaseDevice::kNever_TileUsage, 26 kUnknown_SkPixelGeometry, 27 true /*forImageFilter*/); 28 SkBaseDevice* dev = fDevice->onCreateDevice(cinfo, NULL); 29 if (NULL == dev) { 30 dev = SkBitmapDevice::Create(cinfo.fInfo); 31 } 32 return dev; 33 } canHandleImageFilter(const SkImageFilter * filter)34 bool canHandleImageFilter(const SkImageFilter* filter) override { 35 return fDevice->canHandleImageFilter(filter); 36 } filterImage(const SkImageFilter * filter,const SkBitmap & src,const SkImageFilter::Context & ctx,SkBitmap * result,SkIPoint * offset)37 virtual bool filterImage(const SkImageFilter* filter, const SkBitmap& src, 38 const SkImageFilter::Context& ctx, 39 SkBitmap* result, SkIPoint* offset) override { 40 return fDevice->filterImage(filter, src, ctx, result, offset); 41 } 42 surfaceProps()43 const SkSurfaceProps* surfaceProps() const override { 44 return &fProps; 45 } 46 47 private: 48 SkBaseDevice* fDevice; 49 const SkSurfaceProps fProps; 50 }; 51 52 #endif 53