Commit Graph

35 Commits

Author SHA1 Message Date
John Stiles
a6841be235 Enable ClangTidy check llvm-namespace-comment.
This fixes a large number of SkSL namespaces which were labeled as if
they were anonymous, and also a handful of other mislabeled namespaces.
Missing namespace-end comments have been added throughout.
A number of diffs are just indentation-related (adjusting 1- or 3-
space indents to 2-space).

Change-Id: I6c62052a0d3aea4ae12ca07e0c2a8587b2fce4ec
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/308503
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2020-08-06 19:07:52 +00:00
Mike Klein
a9609ea8c5 turn on -Wreturn-std-move-in-c++11
This CL has a complicated back story, but it's concrete change is
simple, just turning the warning on and converting a bunch of

    return foo;

to

    return std::move(foo);

These changes are exclusively in places where RVO and NRVO do not apply,
so it should not conflict with warnings like -Wpessimizing-move.

Since C++11, when you return a named local and its type doesn't match
the declared return type exactly, there's an implicit std::move()
wrapped around the value (what I'm making explicit here) so the move
constructor gets an opportunity to take precedence over the copy
constructor.  You can read about this implicit move here under the
section "automatic move from local variables and parameters":
https://en.cppreference.com/w/cpp/language/return#Notes.

This situation comes up for us with smart pointers: a function declares
its return type as std::unique_ptr<Base> or sk_sp<Base>, and we return a
std::unique_ptr<Impl> or sk_sp<Impl>.  Those types don't match exactly,
so RVO and NRVO don't come into play.  They've always been going through
move constructors, and that's not changed here, just made explicit.

There was apparently once a bug in the C++11 standard and compilers
implementing that which made these copy instead of move, and then this
sort of code would do a little unnecessary ref/unref dance for sk_sp,
and would entirely fail to compile for uncopyable std::unique_ptr.
These explicit moves ostensibly will make our code more compatible with
those older compilers.

That compatibility alone is, I think, a terrible reason to land this CL.
Like, actively bad.  But... to balance that out, I think the explicit
std::move()s here actually help remind us that RVO/NRVO are not in play,
and remind us we're going to call the move constructor.  So that C++11
standard bug becomes kind of useful for us, in that Clang added this
warning to catch it, and its fix improves readability.

So really read this all as, "warn about implicit std::move() on return".
In the end I think it's just about readability.  I don't really hold any
hope out that we'll become compatible with those older compilers.

Bug: skia:9909
Change-Id: Id596e9261188b6f10e759906af6c95fe303f6ffe
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/271601
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
2020-02-18 23:55:35 +00:00
Mike Klein
334a642b20 remove unused sk_sp comparison operators
These unused comparison operators are the only users of
<functional> in SkRefCnt.h, for std::less.  <functional>
is an expensive header to compile, and SkRefCnt.h is popular,
so it helps to cut dependencies like this.

Mostly we just need to add #include <functional> in a few
places that were picking it up via SkRefCnt.h.

In SkPixmapPriv.h, it looked simpler to template the argument,
since everything was inline anyway.

Change-Id: I7c125bb26a04199847357c729a1b178256c6ef8d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/236942
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
2019-08-27 14:52:01 +00:00
Brian Salomon
9c73e3df83 Turn off -Wreturn-std-move-in-c++11
Change-Id: I127c979670c3dc7dac2e35908a795afbdefca8f6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/234902
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
2019-08-15 17:45:58 +00:00
Mike Klein
c0bd9f9fe5 rewrite includes to not need so much -Ifoo
Current strategy: everything from the top

Things to look at first are the manual changes:

   - added tools/rewrite_includes.py
   - removed -Idirectives from BUILD.gn
   - various compile.sh simplifications
   - tweak tools/embed_resources.py
   - update gn/find_headers.py to write paths from the top
   - update gn/gn_to_bp.py SkUserConfig.h layout
     so that #include "include/config/SkUserConfig.h" always
     gets the header we want.

No-Presubmit: true
Change-Id: I73a4b181654e0e38d229bc456c0d0854bae3363e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/209706
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Hal Canary <halcanary@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
2019-04-24 16:27:11 +00:00
Mike Klein
1688507f83 Try out clang-tidy, starting with bugprone-use-after-move
- add drop-in clang-tidy cxx wrapper
 - get build clean for bugprone-use-after-move

The wrapper can be used by setting

   cxx = "/path/to/skia/tools/clang-tidy.sh"

in GN.

Change-Id: Idbba911e23bd6ef7530b08fd31906b92c1c1b28c
Reviewed-on: https://skia-review.googlesource.com/c/176523
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
2018-12-11 17:28:19 +00:00
Brian Salomon
2335644771 Fix occurrences of "-Wextra-semi-stmt"
Docs-Preview: https://skia.org/?cl=173761
Change-Id: Iefdb91cd28eabb4b01b7b42a4f300b0b4caf05d9
Reviewed-on: https://skia-review.googlesource.com/c/173761
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
2018-11-30 23:23:09 +00:00
Hal Canary
8a00144035 test,tools: whitespace changes for clang-format
Change-Id: I67529f6c0ac26da603f60af22c620f8f603d8a19
Reviewed-on: https://skia-review.googlesource.com/155564
Commit-Queue: Ben Wagner <bungeman@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
Auto-Submit: Hal Canary <halcanary@google.com>
2018-09-19 17:50:51 +00:00
Mike Klein
03141d25cf remove SkThread, using std::thread instead
Change-Id: I871dd5eea4496e87c206b46d9eae81cb521b11ce
Reviewed-on: https://skia-review.googlesource.com/65103
Reviewed-by: Hal Canary <halcanary@google.com>
Commit-Queue: Mike Klein <mtklein@chromium.org>
2017-10-30 16:45:29 +00:00
Brian Osman
40540a7135 Actually test our ref-counting in release builds
BUG=skia:

Change-Id: I8df5c84bf961a3be68a642ba338fdc641e09df59
Reviewed-on: https://skia-review.googlesource.com/8889
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Brian Osman <brianosman@google.com>
2017-02-22 21:31:29 +00:00
Mike Klein
fc6c37b981 Remove stray semicolons.
Turns out function declarations don't end in semicolons...

BUG=skia:

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2720

No public API changes.
TBR=reed@google.com

Change-Id: I72b56d52e1ff7fa6e89c295b0de8c46599791ebb
Reviewed-on: https://skia-review.googlesource.com/2720
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Mike Klein <mtklein@chromium.org>
2016-09-27 14:04:26 +00:00
bungeman
2c4bd0798e Convert SkRefCnt to std::atomic.
This enables removing the more complicated atomic shims from SkAtomics.h.

TBR=reed
This doesn't actually change any API.

CQ_EXTRA_TRYBOTS=client.skia:Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-TSAN-Trybot,Test-Ubuntu-GCC-Golo-GPU-GT610-x86_64-Release-TSAN-Trybot

Review URL: https://codereview.chromium.org/1867863002
2016-04-08 06:58:52 -07:00
reed
647cc84748 Add sk_ref_sp helper function.
Review URL: https://codereview.chromium.org/1773943004
2016-03-08 12:54:48 -08:00
bungeman
c901c11549 Add element_type, swap, operators, fix reset on sk_sp.
The 'element_type' typedef is to play nice with std::pointer_traits.

The full complement of operators and swap to match unique_ptr so that
sk_sp can be properly compared to nullptr and used with standard
containers.

Update to 'reset' so that calling 'unref' is the last operation.

This also adds tests for these changes, and sets the fPtr to nullptr
in debug for easier bug finding.

Review URL: https://codereview.chromium.org/1773453002
2016-03-08 08:35:23 -08:00
mtklein
71aca54991 add virtual ~Effect()
Today we make an sk_sp<Effect> from an sk_sp<EffectImpl>.
But when the sk_sp<Effect> dies, it calls ~Effect(), not ~EffectImpl().
Making ~Effect() virtual fixes this.

This should make our Google3 tests sized-delete clean, unblocking those folks.

Review URL: https://codereview.chromium.org/1769093002
2016-03-07 12:28:17 -08:00
reed
941da9d661 Fix behavior of sk_sp::reset(T*) and add unittest.
Previously, sk_sp::reset(T* t) did not release its own reference
if its internal pointer was the same as 't'. This leaks a reference.
Now always release the current reference when non-nullptr.

Review URL: https://codereview.chromium.org/1767983002
2016-03-06 13:54:00 -08:00
halcanary
ffa39e02bc sk_sp: fix contravariant constructors
TBR=reed
This is obviously correct and needs to be fixed.

Review URL: https://codereview.chromium.org/1771583002
2016-03-05 08:30:28 -08:00
bungeman
beab9e7ba0 Add operator* and operator safe-bool to sk_sp.
This greatly reduces the need to use '.get()' in conditionals.

Review URL: https://codereview.chromium.org/1760453004
2016-03-03 07:50:49 -08:00
halcanary
cb6cb3841a sk_sp: Covariant Move Constructor and Move Assignment
Also Covariant Copy Constructor, Copy Assignment,
and comparison operators.

GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1752093002

Review URL: https://codereview.chromium.org/1752093002
2016-03-02 08:11:26 -08:00
halcanary
217c0b3f13 sk_make_sp<T>()
because
    auto atm = sk_make_sp<SkAdvancedTypefaceMetrics>();
is better than
    sk_sp<SkAdvancedTypefaceMetrics> atm(new SkAdvancedTypefaceMetrics);

GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1753973002

Review URL: https://codereview.chromium.org/1753973002
2016-03-02 08:06:20 -08:00
reed
bb7b043b2d isolate sk_sp from larger cl
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1752683002

Review URL: https://codereview.chromium.org/1752683002
2016-03-01 07:28:51 -08:00
mtklein
a1bde7d2e1 Remove SkThread::setProcessorAffinity()
It's only used by a couple unit tests.  We have other ways of getting
the same quality testing of our ref-count code now (e.g. TSAN).

BUG=skia:
CQ_EXTRA_TRYBOTS=client.skia.compile:Build-Ubuntu-GCC-x86_64-Release-CMake-Trybot,Build-Mac10.9-Clang-x86_64-Release-CMake-Trybot

Review URL: https://codereview.chromium.org/1408213005
2015-10-20 11:05:06 -07:00
bungeman
693e993057 Remove unused InstCounterClass.
This was added with r4719 (f7943035) to support testing
SkTRefArray. With 703d3c70 SkTRefArray and the associated test was
removed, but the supporting InstCounterClass was not.

Review URL: https://codereview.chromium.org/1063403003
2015-04-08 08:06:26 -07:00
mtklein
bbb61d7268 make SkRefCnt::getRefCnt() debug-only, remove it from SkNVRefCnt.
Only (unused) API removed.
TBR=reed@google.com

BUG=skia:3160

Review URL: https://codereview.chromium.org/752263002
2014-11-24 13:09:39 -08:00
mtklein
703d3c7093 Followup: remove unnecessary SkTRefArray
BUG=skia:

Review URL: https://codereview.chromium.org/719113004
2014-11-12 11:08:20 -08:00
Mike Klein
874a62acef Revert "Remove ability for Release code to call getRefCnt() or getWeakRefCnt()."
This reverts commit 4ae94ffce5.

BUG=skia:

Review URL: https://codereview.chromium.org/382523002
2014-07-09 09:04:07 -04:00
mtklein
4ae94ffce5 Remove ability for Release code to call getRefCnt() or getWeakRefCnt().
These getRefCnt() methods are not thread safe, so Skia code should not
be calling them.  unique() is fine.

SkDEBUG code (SkASSERTs) can still call getRefCnt() / getWeakRefCnt().

This adds tools/RefCntIs.{h,cpp}, which lets tests make their assertions in
both debug and release modes.

BUG=skia:2726
R=senorblanco@chromium.org, mtklein@google.com, reed@google.com

Author: mtklein@chromium.org

Review URL: https://codereview.chromium.org/378643003
2014-07-08 06:48:17 -07:00
tfarina@chromium.org
8f6884aab8 Cleanup: Sanitize the order of includes under tests/
Initially this was to make sure Test.h appeared after the Sk*.h includes.

Patch generated by the following command line:

$ ~/chromium/src/tools/sort-headers.py tests/*.cpp

BUG=None
TEST=tests
R=robertphillips@google.com

Review URL: https://codereview.chromium.org/145313004

git-svn-id: http://skia.googlecode.com/svn/trunk@13177 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-24 20:56:26 +00:00
commit-bot@chromium.org
e2eac8b2fd Move macros from TestClassDef.h to Test.h
Motivation: those macros don't make any sense without the definitions
in Test.h.

BUG=
R=mtklein@google.com

Author: halcanary@google.com

Review URL: https://codereview.chromium.org/138563004

git-svn-id: http://skia.googlecode.com/svn/trunk@13074 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-14 21:04:37 +00:00
tfarina@chromium.org
e4fafb146e Use DEFINE_TESTCLASS_SHORT macro in tests.
The three version of DEFINE_TESTCLASS macro is deprecated and thus just
use the simple, short one.

BUG=None
TEST=out/Debug/tests
R=mtklein@google.com, bsalomon@google.com, robertphillips@google.com

Review URL: https://codereview.chromium.org/100113004

git-svn-id: http://skia.googlecode.com/svn/trunk@12653 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-12-12 21:11:12 +00:00
rmistry@google.com
d6176b0dca Result of running tools/sanitize_source_files.py (which was added in https://codereview.appspot.com/6465078/)
This CL is part II of IV (I broke down the 1280 files into 4 CLs).
Review URL: https://codereview.appspot.com/6474054

git-svn-id: http://skia.googlecode.com/svn/trunk@5263 2bbb7eff-a529-9590-31e7-b0007b416f81
2012-08-23 18:14:13 +00:00
reed@google.com
f79430350d add protected method for internal_dispose overrides to jam fRefCnt before
calling destructor.

move SkTRefArray to actually inherit from SkRefCnt
Review URL: https://codereview.appspot.com/6422057

git-svn-id: http://skia.googlecode.com/svn/trunk@4719 2bbb7eff-a529-9590-31e7-b0007b416f81
2012-07-23 14:50:38 +00:00
reed@google.com
80ba7964cd add SkTRefArray, in hopes that it will enable more sharing between pictureplaybacks
in different threads.



git-svn-id: http://skia.googlecode.com/svn/trunk@4709 2bbb7eff-a529-9590-31e7-b0007b416f81
2012-07-21 17:31:40 +00:00
bungeman@google.com
a02bc1519c WeakRefCnt
http://codereview.appspot.com/5649046/


git-svn-id: http://skia.googlecode.com/svn/trunk@3978 2bbb7eff-a529-9590-31e7-b0007b416f81
2012-05-16 18:21:56 +00:00
bungeman@google.com
5548752100 Add bench and test for SkRefCnt.
http://codereview.appspot.com/6195071/

This also adds a cross platform SkThread for testing purposes.


git-svn-id: http://skia.googlecode.com/svn/trunk@3921 2bbb7eff-a529-9590-31e7-b0007b416f81
2012-05-14 14:09:24 +00:00