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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 | 126 |
127 struct GrSkDrawProcs : public SkDrawProcs { | 127 struct GrSkDrawProcs : public SkDrawProcs { |
128 public: | 128 public: |
129 GrContext* fContext; | 129 GrContext* fContext; |
130 GrTextContext* fTextContext; | 130 GrTextContext* fTextContext; |
131 GrFontScaler* fFontScaler; // cached in the skia glyphcache | 131 GrFontScaler* fFontScaler; // cached in the skia glyphcache |
132 }; | 132 }; |
133 | 133 |
134 /////////////////////////////////////////////////////////////////////////////// | 134 /////////////////////////////////////////////////////////////////////////////// |
135 | 135 |
136 SkGpuDevice* SkGpuDevice::Create(GrSurface* surface, const SkSurfaceProps& props
, unsigned flags) { | 136 SkGpuDevice* SkGpuDevice::Create(GrSurface* surface, unsigned flags) { |
137 SkASSERT(surface); | 137 SkASSERT(surface); |
138 if (NULL == surface->asRenderTarget() || surface->wasDestroyed()) { | 138 if (NULL == surface->asRenderTarget() || surface->wasDestroyed()) { |
139 return NULL; | 139 return NULL; |
140 } | 140 } |
141 return SkNEW_ARGS(SkGpuDevice, (surface, props, flags)); | 141 return SkNEW_ARGS(SkGpuDevice, (surface, flags)); |
142 } | 142 } |
143 | 143 |
144 SkGpuDevice::SkGpuDevice(GrSurface* surface, const SkSurfaceProps& props, unsign
ed flags) { | 144 SkGpuDevice::SkGpuDevice(GrSurface* surface, unsigned flags) { |
145 | 145 |
146 fDrawProcs = NULL; | 146 fDrawProcs = NULL; |
147 | 147 |
148 fContext = SkRef(surface->getContext()); | 148 fContext = SkRef(surface->getContext()); |
149 | 149 |
150 fNeedClear = flags & kNeedClear_Flag; | 150 fNeedClear = flags & kNeedClear_Flag; |
151 | 151 |
152 fRenderTarget = SkRef(surface->asRenderTarget()); | 152 fRenderTarget = SkRef(surface->asRenderTarget()); |
153 | 153 |
154 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, | 154 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, |
155 (surface->info(), surface, SkToBool(flags & kCac
hed_Flag))); | 155 (surface->info(), surface, SkToBool(flags & kCac
hed_Flag))); |
156 fLegacyBitmap.setInfo(surface->info()); | 156 fLegacyBitmap.setInfo(surface->info()); |
157 fLegacyBitmap.setPixelRef(pr)->unref(); | 157 fLegacyBitmap.setPixelRef(pr)->unref(); |
158 | 158 |
159 this->setPixelGeometry(props.pixelGeometry()); | |
160 | |
161 bool useDFFonts = !!(flags & kDFFonts_Flag); | 159 bool useDFFonts = !!(flags & kDFFonts_Flag); |
162 fMainTextContext = fContext->createTextContext(fRenderTarget, this->getLeaky
Properties(), useDFFonts); | 160 fMainTextContext = fContext->createTextContext(fRenderTarget, this->getLeaky
Properties(), useDFFonts); |
163 fFallbackTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, this->getL
eakyProperties())); | 161 fFallbackTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, this->getL
eakyProperties())); |
164 } | 162 } |
165 | 163 |
166 SkGpuDevice* SkGpuDevice::Create(GrContext* context, const SkImageInfo& origInfo
, | 164 SkGpuDevice* SkGpuDevice::Create(GrContext* context, const SkImageInfo& origInfo
, |
167 const SkSurfaceProps& props, int sampleCount) { | 165 int sampleCount) { |
168 if (kUnknown_SkColorType == origInfo.colorType() || | 166 if (kUnknown_SkColorType == origInfo.colorType() || |
169 origInfo.width() < 0 || origInfo.height() < 0) { | 167 origInfo.width() < 0 || origInfo.height() < 0) { |
170 return NULL; | 168 return NULL; |
171 } | 169 } |
172 | 170 |
173 SkColorType ct = origInfo.colorType(); | 171 SkColorType ct = origInfo.colorType(); |
174 SkAlphaType at = origInfo.alphaType(); | 172 SkAlphaType at = origInfo.alphaType(); |
175 // TODO: perhaps we can loosen this check now that colortype is more detaile
d | 173 // TODO: perhaps we can loosen this check now that colortype is more detaile
d |
176 // e.g. can we support both RGBA and BGRA here? | 174 // e.g. can we support both RGBA and BGRA here? |
177 if (kRGB_565_SkColorType == ct) { | 175 if (kRGB_565_SkColorType == ct) { |
(...skipping 11 matching lines...) Expand all Loading... |
189 desc.fWidth = info.width(); | 187 desc.fWidth = info.width(); |
190 desc.fHeight = info.height(); | 188 desc.fHeight = info.height(); |
191 desc.fConfig = SkImageInfo2GrPixelConfig(info); | 189 desc.fConfig = SkImageInfo2GrPixelConfig(info); |
192 desc.fSampleCnt = sampleCount; | 190 desc.fSampleCnt = sampleCount; |
193 | 191 |
194 SkAutoTUnref<GrTexture> texture(context->createUncachedTexture(desc, NULL, 0
)); | 192 SkAutoTUnref<GrTexture> texture(context->createUncachedTexture(desc, NULL, 0
)); |
195 if (!texture.get()) { | 193 if (!texture.get()) { |
196 return NULL; | 194 return NULL; |
197 } | 195 } |
198 | 196 |
199 return SkNEW_ARGS(SkGpuDevice, (texture.get(), props)); | 197 return SkNEW_ARGS(SkGpuDevice, (texture.get())); |
200 } | 198 } |
201 | 199 |
202 SkGpuDevice::~SkGpuDevice() { | 200 SkGpuDevice::~SkGpuDevice() { |
203 if (fDrawProcs) { | 201 if (fDrawProcs) { |
204 delete fDrawProcs; | 202 delete fDrawProcs; |
205 } | 203 } |
206 | 204 |
207 delete fMainTextContext; | 205 delete fMainTextContext; |
208 delete fFallbackTextContext; | 206 delete fFallbackTextContext; |
209 | 207 |
(...skipping 1590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1800 // match and ignore any padding. | 1798 // match and ignore any padding. |
1801 flags |= kCached_Flag; | 1799 flags |= kCached_Flag; |
1802 const GrContext::ScratchTexMatch match = (kSaveLayer_Usage == usage) ? | 1800 const GrContext::ScratchTexMatch match = (kSaveLayer_Usage == usage) ? |
1803 GrContext::kApprox_ScratchTexMat
ch : | 1801 GrContext::kApprox_ScratchTexMat
ch : |
1804 GrContext::kExact_ScratchTexMatc
h; | 1802 GrContext::kExact_ScratchTexMatc
h; |
1805 texture.reset(fContext->lockAndRefScratchTexture(desc, match)); | 1803 texture.reset(fContext->lockAndRefScratchTexture(desc, match)); |
1806 #else | 1804 #else |
1807 texture.reset(fContext->createUncachedTexture(desc, NULL, 0)); | 1805 texture.reset(fContext->createUncachedTexture(desc, NULL, 0)); |
1808 #endif | 1806 #endif |
1809 if (texture.get()) { | 1807 if (texture.get()) { |
1810 return SkGpuDevice::Create(texture, SkSurfaceProps(SkSurfaceProps::kLega
cyFontHost_InitType), flags); | 1808 return SkGpuDevice::Create(texture, flags); |
1811 } else { | 1809 } else { |
1812 GrPrintf("---- failed to create compatible device texture [%d %d]\n", | 1810 GrPrintf("---- failed to create compatible device texture [%d %d]\n", |
1813 info.width(), info.height()); | 1811 info.width(), info.height()); |
1814 return NULL; | 1812 return NULL; |
1815 } | 1813 } |
1816 } | 1814 } |
1817 | 1815 |
1818 SkSurface* SkGpuDevice::newSurface(const SkImageInfo& info, const SkSurfaceProps
& props) { | 1816 SkSurface* SkGpuDevice::newSurface(const SkImageInfo& info) { |
1819 return SkSurface::NewRenderTarget(fContext, info, fRenderTarget->numSamples(
), &props); | 1817 return SkSurface::NewRenderTarget(fContext, info, fRenderTarget->numSamples(
)); |
1820 } | 1818 } |
1821 | 1819 |
1822 void SkGpuDevice::EXPERIMENTAL_optimize(const SkPicture* picture) { | 1820 void SkGpuDevice::EXPERIMENTAL_optimize(const SkPicture* picture) { |
1823 fContext->getLayerCache()->processDeletedPictures(); | 1821 fContext->getLayerCache()->processDeletedPictures(); |
1824 | 1822 |
1825 if (picture->fData.get() && !picture->fData->suitableForLayerOptimization())
{ | 1823 if (picture->fData.get() && !picture->fData->suitableForLayerOptimization())
{ |
1826 return; | 1824 return; |
1827 } | 1825 } |
1828 | 1826 |
1829 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); | 1827 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1881 GrLayerHoister::UnlockLayers(fContext->getLayerCache(), picture); | 1879 GrLayerHoister::UnlockLayers(fContext->getLayerCache(), picture); |
1882 | 1880 |
1883 return true; | 1881 return true; |
1884 } | 1882 } |
1885 | 1883 |
1886 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1884 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
1887 // We always return a transient cache, so it is freed after each | 1885 // We always return a transient cache, so it is freed after each |
1888 // filter traversal. | 1886 // filter traversal. |
1889 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 1887 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
1890 } | 1888 } |
OLD | NEW |