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

Side by Side Diff: cc/resources/raster_worker_pool.cc

Issue 21159007: cc: Adding support for RGBA_4444 tile textures (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review feedback Created 7 years, 3 months 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/resources/raster_worker_pool.h" 5 #include "cc/resources/raster_worker_pool.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "cc/debug/benchmark_instrumentation.h" 10 #include "cc/debug/benchmark_instrumentation.h"
11 #include "cc/debug/devtools_instrumentation.h" 11 #include "cc/debug/devtools_instrumentation.h"
12 #include "cc/debug/traced_value.h" 12 #include "cc/debug/traced_value.h"
13 #include "cc/resources/picture_pile_impl.h" 13 #include "cc/resources/picture_pile_impl.h"
14 #include "skia/ext/lazy_pixel_ref.h" 14 #include "skia/ext/lazy_pixel_ref.h"
15 #include "skia/ext/paint_simplifier.h" 15 #include "skia/ext/paint_simplifier.h"
16 #include "third_party/skia/include/core/SkBitmap.h"
16 17
17 namespace cc { 18 namespace cc {
18 19
19 namespace { 20 namespace {
20 21
22 // Subclass of Allocator that takes a suitably allocated pointer and uses
23 // it as the pixel memory for the bitmap.
24 class IdentityAllocator : public SkBitmap::Allocator {
25 public:
26 explicit IdentityAllocator(void* buffer) : buffer_(buffer) {}
27 virtual bool allocPixelRef(SkBitmap* dst, SkColorTable*) OVERRIDE {
28 dst->setPixels(buffer_);
29 return true;
30 }
31 private:
32 void* buffer_;
33 };
34
21 // Flag to indicate whether we should try and detect that 35 // Flag to indicate whether we should try and detect that
22 // a tile is of solid color. 36 // a tile is of solid color.
23 const bool kUseColorEstimator = true; 37 const bool kUseColorEstimator = true;
24 38
25 class DisableLCDTextFilter : public SkDrawFilter { 39 class DisableLCDTextFilter : public SkDrawFilter {
26 public: 40 public:
27 // SkDrawFilter interface. 41 // SkDrawFilter interface.
28 virtual bool filter(SkPaint* paint, SkDrawFilter::Type type) OVERRIDE { 42 virtual bool filter(SkPaint* paint, SkDrawFilter::Type type) OVERRIDE {
29 if (type != SkDrawFilter::kText_Type) 43 if (type != SkDrawFilter::kText_Type)
30 return true; 44 return true;
31 45
32 paint->setLCDRenderText(false); 46 paint->setLCDRenderText(false);
33 return true; 47 return true;
34 } 48 }
35 }; 49 };
36 50
51 SkBitmap::Config SkBitmapConfigFromFormat(ResourceFormat format) {
52 switch (format) {
53 case RGBA_4444:
54 return SkBitmap::kARGB_4444_Config;
55 case RGBA_8888:
56 case BGRA_8888:
57 return SkBitmap::kARGB_8888_Config;
58 case LUMINANCE_8:
59 NOTREACHED();
60 break;
61 }
62 NOTREACHED();
63 return SkBitmap::kARGB_8888_Config;
64 }
65
66 void ChangeBitmapConfigIfPossible(const SkBitmap& bitmap,
reveman 2013/09/14 00:58:39 IfRequired? IfNeeded?
kaanb 2013/09/16 07:22:25 Done.
67 void* buffer,
68 ResourceFormat format) {
69 TRACE_EVENT0("cc", "ChangeBitmapConfigIfPossible");
70 if (bitmap.getConfig() != SkBitmapConfigFromFormat(format)) {
reveman 2013/09/14 00:58:39 nit: store SkBitmapConfigFromFormat result in temp
kaanb 2013/09/16 07:22:25 Done.
71 SkBitmap bitmap_dest;
72 IdentityAllocator allocator(buffer);
73 bitmap.copyTo(&bitmap_dest, SkBitmapConfigFromFormat(format), &allocator);
74 }
75 }
76
37 class RasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask { 77 class RasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask {
38 public: 78 public:
39 RasterWorkerPoolTaskImpl(const Resource* resource, 79 RasterWorkerPoolTaskImpl(const Resource* resource,
40 PicturePileImpl* picture_pile, 80 PicturePileImpl* picture_pile,
41 gfx::Rect content_rect, 81 gfx::Rect content_rect,
42 float contents_scale, 82 float contents_scale,
43 RasterMode raster_mode, 83 RasterMode raster_mode,
44 bool is_tile_in_pending_tree_now_bin, 84 bool is_tile_in_pending_tree_now_bin,
45 TileResolution tile_resolution, 85 TileResolution tile_resolution,
46 int layer_id, 86 int layer_id,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 122
83 // Record the solid color prediction. 123 // Record the solid color prediction.
84 UMA_HISTOGRAM_BOOLEAN("Renderer4.SolidColorTilesAnalyzed", 124 UMA_HISTOGRAM_BOOLEAN("Renderer4.SolidColorTilesAnalyzed",
85 analysis_.is_solid_color); 125 analysis_.is_solid_color);
86 rendering_stats_->AddAnalysisResult(duration, analysis_.is_solid_color); 126 rendering_stats_->AddAnalysisResult(duration, analysis_.is_solid_color);
87 127
88 // Clear the flag if we're not using the estimator. 128 // Clear the flag if we're not using the estimator.
89 analysis_.is_solid_color &= kUseColorEstimator; 129 analysis_.is_solid_color &= kUseColorEstimator;
90 } 130 }
91 131
92 bool RunRasterOnThread(SkBaseDevice* device, unsigned thread_index) { 132 bool RunRasterOnThread(unsigned thread_index,
133 void* buffer,
134 gfx::Size size,
135 int stride) {
93 TRACE_EVENT2( 136 TRACE_EVENT2(
94 benchmark_instrumentation::kCategory, 137 benchmark_instrumentation::kCategory,
95 benchmark_instrumentation::kRunRasterOnThread, 138 benchmark_instrumentation::kRunRasterOnThread,
96 benchmark_instrumentation::kData, 139 benchmark_instrumentation::kData,
97 TracedValue::FromValue(DataAsValue().release()), 140 TracedValue::FromValue(DataAsValue().release()),
98 "raster_mode", 141 "raster_mode",
99 TracedValue::FromValue(RasterModeAsValue(raster_mode_).release())); 142 TracedValue::FromValue(RasterModeAsValue(raster_mode_).release()));
100 143
101 devtools_instrumentation::ScopedLayerTask raster_task( 144 devtools_instrumentation::ScopedLayerTask raster_task(
102 devtools_instrumentation::kRasterTask, layer_id_); 145 devtools_instrumentation::kRasterTask, layer_id_);
103 146
104 DCHECK(picture_pile_.get()); 147 DCHECK(picture_pile_.get());
105 DCHECK(device); 148 DCHECK(buffer);
106 149
107 if (analysis_.is_solid_color) 150 if (analysis_.is_solid_color)
108 return false; 151 return false;
109 152
110 PicturePileImpl* picture_clone = 153 PicturePileImpl* picture_clone =
111 picture_pile_->GetCloneForDrawingOnThread(thread_index); 154 picture_pile_->GetCloneForDrawingOnThread(thread_index);
112 155
113 SkCanvas canvas(device); 156 SkBitmap bitmap;
157 switch (resource()->format()) {
158 case RGBA_4444:
159 // Use the default stride if we will eventually convert this
160 // bitmap to 4444.
161 bitmap.setConfig(SkBitmap::kARGB_8888_Config,
162 size.width(),
163 size.height());
164 bitmap.allocPixels();
165 break;
166 case RGBA_8888:
167 case BGRA_8888:
168 bitmap.setConfig(SkBitmap::kARGB_8888_Config,
169 size.width(),
170 size.height(),
171 stride);
172 bitmap.setPixels(buffer);
173 break;
174 case LUMINANCE_8:
175 NOTREACHED();
176 break;
177 }
114 178
179 SkBitmapDevice device(bitmap);
180 SkCanvas canvas(&device);
115 skia::RefPtr<SkDrawFilter> draw_filter; 181 skia::RefPtr<SkDrawFilter> draw_filter;
116 switch (raster_mode_) { 182 switch (raster_mode_) {
117 case LOW_QUALITY_RASTER_MODE: 183 case LOW_QUALITY_RASTER_MODE:
118 draw_filter = skia::AdoptRef(new skia::PaintSimplifier); 184 draw_filter = skia::AdoptRef(new skia::PaintSimplifier);
119 break; 185 break;
120 case HIGH_QUALITY_NO_LCD_RASTER_MODE: 186 case HIGH_QUALITY_NO_LCD_RASTER_MODE:
121 draw_filter = skia::AdoptRef(new DisableLCDTextFilter); 187 draw_filter = skia::AdoptRef(new DisableLCDTextFilter);
122 break; 188 break;
123 case HIGH_QUALITY_RASTER_MODE: 189 case HIGH_QUALITY_RASTER_MODE:
124 break; 190 break;
(...skipping 17 matching lines...) Expand all
142 HISTOGRAM_CUSTOM_COUNTS( 208 HISTOGRAM_CUSTOM_COUNTS(
143 "Renderer4.PictureRasterTimeUS", 209 "Renderer4.PictureRasterTimeUS",
144 raster_stats.total_rasterize_time.InMicroseconds(), 210 raster_stats.total_rasterize_time.InMicroseconds(),
145 0, 211 0,
146 100000, 212 100000,
147 100); 213 100);
148 } else { 214 } else {
149 picture_clone->RasterToBitmap( 215 picture_clone->RasterToBitmap(
150 &canvas, content_rect_, contents_scale_, NULL); 216 &canvas, content_rect_, contents_scale_, NULL);
151 } 217 }
218
219 ChangeBitmapConfigIfPossible(bitmap, buffer, resource()->format());
220
152 return true; 221 return true;
153 } 222 }
154 223
155 // Overridden from internal::RasterWorkerPoolTask: 224 // Overridden from internal::RasterWorkerPoolTask:
156 virtual bool RunOnWorkerThread(SkBaseDevice* device, unsigned thread_index) 225 virtual bool RunOnWorkerThread(unsigned thread_index,
226 void* buffer,
227 gfx::Size size,
228 int stride)
157 OVERRIDE { 229 OVERRIDE {
158 RunAnalysisOnThread(thread_index); 230 RunAnalysisOnThread(thread_index);
159 return RunRasterOnThread(device, thread_index); 231 return RunRasterOnThread(thread_index, buffer, size, stride);
160 } 232 }
161 virtual void CompleteOnOriginThread() OVERRIDE { 233 virtual void CompleteOnOriginThread() OVERRIDE {
162 reply_.Run(analysis_, !HasFinishedRunning() || WasCanceled()); 234 reply_.Run(analysis_, !HasFinishedRunning() || WasCanceled());
163 } 235 }
164 236
165 protected: 237 protected:
166 virtual ~RasterWorkerPoolTaskImpl() {} 238 virtual ~RasterWorkerPoolTaskImpl() {}
167 239
168 private: 240 private:
169 scoped_ptr<base::Value> DataAsValue() const { 241 scoped_ptr<base::Value> DataAsValue() const {
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 606
535 internal::GraphNode* decode_node = CreateGraphNodeForTask( 607 internal::GraphNode* decode_node = CreateGraphNodeForTask(
536 decode_task, priority, graph); 608 decode_task, priority, graph);
537 decode_node->add_dependent(raster_node); 609 decode_node->add_dependent(raster_node);
538 } 610 }
539 611
540 return raster_node; 612 return raster_node;
541 } 613 }
542 614
543 } // namespace cc 615 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698