Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(63)

Issue 6849109: Allow passing ownership with SkAutoTUnref (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
13 years ago by danakj
Modified:
13 years ago
CC:
skia-review_googlegroups.com, enne, piman, backer_chromium.org, Steve VanDeBogart, willchan
Base URL:
http://skia.googlecode.com/svn/trunk
Visibility:
Public.

Description

Allow passing ownership with SkAutoTUnref In the past, SkAutoTUnref would take ownership of a ref-counted object, and in order to pass ownership elsewhere, you would pull the raw pointer out of the SkAutoTUnref, and pass that around. This led to requiring manual ->ref() calls still when you wanted to share the reference with the callsite. Now SkAutoTUnref includes a copy constructor and operator= that allow it to pass a ref-counted object into another SkAutoTUnref, and keep a reference to the underlying object in both SkAutoTUnref instances. Then, when both instances are destroyed, the underlying object is as well.

Patch Set 1 #

Total comments: 4

Patch Set 2 : AdoptRef() instead of StealRef() #

Total comments: 7

Patch Set 3 : Allow SKAutoTUnref to pass ownership #

Patch Set 4 : Keep operator T* #

Patch Set 5 : spelling #

Total comments: 2

Patch Set 6 : comments #

Total comments: 3
Unified diffs Side-by-side diffs Delta from patch set Stats (+61 lines, -1 line) Patch
M include/core/SkRefCnt.h View 1 2 3 4 5 2 chunks +13 lines, -1 line 3 comments Download
M tests/RefCntTest.cpp View 1 2 3 1 chunk +48 lines, -0 lines 0 comments Download

Messages

Total messages: 39
danakj
13 years ago (2012-11-27 01:28:42 UTC) #1
Stephen White
https://codereview.appspot.com/6849109/diff/1/include/core/SkRefCnt.h File include/core/SkRefCnt.h (right): https://codereview.appspot.com/6849109/diff/1/include/core/SkRefCnt.h#newcode249 include/core/SkRefCnt.h:249: static SkRefPtr<T> StealRef(T* obj) { Bikeshed: Couldn't we just ...
13 years ago (2012-11-27 01:52:21 UTC) #2
danakj
https://codereview.appspot.com/6849109/diff/1/include/core/SkRefCnt.h File include/core/SkRefCnt.h (right): https://codereview.appspot.com/6849109/diff/1/include/core/SkRefCnt.h#newcode249 include/core/SkRefCnt.h:249: static SkRefPtr<T> StealRef(T* obj) { On 2012/11/27 01:52:22, Stephen ...
13 years ago (2012-11-27 02:40:13 UTC) #3
danakj
On 2012/11/27 02:40:13, danakj wrote: > https://codereview.appspot.com/6849109/diff/1/include/core/SkRefCnt.h > File include/core/SkRefCnt.h (right): > > https://codereview.appspot.com/6849109/diff/1/include/core/SkRefCnt.h#newcode249 > ...
13 years ago (2012-11-27 03:18:07 UTC) #4
reed1
https://codereview.appspot.com/6849109/diff/4001/include/core/SkRefCnt.h File include/core/SkRefCnt.h (right): https://codereview.appspot.com/6849109/diff/4001/include/core/SkRefCnt.h#newcode258 include/core/SkRefCnt.h:258: Lets keep these in the SkRefPtr scope for now, ...
13 years ago (2012-11-27 14:06:01 UTC) #5
reed1
Many many of the changes to the .cpp files could be done with our existing ...
13 years ago (2012-11-27 14:07:26 UTC) #6
TomH
On 2012/11/27 14:07:26, reed1 wrote: > Many many of the changes to the .cpp files ...
13 years ago (2012-11-27 15:53:24 UTC) #7
Stephen White
On 2012/11/27 15:53:24, TomH wrote: > On 2012/11/27 14:07:26, reed1 wrote: > > Many many ...
13 years ago (2012-11-27 16:48:45 UTC) #8
reed1
Looks like in that case, we don't want adopt either, as the receiver and the ...
13 years ago (2012-11-27 16:55:23 UTC) #9
danakj
On 2012/11/27 16:55:23, reed1 wrote: > Looks like in that case, we don't want adopt ...
13 years ago (2012-11-27 17:09:17 UTC) #10
reed1
I think making your own, for now, is most expedient. That gives you the freedom ...
13 years ago (2012-11-27 17:22:53 UTC) #11
Stephen White
On 2012/11/27 17:22:53, reed1 wrote: > I think making your own, for now, is most ...
13 years ago (2012-11-27 18:00:10 UTC) #12
reed1
Skia has two, and we are working to get it down to one. Adding more ...
13 years ago (2012-11-27 18:24:34 UTC) #13
Stephen White
On 2012/11/27 18:24:34, reed1 wrote: > Skia has two, and we are working to get ...
13 years ago (2012-11-27 18:30:29 UTC) #14
reed1
SkAutoTUnref is used in over 90 files. Lets keep that as Skia's pattern for now.
13 years ago (2012-11-27 18:34:23 UTC) #15
danakj
On 2012/11/27 18:30:29, Stephen White wrote: > On 2012/11/27 18:24:34, reed1 wrote: > > Skia ...
13 years ago (2012-11-27 18:35:45 UTC) #16
danakj
Updated. The patch is larger, but the parts of interest are: include/core/SkRefCnt.h: Updated the SkAutoTUnref ...
13 years ago (2012-11-27 20:03:54 UTC) #17
danakj
On 2012/11/27 20:03:54, danakj wrote: > Updated. > > The patch is larger, but the ...
13 years ago (2012-11-27 20:05:17 UTC) #18
reed1
I vote against removing the implicit conversion to T*. Passing a ptr or passing a ...
13 years ago (2012-11-27 20:23:36 UTC) #19
danakj
On 2012/11/27 20:23:36, reed1 wrote: > I vote against removing the implicit conversion to T*. ...
13 years ago (2012-11-27 20:34:01 UTC) #20
reed1
works for me, with nit about location and dox. https://codereview.appspot.com/6849109/diff/11003/include/core/SkRefCnt.h File include/core/SkRefCnt.h (right): https://codereview.appspot.com/6849109/diff/11003/include/core/SkRefCnt.h#newcode180 include/core/SkRefCnt.h:180: ...
13 years ago (2012-11-27 20:42:11 UTC) #21
bsalomon
On 2012/11/27 20:42:11, reed1 wrote: > works for me, with nit about location and dox. ...
13 years ago (2012-11-27 20:51:43 UTC) #22
danakj
On 2012/11/27 20:51:43, bsalomon wrote: > On 2012/11/27 20:42:11, reed1 wrote: > > works for ...
13 years ago (2012-11-27 20:55:50 UTC) #23
danakj
https://codereview.appspot.com/6849109/diff/11003/include/core/SkRefCnt.h File include/core/SkRefCnt.h (right): https://codereview.appspot.com/6849109/diff/11003/include/core/SkRefCnt.h#newcode180 include/core/SkRefCnt.h:180: // Copy and assign take a reference on the ...
13 years ago (2012-11-27 20:58:21 UTC) #24
reed1
void LayerImpl::setFilter(SkImageFilter* filter); IMHO, for a skia call, this looks exactly right. It means the ...
13 years ago (2012-11-27 21:01:45 UTC) #25
bsalomon
On 2012/11/27 20:55:50, danakj wrote: > On 2012/11/27 20:51:43, bsalomon wrote: > > On 2012/11/27 ...
13 years ago (2012-11-27 21:02:02 UTC) #26
danakj
For reference, here is the chromium-dev thread about why operator T* is bad. https://groups.google.com/a/chromium.org/forum/?fromgroups#!searchin/chromium-dev/CreateRefCountedT/chromium-dev/CNTCtqGkk0M/ncPdsyPrhrgJ
13 years ago (2012-11-27 21:13:39 UTC) #27
danakj
On Tue, Nov 27, 2012 at 4:01 PM, <reed@google.com> wrote: > void LayerImpl::setFilter(SkImageFilter* filter); > ...
13 years ago (2012-11-27 21:17:15 UTC) #28
bsalomon
On 2012/11/27 21:13:39, danakj wrote: > For reference, here is the chromium-dev thread about why ...
13 years ago (2012-11-27 21:24:54 UTC) #29
danakj
On 2012/11/27 21:24:54, bsalomon wrote: > On 2012/11/27 21:13:39, danakj wrote: > > For reference, ...
13 years ago (2012-11-27 21:31:57 UTC) #30
reed1
Every SkPaint method for ref'able objects returns a raw pointer, so forbidding raw ptrs in ...
13 years ago (2012-11-27 21:36:34 UTC) #31
reed1
just a note: SkAutoTUnref never appears as part of Skia's public API. This is by ...
13 years ago (2012-11-27 21:40:11 UTC) #32
bsalomon
On 2012/11/27 21:31:57, danakj wrote: > On 2012/11/27 21:24:54, bsalomon wrote: > > On 2012/11/27 ...
13 years ago (2012-11-27 21:43:45 UTC) #33
danakj
On 2012/11/27 21:36:34, reed1 wrote: > Every SkPaint method for ref'able objects returns a raw ...
13 years ago (2012-11-27 21:43:47 UTC) #34
bungeman
Much of this may already have been said, but here are my notes that I've ...
13 years ago (2012-11-27 21:44:26 UTC) #35
danakj
On 2012/11/27 21:43:45, bsalomon wrote: > Not arguing the WK vs Skia ref conventions as ...
13 years ago (2012-11-27 21:48:10 UTC) #36
bsalomon
On 2012/11/27 21:48:10, danakj wrote: > On 2012/11/27 21:43:45, bsalomon wrote: > > Not arguing ...
13 years ago (2012-11-27 21:51:07 UTC) #37
danakj
On Tue, Nov 27, 2012 at 4:51 PM, <bsalomon@google.com> wrote: > On 2012/11/27 21:48:10, danakj ...
13 years ago (2012-11-27 21:58:18 UTC) #38
TomH
13 years ago (2012-11-28 09:15:05 UTC) #39
On 2012/11/27 21:58:18, danakj wrote:
> Right, which is the whole thing I'm trying to avoid. I'd like
> refcounting for SkImageFilter* to be implicit and decided by scope. If
> we have to type it, then it's easy to mess up.
> 
> Mike: I didn't realize that SkAutoTUnref is not a public class. I
> guess I'd want to make it one. I do feel like the internals of Skia
> would benefit from not having to ever type ref() and unref(), but at
> the moment I'm really just trying to have a class that wraps pointers
> coming out of the public API. senorblanco@ suggested this class since
> it's what Skia uses internally, and I think that makes a lot of sense.
> Suddenly it makes us examine how ref-counting happens internally too,
> since this is used there.
> 
> We could hash out what Skia should have available/desired patterns
> internally, if you like, but maybe we can move forward for external
> use too.
> 
> - Maybe it would make sense to have a subclass of SkAutoTUnref that is
> for external use, and adds the operator=, copy-constructor, and drops
> the operator T*.
> - Personally, I think it would be nice if the Skia public API migrated
> to passing out this class instead of raw pointers. That way call sites
> don't have to think about (and maybe mess up) doing ref() explicitly
> before they hold onto the pointer/stick it into this class.


I'd like to take the opposite approach:
  Keep SkAutoTUnref private.
  Acknowledge that the Skia <-> Chrome interface is a transition point between
different projects, and so people need to be explicit about ownership. Accept
the Skia design decision *not* to have wrapped pointers coming out of the public
API.
  Find an owner to *fix* the bad code in Skia PDF so that well-intentioned
Chrome project members don't keep thinking it's how things should be done.

I volunteer to do this last when I'm back on the Skia team, but that's 10 months
away, and it's been festering too long - this seems to crop up every 6 months. I
don't know if I can justify carving out time from my current assignment within
the next month.

Junction independent projects with the simplest semantics possible, rather than
forcing complex semantics in one project to spread into all the others.

Tom
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b