Skip to content

Commit

Permalink
Bug 1116905 - part 3 - remove dependence on implicit conversion from …
Browse files Browse the repository at this point in the history
…T* to TemporaryRef<T>, gfx changes; r=jrmuizel
  • Loading branch information
froydnj committed Apr 30, 2015
1 parent eec74c4 commit 9172746
Show file tree
Hide file tree
Showing 36 changed files with 113 additions and 94 deletions.
4 changes: 3 additions & 1 deletion gfx/2d/DataSourceSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ namespace gfx {
TemporaryRef<DataSourceSurface>
DataSourceSurface::GetDataSurface()
{
return (GetType() == SurfaceType::DATA) ? this : new DataSourceSurfaceWrapper(this);
RefPtr<DataSourceSurface> surface =
(GetType() == SurfaceType::DATA) ? this : new DataSourceSurfaceWrapper(this);
return surface.forget();
}

}
Expand Down
9 changes: 5 additions & 4 deletions gfx/2d/DrawTargetCG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ DrawTargetCG::Snapshot()
{
if (!mSnapshot) {
if (GetContextType(mCg) == CG_CONTEXT_TYPE_IOSURFACE) {
return new SourceSurfaceCGIOSurfaceContext(this);
return MakeAndAddRef<SourceSurfaceCGIOSurfaceContext>(this);
}
Flush();
mSnapshot = new SourceSurfaceCGBitmapContext(this);
Expand Down Expand Up @@ -262,7 +262,8 @@ GetRetainedImageFromSourceSurface(SourceSurface *aSurface)
TemporaryRef<SourceSurface>
DrawTargetCG::OptimizeSourceSurface(SourceSurface *aSurface) const
{
return aSurface;
RefPtr<SourceSurface> surface(aSurface);
return surface.forget();
}

class UnboundnessFixer
Expand Down Expand Up @@ -465,7 +466,7 @@ DrawTargetCG::CreateGradientStops(GradientStop *aStops, uint32_t aNumStops,
ExtendMode aExtendMode) const
{
std::vector<GradientStop> stops(aStops, aStops+aNumStops);
return new GradientStopsCG(mColorSpace, stops, aExtendMode);
return MakeAndAddRef<GradientStopsCG>(mColorSpace, stops, aExtendMode);
}

static void
Expand Down Expand Up @@ -1905,7 +1906,7 @@ DrawTargetCG::Init(BackendType aType, const IntSize &aSize, SurfaceFormat &aForm
TemporaryRef<PathBuilder>
DrawTargetCG::CreatePathBuilder(FillRule aFillRule) const
{
return new PathBuilderCG(aFillRule);
return MakeAndAddRef<PathBuilderCG>(aFillRule);
}

void*
Expand Down
29 changes: 15 additions & 14 deletions gfx/2d/DrawTargetCairo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@ DrawTargetCairo::PopClip()
TemporaryRef<PathBuilder>
DrawTargetCairo::CreatePathBuilder(FillRule aFillRule /* = FillRule::FILL_WINDING */) const
{
return new PathBuilderCairo(aFillRule);
return MakeAndAddRef<PathBuilderCairo>(aFillRule);
}

void
Expand All @@ -1346,7 +1346,7 @@ TemporaryRef<GradientStops>
DrawTargetCairo::CreateGradientStops(GradientStop *aStops, uint32_t aNumStops,
ExtendMode aExtendMode) const
{
return new GradientStopsCairo(aStops, aNumStops, aExtendMode);
return MakeAndAddRef<GradientStopsCairo>(aStops, aNumStops, aExtendMode);
}

TemporaryRef<FilterNode>
Expand Down Expand Up @@ -1400,21 +1400,22 @@ DestroyPixmap(void *data)
TemporaryRef<SourceSurface>
DrawTargetCairo::OptimizeSourceSurface(SourceSurface *aSurface) const
{
RefPtr<SourceSurface> surface(aSurface);
#ifdef CAIRO_HAS_XLIB_SURFACE
cairo_surface_type_t ctype = cairo_surface_get_type(mSurface);
if (aSurface->GetType() == SurfaceType::CAIRO &&
cairo_surface_get_type(
static_cast<SourceSurfaceCairo*>(aSurface)->GetSurface()) == ctype) {
return aSurface;
return surface.forget();
}

if (ctype != CAIRO_SURFACE_TYPE_XLIB) {
return aSurface;
return surface.forget();
}

IntSize size = aSurface->GetSize();
if (!size.width || !size.height) {
return aSurface;
return surface.forget();
}

// Although the dimension parameters in the xCreatePixmapReq wire protocol are
Expand All @@ -1424,7 +1425,7 @@ DrawTargetCairo::OptimizeSourceSurface(SourceSurface *aSurface) const

if (size.width > XLIB_IMAGE_SIDE_SIZE_LIMIT ||
size.height > XLIB_IMAGE_SIDE_SIZE_LIMIT) {
return aSurface;
return surface.forget();
}

SurfaceFormat format = aSurface->GetFormat();
Expand All @@ -1442,17 +1443,17 @@ DrawTargetCairo::OptimizeSourceSurface(SourceSurface *aSurface) const
xrenderFormat = XRenderFindStandardFormat(dpy, PictStandardA8);
break;
default:
return aSurface;
return surface.forget();
}
if (!xrenderFormat) {
return aSurface;
return surface.forget();
}

Drawable pixmap = XCreatePixmap(dpy, RootWindowOfScreen(screen),
size.width, size.height,
xrenderFormat->depth);
if (!pixmap) {
return aSurface;
return surface.forget();
}

ScopedDeletePtr<DestroyPixmapClosure> closure(
Expand All @@ -1463,26 +1464,26 @@ DrawTargetCairo::OptimizeSourceSurface(SourceSurface *aSurface) const
screen, xrenderFormat,
size.width, size.height));
if (!csurf || cairo_surface_status(csurf)) {
return aSurface;
return surface.forget();
}

cairo_surface_set_user_data(csurf, &gDestroyPixmapKey,
closure.forget(), DestroyPixmap);

RefPtr<DrawTargetCairo> dt = new DrawTargetCairo();
if (!dt->Init(csurf, size, &format)) {
return aSurface;
return surface.forget();
}

dt->CopySurface(aSurface,
IntRect(0, 0, size.width, size.height),
IntPoint(0, 0));
dt->Flush();

return new SourceSurfaceCairo(csurf, size, format);
surface = new SourceSurfaceCairo(csurf, size, format);
#endif

return aSurface;
return surface.forget();
}

TemporaryRef<SourceSurface>
Expand All @@ -1495,7 +1496,7 @@ DrawTargetCairo::CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurf
return nullptr;
}
cairo_surface_t* surf = static_cast<cairo_surface_t*>(aSurface.mSurface);
return new SourceSurfaceCairo(surf, aSurface.mSize, aSurface.mFormat);
return MakeAndAddRef<SourceSurfaceCairo>(surf, aSurface.mSize, aSurface.mFormat);
}

