Bug 1192466 - Prune header includes for SkiaGLGlue.h - r=bgirard

This commit is contained in:
Jeff Gilbert 2015-08-07 19:27:14 -07:00
parent 0095cf45f9
commit 495915511d
6 changed files with 122 additions and 93 deletions

View File

@ -15,6 +15,7 @@
#endif
#include "mozilla/Assertions.h"
#include <vector>
#include "RefPtrSkia.h"
namespace mozilla {
namespace gfx {
@ -147,7 +148,7 @@ StrokeOptionsToPaint(SkPaint& aPaint, const StrokeOptions &aOptions)
}
SkDashPathEffect* dash = SkDashPathEffect::Create(&pattern.front(),
dashCount,
dashCount,
SkFloatToScalar(aOptions.mDashOffset));
SkSafeUnref(aPaint.setPathEffect(dash));
}
@ -237,14 +238,14 @@ static inline SkColor ColorToSkColor(const Color &color, Float aAlpha)
static inline SkRect
RectToSkRect(const Rect& aRect)
{
return SkRect::MakeXYWH(SkFloatToScalar(aRect.x), SkFloatToScalar(aRect.y),
return SkRect::MakeXYWH(SkFloatToScalar(aRect.x), SkFloatToScalar(aRect.y),
SkFloatToScalar(aRect.width), SkFloatToScalar(aRect.height));
}
static inline SkRect
IntRectToSkRect(const IntRect& aRect)
{
return SkRect::MakeXYWH(SkIntToScalar(aRect.x), SkIntToScalar(aRect.y),
return SkRect::MakeXYWH(SkIntToScalar(aRect.x), SkIntToScalar(aRect.y),
SkIntToScalar(aRect.width), SkIntToScalar(aRect.height));
}
@ -289,74 +290,6 @@ ExtendModeToTileMode(ExtendMode aMode)
return SkShader::kClamp_TileMode;
}
// The following class was imported from Skia, which is under the
// following licence:
//
// Copyright (c) 2011 Google Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
template <typename T> class RefPtrSkia {
public:
RefPtrSkia() : fObj(NULL) {}
explicit RefPtrSkia(T* obj) : fObj(obj) { SkSafeRef(fObj); }
RefPtrSkia(const RefPtrSkia& o) : fObj(o.fObj) { SkSafeRef(fObj); }
~RefPtrSkia() { SkSafeUnref(fObj); }
RefPtrSkia& operator=(const RefPtrSkia& rp) {
SkRefCnt_SafeAssign(fObj, rp.fObj);
return *this;
}
RefPtrSkia& operator=(T* obj) {
SkRefCnt_SafeAssign(fObj, obj);
return *this;
}
T* get() const { return fObj; }
T& operator*() const { return *fObj; }
T* operator->() const { return fObj; }
RefPtrSkia& adopt(T* obj) {
SkSafeUnref(fObj);
fObj = obj;
return *this;
}
typedef T* RefPtrSkia::*unspecified_bool_type;
operator unspecified_bool_type() const {
return fObj ? &RefPtrSkia::fObj : NULL;
}
private:
T* fObj;
};
// End of code imported from Skia.
} // namespace gfx
} // namespace mozilla

83
gfx/2d/RefPtrSkia.h Normal file
View File

@ -0,0 +1,83 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef MOZILLA_GFX_REFPTRSKIA_H_
#define MOZILLA_GFX_REFPTRSKIA_H_
namespace mozilla {
namespace gfx {
// The following class was imported from Skia, which is under the
// following licence:
//
// Copyright (c) 2011 Google Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
template <typename T> class RefPtrSkia {
public:
RefPtrSkia() : fObj(NULL) {}
explicit RefPtrSkia(T* obj) : fObj(obj) { SkSafeRef(fObj); }
RefPtrSkia(const RefPtrSkia& o) : fObj(o.fObj) { SkSafeRef(fObj); }
~RefPtrSkia() { SkSafeUnref(fObj); }
RefPtrSkia& operator=(const RefPtrSkia& rp) {
SkRefCnt_SafeAssign(fObj, rp.fObj);
return *this;
}
RefPtrSkia& operator=(T* obj) {
SkRefCnt_SafeAssign(fObj, obj);
return *this;
}
T* get() const { return fObj; }
T& operator*() const { return *fObj; }
T* operator->() const { return fObj; }
RefPtrSkia& adopt(T* obj) {
SkSafeUnref(fObj);
fObj = obj;
return *this;
}
typedef T* RefPtrSkia::*unspecified_bool_type;
operator unspecified_bool_type() const {
return fObj ? &RefPtrSkia::fObj : NULL;
}
private:
T* fObj;
};
// End of code imported from Skia.
} // namespace gfx
} // namespace mozilla
#endif /* MOZILLA_GFX_REFPTRSKIA_H_ */

