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 "GrBlurUtils.h" | 10 #include "GrBlurUtils.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 152 |
153 SkGpuDevice* SkGpuDevice::Create(GrRenderTarget* rt, int width, int height, | 153 SkGpuDevice* SkGpuDevice::Create(GrRenderTarget* rt, int width, int height, |
154 const SkSurfaceProps* props, InitContents init)
{ | 154 const SkSurfaceProps* props, InitContents init)
{ |
155 if (!rt || rt->wasDestroyed()) { | 155 if (!rt || rt->wasDestroyed()) { |
156 return NULL; | 156 return NULL; |
157 } | 157 } |
158 unsigned flags; | 158 unsigned flags; |
159 if (!CheckAlphaTypeAndGetFlags(NULL, init, &flags)) { | 159 if (!CheckAlphaTypeAndGetFlags(NULL, init, &flags)) { |
160 return NULL; | 160 return NULL; |
161 } | 161 } |
162 return SkNEW_ARGS(SkGpuDevice, (rt, width, height, props, flags)); | 162 return new SkGpuDevice(rt, width, height, props, flags); |
163 } | 163 } |
164 | 164 |
165 SkGpuDevice* SkGpuDevice::Create(GrContext* context, SkSurface::Budgeted budgete
d, | 165 SkGpuDevice* SkGpuDevice::Create(GrContext* context, SkSurface::Budgeted budgete
d, |
166 const SkImageInfo& info, int sampleCount, | 166 const SkImageInfo& info, int sampleCount, |
167 const SkSurfaceProps* props, InitContents init)
{ | 167 const SkSurfaceProps* props, InitContents init)
{ |
168 unsigned flags; | 168 unsigned flags; |
169 if (!CheckAlphaTypeAndGetFlags(&info, init, &flags)) { | 169 if (!CheckAlphaTypeAndGetFlags(&info, init, &flags)) { |
170 return NULL; | 170 return NULL; |
171 } | 171 } |
172 | 172 |
173 SkAutoTUnref<GrRenderTarget> rt(CreateRenderTarget(context, budgeted, info,
sampleCount)); | 173 SkAutoTUnref<GrRenderTarget> rt(CreateRenderTarget(context, budgeted, info,
sampleCount)); |
174 if (NULL == rt) { | 174 if (NULL == rt) { |
175 return NULL; | 175 return NULL; |
176 } | 176 } |
177 | 177 |
178 return SkNEW_ARGS(SkGpuDevice, (rt, info.width(), info.height(), props, flag
s)); | 178 return new SkGpuDevice(rt, info.width(), info.height(), props, flags); |
179 } | 179 } |
180 | 180 |
181 SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, int width, int height, | 181 SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, int width, int height, |
182 const SkSurfaceProps* props, unsigned flags) | 182 const SkSurfaceProps* props, unsigned flags) |
183 : INHERITED(SkSurfacePropsCopyOrDefault(props)) | 183 : INHERITED(SkSurfacePropsCopyOrDefault(props)) |
184 { | 184 { |
185 fDrawProcs = NULL; | 185 fDrawProcs = NULL; |
186 | 186 |
187 fContext = SkRef(rt->getContext()); | 187 fContext = SkRef(rt->getContext()); |
188 fNeedClear = SkToBool(flags & kNeedClear_Flag); | 188 fNeedClear = SkToBool(flags & kNeedClear_Flag); |
189 fOpaque = SkToBool(flags & kIsOpaque_Flag); | 189 fOpaque = SkToBool(flags & kIsOpaque_Flag); |
190 | 190 |
191 fRenderTarget = SkRef(rt); | 191 fRenderTarget = SkRef(rt); |
192 | 192 |
193 SkAlphaType at = fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; | 193 SkAlphaType at = fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; |
194 SkImageInfo info = rt->surfacePriv().info(at).makeWH(width, height); | 194 SkImageInfo info = rt->surfacePriv().info(at).makeWH(width, height); |
195 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, rt)); | 195 SkPixelRef* pr = new SkGrPixelRef(info, rt); |
196 fLegacyBitmap.setInfo(info); | 196 fLegacyBitmap.setInfo(info); |
197 fLegacyBitmap.setPixelRef(pr)->unref(); | 197 fLegacyBitmap.setPixelRef(pr)->unref(); |
198 | 198 |
199 fDrawContext.reset(SkRef(fContext->drawContext(&this->surfaceProps()))); | 199 fDrawContext.reset(SkRef(fContext->drawContext(&this->surfaceProps()))); |
200 } | 200 } |
201 | 201 |
202 GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkSurface::B
udgeted budgeted, | 202 GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkSurface::B
udgeted budgeted, |
203 const SkImageInfo& origInfo, int
sampleCount) { | 203 const SkImageInfo& origInfo, int
sampleCount) { |
204 if (kUnknown_SkColorType == origInfo.colorType() || | 204 if (kUnknown_SkColorType == origInfo.colorType() || |
205 origInfo.width() < 0 || origInfo.height() < 0) { | 205 origInfo.width() < 0 || origInfo.height() < 0) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 SkASSERT(fRenderTarget != newRT); | 363 SkASSERT(fRenderTarget != newRT); |
364 | 364 |
365 fRenderTarget->unref(); | 365 fRenderTarget->unref(); |
366 fRenderTarget = newRT.detach(); | 366 fRenderTarget = newRT.detach(); |
367 | 367 |
368 #ifdef SK_DEBUG | 368 #ifdef SK_DEBUG |
369 SkImageInfo info = fRenderTarget->surfacePriv().info(fOpaque ? kOpaque_SkAlp
haType : | 369 SkImageInfo info = fRenderTarget->surfacePriv().info(fOpaque ? kOpaque_SkAlp
haType : |
370 kPremul_SkAlp
haType); | 370 kPremul_SkAlp
haType); |
371 SkASSERT(info == fLegacyBitmap.info()); | 371 SkASSERT(info == fLegacyBitmap.info()); |
372 #endif | 372 #endif |
373 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (fLegacyBitmap.info(), fRenderTarg
et)); | 373 SkPixelRef* pr = new SkGrPixelRef(fLegacyBitmap.info(), fRenderTarget); |
374 fLegacyBitmap.setPixelRef(pr)->unref(); | 374 fLegacyBitmap.setPixelRef(pr)->unref(); |
375 | 375 |
376 fDrawContext.reset(SkRef(fRenderTarget->getContext()->drawContext(&this->sur
faceProps()))); | 376 fDrawContext.reset(SkRef(fRenderTarget->getContext()->drawContext(&this->sur
faceProps()))); |
377 } | 377 } |
378 | 378 |
379 /////////////////////////////////////////////////////////////////////////////// | 379 /////////////////////////////////////////////////////////////////////////////// |
380 | 380 |
381 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { | 381 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { |
382 CHECK_SHOULD_DRAW(draw); | 382 CHECK_SHOULD_DRAW(draw); |
383 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPaint", fContext); | 383 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPaint", fContext); |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 fDrawContext->drawOval(fRenderTarget, fClip, grPaint, *draw.fMatrix, oval, s
trokeInfo); | 661 fDrawContext->drawOval(fRenderTarget, fClip, grPaint, *draw.fMatrix, oval, s
trokeInfo); |
662 } | 662 } |
663 | 663 |
664 #include "SkMaskFilter.h" | 664 #include "SkMaskFilter.h" |
665 | 665 |
666 /////////////////////////////////////////////////////////////////////////////// | 666 /////////////////////////////////////////////////////////////////////////////// |
667 | 667 |
668 static SkBitmap wrap_texture(GrTexture* texture, int width, int height) { | 668 static SkBitmap wrap_texture(GrTexture* texture, int width, int height) { |
669 SkBitmap result; | 669 SkBitmap result; |
670 result.setInfo(SkImageInfo::MakeN32Premul(width, height)); | 670 result.setInfo(SkImageInfo::MakeN32Premul(width, height)); |
671 result.setPixelRef(SkNEW_ARGS(SkGrPixelRef, (result.info(), texture)))->unre
f(); | 671 result.setPixelRef(new SkGrPixelRef(result.info(), texture))->unref(); |
672 return result; | 672 return result; |
673 } | 673 } |
674 | 674 |
675 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, | 675 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, |
676 const SkPaint& paint, const SkMatrix* prePathMatrix, | 676 const SkPaint& paint, const SkMatrix* prePathMatrix, |
677 bool pathIsMutable) { | 677 bool pathIsMutable) { |
678 CHECK_FOR_ANNOTATION(paint); | 678 CHECK_FOR_ANNOTATION(paint); |
679 CHECK_SHOULD_DRAW(draw); | 679 CHECK_SHOULD_DRAW(draw); |
680 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPath", fContext); | 680 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPath", fContext); |
681 | 681 |
(...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1623 triangleCount = n - 2; | 1623 triangleCount = n - 2; |
1624 break; | 1624 break; |
1625 } | 1625 } |
1626 | 1626 |
1627 VertState state(vertexCount, indices, indexCount); | 1627 VertState state(vertexCount, indices, indexCount); |
1628 VertState::Proc vertProc = state.chooseProc(vmode); | 1628 VertState::Proc vertProc = state.chooseProc(vmode); |
1629 | 1629 |
1630 //number of indices for lines per triangle with kLines | 1630 //number of indices for lines per triangle with kLines |
1631 indexCount = triangleCount * 6; | 1631 indexCount = triangleCount * 6; |
1632 | 1632 |
1633 outAlloc.reset(SkNEW_ARRAY(uint16_t, indexCount)); | 1633 outAlloc.reset(new uint16_t[indexCount]); |
1634 outIndices = outAlloc.get(); | 1634 outIndices = outAlloc.get(); |
1635 uint16_t* auxIndices = outAlloc.get(); | 1635 uint16_t* auxIndices = outAlloc.get(); |
1636 int i = 0; | 1636 int i = 0; |
1637 while (vertProc(&state)) { | 1637 while (vertProc(&state)) { |
1638 auxIndices[i] = state.f0; | 1638 auxIndices[i] = state.f0; |
1639 auxIndices[i + 1] = state.f1; | 1639 auxIndices[i + 1] = state.f1; |
1640 auxIndices[i + 2] = state.f1; | 1640 auxIndices[i + 2] = state.f1; |
1641 auxIndices[i + 3] = state.f2; | 1641 auxIndices[i + 3] = state.f2; |
1642 auxIndices[i + 4] = state.f2; | 1642 auxIndices[i + 4] = state.f2; |
1643 auxIndices[i + 5] = state.f0; | 1643 auxIndices[i + 5] = state.f0; |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1900 #endif | 1900 #endif |
1901 } | 1901 } |
1902 | 1902 |
1903 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1903 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
1904 // We always return a transient cache, so it is freed after each | 1904 // We always return a transient cache, so it is freed after each |
1905 // filter traversal. | 1905 // filter traversal. |
1906 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 1906 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
1907 } | 1907 } |
1908 | 1908 |
1909 #endif | 1909 #endif |
OLD | NEW |