| 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 20 matching lines...) Expand all Loading... |
| 31 #include "SkImageFilter.h" | 31 #include "SkImageFilter.h" |
| 32 #include "SkLayerInfo.h" | 32 #include "SkLayerInfo.h" |
| 33 #include "SkMaskFilter.h" | 33 #include "SkMaskFilter.h" |
| 34 #include "SkPathEffect.h" | 34 #include "SkPathEffect.h" |
| 35 #include "SkPicture.h" | 35 #include "SkPicture.h" |
| 36 #include "SkPictureData.h" | 36 #include "SkPictureData.h" |
| 37 #include "SkRecord.h" | 37 #include "SkRecord.h" |
| 38 #include "SkRRect.h" | 38 #include "SkRRect.h" |
| 39 #include "SkStroke.h" | 39 #include "SkStroke.h" |
| 40 #include "SkSurface.h" | 40 #include "SkSurface.h" |
| 41 #include "SkSurface_Gpu.h" |
| 41 #include "SkTLazy.h" | 42 #include "SkTLazy.h" |
| 42 #include "SkUtils.h" | 43 #include "SkUtils.h" |
| 43 #include "SkVertState.h" | 44 #include "SkVertState.h" |
| 44 #include "SkXfermode.h" | 45 #include "SkXfermode.h" |
| 45 #include "SkErrorInternals.h" | 46 #include "SkErrorInternals.h" |
| 46 | 47 |
| 47 #if SK_SUPPORT_GPU | 48 #if SK_SUPPORT_GPU |
| 48 | 49 |
| 49 enum { kDefaultImageFilterCacheSize = 32 * 1024 * 1024 }; | 50 enum { kDefaultImageFilterCacheSize = 32 * 1024 * 1024 }; |
| 50 | 51 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 159 |
| 159 SkImageInfo info = rt->surfacePriv().info(); | 160 SkImageInfo info = rt->surfacePriv().info(); |
| 160 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, rt)); | 161 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, rt)); |
| 161 fLegacyBitmap.setInfo(info); | 162 fLegacyBitmap.setInfo(info); |
| 162 fLegacyBitmap.setPixelRef(pr)->unref(); | 163 fLegacyBitmap.setPixelRef(pr)->unref(); |
| 163 | 164 |
| 164 bool useDFT = fSurfaceProps.isUseDistanceFieldFonts(); | 165 bool useDFT = fSurfaceProps.isUseDistanceFieldFonts(); |
| 165 fTextContext = fContext->createTextContext(fRenderTarget, this->getLeakyProp
erties(), useDFT); | 166 fTextContext = fContext->createTextContext(fRenderTarget, this->getLeakyProp
erties(), useDFT); |
| 166 } | 167 } |
| 167 | 168 |
| 168 SkGpuDevice* SkGpuDevice::Create(GrContext* context, SkSurface::Budgeted budgete
d, | 169 GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkSurface::B
udgeted budgeted, |
| 169 const SkImageInfo& origInfo, int sampleCount, | 170 const SkImageInfo& origInfo, int
sampleCount) { |
| 170 const SkSurfaceProps* props, unsigned flags) { | |
| 171 if (kUnknown_SkColorType == origInfo.colorType() || | 171 if (kUnknown_SkColorType == origInfo.colorType() || |
| 172 origInfo.width() < 0 || origInfo.height() < 0) { | 172 origInfo.width() < 0 || origInfo.height() < 0) { |
| 173 return NULL; | 173 return NULL; |
| 174 } | 174 } |
| 175 | 175 |
| 176 if (!context) { | 176 if (!context) { |
| 177 return NULL; | 177 return NULL; |
| 178 } | 178 } |
| 179 | 179 |
| 180 SkColorType ct = origInfo.colorType(); | 180 SkColorType ct = origInfo.colorType(); |
| 181 SkAlphaType at = origInfo.alphaType(); | 181 SkAlphaType at = origInfo.alphaType(); |
| 182 if (kRGB_565_SkColorType == ct) { | 182 if (kRGB_565_SkColorType == ct) { |
| 183 at = kOpaque_SkAlphaType; // force this setting | 183 at = kOpaque_SkAlphaType; // force this setting |
| 184 } else if (ct != kBGRA_8888_SkColorType && ct != kRGBA_8888_SkColorType) { | 184 } else if (ct != kBGRA_8888_SkColorType && ct != kRGBA_8888_SkColorType) { |
| 185 // Fall back from whatever ct was to default of kRGBA or kBGRA which is
aliased as kN32 | 185 // Fall back from whatever ct was to default of kRGBA or kBGRA which is
aliased as kN32 |
| 186 ct = kN32_SkColorType; | 186 ct = kN32_SkColorType; |
| 187 } | 187 } |
| 188 if (kOpaque_SkAlphaType != at) { | 188 if (kOpaque_SkAlphaType != at) { |
| 189 at = kPremul_SkAlphaType; // force this setting | 189 at = kPremul_SkAlphaType; // force this setting |
| 190 } | 190 } |
| 191 const SkImageInfo info = SkImageInfo::Make(origInfo.width(), origInfo.height
(), ct, at); | 191 const SkImageInfo info = SkImageInfo::Make(origInfo.width(), origInfo.height
(), ct, at); |
| 192 | 192 |
| 193 GrSurfaceDesc desc; | 193 GrSurfaceDesc desc; |
| 194 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 194 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 195 desc.fWidth = info.width(); | 195 desc.fWidth = info.width(); |
| 196 desc.fHeight = info.height(); | 196 desc.fHeight = info.height(); |
| 197 desc.fConfig = SkImageInfo2GrPixelConfig(info); | 197 desc.fConfig = SkImageInfo2GrPixelConfig(info); |
| 198 desc.fSampleCnt = sampleCount; | 198 desc.fSampleCnt = sampleCount; |
| 199 GrTexture* texture = context->createTexture(desc, SkToBool(budgeted), NULL,
0); |
| 200 if (NULL == texture) { |
| 201 return NULL; |
| 202 } |
| 203 SkASSERT(NULL != texture->asRenderTarget()); |
| 204 return texture->asRenderTarget(); |
| 205 } |
| 199 | 206 |
| 200 SkAutoTUnref<GrTexture> texture(context->createTexture(desc, SkToBool(budget
ed), NULL, 0)); | 207 SkGpuDevice* SkGpuDevice::Create(GrContext* context, SkSurface::Budgeted budgete
d, |
| 201 if (!texture) { | 208 const SkImageInfo& info, int sampleCount, |
| 209 const SkSurfaceProps* props, unsigned flags) { |
| 210 |
| 211 SkAutoTUnref<GrRenderTarget> rt(CreateRenderTarget(context, budgeted, info,
sampleCount)); |
| 212 if (!rt) { |
| 202 return NULL; | 213 return NULL; |
| 203 } | 214 } |
| 204 | 215 |
| 205 return SkNEW_ARGS(SkGpuDevice, (texture->asRenderTarget(), props, flags)); | 216 return SkNEW_ARGS(SkGpuDevice, (rt, props, flags)); |
| 206 } | 217 } |
| 207 | 218 |
| 208 SkGpuDevice::~SkGpuDevice() { | 219 SkGpuDevice::~SkGpuDevice() { |
| 209 if (fDrawProcs) { | 220 if (fDrawProcs) { |
| 210 delete fDrawProcs; | 221 delete fDrawProcs; |
| 211 } | 222 } |
| 212 | 223 |
| 213 delete fTextContext; | 224 delete fTextContext; |
| 214 | 225 |
| 215 // The GrContext takes a ref on the target. We don't want to cause the rende
r | 226 // The GrContext takes a ref on the target. We don't want to cause the rende
r |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 } | 315 } |
| 305 | 316 |
| 306 void SkGpuDevice::clearAll() { | 317 void SkGpuDevice::clearAll() { |
| 307 GrColor color = 0; | 318 GrColor color = 0; |
| 308 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::clearAll", fContext); | 319 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::clearAll", fContext); |
| 309 SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); | 320 SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); |
| 310 fContext->clear(&rect, color, true, fRenderTarget); | 321 fContext->clear(&rect, color, true, fRenderTarget); |
| 311 fNeedClear = false; | 322 fNeedClear = false; |
| 312 } | 323 } |
| 313 | 324 |
| 325 void SkGpuDevice::swapRenderTarget(GrRenderTarget* newRenderTarget) { |
| 326 SkASSERT(!fNeedClear); |
| 327 if (fContext->getRenderTarget() == fRenderTarget) { |
| 328 fContext->setRenderTarget(NULL); |
| 329 } |
| 330 SkRefCnt_SafeAssign(fRenderTarget, newRenderTarget); |
| 331 SkASSERT(newRenderTarget->surfacePriv().info() == fLegacyBitmap.info()); |
| 332 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (newRenderTarget->surfacePriv().in
fo(), |
| 333 newRenderTarget)); |
| 334 fLegacyBitmap.setPixelRef(pr)->unref(); |
| 335 } |
| 336 |
| 314 /////////////////////////////////////////////////////////////////////////////// | 337 /////////////////////////////////////////////////////////////////////////////// |
| 315 | 338 |
| 316 SK_COMPILE_ASSERT(SkShader::kNone_BitmapType == 0, shader_type_mismatch); | 339 SK_COMPILE_ASSERT(SkShader::kNone_BitmapType == 0, shader_type_mismatch); |
| 317 SK_COMPILE_ASSERT(SkShader::kDefault_BitmapType == 1, shader_type_mismatch); | 340 SK_COMPILE_ASSERT(SkShader::kDefault_BitmapType == 1, shader_type_mismatch); |
| 318 SK_COMPILE_ASSERT(SkShader::kRadial_BitmapType == 2, shader_type_mismatch); | 341 SK_COMPILE_ASSERT(SkShader::kRadial_BitmapType == 2, shader_type_mismatch); |
| 319 SK_COMPILE_ASSERT(SkShader::kSweep_BitmapType == 3, shader_type_mismatch); | 342 SK_COMPILE_ASSERT(SkShader::kSweep_BitmapType == 3, shader_type_mismatch); |
| 320 SK_COMPILE_ASSERT(SkShader::kTwoPointRadial_BitmapType == 4, | 343 SK_COMPILE_ASSERT(SkShader::kTwoPointRadial_BitmapType == 4, |
| 321 shader_type_mismatch); | 344 shader_type_mismatch); |
| 322 SK_COMPILE_ASSERT(SkShader::kTwoPointConical_BitmapType == 5, | 345 SK_COMPILE_ASSERT(SkShader::kTwoPointConical_BitmapType == 5, |
| 323 shader_type_mismatch); | 346 shader_type_mismatch); |
| (...skipping 1580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1904 #endif | 1927 #endif |
| 1905 } | 1928 } |
| 1906 | 1929 |
| 1907 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1930 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
| 1908 // We always return a transient cache, so it is freed after each | 1931 // We always return a transient cache, so it is freed after each |
| 1909 // filter traversal. | 1932 // filter traversal. |
| 1910 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 1933 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
| 1911 } | 1934 } |
| 1912 | 1935 |
| 1913 #endif | 1936 #endif |
| OLD | NEW |