View File

@ -81,6 +81,7 @@ if CONFIG['MOZ_ENABLE_SKIA']:
]
EXPORTS.mozilla.gfx += [
'HelpersSkia.h',
'RefPtrSkia.h',
]
# Are we targeting x86 or x64? If so, build SSE2 files.

View File

@ -872,7 +872,7 @@ static GrGLInterface* CreateGrGLInterfaceFromGLContext(GLContext* context)
i->fFunctions.fDeleteVertexArrays = glDeleteVertexArrays_mozilla;
i->fFunctions.fGenVertexArrays = glGenVertexArrays_mozilla;
// Desktop GL
// Desktop GL
i->fFunctions.fGetTexLevelParameteriv = glGetTexLevelParameteriv_mozilla;
i->fFunctions.fDrawBuffer = glDrawBuffer_mozilla;
i->fFunctions.fReadBuffer = glReadBuffer_mozilla;
@ -899,3 +899,15 @@ SkiaGLGlue::SkiaGLGlue(GLContext* context)
mGrGLInterface->fCallbackData = reinterpret_cast<GrGLInterfaceCallbackData>(this);
mGrContext.adopt(GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)mGrGLInterface.get()));
}
SkiaGLGlue::~SkiaGLGlue()
{
/*
* These members have inter-dependencies, but do not keep each other alive, so
* destruction order is very important here: mGrContext uses mGrGLInterface, and
* through it, uses mGLContext
*/
mGrContext = nullptr;
mGrGLInterface = nullptr;
mGLContext = nullptr;
}

View File

@ -3,18 +3,22 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/RefPtr.h"
#ifndef SKIA_GL_GLUE_H_
#define SKIA_GL_GLUE_H_
#ifdef USE_SKIA_GPU
#include "GLContext.h"
#include "skia/include/gpu/gl/GrGLInterface.h"
#include "skia/include/gpu/GrContext.h"
#include "mozilla/gfx/HelpersSkia.h"
#include "mozilla/gfx/RefPtrSkia.h"
#include "mozilla/RefPtr.h"
struct GrGLInterface;
class GrContext;
namespace mozilla {
namespace gl {
class GLContext;
class SkiaGLGlue : public GenericAtomicRefCounted
{
public:
@ -24,27 +28,18 @@ public:
GrContext* GetGrContext() const { return mGrContext.get(); }
protected:
virtual ~SkiaGLGlue() {
/*
* These members have inter-dependencies, but do not keep each other alive, so
* destruction order is very important here: mGrContext uses mGrGLInterface, and
* through it, uses mGLContext
*/
mGrContext = nullptr;
mGrGLInterface = nullptr;
mGLContext = nullptr;
}
virtual ~SkiaGLGlue();
private:
RefPtr<GLContext> mGLContext;
mozilla::gfx::RefPtrSkia<GrGLInterface> mGrGLInterface;
mozilla::gfx::RefPtrSkia<GrContext> mGrContext;
gfx::RefPtrSkia<GrGLInterface> mGrGLInterface;
gfx::RefPtrSkia<GrContext> mGrContext;
};
} // namespace gl
} // namespace mozilla
#else
#else // USE_SKIA_GPU
class GrContext;
@ -60,7 +55,10 @@ public:
GLContext* GetGLContext() const { return nullptr; }
GrContext* GetGrContext() const { return nullptr; }
};
}
}
#endif
} // namespace gl
} // namespace mozilla
#endif // USE_SKIA_GPU
#endif // SKIA_GL_GLUE_H_

View File

@ -93,6 +93,8 @@
#ifdef USE_SKIA
#include "skia/include/core/SkGraphics.h"
# ifdef USE_SKIA_GPU
# include "skia/include/gpu/GrContext.h"
# include "skia/include/gpu/gl/GrGLInterface.h"
# include "SkiaGLGlue.h"
# endif
#endif