| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "base/debug/trace_event.h" | 5 #include "base/debug/trace_event.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "skia/ext/analysis_canvas.h" | 7 #include "skia/ext/analysis_canvas.h" |
| 8 #include "third_party/skia/include/core/SkDraw.h" | 8 #include "third_party/skia/include/core/SkDraw.h" |
| 9 #include "third_party/skia/include/core/SkRRect.h" | 9 #include "third_party/skia/include/core/SkRRect.h" |
| 10 #include "third_party/skia/include/core/SkShader.h" | 10 #include "third_party/skia/include/core/SkShader.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 if (is_forced_not_solid_) | 88 if (is_forced_not_solid_) |
| 89 is_solid_color_ = false; | 89 is_solid_color_ = false; |
| 90 } | 90 } |
| 91 | 91 |
| 92 void AnalysisCanvas::SetForceNotTransparent(bool flag) { | 92 void AnalysisCanvas::SetForceNotTransparent(bool flag) { |
| 93 is_forced_not_transparent_ = flag; | 93 is_forced_not_transparent_ = flag; |
| 94 if (is_forced_not_transparent_) | 94 if (is_forced_not_transparent_) |
| 95 is_transparent_ = false; | 95 is_transparent_ = false; |
| 96 } | 96 } |
| 97 | 97 |
| 98 void AnalysisCanvas::drawPaint(const SkPaint& paint) { | 98 void AnalysisCanvas::onDrawPaint(const SkPaint& paint) { |
| 99 SkRect rect; | 99 SkRect rect; |
| 100 getClipBounds(&rect); | 100 getClipBounds(&rect); |
| 101 drawRect(rect, paint); | 101 drawRect(rect, paint); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void AnalysisCanvas::drawPoints(SkCanvas::PointMode mode, | 104 void AnalysisCanvas::onDrawPoints(SkCanvas::PointMode mode, |
| 105 size_t count, | 105 size_t count, |
| 106 const SkPoint points[], | 106 const SkPoint points[], |
| 107 const SkPaint& paint) { | 107 const SkPaint& paint) { |
| 108 is_solid_color_ = false; | 108 is_solid_color_ = false; |
| 109 is_transparent_ = false; | 109 is_transparent_ = false; |
| 110 ++draw_op_count_; | 110 ++draw_op_count_; |
| 111 } | 111 } |
| 112 | 112 |
| 113 void AnalysisCanvas::drawRect(const SkRect& rect, const SkPaint& paint) { | 113 void AnalysisCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) { |
| 114 // This recreates the early-exit logic in SkCanvas.cpp. | 114 // This recreates the early-exit logic in SkCanvas.cpp. |
| 115 SkRect scratch; | 115 SkRect scratch; |
| 116 if (paint.canComputeFastBounds() && | 116 if (paint.canComputeFastBounds() && |
| 117 quickReject(paint.computeFastBounds(rect, &scratch))) { | 117 quickReject(paint.computeFastBounds(rect, &scratch))) { |
| 118 return; | 118 return; |
| 119 } | 119 } |
| 120 | 120 |
| 121 // An extra no-op check SkCanvas.cpp doesn't do. | 121 // An extra no-op check SkCanvas.cpp doesn't do. |
| 122 if (paint.nothingToDraw()) | 122 if (paint.nothingToDraw()) |
| 123 return; | 123 return; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 151 // - The quad is a full tile quad | 151 // - The quad is a full tile quad |
| 152 if (!is_forced_not_solid_ && IsSolidColorPaint(paint) && does_cover_canvas) { | 152 if (!is_forced_not_solid_ && IsSolidColorPaint(paint) && does_cover_canvas) { |
| 153 is_solid_color_ = true; | 153 is_solid_color_ = true; |
| 154 color_ = paint.getColor(); | 154 color_ = paint.getColor(); |
| 155 } else { | 155 } else { |
| 156 is_solid_color_ = false; | 156 is_solid_color_ = false; |
| 157 } | 157 } |
| 158 ++draw_op_count_; | 158 ++draw_op_count_; |
| 159 } | 159 } |
| 160 | 160 |
| 161 void AnalysisCanvas::drawOval(const SkRect& oval, const SkPaint& paint) { | 161 void AnalysisCanvas::onDrawOval(const SkRect& oval, const SkPaint& paint) { |
| 162 is_solid_color_ = false; | 162 is_solid_color_ = false; |
| 163 is_transparent_ = false; | 163 is_transparent_ = false; |
| 164 ++draw_op_count_; | 164 ++draw_op_count_; |
| 165 } | 165 } |
| 166 | 166 |
| 167 void AnalysisCanvas::drawRRect(const SkRRect& rr, const SkPaint& paint) { | 167 void AnalysisCanvas::onDrawRRect(const SkRRect& rr, const SkPaint& paint) { |
| 168 // This should add the SkRRect to an SkPath, and call | 168 // This should add the SkRRect to an SkPath, and call |
| 169 // drawPath, but since drawPath ignores the SkPath, just | 169 // drawPath, but since drawPath ignores the SkPath, just |
| 170 // do the same work here. | 170 // do the same work here. |
| 171 is_solid_color_ = false; | 171 is_solid_color_ = false; |
| 172 is_transparent_ = false; | 172 is_transparent_ = false; |
| 173 ++draw_op_count_; | 173 ++draw_op_count_; |
| 174 } | 174 } |
| 175 | 175 |
| 176 void AnalysisCanvas::drawPath(const SkPath& path, const SkPaint& paint) { | 176 void AnalysisCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) { |
| 177 is_solid_color_ = false; | 177 is_solid_color_ = false; |
| 178 is_transparent_ = false; | 178 is_transparent_ = false; |
| 179 ++draw_op_count_; | 179 ++draw_op_count_; |
| 180 } | 180 } |
| 181 | 181 |
| 182 void AnalysisCanvas::drawBitmap(const SkBitmap& bitmap, | 182 void AnalysisCanvas::onDrawBitmap(const SkBitmap& bitmap, |
| 183 SkScalar left, | 183 SkScalar left, |
| 184 SkScalar top, | 184 SkScalar top, |
| 185 const SkPaint*) { | 185 const SkPaint*) { |
| 186 is_solid_color_ = false; | 186 is_solid_color_ = false; |
| 187 is_transparent_ = false; | 187 is_transparent_ = false; |
| 188 ++draw_op_count_; | 188 ++draw_op_count_; |
| 189 } | 189 } |
| 190 | 190 |
| 191 void AnalysisCanvas::drawBitmapRectToRect(const SkBitmap&, | 191 void AnalysisCanvas::onDrawBitmapRect(const SkBitmap&, |
| 192 const SkRect* src, | 192 const SkRect* src, |
| 193 const SkRect& dst, | 193 const SkRect& dst, |
| 194 const SkPaint* paint, | 194 const SkPaint* paint, |
| 195 DrawBitmapRectFlags flags) { | 195 DrawBitmapRectFlags flags) { |
| 196 // Call drawRect to determine transparency, | 196 // Call drawRect to determine transparency, |
| 197 // but reset solid color to false. | 197 // but reset solid color to false. |
| 198 SkPaint tmpPaint; | 198 SkPaint tmpPaint; |
| 199 if (!paint) | 199 if (!paint) |
| 200 paint = &tmpPaint; | 200 paint = &tmpPaint; |
| 201 drawRect(dst, *paint); | 201 drawRect(dst, *paint); |
| 202 is_solid_color_ = false; | 202 is_solid_color_ = false; |
| 203 ++draw_op_count_; | 203 ++draw_op_count_; |
| 204 } | 204 } |
| 205 | 205 |
| 206 void AnalysisCanvas::drawBitmapNine(const SkBitmap& bitmap, | 206 void AnalysisCanvas::onDrawBitmapNine(const SkBitmap& bitmap, |
| 207 const SkIRect& center, | 207 const SkIRect& center, |
| 208 const SkRect& dst, | 208 const SkRect& dst, |
| 209 const SkPaint* paint) { | 209 const SkPaint* paint) { |
| 210 is_solid_color_ = false; | 210 is_solid_color_ = false; |
| 211 is_transparent_ = false; | 211 is_transparent_ = false; |
| 212 ++draw_op_count_; | 212 ++draw_op_count_; |
| 213 } | 213 } |
| 214 | 214 |
| 215 void AnalysisCanvas::drawSprite(const SkBitmap& bitmap, | 215 void AnalysisCanvas::onDrawSprite(const SkBitmap& bitmap, |
| 216 int left, | 216 int left, |
| 217 int top, | 217 int top, |
| 218 const SkPaint* paint) { | 218 const SkPaint* paint) { |
| 219 is_solid_color_ = false; | 219 is_solid_color_ = false; |
| 220 is_transparent_ = false; | 220 is_transparent_ = false; |
| 221 ++draw_op_count_; | 221 ++draw_op_count_; |
| 222 } | 222 } |
| 223 | 223 |
| 224 void AnalysisCanvas::onDrawText(const void* text, | 224 void AnalysisCanvas::onDrawText(const void* text, |
| 225 size_t len, | 225 size_t len, |
| 226 SkScalar x, | 226 SkScalar x, |
| 227 SkScalar y, | 227 SkScalar y, |
| 228 const SkPaint& paint) { | 228 const SkPaint& paint) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 } | 270 } |
| 271 | 271 |
| 272 void AnalysisCanvas::onDrawDRRect(const SkRRect& outer, | 272 void AnalysisCanvas::onDrawDRRect(const SkRRect& outer, |
| 273 const SkRRect& inner, | 273 const SkRRect& inner, |
| 274 const SkPaint& paint) { | 274 const SkPaint& paint) { |
| 275 is_solid_color_ = false; | 275 is_solid_color_ = false; |
| 276 is_transparent_ = false; | 276 is_transparent_ = false; |
| 277 ++draw_op_count_; | 277 ++draw_op_count_; |
| 278 } | 278 } |
| 279 | 279 |
| 280 void AnalysisCanvas::drawVertices(SkCanvas::VertexMode, | 280 void AnalysisCanvas::onDrawVertices(SkCanvas::VertexMode, |
| 281 int vertex_count, | 281 int vertex_count, |
| 282 const SkPoint verts[], | 282 const SkPoint verts[], |
| 283 const SkPoint texs[], | 283 const SkPoint texs[], |
| 284 const SkColor colors[], | 284 const SkColor colors[], |
| 285 SkXfermode* xmode, | 285 SkXfermode* xmode, |
| 286 const uint16_t indices[], | 286 const uint16_t indices[], |
| 287 int index_count, | 287 int index_count, |
| 288 const SkPaint& paint) { | 288 const SkPaint& paint) { |
| 289 is_solid_color_ = false; | 289 is_solid_color_ = false; |
| 290 is_transparent_ = false; | 290 is_transparent_ = false; |
| 291 ++draw_op_count_; | 291 ++draw_op_count_; |
| 292 } | 292 } |
| 293 | 293 |
| 294 // Needed for now, since SkCanvas requires a bitmap, even if it is not backed | 294 // Needed for now, since SkCanvas requires a bitmap, even if it is not backed |
| 295 // by any pixels | 295 // by any pixels |
| 296 static SkBitmap MakeEmptyBitmap(int width, int height) { | 296 static SkBitmap MakeEmptyBitmap(int width, int height) { |
| 297 SkBitmap bitmap; | 297 SkBitmap bitmap; |
| 298 bitmap.setInfo(SkImageInfo::MakeUnknown(width, height)); | 298 bitmap.setInfo(SkImageInfo::MakeUnknown(width, height)); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 force_not_transparent_stack_level_ = kNoLayer; | 445 force_not_transparent_stack_level_ = kNoLayer; |
| 446 } | 446 } |
| 447 } | 447 } |
| 448 | 448 |
| 449 INHERITED::willRestore(); | 449 INHERITED::willRestore(); |
| 450 } | 450 } |
| 451 | 451 |
| 452 } // namespace skia | 452 } // namespace skia |
| 453 | 453 |
| 454 | 454 |
| OLD | NEW |