return nullptr;
Expand Down
7 changes: 4 additions & 3 deletions gfx/2d/DrawTargetD2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,8 @@ DrawTargetD2D::OptimizeSourceSurface(SourceSurface *aSurface) const
{
if (aSurface->GetType() == SurfaceType::D2D1_BITMAP ||
aSurface->GetType() == SurfaceType::D2D1_DRAWTARGET) {
return aSurface;
RefPtr<SourceSurface> surface(aSurface);
return surface.forget();
}

RefPtr<DataSourceSurface> data = aSurface->GetDataSurface();
Expand Down Expand Up @@ -1284,7 +1285,7 @@ DrawTargetD2D::CreatePathBuilder(FillRule aFillRule) const
sink->SetFillMode(D2D1_FILL_MODE_WINDING);
}

return new PathBuilderD2D(sink, path, aFillRule, BackendType::DIRECT2D);
return MakeAndAddRef<PathBuilderD2D>(sink, path, aFillRule, BackendType::DIRECT2D);
}

TemporaryRef<GradientStops>
Expand All @@ -1310,7 +1311,7 @@ DrawTargetD2D::CreateGradientStops(GradientStop *rawStops, uint32_t aNumStops, E
return nullptr;
}

return new GradientStopsD2D(stopCollection, Factory::GetDirect3D11Device());
return MakeAndAddRef<GradientStopsD2D>(stopCollection, Factory::GetDirect3D11Device());
}

