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

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

Issue 69343005: Added preliminary support for tile rasterization with Ganesh (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reveman's comments. 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "cc/resources/gpu_rasterizer.h"
6
7 #include "base/logging.h"
8 #include "cc/output/context_provider.h"
9 #include "cc/resources/resource_format.h"
10 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
11 #include "third_party/skia/include/core/SkCanvas.h"
12 #include "third_party/skia/include/gpu/GrContext.h"
13 #include "third_party/skia/include/gpu/SkGpuDevice.h"
14 #include "ui/gfx/size_conversions.h"
15
16 namespace cc {
17
18 namespace {
19
20 GrPixelConfig toGrFormat(ResourceFormat format) {
21 switch (format) {
22 case RGBA_8888:
23 return kRGBA_8888_GrPixelConfig;
24 case BGRA_8888:
25 return kBGRA_8888_GrPixelConfig;
26 case RGBA_4444:
27 return kRGBA_4444_GrPixelConfig;
28 default:
29 break; // If you break here, you're gonna have a bad time.
30 }
31 DCHECK(false) << "Unsupported resource format.";
32 return kSkia8888_GrPixelConfig;
33 }
34
35 } // namespace
36
37 GpuRasterizer::RasterTask::RasterTask(
38 Tile* tile, scoped_ptr<ResourcePool::Resource> resource)
39 : tile_(tile), resource_(resource.Pass()) {
40 }
41
42 GpuRasterizer::RasterTask::~RasterTask() {
43 }
44
45 scoped_ptr<GpuRasterizer> GpuRasterizer::Create(
46 ContextProvider* context_provider,
47 ResourceProvider* resource_provider) {
48 return make_scoped_ptr(
49 new GpuRasterizer(context_provider, resource_provider));
50 }
51
52 GpuRasterizer::GpuRasterizer(
53 ContextProvider* context_provider,
54 ResourceProvider* resource_provider)
55 : client_(NULL),
56 context_provider_(context_provider),
57 resource_provider_(resource_provider) {
58 DCHECK(context_provider_->Context3d());
59 DCHECK(context_provider_->GrContext());
60 }
61
62 GpuRasterizer::~GpuRasterizer() {
63 }
64
65 void GpuRasterizer::SetClient(GpuRasterizerClient* client) {
66 client_ = client;
67 }
68
69 void GpuRasterizer::PushRasterTask(
70 Tile* tile, scoped_ptr<ResourcePool::Resource> resource) {
71 raster_tasks_.push_back(new RasterTask(tile, resource.Pass()));
72 }
73
74 void GpuRasterizer::FlushRasterTasks(
75 RenderingStatsInstrumentation* rendering_stats_instrumentation) {
76 TRACE_EVENT0("cc", "GpuRasterizer::Rasterize");
77
78 if (raster_tasks_.empty())
79 return;
80
81 blink::WebGraphicsContext3D* context = context_provider_->Context3d();
82 GrContext* gr_context = context_provider_->GrContext();
83
84 context->makeContextCurrent();
85 gr_context->resetContext();
86 for (RasterTaskVector::iterator it = raster_tasks_.begin();
87 it != raster_tasks_.end(); ++it) {
88 RasterTask* task = *it;
89 Tile* tile = task->tile_;
90 ManagedTileState& mts = tile->managed_state();
91 DCHECK(mts.raster_mode == GPU_RASTER_MODE);
92 DCHECK_NE(task->resource_->id(), 0u);
93 {
94 ResourceProvider::ScopedWriteLockGL lock(
95 resource_provider_, task->resource_->id());
96
97 DCHECK_NE(lock.texture_id(), 0u);
98 GrBackendTextureDesc desc;
99 desc.fFlags = kRenderTarget_GrBackendTextureFlag;
100 desc.fWidth = tile->size().width();
101 desc.fHeight = tile->size().height();
102 desc.fConfig = toGrFormat(lock.format());
103 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
104 desc.fTextureHandle = lock.texture_id();
105 skia::RefPtr<GrTexture> texture =
106 skia::AdoptRef(gr_context->wrapBackendTexture(desc));
107 skia::RefPtr<SkGpuDevice> device =
108 skia::AdoptRef(SkGpuDevice::Create(texture.get()));
109 CHECK(device);
110 skia::RefPtr<SkCanvas> canvas =
111 skia::AdoptRef(new SkCanvas(device.get()));
112
113 if (tile->opaque_rect().IsEmpty())
114 canvas->clear(SK_ColorTRANSPARENT);
115
116 tile->picture_pile_->RasterDirect(
117 canvas.get(), tile->content_rect_, tile->contents_scale_,
118 rendering_stats_instrumentation);
119 }
120
121 if (client_)
122 client_->OnGpuRasterTaskCompleted(tile, task->resource_.Pass(), false);
123 }
124 gr_context->flush();
125 raster_tasks_.clear();
126 }
127
128 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698