Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(701)

Side by Side Diff: src/gpu/SkGrPixelRef.cpp

Issue 112603003: Reverting r12665 & r12666 (Remove duplicate impl for SkImageInfo flattening) due to Chromium/Blink … (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/gpu/SkGr.cpp ('k') | src/image/SkDataPixelRef.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2010 Google Inc. 3 * Copyright 2010 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 10
11 #include "SkGrPixelRef.h" 11 #include "SkGrPixelRef.h"
12 #include "GrContext.h" 12 #include "GrContext.h"
13 #include "GrTexture.h" 13 #include "GrTexture.h"
14 #include "SkGr.h" 14 #include "SkGr.h"
15 #include "SkRect.h" 15 #include "SkRect.h"
16 16
17 // since we call lockPixels recursively on fBitmap, we need a distinct mutex, 17 // since we call lockPixels recursively on fBitmap, we need a distinct mutex,
18 // to avoid deadlock with the default one provided by SkPixelRef. 18 // to avoid deadlock with the default one provided by SkPixelRef.
19 SK_DECLARE_STATIC_MUTEX(gROLockPixelsPixelRefMutex); 19 SK_DECLARE_STATIC_MUTEX(gROLockPixelsPixelRefMutex);
20 20
21 SkROLockPixelsPixelRef::SkROLockPixelsPixelRef(const SkImageInfo& info) 21 SkROLockPixelsPixelRef::SkROLockPixelsPixelRef() : INHERITED(&gROLockPixelsPixel RefMutex) {
22 : INHERITED(info, &gROLockPixelsPixelRefMutex) {
23 } 22 }
24 23
25 SkROLockPixelsPixelRef::~SkROLockPixelsPixelRef() { 24 SkROLockPixelsPixelRef::~SkROLockPixelsPixelRef() {
26 } 25 }
27 26
28 bool SkROLockPixelsPixelRef::onNewLockPixels(LockRec* rec) { 27 void* SkROLockPixelsPixelRef::onLockPixels(SkColorTable** ctable) {
28 if (ctable) {
29 *ctable = NULL;
30 }
29 fBitmap.reset(); 31 fBitmap.reset();
30 // SkDebugf("---------- calling readpixels in support of lockpixels\n"); 32 // SkDebugf("---------- calling readpixels in support of lockpixels\n");
31 if (!this->onReadPixels(&fBitmap, NULL)) { 33 if (!this->onReadPixels(&fBitmap, NULL)) {
32 SkDebugf("SkROLockPixelsPixelRef::onLockPixels failed!\n"); 34 SkDebugf("SkROLockPixelsPixelRef::onLockPixels failed!\n");
33 return false; 35 return NULL;
34 } 36 }
35 fBitmap.lockPixels(); 37 fBitmap.lockPixels();
36 if (NULL == fBitmap.getPixels()) { 38 return fBitmap.getPixels();
37 return false;
38 }
39
40 rec->fPixels = fBitmap.getPixels();
41 rec->fColorTable = NULL;
42 rec->fRowBytes = fBitmap.rowBytes();
43 return true;
44 } 39 }
45 40
46 void SkROLockPixelsPixelRef::onUnlockPixels() { 41 void SkROLockPixelsPixelRef::onUnlockPixels() {
47 fBitmap.unlockPixels(); 42 fBitmap.unlockPixels();
48 } 43 }
49 44
50 bool SkROLockPixelsPixelRef::onLockPixelsAreWritable() const { 45 bool SkROLockPixelsPixelRef::onLockPixelsAreWritable() const {
51 return false; 46 return false;
52 } 47 }
53 48
(...skipping 20 matching lines...) Expand all
74 pointStorage.set(subset->x(), subset->y()); 69 pointStorage.set(subset->x(), subset->y());
75 topLeft = &pointStorage; 70 topLeft = &pointStorage;
76 } else { 71 } else {
77 desc.fWidth = texture->width(); 72 desc.fWidth = texture->width();
78 desc.fHeight = texture->height(); 73 desc.fHeight = texture->height();
79 topLeft = NULL; 74 topLeft = NULL;
80 } 75 }
81 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; 76 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
82 desc.fConfig = SkBitmapConfig2GrPixelConfig(dstConfig); 77 desc.fConfig = SkBitmapConfig2GrPixelConfig(dstConfig);
83 78
84 SkImageInfo info;
85 if (!GrPixelConfig2ColorType(desc.fConfig, &info.fColorType)) {
86 return NULL;
87 }
88 info.fWidth = desc.fWidth;
89 info.fHeight = desc.fHeight;
90 info.fAlphaType = kPremul_SkAlphaType;
91
92 GrTexture* dst = context->createUncachedTexture(desc, NULL, 0); 79 GrTexture* dst = context->createUncachedTexture(desc, NULL, 0);
93 if (NULL == dst) { 80 if (NULL == dst) {
94 return NULL; 81 return NULL;
95 } 82 }
96 83
97 context->copyTexture(texture, dst->asRenderTarget(), topLeft); 84 context->copyTexture(texture, dst->asRenderTarget(), topLeft);
98 85
99 // TODO: figure out if this is responsible for Chrome canvas errors 86 // TODO: figure out if this is responsible for Chrome canvas errors
100 #if 0 87 #if 0
101 // The render texture we have created (to perform the copy) isn't fully 88 // The render texture we have created (to perform the copy) isn't fully
102 // functional (since it doesn't have a stencil buffer). Release it here 89 // functional (since it doesn't have a stencil buffer). Release it here
103 // so the caller doesn't try to render to it. 90 // so the caller doesn't try to render to it.
104 // TODO: we can undo this release when dynamic stencil buffer attach/ 91 // TODO: we can undo this release when dynamic stencil buffer attach/
105 // detach has been implemented 92 // detach has been implemented
106 dst->releaseRenderTarget(); 93 dst->releaseRenderTarget();
107 #endif 94 #endif
108 95
109 SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, dst)); 96 SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (dst));
110 SkSafeUnref(dst); 97 SkSafeUnref(dst);
111 return pixelRef; 98 return pixelRef;
112 } 99 }
113 100
114 /////////////////////////////////////////////////////////////////////////////// 101 ///////////////////////////////////////////////////////////////////////////////
115 102
116 SkGrPixelRef::SkGrPixelRef(const SkImageInfo& info, GrSurface* surface, 103 SkGrPixelRef::SkGrPixelRef(GrSurface* surface, bool transferCacheLock) {
117 bool transferCacheLock)
118 : INHERITED(info)
119 {
120 // TODO: figure out if this is responsible for Chrome canvas errors 104 // TODO: figure out if this is responsible for Chrome canvas errors
121 #if 0 105 #if 0
122 // The GrTexture has a ref to the GrRenderTarget but not vice versa. 106 // The GrTexture has a ref to the GrRenderTarget but not vice versa.
123 // If the GrTexture exists take a ref to that (rather than the render 107 // If the GrTexture exists take a ref to that (rather than the render
124 // target) 108 // target)
125 fSurface = surface->asTexture(); 109 fSurface = surface->asTexture();
126 #else 110 #else
127 fSurface = NULL; 111 fSurface = NULL;
128 #endif 112 #endif
129 if (NULL == fSurface) { 113 if (NULL == fSurface) {
130 fSurface = surface; 114 fSurface = surface;
131 } 115 }
132 fUnlock = transferCacheLock; 116 fUnlock = transferCacheLock;
133 SkSafeRef(surface); 117 SkSafeRef(surface);
134 } 118 }
135 119
120 SkGrPixelRef::SkGrPixelRef(const SkImageInfo&, GrSurface* surface, bool transfer CacheLock) {
121 // TODO: figure out if this is responsible for Chrome canvas errors
122 #if 0
123 // The GrTexture has a ref to the GrRenderTarget but not vice versa.
124 // If the GrTexture exists take a ref to that (rather than the render
125 // target)
126 fSurface = surface->asTexture();
127 #else
128 fSurface = NULL;
129 #endif
130 if (NULL == fSurface) {
131 fSurface = surface;
132 }
133 fUnlock = transferCacheLock;
134 SkSafeRef(surface);
135 }
136
136 SkGrPixelRef::~SkGrPixelRef() { 137 SkGrPixelRef::~SkGrPixelRef() {
137 if (fUnlock) { 138 if (fUnlock) {
138 GrContext* context = fSurface->getContext(); 139 GrContext* context = fSurface->getContext();
139 GrTexture* texture = fSurface->asTexture(); 140 GrTexture* texture = fSurface->asTexture();
140 if (NULL != context && NULL != texture) { 141 if (NULL != context && NULL != texture) {
141 context->unlockScratchTexture(texture); 142 context->unlockScratchTexture(texture);
142 } 143 }
143 } 144 }
144 SkSafeUnref(fSurface); 145 SkSafeUnref(fSurface);
145 } 146 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 if (!dst->allocPixels()) { 187 if (!dst->allocPixels()) {
187 SkDebugf("SkGrPixelRef::onReadPixels failed to alloc bitmap for result!\ n"); 188 SkDebugf("SkGrPixelRef::onReadPixels failed to alloc bitmap for result!\ n");
188 return false; 189 return false;
189 } 190 }
190 SkAutoLockPixels al(*dst); 191 SkAutoLockPixels al(*dst);
191 void* buffer = dst->getPixels(); 192 void* buffer = dst->getPixels();
192 return fSurface->readPixels(left, top, width, height, 193 return fSurface->readPixels(left, top, width, height,
193 kSkia8888_GrPixelConfig, 194 kSkia8888_GrPixelConfig,
194 buffer, dst->rowBytes()); 195 buffer, dst->rowBytes());
195 } 196 }
OLDNEW
« no previous file with comments | « src/gpu/SkGr.cpp ('k') | src/image/SkDataPixelRef.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698