TemporaryRef<FilterNode>
Expand Down
11 changes: 6 additions & 5 deletions gfx/2d/DrawTargetD2D1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ DrawTargetD2D1::CreateSourceSurfaceFromData(unsigned char *aData,
return nullptr;
}

return new SourceSurfaceD2D1(bitmap.get(), mDC, aFormat, aSize);
return MakeAndAddRef<SourceSurfaceD2D1>(bitmap.get(), mDC, aFormat, aSize);
}

TemporaryRef<DrawTarget>
Expand Down Expand Up @@ -694,7 +694,7 @@ DrawTargetD2D1::CreatePathBuilder(FillRule aFillRule) const
sink->SetFillMode(D2D1_FILL_MODE_WINDING);
}

return new PathBuilderD2D(sink, path, aFillRule, BackendType::DIRECT2D1_1);
return MakeAndAddRef<PathBuilderD2D>(sink, path, aFillRule, BackendType::DIRECT2D1_1);
}

TemporaryRef<GradientStops>
Expand Down Expand Up @@ -725,7 +725,7 @@ DrawTargetD2D1::CreateGradientStops(GradientStop *rawStops, uint32_t aNumStops,
return nullptr;
}

return new GradientStopsD2D(stopCollection, Factory::GetDirect3D11Device());
return MakeAndAddRef<GradientStopsD2D>(stopCollection, Factory::GetDirect3D11Device());
}

TemporaryRef<FilterNode>
Expand Down Expand Up @@ -1459,7 +1459,8 @@ TemporaryRef<SourceSurface>
DrawTargetD2D1::OptimizeSourceSurface(SourceSurface* aSurface) const
{
if (aSurface->GetType() == SurfaceType::D2D1_1_IMAGE) {
return aSurface;
RefPtr<SourceSurface> surface(aSurface);
return surface.forget();
}

RefPtr<DataSourceSurface> data = aSurface->GetDataSurface();
Expand All @@ -1484,7 +1485,7 @@ DrawTargetD2D1::OptimizeSourceSurface(SourceSurface* aSurface) const
return data.forget();
}

return new SourceSurfaceD2D1(bitmap.get(), mDC, data->GetFormat(), data->GetSize());
return MakeAndAddRef<SourceSurfaceD2D1>(bitmap.get(), mDC, data->GetFormat(), data->GetSize());
}

void
Expand Down
2 changes: 1 addition & 1 deletion gfx/2d/DrawTargetDual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ DrawTargetDual::CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFor
return nullptr;
}

return new DrawTargetDual(dtA, dtB);
return MakeAndAddRef<DrawTargetDual>(dtA, dtB);
}

}
Expand Down
4 changes: 3 additions & 1 deletion gfx/2d/DrawTargetDual.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ class DrawTargetDual : public DrawTarget

virtual DrawTargetType GetType() const override { return mA->GetType(); }
virtual BackendType GetBackendType() const override { return mA->GetBackendType(); }
virtual TemporaryRef<SourceSurface> Snapshot() override { return new SourceSurfaceDual(mA, mB); }
virtual TemporaryRef<SourceSurface> Snapshot() override {
return MakeAndAddRef<SourceSurfaceDual>(mA, mB);
}
virtual IntSize GetSize() override { return mA->GetSize(); }

FORWARD_FUNCTION(Flush)
Expand Down
4 changes: 2 additions & 2 deletions gfx/2d/DrawTargetRecording.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,14 +541,14 @@ TemporaryRef<DrawTarget>
DrawTargetRecording::CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const
{
RefPtr<DrawTarget> dt = mFinalDT->CreateSimilarDrawTarget(aSize, aFormat);
return new DrawTargetRecording(mRecorder.get(), dt);
return MakeAndAddRef<DrawTargetRecording>(mRecorder.get(), dt);
}

TemporaryRef<PathBuilder>
DrawTargetRecording::CreatePathBuilder(FillRule aFillRule) const
{
RefPtr<PathBuilder> builder = mFinalDT->CreatePathBuilder(aFillRule);
return new PathBuilderRecording(builder, aFillRule);
return MakeAndAddRef<PathBuilderRecording>(builder, aFillRule);
}

TemporaryRef<GradientStops>
Expand Down
11 changes: 6 additions & 5 deletions gfx/2d/DrawTargetSkia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,8 @@ TemporaryRef<SourceSurface>
DrawTargetSkia::OptimizeSourceSurface(SourceSurface *aSurface) const
{
if (aSurface->GetType() == SurfaceType::SKIA) {
return aSurface;
RefPtr<SourceSurface> surface(aSurface);
return surface.forget();
}

if (!UsingSkiaGPU()) {
Expand Down Expand Up @@ -741,13 +742,13 @@ DrawTargetSkia::CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurfa
return nullptr;
}
cairo_surface_t* surf = static_cast<cairo_surface_t*>(aSurface.mSurface);
return new SourceSurfaceCairo(surf, aSurface.mSize, aSurface.mFormat);
return MakeAndAddRef<SourceSurfaceCairo>(surf, aSurface.mSize, aSurface.mFormat);
#if USE_SKIA_GPU
} else if (aSurface.mType == NativeSurfaceType::OPENGL_TEXTURE && UsingSkiaGPU()) {
RefPtr<SourceSurfaceSkia> newSurf = new SourceSurfaceSkia();
unsigned int texture = (unsigned int)((uintptr_t)aSurface.mSurface);
if (newSurf->InitFromTexture((DrawTargetSkia*)this, texture, aSurface.mSize, aSurface.mFormat)) {
return newSurf;
return newSurf.forget();
}
return nullptr;
#endif
Expand Down Expand Up @@ -928,7 +929,7 @@ DrawTargetSkia::GetNativeSurface(NativeSurfaceType aType)
TemporaryRef<PathBuilder>
DrawTargetSkia::CreatePathBuilder(FillRule aFillRule) const
{
return new PathBuilderSkia(aFillRule);
return MakeAndAddRef<PathBuilderSkia>(aFillRule);
}

void
Expand Down Expand Up @@ -981,7 +982,7 @@ DrawTargetSkia::CreateGradientStops(GradientStop *aStops, uint32_t aNumStops, Ex
}
std::stable_sort(stops.begin(), stops.end());

return new GradientStopsSkia(stops, aNumStops, aExtendMode);
return MakeAndAddRef<GradientStopsSkia>(stops, aNumStops, aExtendMode);
}

TemporaryRef<FilterNode>
Expand Down
2 changes: 1 addition & 1 deletion gfx/2d/DrawTargetTiled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ DrawTargetTiled::Init(const TileSet& aTiles)
TemporaryRef<SourceSurface>
DrawTargetTiled::Snapshot()
{
return new SnapshotTiled(mTiles, mRect);
return MakeAndAddRef<SnapshotTiled>(mTiles, mRect);
}

// Skip the mClippedOut check since this is only used for Flush() which
Expand Down
Loading

0 comments on commit 9172746

Please sign in to comment.